akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define INFINITY (1<<21)
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(){
  int minv,i,j,v,u;
  int d[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFINITY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while (1) {
    minv=INFINITY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] !=INFINITY){
        if( d[v] > d[u]+ M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] =GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",i);
    if(d[i] == INFINITY)printf(" -1\n");
    else printf(" %d\n",d[i]);
  }
}

int main(){
  int i,j,v,c,u,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = INFINITY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n){
        vi v(n); rep(i,n)cin>>v[i];
        sort(all(v));int ans=0;
        rep(i,n-1)v[i+1]+=v[i];
        rep(i,n)ans+=v[i];cout<<ans<<endl;
    }
}

Measured memory_bytes: 3148
n,m=map(int,input().split())
x=[int(i) for i in input().split()]

x.sort()
y=[]
if n-m>=0:
  print(0)
  exit(0)
else:
  for i in range(m-1):
    y.append(x[i+1]-x[i])
y.sort()
print(sum(y[:m-n]))


Measured memory_bytes: 13840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める
bool prime(int n){
    double rn = sqrt(n);
    for(int i=2;i<=rn;i++){
        if(n%i == 0){
            return false;
        }
    }
    return true;
}
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    rep(i,n) {
        if(prime(p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3128
#include "stdio.h"
#include "stdarg.h"
#include "math.h"
#include "limits.h"

#define SWAP(type,a,b) do{type c=a;a=b;b=c;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define DEBUG(format,a) do{printf(#a" : "#format,a);}while(0)


int main() {
	int a,ans=0;
	scanf("%d", &a);

	int c = 0;
	if (a == 2) {
		printf("%d", 2);
	}else {
		while (1) {
			for (int i = 2;i < a + c;i++) {
				if ((a + c) % i == 0)break;
				else if (i == a + c - 1) {
					ans = a + c;
					break;
				}
			}
			if (ans != 0)break;
			c++;
		}
		printf("%d", ans);
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for(int i=0; i<values.length; i++){
                values[i]= i+1;
            }
            for(int i=0; i<n; i++){
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0])-1;
                int b = Integer.parseInt(ab[1])-1;
                int tmp = values[a];
                values[a] = values[b];
                values[b] = tmp;
            }
            for(int i=0; i<values.length; i++){
                System.out.println(values[i]);
            }
        }
    }
}


Measured memory_bytes: 26192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,ans=0;
    int l[110],d[110];
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>l[i];
    d[0]=0;
    for(int i=1;i<=n;i++) d[i]=d[i-1]+l[i-1];
    for(int i=0;i<=n;i++) if(d[i]<=x) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a[31]={},m,l,n;
    a[1]=1;
    a[2]=2;
    a[3]=4;
    for(int i=4;i<31;i++){
        a[i]=a[i-1]+a[i-2]+a[i-3];
    }
    while(true){
        cin >>n;
        m=(a[n]/10)+1;
        l=(m/365)+1;
        if(n==0)break;
        cout <<l<<endl;
    }
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll a, b , c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(0LL, min(b,d)-max(a,c));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll wei[105], val[105], dp[105][100005], inf = 1LL << 60;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w, tv = 0;
	cin >> n >> w;
	for (int i = 1; i <= n; ++i) {
		cin >> wei[i] >> val[i];
		tv += val[i];
		dp[i][val[i]] = wei[i];
	}
	for (int i = 1; i <= tv; ++i)
		dp[0][i] = inf;
	for (int i = 1; i <= tv; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (!dp[j][i])
				dp[j][i] = inf;
			if (val[j] > i) {
				dp[j][i] = dp[j - 1][i];
				continue;
			}
			dp[j][i] = min(min(dp[j][i], dp[j - 1][i]), dp[j - 1][i - val[j]] + wei[j]);
			if (dp[j][i] > w)
				dp[j][i] = inf;
		}
	}
	ll ans = 0;
	bool flag = false;
	for (int i = tv; i > 0 && !flag; --i)
		for (int j = 1; j <= n && !flag; ++j)
			if (dp[j][i] != inf) {
				flag = true;
				ans = i;
			}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, B = 30;
	cin >> N;
	vector<int> ops(N, 0);
	vector<bool> pw2(N, false);
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		for(int j = 0; j < B; j++) {
			if(a == (1<<j)) pw2[i] = true;
			if(a > (1<<j)) ops[i] = j+1;
		}
	}
	vector<int> ans(B+1, N*B);
	ans[0] = 0;
	for(int i = 0; i < N; i++) {
		vector<int> ans_nw(B+1, N*B);
		for(int j = 0; j <= ops[i]; j++) for(int del = 0; del <= ops[i]; del++) {
			int add = ops[i]-j;
			if(!pw2[i] && add+del == 0) continue;
			ans_nw[ops[i]-del] = min(ans_nw[ops[i]-del], ans[j]+add);
		}
		ans = ans_nw;
	}
	cout << ans[0] << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 640
