akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
l = [i for i in range(1,n+1)]
h = list(map(int,input().split()))
d_h = dict(zip(l,h))
d_r = {}
for i in range(1,n+1):
    d_r[i] = []
for i in range(m):
    x,y = map(int,input().split())
    d_r[x].append(y)
    d_r[y].append(x)
count = 0
for i in d_r.keys():
    key_height = d_h[i]
    if len(d_r[i]) == 0:
        count += 1
    else:
        flag = 0
        for j in d_r[i]:
            if d_h[j] < key_height:
                continue
            else:
                flag = 1
                break
        if flag == 0:
            count += 1
print(count)

    
    

Measured memory_bytes: 50856
#include <bits/stdc++.h>
#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
 
using namespace std;
using namespace atcoder;
using ll = long long;
 
int main() {
	int n, q;
	cin >> n >> q;
	dsu d(n);
	rep(i, q) {
		bool t;
		int a, b;
		cin >> t >> a >> b;
		if (t) {
			bool s;
			s = d.same(a, b);
			cout << (s ? 1 : 0) << endl;
		}
		else {
			d.merge(a, b);
		}
	}
	return 0;
}

Measured memory_bytes: 3892
#include <iostream>
#include <algorithm>

using namespace std;

int l1_dist(pair<int, int> a, pair<int, int> b){
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int main(){
    int H, W, D;
    cin >> H >> W >> D;
    pair<int, int> loc[H * W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int num;
            cin >> num;
            num--;
            loc[num] = {i, j};
        }
    }    
    int Q;
    cin >> Q;
    int L[Q], R[Q];
    for(int i=0; i<Q; i++){
        cin >> L[i] >> R[i];
        L[i]--; R[i]--;
    }
    int dist[D][H * W / D + 10];
    for(int i=0; i<D; i++){
        for(int j=0; i + j * D < H * W; j++){
            if(j == 0) dist[i][j] = 0;
            else{
                dist[i][j] = dist[i][j-1] + l1_dist(loc[i + j * D], loc[i + (j - 1) * D]);
            }
        }
    }
    
    for(int i=0; i<Q; i++){
        int offset = L[i] % D;
        cout << dist[offset][R[i]/D] - dist[offset][L[i]/D] << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long a,b,c=0,k,d=0,i,n,j,temp,p,m,ex1,ex2,ex3,ex4,x,y;
	    string s;
	    cin>>s;
	    
	    for(i=0;i<s.length();i++)
	    {
	        if(i%2==0)
	        {
	           if(s[i]=='p')
	                c--;
	          
	        }
	        else 
	        {
	           if(s[i]=='g')
	                c++; 
	        }
	    }
	    
	    cout<<(c);
    }
    
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(void)
{
	int s,h,m;
 
	scanf("%d",&s);
 
	h=s/3600;
	m=(s%3600)/60;
	s=(s%3600)%60;
 
	printf("%d:%d:%d\n",h,m,s);
 
	return 0;
}

Measured memory_bytes: 592
import { readFileSync } from 'fs'

function main(input: string) {
  const list = input.trim().split('')

  const result = list.every(char =>
    list.filter(c => c === char).length === 2
  )

  console.log(result ? 'Yes' : 'No')
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int x[100000],y[100000],z[100000];
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n-1){
		cin>>x[i];
		if(i)ans+=min(x[i],x[i-1]);
		else ans+=x[i];
	}
	ans+=x[n-2];
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,x,ans=0;
    cin >> n >> x;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for (ll i=0;i<n;i++){
        if (x>=a[i]){
            ans++;
        }
        x-=a[i];
    }
    if (x>0)ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2010,maxm=maxn<<1;
#define mod 924844033
int vis[maxn][2],ed[maxm];
int tot;LL f[maxm][maxn][2],fac[maxn];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		for(int j=0;j<=1;++j){
			if(!vis[i][j]){
				int len=0;
				for(int x=i,y=j;x<=n;x+=k,y^=1){
					vis[x][y]=1;len++;
				}
				ed[tot+=len]=1;
			}
		}
	}
	f[1][0][0]=1;
	for(int i=1;i<tot;++i){
		for(int j=0;j<=n;++j){
			f[i+1][j][0]=(f[i][j][1]+f[i][j][0])%mod;
			if(!ed[i])f[i+1][j+1][1]=f[i][j][0];
		}	
	}
	fac[0]=1;
	for(LL i=1;i<=n;++i)fac[i]=fac[i-1]*i%mod;
	LL ans=fac[n];
	for(LL i=1,j=-1;i<=n;++i,j=-j){
/**/	ans=(ans+mod+j*fac[n-i]*((f[tot][i][0]+f[tot][i][1])%mod)%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 125952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {
    int n;
    Point[] rs, bs;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        rs = new Point[n];
        bs = new Point[n];
        for (int i = 0; i < n; i++) {
            rs[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
            bs[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        solve();
    }

    void solve() {
        int count = 0;
        boolean[] paired = new boolean[n];
        Arrays.sort(bs, new sortByX());
        for (int i = 0; i < n; i++) {
            Point b = bs[i];
            int index = -1;
            int maxY = -1;
            for (int j = 0; j < n; j++) {
                if (paired[j] || rs[j].x >= b.x || rs[j].y >= b.y) {
                    continue;
                }
                if (rs[j].y > maxY) {
                    index = j;
                    maxY = rs[j].y;
                }
            }
            if (maxY > -1) {
                paired[index] = true;
                count++;
            }
        }
        System.out.println(count);
    }

    class sortByX implements Comparator<Point> {
        public int compare(Point a, Point b) {
            return a.x - b.x;
        }
    }

    class Point {
        int x;
        int y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23380
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
ll a[100005];
int main() {
	ll x;
	cin >> n >> x;
	rep(i, n)
		cin >> a[i];
	int tx = x;
	ll ans = 0;
	rep(i, n - 1) {
		if (a[i] + a[i + 1] > x) {
			ll tm = a[i] + a[i + 1] - x;
			ans += tm;
			ll mn = min(a[i + 1] , tm);
			a[i + 1] -= mn;
			tm -= mn;
			if (a[i] + a[i + 1] > x) {
				a[i] -= tm;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
unsigned long xor_x=88172645463325252ULL;
unsigned long rng()
{
	xor_x^=xor_x<<7;
	return xor_x^=xor_x>>9;
}
int D;
int c[26],s[365][26];
int t[365],now;
int anst[365],ans;
void calc()
{
	int lst[26];
	for(int i=0;i<26;i++)lst[i]=-1;
	now=0;
	for(int i=0;i<D;i++)
	{
		now+=s[i][t[i]];
		lst[t[i]]=i;
		for(int j=0;j<26;j++)now-=c[j]*(i-lst[j]);
	}
}
int change(int d,int q)
{
	int ret=0;
	ret-=s[d][t[d]];
	ret+=s[d][q];
	{
		int r=d+1;
		while(r<D&&t[r]!=t[d])r++;
		int l=d-1;
		while(l>=0&&t[l]!=t[d])l--;
		ret-=c[t[d]]*(r-d)*(d-l);
	}
	{
		int r=d+1;
		while(r<D&&t[r]!=q)r++;
		int l=d-1;
		while(l>=0&&t[l]!=q)l--;
		ret+=c[q]*(r-d)*(d-l);
	}
	return ret;
}
main()
{
	cin>>D;
	for(int i=0;i<26;i++)cin>>c[i];
	for(int i=0;i<D;i++)for(int j=0;j<26;j++)cin>>s[i][j];
	{
		int lst[26];
		for(int i=0;i<26;i++)lst[i]=-1;
		for(int i=0;i<D;i++)
		{
			int x=-1,tc=-1;
			for(int j=0;j<26;j++)
			{
				int u=s[i][j]+c[j]*(i-lst[j])*5;
				if(tc<u)
				{
					tc=u;
					x=j;
				}
			}
			anst[i]=t[i]=x;
			lst[x]=i;
		}
	}
	calc();
	ans=now;
	for(int tm=0;tm<3000;tm++)
	{
		while(true)
		{
			int d=rng()%D,q=rng()%26;
			int ret=change(d,q);
			if(rng()%2000>tm||ret>=0)
			{
				now+=ret;
				t[d]=q;
				break;
			}
		}
		for(int k=0;k<3000;k++)
		{
			int d1=rng()%(D-1)+1,d2=rng()%d1;
			int pt1=t[d1],pt2=t[d2];
			int diff=0;
			diff+=change(d1,pt2);
			t[d1]=pt2;
			diff+=change(d2,pt1);
			t[d2]=pt1;
			if(diff>=0)
			{
				now+=diff;
			}
			else
			{
				t[d1]=pt1;
				t[d2]=pt2;
			}
		}
		if(ans<=now)
		{
			ans=now;
			for(int i=0;i<D;i++)anst[i]=t[i];
		}
		else if(rng()%2000<tm)
		{
			now=ans;
			for(int i=0;i<D;i++)t[i]=anst[i];
		}
	}
	for(int i=0;i<D;i++)cout<<anst[i]+1<<endl;
	cerr<<ans<<endl;
}


Measured memory_bytes: 3680
import sys
input = sys.stdin.readline

def main():
    s=input()
    t=input()
    sl,tl=len(s),len(t)
    lcs=[[0]*(tl+1) for _ in range(sl+1)]
    for i in range(1,sl+1):
        for j in range(1,tl+1):
            if s[i-1]==t[j-1]:
                lcs[i][j]=lcs[i-1][j-1]+1
            else:
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1])
    k = lcs[i][j]
    r = ''
    while k:
        if lcs[i - 1][j] == k:
            i -= 1
        elif lcs[i][j - 1] == k:
            j -= 1
        else:
            k -= 1
            i -= 1
            j -= 1
            r += s[i]
    print(r[::-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 111708
/****************************************************************************************************
                                        SUBMITTED BY-

                                            AISH_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
int main()
{
    int n;
    cin>>n;

    ll h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];

    int flag=1;

    for(int i=1;i<n;i++)
    {
        if(h[i]==h[i-1])
            continue;
        else if(h[i]>h[i-1])
            h[i]--;
        else
        {
            flag=0;
            break;
        }
    }
    if(flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
ll dp[MAX], a[MAX];
int nxt[MAX];

int main() {
	int n;
	scanf("%d", &n);
	fori(i, 1, n + 1) {
		scanf("%lld", a + i);
		nxt[i] = n + 1;
	}
	
	stack< pair<ll, int> > s;
	ford(i, n, 1) {
		while(!s.empty() && s.top().first > a[i]) {
			s.pop();
		}
		if(!s.empty()) {
			nxt[i] = s.top().second;
		}
		s.emplace(a[i], i);
	}

	ll ans = 0;
	ford(i, n, 1) {
		dp[i] = (nxt[i] - i) * a[i] + dp[nxt[i]];
		ans += dp[i];
	}

	printf("%lld\n", ans);

	return 0;
}



Measured memory_bytes: 7424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][--v] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }
}


Measured memory_bytes: 25464
#include <stdio.h>
int main(void){
    int i, x[10000];
    
    for (i = 1; i <= 10000; i++) {
        scanf("%d\n", &x[i]);
        if(x[i] == 0) break;
        printf("Case %d: %d\n", i, x[i]);    
    }
    
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

template<typename T> T gcd(T a, T b){
  if(b==0){
    return a;
  }
  return gcd(b, a%b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k;
  cin>>k;
  ll ans=0;
  FOR(i, 1, k+1){
    FOR(j, 1, k+1){
      FOR(l, 1, k+1){
        ans+=gcd(i, gcd(j, l));
      }
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n;
    string s;
    cin >> n;
    map<char, long long> cnt;
    for (int i = 0; i < n; i++){
        cin >> s;
        cnt[s[0]]++;
    }
    cout << 
    cnt['M'] * cnt['A'] * cnt['R'] + 
    cnt['M'] * cnt['A'] * cnt['C'] + 
    cnt['M'] * cnt['A'] * cnt['H'] + 
    cnt['M'] * cnt['R'] * cnt['C'] + 
    cnt['M'] * cnt['R'] * cnt['H'] + 
    cnt['M'] * cnt['C'] * cnt['H'] + 
    cnt['A'] * cnt['R'] * cnt['C'] + 
    cnt['A'] * cnt['R'] * cnt['H'] + 
    cnt['A'] * cnt['C'] * cnt['H'] + 
    cnt['R'] * cnt['C'] * cnt['H']
    << endl;
}

Measured memory_bytes: 256
str = gets.chomp.split(//)
module Test
  def print(a, b)
    puts self[ran(a, b)].join
  end
  
  def reverse(a, b)
    self[ran(a, b)] = self[ran(a, b)].reverse
  end
  
  def replace(a, b, other)
    self[ran(a, b)] = other.to_s.split(//)
  end
  
  private
  def ran(a, b)
    return a.to_s.to_i..b.to_s.to_i
  end
end
str.extend(Test)
gets.to_i.times do
  str.send(*gets.chomp.split(" ").map(&:to_sym))
end

Measured memory_bytes: 6172
#include <bits/stdc++.h>
using namespace std;

int main() {
    string S;
    cin>>S;
    if(S=="AAA"){
        cout<<"No"<<endl;
    }
    else if(S=="BBB"){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    ll n; cin>>n;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    vector<ll> v;
    for(ll i=2; i*i<=n; i++){
        if(n%i!=0) continue;
        ll q=1;
        while(n%i==0){
            n/=i;
            q*=i;
        }
        if(i==2) q*=2;
        v.push_back(q);
    }
    if(n>1) v.push_back(n);
    int m=v.size();
    ll ans=1e18;
    for(int i=0; i<(1<<m); i++){
        vector<ll> r(m);
        for(int j=0; j<m; j++){
            if(i&(1<<j)) r[j]=v[j]-1;
        }
        auto yz=crt(r, v);
        if(yz.first==0) ans=min(ans, yz.second);
        else ans=min(ans, yz.first);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
ll A[200000];
ll sum;
map<ll, ll> mp;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
        if(mp.count(A[i]) == 0){
            mp[A[i]] = 1;
        }else{
            mp[A[i]]++;
        }
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int b, c;
        cin >> b >> c;
        ll cnt = 0;
        if(mp.count(b) != 0) {
            cnt = mp[b];
            sum -= b*cnt;
            sum += c*cnt;  
        }
        mp.erase(b);
        if(mp.count(c) == 0){
            mp[c] = cnt;
        }else{
            mp[c] += cnt;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 8396
//周♂雨扬是最强的！！！
//大佬祝您AK
//沈哲♂贝是最强的！！！
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<fstream>
using namespace std;
//ifstream fin(.in);
//ofstream fout(.out);
long long n,m,ans=0;
int main(){
	cin>>n>>m;
	if(m>=2*n){
		ans=ans+n;
		m=m-2*n;
		ans=ans+(m/4);
		cout<<ans<<endl;
	}else{
		cout<<m/2<<endl;
	}
	return 0;
}
//沈♂哲贝是最强的！！！
//大佬祝您AK
//周♂雨扬是最强的！！！

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
ll D;
int dx1[30],dx2[30];
ll pw[20];
vector<ll>vv;

void dfs(int cur,int ed,vector<pair<ll,ll> >&w,ll val,ll cnt){
	if(cur==ed){
		w.push_back(make_pair(val,cnt));
		return;
	}
	for(int i=-9;i<=9;i++){
		dfs(cur+1,ed,w,val+i*vv[cur],cnt*(cur==0?dx2[i+10]:dx1[i+10]));
	}
}

ll solve(int l){
	vv.clear();
	for(int i=0;l-1-i>i;i++){
		vv.push_back(pw[l-1-i]-pw[i]);
	}
	map<ll,ll>mp;
	vector<pair<ll,ll> >v1,v2;
	
	dfs(0,(SZ(vv)+1)/2,v1,0,1);
	dfs((SZ(vv)+1)/2,SZ(vv),v2,0,1);
	
	ll ans=0;
	for(int i=0;i<SZ(v2);i++)mp[v2[i].first]+=v2[i].second;
	for(int i=0;i<SZ(v1);i++){
		ans+=mp[v1[i].first+D]*v1[i].second;
	}
	if(l%2==1)ans*=10;
	return ans;
}
int main(){
	cin>>D;
	if(D%9!=0){
		cout<<0<<endl;
		return 0;
	}
	pw[0]=1;
	for(int i=1;i<20;i++)pw[i]=pw[i-1]*10;
	
	for(int i=0;i<10;i++)for(int j=0;j<10;j++){
		dx1[i-j+10]++;
	}
	for(int i=1;i<10;i++)for(int j=0;j<10;j++){
		dx2[i-j+10]++;
	}
	
	ll ans=0;
	for(int i=2;i<=18;i++)ans+=solve(i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 207052
#include <bits/stdc++.h>
using namespace std;


int main(){
  
  int N,c=0;
  cin >> N;
  int t=N;
  
  while(t>0){
    c += t % 10;
    t /= 10;
  }
  
  
  if(N%c==0){cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>

using namespace std;

typedef struct _process {
	char name[11];
	int quantum;
} process_t;

int main() {
	queue<process_t> qu;
	process_t tmp;
	int num, q, c, elaps;

	cin >> num >> q;
	while ( num ) {
		scanf( "%s %d", tmp.name, &tmp.quantum );
		qu.push( tmp );
		num--;
	}

	while ( !qu.empty() ) {
		tmp = qu.front();
		qu.pop();
		c = min( tmp.quantum, q );
		tmp.quantum -= c;
		elaps += c;
		if ( tmp.quantum > 0 ) {
			qu.push( tmp );
		} else {
			cout << tmp.name << " " << elaps << endl;
		}
	}
	return 0;
}

int min( int a, int b ) {
	return ( a < b ? a : b );
}



Measured memory_bytes: 3752
#include <iostream>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    cout << "a ";
    if(a<b)
        cout << "<";
    else if(a>b)
        cout << ">";
    else
        cout << "==";
    cout << " b" << endl;
    return 0;
}

Measured memory_bytes: 3076
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static  long  w;
	public static int n;
	public static long  wi[],vi[];
	public static long [][] dp;
	public static long maxpro(int pos,long rem)
	{   if(pos>=n)
			return 0;
		if(dp[pos][(int) rem]!=-1)
			return dp[pos][(int) rem];
		long ex;
		long in=Integer.MIN_VALUE;
		if(rem-wi[pos]>=0)
			in=vi[pos]+maxpro(pos+1,rem-wi[pos]);
		ex=maxpro(pos+1,rem);
		//System.out.println("dp["+pos+"]["+rem+"]="+Math.max(in, ex));
		return dp[pos][(int) rem]=Math.max(in, ex);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		w=in.nextLong();
		wi=new long [n];
		vi=new long[n];
		dp=new long[n+1][(int) (w+1)];
		for(int i=0;i<n;i++)
			{ wi[i]=in.nextLong();
			  vi[i]=in.nextLong();
			}
		for(int i=0;i<=n;i++)
			Arrays.fill(dp[i],-1);
	
		System.out.print(maxpro(0,w));
	}

}


Measured memory_bytes: 141020
n = int(input())

def dfs(s):
	if int(s) > n:#nより大きいならカウントしない
		#print(int(s))
		return 0

	ret = 1 if all(s.count(c) > 0 for c in '753') else 0
	#753,全てが含まれているなら1
	
	for c in '753':
		ret += dfs(s+c)
		#print(s+c)
	return ret

print(dfs('0'))




Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int INF = 1000000;
int dp[1<<20];


int n,m;
int p[20][100001];
int num[20];

int solve(int s){
	if(~dp[s])return dp[s];
	int res=INF;
	REP(i,m){
		if(!(s & 1<<i))continue;
		int nb = ~(1<<i) & s;
		int oth = 0;
		REP(j,m){
			if(!(nb & 1<<j))continue;
			oth += num[j];
		}
		int am = p[i][oth + num[i]] - p[i][oth];
		res=min(res,solve(nb) + (num[i] - am));
	}
	return dp[s] = res;
}

int main() {
	cin>>n>>m;
	REP(i,n){
		int k;
		cin>>k;
		k--;
		p[k][i+1]++;
		num[k]++;
	}
	REP(i,n){
		REP(k,m)p[k][i+1]+=p[k][i];
	}
	// [a,b) p[k][b] - p[k][a]
	memset(dp, -1, sizeof(dp));
	dp[0]=0;
	cout<<solve((1<<m)-1)<<endl;
	return 0;
}

Measured memory_bytes: 14872
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])
        {
            cout<<"No\n";
            return 0;
        }

    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

bool cmp(pair<int, int> &x, pair<int, int> &y)
{
	return x.second > y.second;
}

int main(void)
{
	int n, m;
	while(cin >> n >> m, n > 0){
		int j = 0, ans = 0;
		vector<pair<int, int>> dp(n);
		rep(i, n){
			int d, p;
			cin >> d >> p;
			dp[i] = make_pair(d, p);
		}
		sort(dp.begin(), dp.end(), cmp);
		while(m > 0){
			if (m > dp[j].first){
				m -= dp[j].first;
				dp[j].first = 0;
				j++;
				if (j == n) break;
			}else{
				dp[j].first -= m;
				m = 0;
			}
		}
		rep(i, n){
			ans += dp[i].first * dp[i].second;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int main(){
  int x,y;
  while(1){
      scanf("%d %d",&x,&y);
    if(x==0&&y==0)break;
    if(y<=x){printf("%d %d\n",y,x);}
    else{printf("%d %d\n",x,y);}}
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int N,M;
vector<int> L[10];
bool isvisit[10];
ll ans;

void dfs(int v){
    isvisit[v] = true;
    bool update = false;
    for(int i = 0; i < L[v].size(); i++){
        int next = L[v][i];
        if(!isvisit[next]){
            dfs(next);
            update = true;
        }
    }

    if(!update){
        REP(i,N){
            if(!isvisit[i])
                goto fin;
        }
        ans++;
    }
fin:
    isvisit[v] = false;
}

int main(){
    cin >> N >> M;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        L[a].push_back(b);
        L[b].push_back(a);
    }

    dfs(0);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 222;
const int MAXR = 1111;
const ll INF = 1ll<<55;
int N, M, R;
// d1: land d2: sea
ll d1[MAXN][MAXN], d2[MAXN][MAXN];
int z[MAXR];

ll dp[MAXR][MAXN];

ll dfs(int turn, int ship) {
	ll& ret = dp[turn][ship];
	if (ret >= 0) return ret;
	if (turn == R-1) return ret = 0;
	// ??????
	ret = d1[z[turn]][z[turn+1]] + dfs(turn+1, ship);
	// ???
	for (int v = 0; v < N; v++) {
		ll tmp = d1[z[turn]][ship] + d2[ship][v] + d1[v][z[turn+1]];
		if (tmp >= INF) continue;
		tmp += dfs(turn+1, v);
		ret = min(ret, tmp);
	}
	return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N >> M) {
    	if (N==0 && M==0) break;
    	for (int i = 0; i < N; i++) {
    		for (int j = 0; j < N; j++) {
    			d1[i][j] = d2[i][j] = INF;
    		}
    		d1[i][i] = d2[i][i] = 0;
    	}
    	for (int i = 0; i < M; i++) {
    		int x, y, t;
    		char sl;
    		cin >> x >> y >> t >> sl;
    		x--; y--;
    		if (sl == 'L') {
    			d1[x][y] = min<ll>(d1[x][y], t);
    			d1[y][x] = d1[x][y];
    		} else {
    			d2[x][y] = min<ll>(d2[x][y], t);
    			d2[y][x] = d2[x][y];
    		}
    	}
    	for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
    		d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
    		d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
    	}
    	cin >> R;
    	for (int i = 0; i < R; i++) {
    		cin >> z[i];
    		z[i]--;
    	}
    	memset(dp, -1, sizeof(dp));
    	cout << dfs(0, z[0]) << endl;
    }
    return 0;
}

Measured memory_bytes: 5736
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    set<int> a;
    for (int q = 1; q <= n; q++){
        a.insert(q);
    }
    for (int q = 0; q < k; q++){
        int w;
        cin >> w;
        for (int q1 = 0; q1 < w; q1++){
            int w1;
            cin >> w1;
            if (a.find(w1) != a.end()){
                a.erase(w1);
            }
        }
    }
    cout << a.size() << endl;
    return 0;
}


Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top, S[1000];
 
void push(int x) {
    S[++top] = x;
}
 
int pop() {
    top--;
    return S[top+1];
}
 
int main() {
    int a, b;
    top = 0;
    char s[100];
 
    while (scanf("%s",s) != EOF) {
        if (s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        }
        else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        }
        else if (s[0] == '*') {
            a= pop();
            b= pop();
            push(a*b);
        }
        else {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
 
    return 0;
}

Measured memory_bytes: 1812
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
int x,a,b;
cin>>x>>a>>b;
cout<<(x-a)%b<<endl;
	return 0;
}



Measured memory_bytes: 256
A, B, N = map(int, input().split())
Smx = 0
if B<N:
    N = B
for i in range(N,0,-1):
    if i<N-A:
        break
    S = int((A*(i % B) - ((A*i) % B))/B)
    if Smx<S:
        Smx = S
print(Smx)

Measured memory_bytes: 9200
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second

vector<pair<ll,ll>> v;
ll dp[200][200005];

ll solve(ll i,ll s,ll n)
{
    if(s==0)    return 0;
    if(s < 0)   return INT_MAX;
    
    if(i==n)    return INT_MAX;
    
    if(dp[i][s]!=-1)    return dp[i][s];
    
    ll ans = INT_MAX;
    
    ans = min(ans,v[i].ff + solve(i+1,s-v[i].ss,n));
    ans = min(ans,solve(i+1,s,n));

    dp[i][s] = ans;
    return ans;
}

int main() {
    
    memset(dp,-1,sizeof(dp));
    
    ll n,s;
    cin >> n >> s;
    // swap(n,s);
    ll sum=0;
    
    for(ll i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        v.push_back({a,b});
        sum += b;
    }    
    
    while(sum){
        // cout<<sum;
        ll ans = solve(0,sum,n);
        // cout<<ans<<" ";
        if(ans <= s){
            cout<<sum;
            exit(0);
        }
        sum--;
    }
    cout<<0;
	return 0;
}

Measured memory_bytes: 312704
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]:
                    ans+=1
                else:
                    pass
print(ans)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n,k;
    cin >> n >> k;
    cout << fixed << setprecision(13);
    double ans = 0;
    for(int i=1; i<=n; i++){
        int score = i;
        double p = 1.0/n;
        while(score <= k-1){
            p /= 2.0;
            score *= 2;
        }
        ans += p;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> cnt;
	char last = s[0];
	int tmp = 0;
	FOR(i,0,n){
		if(s[i] == last){
			tmp++;
		}else{
			cnt.pb(tmp);
			tmp = 1;
		}
		last = s[i];
	}
	cnt.pb(tmp);
	vector<int> cntRuiseki;
	cntRuiseki.pb(0);
	FOR(i,0,(int)cnt.size()){
		cntRuiseki.pb(cnt[i] + cntRuiseki[i]);
	}
	int i;
	if(s[0] == '0'){
		i = 1;
	}else{
		i = 0;
	}
	int ans = 0;
	while(i < (int)cnt.size()){
		tmp = cntRuiseki[min(i+k*2+1, (int)cntRuiseki.size()-1)] - cntRuiseki[i];
		/*FOR(j,0,k*2+1){
			if(i+j >= (int)cnt.size())break;
			tmp += cnt[i+j];
		}*/
		ans = max(ans, tmp);
		i+=2;
	}
	if(s[0] == '0'){
		i = 0;
	}else{
		i = 1;
	}
	while(i < (int)cnt.size()){
		tmp = cntRuiseki[min(i+k*2, (int)cntRuiseki.size()-1)] - cntRuiseki[i];
/*		FOR(j,0,k*2){
			if(i+j >= (int)cnt.size())break;
			tmp += cnt[i+j];
		}*/
		ans = max(ans, tmp);
		i+=2;
	}
	//FOR(i,0,(int)cnt.size())ANS(cnt[i]);
	ANS(ans);
	return 0;
}


Measured memory_bytes: 1528
import sys
from bisect import bisect_right


def solve(t):
    global A, B, C
    k = bisect_right(H, B * t)
    cnt = 0
    for i in range(k, N):
        h = H[i]
        h -= B * t
        cnt += (h + C - 1) // C
    return cnt <= t


N, A, B = map(int, input().split())
C = A - B
H = [int(s) for s in sys.stdin.readlines()]

H.sort()

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ng = 0
ok = H[-1] // B + 1
k = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 14252
// 147 B - Palindrome-philia 2019/12/08

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    string s; cin >>s;
    int i=0;int j=s.size()-1;
    int ans=0;
    if(s.size()%2==0){
        for(;i<s.size()/2;){
            if(s[i]!=s[j]) ++ans;
            ++i; --j;
        }
    } else {
        for(;i<s.size()/2+1;){
            if(s[i]!=s[j]) ++ans;
            ++i; --j;        
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]s=new int[m];
		int[]p=new int[m];
		int num=0;
		for(int i=0;i<m;i++) {
			int allS=0;
			int k=sc.nextInt();
			for(int j=0;j<k;j++) {
				allS=allS |1<<(sc.nextInt()-1);
			}
			s[i]=allS;
		}
		for (int i=0;i<1<<n;i++) {
			boolean flag = true;
			for(int j=0;j<m;j++) {
				if(i==0)
					p[j]=sc.nextInt();
				int k=s[j]&i;
				if(Integer.bitCount(k)%2!=p[j]) {
					flag=false;
					continue;
					}
			}
			if(flag)
				num++;
		}
			System.out.println(num);
	}
}


Measured memory_bytes: 22740
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int m, f, r;
		boolean sharp = false;

		while (true) {
			m = scanner.nextInt();
			f = scanner.nextInt();
			r = scanner.nextInt();

			if (m == -1 && f == -1 && r == -1)
				break;

			if (m == -1 || f == -1)
				System.out.println("F");
			else if (m + f >= 80)
				System.out.println("A");
			else if (m + f >= 65)
				System.out.println("B");
			else if (m + f >= 50 || r >= 50)
				System.out.println("C");
			else if (m + f >= 30)
				System.out.println("D");
			else
				System.out.println("F");
		}
	}
}

Measured memory_bytes: 26240
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)


















vector<vector<pair<ll, ll>>> g;
vector<ll> color;

void dfs(ll now){
    for(auto &c : g[now]){
        ll to = c.first, w = c.second;
        if(!color[to]){
            if(w % 2 == 1){
                color[to] = color[now] == 1? 2 : 1;
            }
            else{
                color[to] = color[now] == 1? 1 : 2;
            }
            dfs(to);
        }
    }
}



int main(){
    ll n;
    cin >> n;
    g.resize(n);
    REP(i, n - 1){
        ll u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    
    color.resize(n);
    color[0] = 1;
    dfs(0);
    
    REP(i, n){
        cout << (color[i] == 1? 0 : 1) << endl;
    }
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
int64_t a,b,c;
  cin>>a>>b>>c;
  int64_t sp[a];
  int64_t dp[b];
  rep(i,a) cin>>sp[i];
  rep(i,b) cin>>dp[i];
  int64_t s[c];
  int64_t d[c];
  int64_t mo[c];
  rep(i,c) cin>>s[i]>>d[i]>>mo[i];
  int64_t sum=0;
  int64_t x,y;
  x=1000000000;
  y=1000000000;
 rep(i,a) x=min(x,sp[i]);
  rep(i,b) y=min(y,dp[i]);
  sum=x+y;
  
  rep(i,c){
    int64_t u=s[i]-1;
    int64_t n=d[i]-1;
  sum=min(sum,sp[u]+dp[n]-mo[i]);
  
  }
  cout<<sum;
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int prime[300010];
bool is_prime[300010];

int main(void){
    
    int p=0;
    
    for(int i=0;i<=300000;i++){
        is_prime[i]=true;
    }
    for(int i=1;i*7+1<=300000;i++){
        int b=7*i-1,c=7*i+1;
        if(is_prime[b]){
            prime[p++]=b;
            for(int j=2*b;j<=300000;j+=b)is_prime[j]=false;
        }
        if(is_prime[c]){
            prime[p++]=c;
            for(int j=2*c;j<=300000;j+=c)is_prime[j]=false;
        }
    }


    
    while(1){
        int n;
        cin>>n;
        if(n==1)break;
        cout<<n<<":";
        for(int i=0;i<p;i++){
            if(n%prime[i]==0)cout<<" "<<prime[i];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3540
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();

            int[] a = new int[N];

            for (int i = 0; i < N; i++) a[i] = fs.nextInt();

            Arrays.sort(a);

            int ans = a[N - 1] - a[0];
            System.out.println(ans);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>

typedef long long ll;
const int N = 100054;

int n, p;
int a[N];
ll I = 0, r[N];

void handle(int s, int t) {
	assert(s != t);
	if (s + 1 == t || s + 1 == t + p) return;
	int _;
	if (s < t) --r[s + 2], r[t + 1] += t - s, r[t + 2] += s - t + 1;
	else _ = p - s - 1, --r[s + 2], *r -= _, r[1] += _ - 1, r[t + 1] += t - s + p, r[t + 2] += s - t + 1 - p;
}

int main() {
	int i;
	scanf("%d%d", &n, &p);
	for (i = 0; i < n; ++i) scanf("%d", a + i), --a[i];
	for (i = 1; i < n; ++i)
		I += (a[i] - a[i - 1] + p) % p, handle(a[i - 1], a[i]);
	for (i = 1; i < p; ++i) r[i] += r[i - 1];
	for (i = 1; i < p; ++i) r[i] += r[i - 1];
	printf("%lld\n", I + *std::min_element(r, r + p));
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> z,s;
vector<string> vs;
int rec(int p,int u,int sum){
  if(p==z.size()) return !sum;
  int res=0;
  for(int i=z[p];i<10;i++) if(!((u>>i)&1)) res+=rec(p+1,u|(1<<i),sum+s[p]*i);
  return res;
}
signed main(){
  int n,i,j,k;
  while(cin>>n,n){
    vs.clear();vs.resize(n);
    for(i=0;i<n;i++) cin>>vs[i];
    vector<char> vc;
    map<char,int> m;
    for(i=0;i<vs.size();i++)
      for(j=0;j<vs[i].size();j++)
	if(m.find(vs[i][j])==m.end())
	  m[vs[i][j]]=vc.size(),vc.push_back(vs[i][j]);
    z.clear();z.resize(vc.size(),0);
    s.clear();s.resize(vc.size(),0);
    reverse(vs.begin(),vs.end());
    for(i=0;i<vs.size();i++){
      if(vs[i].size()-1) z[m[vs[i][0]]]=1;
      reverse(vs[i].begin(),vs[i].end());
      for(j=0,k=1;j<vs[i].size();j++) s[m[vs[i][j]]]+=(i?1:-1)*k,k*=10;
    }
    cout << rec(0,0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,k;
priority_queue<int,vector<int>,greater<int>> h;
main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1; i<=n; ++i){
		int x;
		cin>>x;
		h.push(x);
	} 
	if(k>=n) return cout<<0,0;
	int sum=0,cnt=0;
	while(cnt<n-k){
		sum+=h.top();h.pop();cnt++;
	}
	cout<<sum;
}

Measured memory_bytes: 2420
#include<iostream>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    if(S[0] == S[1] && S[1] == S[2]){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
  int n,p;

  for(;cin>>n,n;)
    {
      int sum=0;
      for(int i=0;i<n/4;i++)
	{
	  int tmp;
	  cin>>tmp;
	  sum+=tmp;
	}
      cout<<sum<<endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


int main()
{
    IOS
    ll ans=0;
    ll a,b;
    cin>>a>>b;
    ll cur=1;
    ll cnt=0;
    while(cur<b)
    {
        cur--;
        cnt++;
        cur+=a;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256