h,w = map(int,input().split())
aa = [list(map(int,input().split())) for _ in range(h)]
ans=[]

for hi in range(h):
  for wi in range(w-1):
    if aa[hi][wi] % 2 == 1:      
      aa[hi][wi] -= 1
      aa[hi][wi+1] += 1
      ans.append([hi+1,wi+1,hi+1,wi+2])
      
  if hi < h-1:
    if aa[hi][-1] % 2 ==1:      
      aa[hi][-1] -= 1
      aa[hi+1][-1] += 1
      ans.append([hi+1,w, hi+2, w])

print(len(ans))
for yp,xp,yn,xn in ans:
  print('{} {} {} {}'.format(yp,xp,yn,xn))      

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n; cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) 
        {
                cin >> a[i];
        }
        int mn = INT_MAX, res = 0;
        for (int i = 0; i < n; ++i)
        {
                if (a[i] < mn) 
                {
                        mn = a[i];
                        res++;
                }
        }
        cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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


using namespace std;


int main()
{
    string s;
    cin>>s;
    bool flag=1;
    for(int i=0;i<s.length();i+=2)
    {
        if(s[i]!='R'&&s[i]!='U'&&s[i]!='D')flag=0;
        else continue;
    }
    for(int i=1;i<s.length();i+=2)
    {
        if(s[i]!='L'&&s[i]!='U'&&s[i]!='D')flag=0;
        else continue;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string a;
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  for(int i=0;i<N;i++){
 cin>>a;
    if(a=="AC"){
    ac++;
    }
    else if(a=="WA"){
    wa++;
    }
     else if(a=="TLE"){
    tle++;
    }
    else{
    re++;
    }
    
  }

  cout<<"AC x ";
    cout<<ac<<endl;
  
   cout<<"WA x ";
    cout<<wa<<endl;
  
 cout<<"TLE x ";
    cout<<tle<<endl;
  
   cout<<"RE x ";
    cout<<re<<endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int n,ans;
double t,a,mn;
int main(){
    mn = 100000000;
    cin>>n;
    cin>>t>>a;
    for(int i=1;i<=n;i++){
        double x;
        cin>>x;
        double temp;
        temp = t - x*0.006;
        if(abs(temp-a)<=mn){
            mn = abs(temp-a);
            ans = i;
        }
    }
    cout<<ans<<endl;


}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int X, Y; cin >> X >> Y;

	int ans = 0;
	if(X == 3) ans += 100000;
	if(X == 2) ans += 200000;
	if(X == 1) ans += 300000;
  
	if(Y == 3) ans += 100000;
	if(Y == 2) ans += 200000;
	if(Y == 1) ans += 300000;
  
	if(X == 1 and Y == 1) ans += 400000;

	cout << ans << endl;





	return 0;

}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);

	int n;
	cin >>n;
	
	rep(i,30) rep(j,20){
		if(i*4 + j*7 == n){
			puts("Yes");
			return 0;
		}
	}
	
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

bool judge(long long x,long long y,long long t){
    if(abs(x)+abs(y)<=t){
        if(abs(x)+abs(y)==t)return true;
        else if((t-(abs(x)+abs(y)))%2==0)return true;
        else return false;
    }
    return false;
}

int main(){
    int N;
    while (scanf("%d",&N)==1&&N) {
        bool jud=true;
        long long t=0,x=0,y=0;
        long long t1,x1,y1;
        for(int i=0;i<N;i++){
            scanf("%lld%lld%lld",&t1,&x1,&y1);
            t=t1-t;x=x1-x;y=y1-y;
            if(jud&&!judge(x, y, t)){jud=false;}
        }
        if(jud)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)
int main(){
    int i,n,k,s=1;
    cin >> n >> k;
    //REP(i,n) cin >> i;
    for(i=0;s < n;i++) s += (k-1);
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi   vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input_file.txt", "r", stdin);
	// //freopen("output_file.txt", "w", stdout);
	// #endif
	int i,j,k,l,n,test_case,m,r,a,b,c;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>a>>b>>c;
		cout<<c<<" "<<a<<" "<<b<<"\n";
		// CAB

	}
	
	return 0;
}

Measured memory_bytes: 256
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


using namespace std;


map<int, multiset<int>> mp;
int s[100000];


int main(){
	int n,m;
	cin>>n>>m;
	map<int,int> cnt;
	rep(i,n){
		int x;
		cin>>x;
		cnt[x]++;
	}
	for (auto p:cnt){
		mp[p.first%m].insert(p.second);
		s[p.first %m] += p.second;
	}
	int ans=0;

	rep(_i,m){
		int i=_i;
		int j = (m-i)%m;
		if (i==j){
			ans += s[i]/2;
			mp[i].clear();
		}
		else{
			if (s[i] > s[j]){
				swap(i,j);
			}
			while (s[i]+1 < s[j]){
				auto it = mp[j].rbegin();
				if (*it==1)break;
				int a=*it;
				mp[j].erase(mp[j].find(a));
				s[j]-=2;
				if(a)mp[j].insert(a-2);
				ans ++;
			}
			ans += min(s[i],s[j]);
			s[i] = s[j] = 0;
			mp[i].clear();
			mp[j].clear();
		}
	}

	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 19328
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int main(){
    int k; cin >> k;
    vector <ll> a;
    for (int i=1; i<=9; i++) a.push_back(i);
    while(1){
        if (k<=a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k-=a.size();
        vector <ll> old;
        swap(old,a);
        for (ll x:old){
            for (int i=-1; i<=1; i++){
                int d=x%10+i;
                if (0<=d && d<=9){
                    ll tmp=x*10+d;
                    a.push_back(tmp);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int N;
vector<int> a;

long long solve(bool b) {
    long long count = 0;
    long long sum = a[0];
    if(a[0] == 0) { sum = b ? 1 : -1; count++; }
    else if(b && a[0] < 0) { sum = 1; count = 1 - a[0]; }
    else if(!b && a[0] > 0) { sum = -1; count = a[0] + 1; }

    for(int i = 1; i < N; i++) {
        if(sum * a[i] < 0 && abs(sum) < abs(a[i])) {
            sum += a[i];
        } else {
            if(sum > 0) {
                count += a[i] + sum + 1;
                sum = -1;
            } else {
                count += 1 - sum - a[i];
                sum = 1;
            }
        }
    }
    return count;
}

int main()
{
    cin >> N;
    a.resize(N);
    for(int i = 0; i < N; i++) cin >> a[i];

    cout << min(solve(true), solve(false)) << endl;
    return 0;
}


Measured memory_bytes: 640
_, _, x, y = gets.chomp!.split(' ').map(&:to_i)
x_max = gets.chomp!.split(' ').map(&:to_i).max
y_min = gets.chomp!.split(' ').map(&:to_i).min

war = ((-100..100).find {|z|
    x_max < z && z <= y_min && x < z && z <= y
}) ? "No War" : "War"

puts war


Measured memory_bytes: 1788
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
//}}}

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  map<int, int> mo;
  map<int, int> me;
  rep(i, n) (i % 2 ? mo : me)[v[i]]++;
  vector<pair<int, int>> vo;
  vector<pair<int, int>> ve;
  for(auto x: mo) vo.emplace_back(x.second, x.first);
  for(auto x: me) ve.emplace_back(x.second, x.first);
  sort(vo.rbegin(), vo.rend());
  sort(ve.rbegin(), ve.rend());
  int ans;
  if(vo[0].second != ve[0].second){
    ans = n - vo[0].first - ve[0].first;
  }else{
    ans = n + 1;
    if(vo.size() > 1) ans = min(ans, n - vo[1].first - ve[0].first);
    if(ve.size() > 1) ans = min(ans, n - vo[0].first - ve[1].first);
    if(ans == n + 1) ans = n / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6520
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
  int a,b;
  
  cin >> a >> b;
  
  cout << a/b << " " << a%b << " "  << endl;
  cout << fixed << setprecision(7) << (double)a/b <<endl;

  return 0;
}



Measured memory_bytes: 3268
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Arrays;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[][] d = new int[2][n];
		for(int i = 0; i < n; i++) {
			d[0][i] = sc.nextInt();
			d[1][i] = sc.nextInt();
		}
		String ans = "No";
		for(int i = 0; i < n - 2; i++) {
			if(d[0][i]==d[1][i] && d[0][i+1]==d[1][i+1] && d[0][i+2]==d[1][i+2] ) {
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 27284
a, b, c = map(int, input().split())
counter = 0

tmp_eatable = min(b, c)

counter += tmp_eatable * 2
b -= tmp_eatable
c -=tmp_eatable
# print(a, b, c, counter)
if c > 0 :
	tmp_eatable = min(a, c)
	counter += tmp_eatable
	c -= tmp_eatable
	# print(a, b, c, counter)
	if c > 0 :
		counter += 1

else :
	counter += b

print(counter)

Measured memory_bytes: 3060
mod = 10**9+7

n, k = map(int,input().split())
A = list(map(int,input().split()))

#ラスト一個を除く
tentou = [0]*n
for i in range(n):
    for j in range(i+1,n):
        if A[i] > A[j]:
            tentou[i] += 1

back = [0]*n
for i in range(n):
    for j in range(i+1,n):
        if A[-(j+1)] < A[-(i+1)]:
            back[-(i+1)] += 1

#print(A)         
#print(tentou)
#print(back)

wa = k*(k+1)//2

ans = (wa%mod)*sum(tentou)%mod

ans += sum(back)*(k-1)*k//2

print(ans%mod)

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s, t; cin >> s >> t;
  sort(ALL(s));
  sort(RALL(t));

  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	
	string s;
	cin >> s;
	if(s.size() == 2) cout << s;
	else {
		reverse(s.begin(), s.end());
		cout << s;
	}
}

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

int pow(int p, int q){
  int re = 1;
  for(int  i = 0; i < q; i++){
    re *= p;
  }
  return re;
}

int keta(int p, int q){
  string s = to_string(p);
  return (int)(s[q - 1] - '0');
}

int main(){
  int n, m;
  cin >> n >> m;
  if(m == 0 && n == 1){
    cout << 0 << endl;
    return 0;
  }
  vector<pair<int, int>> cases(m);
  for(int i = 0; i < m; i++){
    cin >> cases[i].first >> cases[i].second;
  }
  for(int i = pow(10, n - 1); i < pow(10, n); i++){
    bool flag = true;
    bool flag1 = false, flag2 = false;
    for(int j = 0; j < m; j++){
      if(cases[j].first == 1 && cases[j].second == 0){
        if(n == 1){
          flag1 = true;
        }else{
          cout << -1 << endl;
          return 0;
        }
      }
      if(n == 1 && cases[j].first == 1 && cases[j].second != 0){
        flag2 = true;
      }
      if(keta(i, cases[j].first) != cases[j].second){
        flag = false;break;
      }
    }
    if(flag1 && flag2){
      cout << -1 << endl;
      return 0;
    }else if(flag1){
      cout << 0 << endl;
      return 0;
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
    cout << -1 << endl;
    return 0;
}

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

struct UnionFind {
  vector<int> data;
  UnionFind() {}
  UnionFind(int n) : data(n, -1) {}
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return (data[x] < 0) ? x : data[x] = root(data[x]); }
  int rank(int x) { return -data[root(x)]; }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, q; cin >> n >> q;
  UnionFind uf(n);
  for (int i = 0; i < q; ++i) {
    int com, x, y; cin >> com >> x >> y;
    if (com) {
      cout << uf.same(x, y) << endl;
    } else {
      uf.unite(x, y);
    }
  }
  return 0;
}



Measured memory_bytes: 3268
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    s=chomp(readline())
    cnt=0
    for i in 1:n
        try
            if s[i]!=s[i+1]
                cnt+=1
            end
        catch
            cnt+=1
        end
    end
    println(cnt)
end
main()

Measured memory_bytes: 111412
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
    	var sc = new Scanner();
    	int n = sc.NextInt();
    	int b = sc.NextInt();
    	int[] x = new int[n];
    	for (int i = 0; i < n; i++)
    	    x[i] = Math.Abs(sc.NextInt() - b);
    	Array.Sort(x);
    	for (int i = 1; i < n; i++)
    	{
    		x[i] = Gcd(x[i - 1], x[i]);
    	}
    	
    	Console.WriteLine(x[n - 1]);
    }
    
    static int Gcd(int a, int b)
    {
    	if (a < b) return Gcd(b, a);
    	if (b == 0) return a;
    	return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }
    
    public double NextDouble()
    {
    	CheckNext();
    	return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

Measured memory_bytes: 18400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
	int q;
	cin >> q;
	vector<int> left(q), right(q);
	vector<int> cnt(100010);
	cnt[0] = 0;

	for (int i = 0; i < q; i++) cin >> left[i] >> right[i];

	for (int i = 1; i <= 100000; i+=2) {
		if (is_prime(i)&&is_prime((i+1)/2))cnt[i] = cnt[i - 1] + 1;
		else cnt[i] = cnt[i - 1];
		cnt[i + 1] = cnt[i];
	}

	for (int i = 0; i < q; i++) {
		cout << cnt[right[i]] - cnt[left[i] - 1] << endl;
	}


	return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        while ((line = in.readLine()) != null) {
            String[] strs = line.split("\\s+");
            int[] a = new int[4];
            for (int i = 0; i < 4; i++) {
                a[i] = Integer.parseInt(strs[i]);
            }
            line = in.readLine();
            strs = line.split("\\s+");
            int[] b = new int[4];
            for (int i = 0; i < 4; i++) {
                b[i] = Integer.parseInt(strs[i]);
            } 
            int hit = 0, blow = 0;
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    if (i != j && a[i] == b[j]) {
                        blow++;
                    } else if (i == j && a[i] == b[j]) {
                        hit++;
                    }
                }
            }
            
            System.out.println(hit + " " + blow);
        } 
    }
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n,aa;
    cin >> n;
    vector<int> a(n),b;
    rep(i,0,n-1){
        cin >> aa;
        a[i] = -aa;
    }

    b.push_back(a[0]);
    rep(i,1,n-1){
           //     vecprint(b);
        auto it = upper_bound(b.begin(),b.end(),a[i]);
        int index = it - b.begin();
      //  cout << index << " " <<a[i] <<  endl;
        if(index == sz(b)){
            b.push_back(a[i]);
            //b.insert(b.end(),a[i]);
            //b[index] = a[i];
        //    cout << "TRUE"  << endl;
        }else{
            b[index] = a[i];
        //    cout << "FALSE" <<endl;
        }

    }

    cout << sz(b) << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;

	if (a - b - b < 0)
		cout << "0";
	else
		cout << a - b - b;

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Function (on)
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- getl toInt
  xs <- rgetl n $ split toInt
  mapM_ (putStrLn . unwords . map show) $ solve xs

solve :: [[Int]] -> [[Int]]
solve = map (minpath tbl)
  where
    tbl = [0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1]

minpath :: [Int] -> [Int] -> [Int]
minpath tbl [x,y] = take (iy - ix + 1) $ drop ix tbl
  where
    ixs = findIndices (== x) tbl
    iys = findIndices (== y) tbl
    (ix,iy) = snd $ minimumBy (compare `on` fst) [(j - i,(i,j)) | i <- ixs, j <- iys, j - i > 0, j - i < 15]

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine


tests :: [Test]
tests = [
  "test1" ~: [2,3,4] ~=? minpath [0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1] [2,4],
  "test2" ~: [4,3,2] ~=? minpath [0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1] [4,2],
  "test3" ~: [8,9,5,4,3,2,1,0,1,2,3,4,5,6,7] ~=? minpath [0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1] [8,7],
  "test4" ~: [[2,3,4],[4,3,2]] ~=? solve [[2,4],[4,2]]
  ]

Measured memory_bytes: 3696
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
template<class T, class U> T lexical_cast(const U& from)
{ T to; stringstream ss; ss << from; ss >> to; return to; }
template<class T> void pv(T a,T b)
{ for(T it = a; it != b; ++it) cerr << *it << '_'; cerr << endl; }
const int INF = (int)1e9;
const double PI = M_PI, EPS = 1e-8;
typedef long long int lli;

bool solve(vector<int> &v, int ok) {
    if(ok >= 4) return true;
    bool valid = false;
    for(int i = 1; i <= 9; i++) {
        if(v[i] >= 3) {
            v[i] -= 3;
            valid = valid || solve(v, ok + 1);
            v[i] += 3;
        }
    }
    for(int i = 1; i <= 7; i++) {
        if(v[i] >= 1 && v[i + 1] >= 1 && v[i + 2] >= 1) {
            v[i]--, v[i + 1]--, v[i + 2]--;
            valid = valid || solve(v, ok + 1);
            v[i]++, v[i + 1]++, v[i + 2]++;
        }
    }
    return valid;
}

int main() {
    string line;
    while(getline(cin, line)) {
        vector<int> counter(10, 0);
        for(char c : line) {
            int i = c - '0';
            counter[i]++;
        }

        vector<int> ans;

        for(int add = 1; add <= 9; add++) {
            counter[add]++;

            bool over = false;
            vector<int> two;
            for(int i = 1; i <= 9; i++) {
                if(counter[i] > 4) over = true;
                if(counter[i] >= 2) two.push_back(i);
            }

            bool valid = false;

            if(over == false) {
                for(int t : two) {
                    counter[t] -= 2;
                    valid = valid || solve(counter, 0);
                    counter[t] += 2;
                }
            }

            if(valid) ans.push_back(add);

            counter[add]--;
        }

        if(ans.size() == 0) cout << 0 << endl;
        else {
            for(int i = 0; i < (int)ans.size() - 1; i++) {
                cout << ans[i] << ' ';
            }
            cout << *ans.rbegin() << endl;
        }
    }
}

Measured memory_bytes: 1196
#[allow(unused_imports)]
use std::{
    i64,
    f64,
    cmp,
    process,
};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };

    (stream = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };

    ($($r:tt)*) => {
        use std::io::*;
        let mut stream = stdin();
        let stream = &mut stream;
        input_inner!{stream, $($r)*}
    };
}

macro_rules! input_inner {
    ($stream:expr) => {};
    ($stream:expr, ) => {};

    ($stream:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($stream, $t);
        input_inner!{$stream $($r)*}
    };
}

macro_rules! read_value {
    ($stream:expr, ( $($t:tt),* )) => {
        ( $(read_value!($stream, $t)),* )
    };

    ($stream:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($stream, $t)).collect::<Vec<_>>()
    };

    ($stream:expr, chars) => {
        read_value!($stream, String).chars().collect::<Vec<char>>()
    };

    ($stream:expr, usize1) => {
        read_value!($stream, usize) - 1
    };

    ($stream:expr, $t:ty) => {
        $stream.by_ref().bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<$t>()
            .expect("Parse error")
    };
}

fn main() {
    input!{n: usize}
    let m = 1 << n;
    input!{s: [i64; m]}
    let mut S = s;
    S.sort();
    let mut S: Vec<Option<i64>> = S.iter().map(|&x| {Some(x)}).collect();
    let mut T: Vec<i64> = vec!{};
    T.push(S.pop().unwrap().unwrap());
    for _ in 0 .. n {
        T.sort();
        let mut U = T.clone();
        let mut idx: usize = S.len();
        while !U.is_empty() && idx > 0 {
            idx -= 1;
            let l = U[U.len() - 1];
            if let Some(s) = S[idx] {
                if s < l {
                    T.push(s);
                    S[idx] = None;
                    U.pop();
                }
            }
        }
        if !U.is_empty() {
            println!("No");
            process::exit(0);
        }
    }

    println!("Yes");
}

Measured memory_bytes: 16636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <limits>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <sstream>
#include <deque>
#include <cmath>

using namespace std;
using ll = long long;

int N, M, X;

int C[1000]{0};
int A[12][12]{0};

int dp_costs[1 << 12]{0};
int dp_understanding[1 << 12][12]{0};

int bestMatching() {
    int bestCost = numeric_limits<int>::max();
    for (int i = 0; i < 1 << N; i++) {
        if (dp_costs[i] >= bestCost) continue;
        for (int m = 0; m < M; m++) {
            if (dp_understanding[i][m] < X) goto next;
        }
        bestCost = dp_costs[i];
        next:;
    }
    if (bestCost == numeric_limits<int>::max()) return -1;
    return bestCost;
}

int firstZeroBit(int n) {
    for (int no = 0; no < 20; no++)
        if ((n & (1 << no)) == 0) return no;
    return -1;
}

int main() {

    cin >> N >> M >> X;

    for (int i = 0; i < N; i++) {
        int c;
        cin >> C[i];
        for (int k = 0; k < M; k++) {
            cin >> A[i][k];
        }
    }

    for (int n = 0; n < N; n++) {
        for (int m = 0; m < M; m++) {
            dp_understanding[(1 << N) - 1][m] += A[n][m];
        }
        dp_costs[(1 << N) - 1] += C[n];
    }

    for (int i = (1 << N) - 2; i > 0; i--) {
        auto firstZero = firstZeroBit(i);
        auto otherIndex = i + (1 << firstZero);
        for (int m = 0; m < M; m++) {
            dp_understanding[i][m] = dp_understanding[otherIndex][m] - A[firstZero][m];
        }
        dp_costs[i] = dp_costs[otherIndex] - C[firstZero];

    }

    cout << bestMatching() << "\n";

    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    int A;
    cin >> A;
    cout << A + A*A+A*A*A << "\n";
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> cnt(100010,0);
    ll sum = 0;
    for (int i = 0;i < n;++i) {
        int a;
        cin >> a;
        sum += a;
        cnt[a]++;
    }
    int q;
    cin >> q;
    while (q--) {
        int b,c;cin >> b >> c;
        sum += (c-b)*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << newl;
    }
}

Measured memory_bytes: 3780
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ABC175
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(" ");
            int[] L = new int[N+1];
            L[0] = 0;
            for(var i =1; i <= N; i++)
            {
                L[i] = int.Parse(input[i-1]);
            }
            Array.Sort(L);
            int cnt = 0;

            for (var i = 1; i <= N-2; i++)
            {
                int a = L[i];
                for (var j = i+1; j <= N-1;j++)
                {
                    int b = L[j];
                    if (a == b) { continue; }
                    for(var k = j+1; k <= N; k++)
                    {
                        int c = L[k];
                        if (b == c) { continue; }
                        if(a+b > c)
                        {
                            cnt++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 27524
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);

    vi c(n);

    rep(i, n) {
        cin >> c[i];
    }

    sort(all(c));

    int pt = 1, bef = c[0], cnt = 1;

    vp cs;

    while (pt < n) {

        if (bef != c[pt]) {
            cs.pb(mp(bef, cnt));
            cnt = 1;
            bef = c[pt++];
        } else {
            cnt++;
            pt++;
        }

    }

    cs.pb(mp(bef, cnt));

    int ret = 0, less = 0;

    rep(i, cs.size()) {
        if (cs[i].second % 2) {
            ret++;
        } else {
            less++;
        }
    }

    cout << ret + less - (less % 2) << endl;

    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
     int n,i;
     long long int sum=0;
    cin >> n;
    for(i=1;i<=n;i++){
        if(i%3==0 || i%5==0)continue;
        sum+=i;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596
a,b,h,m = map(int, input().split())


phi = m * 6

theta = h * 30 + 0.5 * m

import math

apoint = (a*math.cos(math.radians(theta)), a*math.sin(math.radians(theta)))
bpoint = (b*math.cos(math.radians(phi)),   b*math.sin(math.radians(phi)))

#print(theta,phi, apoint, bpoint)

xd = abs(apoint[0] - bpoint[0])
yd = abs(apoint[1] - bpoint[1])

#print(xd, yd)

ans = math.sqrt(math.pow(xd,2) + math.pow(yd,2))

print(ans)


Measured memory_bytes: 9588
#include "bits/stdc++.h"

using namespace std;

enum FACE { TOP = 0, SOUTH = 1, EAST = 2, WEST = 3, NORTH = 4, BOTTOM = 5 };
class Dice {
 public:
  Dice(int top, int south, int east, int west, int north, int bot) {
    id[TOP] = top;
    id[SOUTH] = south;
    id[EAST] = east;
    id[WEST] = west;
    id[NORTH] = north;
    id[BOTTOM] = bot;
  }
  Dice(vector<int> fs) {
    assert((int)fs.size() == 6);
    for (int i = 0; i < 6; i++) {
      id[i] = fs[i];
    }
  }
  int& operator[](FACE f) { return id[f]; }
  const int& operator[](FACE f) const { return id[f]; }
  bool operator==(const Dice& b) const {
    const Dice& a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] && a[SOUTH] == b[SOUTH] &&
           a[NORTH] == b[NORTH] && a[WEST] == b[WEST] && a[EAST] == b[EAST];
  }
  bool operator<(const Dice& b) const {
    auto a = *this;
    return tie(a[TOP], a[SOUTH], a[EAST], a[WEST], a[NORTH], a[BOTTOM]) <
           tie(b[TOP], b[SOUTH], b[EAST], b[WEST], b[NORTH], b[BOTTOM]);
  }
  // TOP -> SOUTH
  void roll_x() { roll(TOP, NORTH, BOTTOM, SOUTH); }
  // TOP -> EAST
  void roll_y() { roll(TOP, WEST, BOTTOM, EAST); }
  // SOUTH -> WEST
  void roll_z() { roll(SOUTH, EAST, NORTH, WEST); }
  vector<Dice> all_rolls() {
    vector<Dice> ret;
    for (int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), ++k)
      for (int i = 0; i < 4; roll_z(), ++i) ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const Dice& di) {
    for (int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), ++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }

 private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    auto tmp = id[a];
    id[a] = id[b];
    id[b] = id[c];
    id[c] = id[d];
    id[d] = tmp;
  }
  int id[6];
};

int main() {
  int n;
  cin >> n;
  vector<Dice> ds;
  for (int i = 0; i < n; i++) {
    vector<int> v(6);
    for (int i = 0; i < 6; i++) cin >> v[i];
    ds.push_back(Dice(v));
  }
  bool f = true;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ds[i].equivalent_to(ds[j])) f = false;
    }
  }
  cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	cin >> N;

	vector <long long> A(N+1);
	vector <long long> B(N);

	for(int i=0; i<N+1; i++) cin >> A[i];
	for(int i=0; i<N; i++)   cin >> B[i];

	long long count = 0;
	for(int i=0; i<N; i++)
	{
		if(B[i] <= A[i])
		{
			count += B[i];
		}
		else
		{
			count += A[i];
			B[i] -= A[i];
			if(B[i] <= A[i+1])
			{
				count += B[i];
				A[i+1] -= B[i];
			}
			else
			{
				count += A[i+1];
				A[i+1] = 0;
			}
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int X,t;
    cin >> X >> t;
    int ans = X - t;
    if(ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int[] aH = new int[10];
        int temp;
        for(int i = 0; i<10; i++){
            aH[i] = s.nextInt();
        }
        
        for(int i = 1; i<10; i++){
            for(int j = i; j>0; j--){
                if(aH[j-1] <aH[j] ){
                    temp = aH[j-1];
                    aH[j-1] = aH[j];
                    aH[j] = temp;
                } else{
                    break;
                }
            }
        }
        
        for(int i = 0; i<3; i++){
            System.out.println(aH[i]);
        }
    }
}

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

using namespace std;

#define int long long
#define M 1000000007

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	string s,t;
	cin >> s >> t;
	int ans=INT_MAX;
	for(int i=0;i<=s.length()-t.length();i++){
		int temp=0;
		int ind=i;
		for(int j=0;j<t.length();ind++,j++){
			if(t[j]!=s[ind]){
				temp++;
			}
		}
		ans=min(temp,ans);
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3644