akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n,k;
	cin>>n>>k;
	ll t[n],d[n],v[100005];
	pair<ll,ll> td[n];
	for(ll i=0;i<n;i++){
		cin>>t[i]>>d[i];
		td[i].first = d[i];
		td[i].second = t[i];
	}
	for(ll i=0;i<100005;i++)v[i]=0;
	sort(td,td+n,greater<pair<ll,ll>>());
	ll tmp=0,res=0,kind_cnt=0;
	for(ll i=0;i<k;i++){
		res += td[i].first;
		v[td[i].second] ++;
		if(v[td[i].second]==1)kind_cnt++;
	}
	res += kind_cnt*kind_cnt;
	//cout<<"RES"<<res<<endl;
	ll cnt=0,sum=res;
	for(ll i=k-1;i>0;i--){
		if(v[td[i].second]>1){
			cnt=-1;
			for(ll j=k;j<n;j++){
				if(v[td[j].second]==0){
					cnt = j;
					break;
				}
			}
			if(cnt==-1LL)break;
			sum -= td[i].first;
			//cout<<"tdi:"<<td[i].first<<"smu:"<<sum<<endl;
			v[td[i].second]--;
			sum+=td[cnt].first;
			//cout<<"tdcnt:"<<td[cnt].first<<"smu:"<<sum<<endl;
			//cout<<"i:"<<i<<"smu:"<<sum<<endl;
			//cout<<cnt<<endl;
			kind_cnt++;
			v[td[cnt].second]++;
			sum += (kind_cnt*kind_cnt - (kind_cnt-1)*(kind_cnt-1));
		}
		res = max(res,sum);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue> 
using namespace std;
const int N=10000001;
int x;
struct node
{
    int d;
    int t;
};
node q[N],tmp;
int main()
{
    cin>>x;
    /*int l=1,r=1;
    q[l]=(node){0,0};
    while(l<=r)
    {
        if(q[l].d==x){cout<<q[l].t;return 0;}
        tmp=q[l];l++;
        q[++r]=(node){tmp.d+(tmp.t+1),tmp.t+1};
        q[++r]=(node){tmp.d,tmp.t+1};
        q[++r]=(node){tmp.d-(tmp.t+1),tmp.t+1};
    }*/
    long long i;
    for(i=1;i<=50000;i++)
        if(i*(i+1)/2>=x)
        {cout<<i;return 0;}
    return 0;
}


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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x;
    if(n<b-1){
        x=n;
    }
    else{
        x=b-1;
    }

    ll ans=a*x/b-a*(x/b);
    cout<<ans<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>

using namespace std;
int n;
int pr[170]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009};
bool prime(int x)
{
	int i;
	for(i=0;pr[i]*pr[i]<=x;i++)
	{
		if(x%pr[i]==0) 
		{
		 return false;
		}
	}
	return true; 
}

int main()
{
    while(cin>>n) {
        if(n==1) {
            printf("0\n");
            continue;
        }
        int ans=1;
        if(n==2) {
            printf("%d\n", ans);
            continue;
        }
        for(int i=3; i<=n; i+=2)
           if(prime(i)) ans++;
        printf("%d\n", ans);
    }
    return 0;
}


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

int main(){
  string s,ans="";
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'&& ans.size()!=0) ans.pop_back();
    else if(s[i]=='0') ans.push_back('0');
    else if(s[i]=='1') ans.push_back('1');
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(2e6)+5;


ll ar[ms];


int main()
{
    idfc;
    int n,m;
    cin>>n>>m;
    int i,j;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    sort(ar+1,ar+n+1);
    int a,b;
    vector<pair<int,int>> vv;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        vv.pb(b,a);
    }
    sort(vv.begin(),vv.end(),greater<>());
    int p=1;
    for(i=0;i<m;i++)
    {
        a=vv[i].first;
        b=vv[i].second;
        while(p<=n&&b--)
        {
            if(a>ar[p])ar[p]=a;
            p++;
        }
        if(p>n)break;
    }
    ll ans=0;
    for(i=1;i<=n;i++)ans+=ar[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5080
if __name__ == '__main__':
    while True:
        N = int(input())
        if N == 0:
            break

        arr = []
        for _ in range(N):
            arr.append(int(input().strip()))
        
        n = sum(arr)
        n -= max(arr) + min(arr)

        print(n // (N - 2))



Measured memory_bytes: 5596
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

a,b =  map(int, sys.stdin.readline().split())

c = (a * b) % 2

if c == 0:
    print('Even')
else:
    print('Odd')



Measured memory_bytes: 5076
N = int(input())
mod = int(1e9) + 7
def doubling(n, m):
    y = 1
    bas = n
    tmp = m
    while tmp:
        if tmp % 2:
            y *= bas
            y %= mod
        bas *= bas
        bas %= mod
        tmp >>= 1
    return y
d10 = doubling(10, N)
d9 = doubling(9, N)
d8 = doubling(8, N)
print((d10 - 2*d9 + d8) % mod)

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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}


int main(){

	string s;
	int ans, last;
	cin >> s;
	ans = s.length();
	last = s[0];

	for (int i = 1; i < s.length(); i++) {
		if (s[i] != last) {
			int t = s.size();
			ans = min(ans, max(i, t - i));
			last = s[i];
		}
	}

	pr(ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
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;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[30][51000];

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    ll dp[n+1];
    fill(dp,dp+n,INF);
    for (ll i=0;i<n;i++){
        *lower_bound(dp,dp+n,a[i])=a[i];
    }
    cout << lower_bound(dp,dp+n,INF)-dp << endl;
    return 0;

}


Measured memory_bytes: 4644
#include <stdio.h>
int main(void){
  int n,i,j,ans=0;
  scanf("%d",&n);
  int d[n];
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      ans=ans+d[i]*d[j];
    }
  }
  printf("%d",ans);
}

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

int main() {
  int N, m;
  cin >> N;
  m = N % 10;
  
  if(m == 2 || m == 4 || m == 5 || m == 7 || m == 9) {
    cout << "hon" << endl;
  }
  else if(m == 0 || m == 1 || m == 6 || m == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "bon" << endl;
  }
}

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

int main() {
	int length;
	cin >> length;
	
	long sum=0;
	int max, min;
	
	for(int i=0; i<length; i++){
		int num;
		cin >> num;
		
		sum+=num;
		
		if(i==0){max=num; min=num;}
		else{
		if(num>max){max=num;}
		if(num<min){min=num;}
		}
		
	}
	
	cout << min << " " << max << " " << sum << endl;
	return 0;
}

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

int main(){
    int ans=0,app=0;
    int n,q;
    int l,r;
    cin >> n >> q;
    int data[n];
    string s;
    cin >> s;

    for (int i = 0; i < n-1; i++){
        
        if(s[i]=='A' && s[i+1]=='C'){
            data[i]=app;
            data[i+1] = ++app;
        }else{
            data[i]=app;
            data[i+1]=app;
        }
    }

    for (int i = 0; i < q; i++){
        cin >>l>>r;
        --l;--r;

        cout << data[r]-data[l] << '\n';
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n,m;
        cin >> n>> m;
        vector<vector<int>> vec(m);
        for(int i = 0; i< m; i++)
        {
               int k;
               cin >>k;
               vec[i].resize(k);
               for(int j =0;j< k;j++)
               {
                       cin >> vec[i][j];
                       vec[i][j]--;
               }
        }
        vector<int>p(m);
        for(int i=0; i< m;i++)
        {
                cin >> p[i];
        }
        int ans = 0;
        for(int i =0; i<(1<<n);i++)
        {
                bool ok = true;
                for(int j=0;j< m;j++)
                {
                        int c= 0;
                        for(int id:vec[j])
                        {
                                if((i>>id)&1){c++;}
                        }
                        c%=2;
                        if(c!=p[j])
                        {
                                ok=false;
                        }

                }
                if(ok)
                {
                        ans++;
                }       

        }

        cout<< ans<< endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
int main() {
	 int N, T, A;
	 cin >> N >> T >> A;

	 double dT = 100000000000.0;
	 int minIndex = -1;

	 for (int i = 1; i <= N; i++) {
	 	int H;
	 	cin >> H;
	 	double cT = T - H * 0.006;

	 	double curdT = fabs(cT - A); 
	 	if (curdT < dT) {
	 		minIndex = i;
	 		dT = curdT;
	 	}
	 }

	 cout << minIndex << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;


const int mod = 100000007;
const int inf = 100000005;
const int N = 3e5, M = N;
ll i,j,n,m;


void solve() {
   ll n,m,k;
   cin>>n>>m>>k;

   ll x;
   vl a,b;
   a.pb(0);
   b.pb(0);

   fo(i,0,n) cin>>x,a.pb(a.back()+x);
   fo(i,0,m) cin>>x,b.pb(b.back()+x);

   int j = m;
   ll ans = 0;
   fo(i,0,n+1) {
    while(j>=0 && b[j]+a[i] > k) j--;
    if(b[j] + a[i] <= k) ans = max(ans , i + j);
   }

   cout<<ans<<"\n";

}


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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 7944
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int H,W;cin>>H>>W;
    vector<string> S(H);
    REP(i,H) cin>>S[i];
    int L[2002][2002]={},R[2002][2002]={},U[2002][2002]={},D[2002][2002]={};
    REP(i,H) REP(j,W){
        if(S[i][j]=='#'){
            L[i+1][j+1]=0;
            U[i+1][j+1]=0;
        }
        else{
            L[i+1][j+1]=L[i+1][j]+1;
            U[i+1][j+1]=U[i][j+1]+1;
        }
    }
    int ans=0;
    REP(i,H) REP(j,W){
        int x=H-i,y=W-j;
        if(S[H-i-1][W-j-1]=='#'){
            R[x][y]=0;
            D[x][y]=0;
        }
        else{
            R[x][y]=R[x][y+1]+1;
            D[x][y]=D[x+1][y]+1;
        }
        ans=max(ans,L[x][y]+R[x][y]+U[x][y]+D[x][y]-3);
    }
    cout<<ans<<endl;
}

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

int main(void){
      int n;
      cin >> n;
      vector<string> s(n);
      for(int i = 0;i < n;i++){
            cin >> s[i];
      }
      bool f = true;
      for(int i = 1;i < n;i++){
            if(s[i][0] != s[i - 1][s[i - 1].size() - 1]){
                  f = false;
            }
            for(int j = 0;j < i;j++){
                  if(s[j] == s[i]){
                        f = false;
                  }
            }
      }
      
      cout << ((f) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dp[200200][3] = {0};
int table[200200][3];

signed main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    int k = x + y;
    vector<int> red(a), green(b), none(c);
    for (int i = 0; i < a; i++)
    {
        cin >> red[i];
    }
    sort(red.rbegin(), red.rend());
    for (int i = 0; i < b; i++)
    {
        cin >> green[i];
    }
    sort(green.rbegin(), green.rend());
    for (int i = 0; i < c; i++)
    {
        cin >> none[i];
    }
    sort(none.rbegin(), none.rend());
    red.resize(x);
    green.resize(y);
    vector<int> anss;
    for (int i = 0; i < x; i++)
    {
        anss.push_back(red[i]);
    }
    for (int i = 0; i < y; i++)
    {
        anss.push_back(green[i]);
    }
    for (int i = 0; i < c; i++)
    {
        anss.push_back(none[i]);
    }
    sort(anss.rbegin(), anss.rend());
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += anss[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 8688
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int sum = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0)sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std; 
long long n,a,ans,f,x=1e9+7; 
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) 
	{
		cin>>a;
		if(a<=0) f++;
		ans+=abs(a);
		x=min(x,abs(a));
	}
	if(f%2==0) cout<<ans;
	else cout<<ans-x*2;
	return 0;
}

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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e3 + 5;
bool isPrime[MAXN];

void sevie() {
    memset(isPrime, 1, sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for (ll i = 2; i * i <= MAXN; i++) {
        if (isPrime[i]) {
            for (ll j = i * 2; j <= MAXN; j += i) {
                isPrime[j] = 0;

            }
        }
    }
}

ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
bool isPrim(int n) {
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}

int n, m;
char arr[100][100];
bool vis[100][100];
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
int mx = 0;

int main() {
    FAST
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> arr[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (arr[i][j] == '.') {
                queue<pair<pair<int, int>, int>> q;
                q.push({{i, j}, 0});
                while (!q.empty()) {
                    int x = q.front().first.first;
                    int y = q.front().first.second;
                    int dis = q.front().second;
                    q.pop();
                    if (vis[x][y])
                        continue;
                    vis[x][y] = 1;
                    for (int k = 0; k < 4; k++) {
                        if (x + xx[k] >= 1 && x + xx[k] <= n && y + yy[k] >= 1 && y + yy[k] <= m &&
                            arr[x + xx[k]][y + yy[k]] == '.') {
                            mx = max(mx, dis);
                            q.push({{x + xx[k], y + yy[k]}, dis + 1});
                        }
                    }
                }
                memset(vis, 0, sizeof(vis));
            }
        }
    }
    cout << mx << endl;


    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,mini=100000000000;
    string s;
    cin>>n>>s;
    vector<ll> w(n+1),e(n+1);
    w[0]=0;
    e[0]=0;
    rep(i,n){
        if(s[i]=='W'){
            w[i+1]=w[i]+1;
            e[i+1]=e[i];
        }else if(s[i]=='E'){
            e[i+1]=e[i]+1;
            w[i+1]=w[i];
        }
    }
    rrep(i,n){
        mini=min(mini,w[i-1] + e[n]-e[i]);
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 5396
from itertools import product

N, M = map(int, input().split())
d = {}
for i in range(M):
    k, *s, = map(int, input().split())
    d[i] = s
    
*p, = map(int, input().split())

ans = 0
for k in product(range(2), repeat=N):
    a = 0
    for i, m in d.items():
        v = 0
        for j in m:
            v += k[j-1]
        if v%2 == p[i]:
            a += 1
    if a==M:
        ans += 1

print(ans)

Measured memory_bytes: 3188
/******************************************************************************

рассвет.

*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int>
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s)
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;

const lli MOD=1e9+7;
const lli MAXN=5e4+1;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("bridges.in", "r", stdin);
    //freopen("bridges.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        int ans=0;
        fr(i,n){
            read(x);
            if(i%2==0 && x%2==1) ++ans;
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3644
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		
		Set<Character> set = new HashSet<>();
		for (int i = 0; i < s.length; i++) {
			set.add(s[i]);
		}
		
		String ans = set.size() == s.length ? "yes" : "no";
		System.out.println(ans);
		
		sc.close();
	}
}




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

int n,k; string s;

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

    cin >> n >> k >> s;
    for(int i=0;i<n;i++){
        if(i+1 == k)s[i] = tolower(s[i]);
        cout << s[i];
    }cout << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 510000 
using namespace std;//10 32 -1


inline int read()
{
	int ret=0,f=1; char c=getchar();
	while(c<48||c>57)
	{
		if(c=='-')f=-1;
	    c=getchar();
	}
	while(c>=48&&c<=57)ret=ret*10+c-48,c=getchar();
	return f*ret;
}
long long u,v,d,di[N],mi,ma,a[N],tot,vi[N],m,n,c[N][3];
//int// ///ll=int //int =ll/////cout
void dfs(int p)
{
	for(int o=a[p]; o; o=c[o][1]){
		if(vi[c[o][0]]){
			if(di[c[o][0]]-di[p]!=c[o][2])
			{
				puts("No");
				exit(0); //return 0  //fl //_
			}
			continue;
		}
		vi[c[o][0]]=1;
		di[c[o][0]]=di[p]+c[o][2];
		ma=max(di[c[o][0]],ma);
		mi=min(di[c[o][0]],mi);
		dfs(c[o][0]);
	} 
} 

int main()
{
	n=read();
	m=read();
	for(int i=1; i<=m; ++i){
		u=read(); v=read(); d=read();
		c[++tot][0]=v;
		c[tot][1]=a[u];
		a[u]=tot;
		c[tot][2]=d;
		c[++tot][0]=u;
		c[tot][1]=a[v];
		a[v]=tot;
		c[tot][2]=-d;
	}
	for(int i=1; i<=n; ++i)if(!vi[i])
	{
    	di[i]=0,ma=mi=0,dfs(i);
    	if(ma-mi>1000000000)
    	{
    		puts("No");
    		exit(0);
//    		return 0;
		}
	}  
	puts("Yes");
}

Measured memory_bytes: 24576
# -*- coding: utf-8 -*-
"""
B - NarrowRectanglesEasy
https://atcoder.jp/contests/abc056/tasks/abc056_b

"""
import sys


def solve(W, a, b):
    if a > b:
        a, b, = b, a
    return max(0, b-(a+W))


def main(args):
    W, a, b = map(int, input().split())
    ans = solve(W, a, b)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }





int main() {
  int N;
  cin >> N;
  int AC = 0, WA = 0, TLE = 0, RE = 0;

  rep(i,0,N){
    string s;
    cin >> s;
    if(s == "AC") AC++;
    else if(s == "WA") WA++;
    else if(s == "TLE") TLE++;
    else
    {
      RE++;
    }
    
  }

  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 3628
import sys
class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x:
        y = x
        if key < x.key:
            x = x.left
        else:
            x = x.right

    if y is None:
        root = Node(key)
    elif key < y.key:
        y.left = Node(key)
    else:
        y.right = Node(key)

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

n = int(input())
for e in sys.stdin:
    if e[0] == 'i':
        insert(int(e[7:]))
    else:
        print(inorder(root))
        print(preorder(root))


Measured memory_bytes: 63544
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
using namespace std;

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

    int n;
    cin >> n;
    
    int ans = 0;
    REP(i, n){
        int a,b;
        cin >> a >> b;

        ans += (b-a+1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
int GCD (int a, int b) { return b ? GCD(b, a % b) : a; }

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    vector<int> left(N+1, 0);
    vector<int>right(N+1, 0);
    for (int i = 0; i < N; i++) {
        left[i+1] = GCD(left[i], v[i]);
    }
    for (int i = N-1; i >= 0; i--) {
        right[i] = GCD(right[i+1], v[i]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int l = left[i];
        int r = right[i+1];
        chmax(ans, GCD(l, r));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,i,j,sum,flg=0,cnt=0,c=1000000000000000000;
  cin>>n;
  ll ar[n+1];
  for(i=0;i<n;i++)
  {
      cin>>ar[i];
      if(ar[i]==0)
        cnt=1;
  }
  sum=ar[0];
  if(cnt==1)
    cout<<0<<endl;
  else
  {
      for(i=1;i<n;i++)
      {
          if(ar[i]<=c/sum)
            sum=sum*ar[i];
          else
          {
              flg=1;
              break;
          }
      }
      if(flg==1)
        cout<<-1<<endl;
      else
        cout<<sum<<endl;
  }

}


Measured memory_bytes: 4368
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define fori(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };



int main()
{
	int n, p;
	cin >> n >> p;
	while (n != 0 || p != 0)
	{
		int ss[100] = {};
		int k = p;
		bool owari = true;
		while (owari)
		{
			for (int i = 0; i < n; i++)
			{
				if (k == 0)
				{
					k += ss[i];
					ss[i] = 0;
				}
				else
				{
					k--;
					ss[i]++;
					if (k == 0)
					{
						bool en = false;
						for (int l = 0; l < n; l++)
						{
							if (l == i)continue;
							if (ss[l] != 0)en = true;
						}
						if (en == false)
						{
							cout << i << endl;
							owari = false;
							break;
						}
					}
				}
			}
		}





		cin >> n >> p;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;

int gcd(int a, int b)
{
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}


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

	int n, i, j, k, ans = 0, g;

	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			g = gcd(i, j);
			for (k = 1; k <= n; k++) ans += gcd(g, k);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3652
ans=10000
i=0

n=int(input())
ls=list(map(int,input().split()))

ls.append(-1)

while ls[i]!=-1:
    ls.pop(-1)
    an=0
    for j in range(i):
        an+=ls[j]
    a=sum(ls)
    ann=a-an*2
    ann=abs(ann)
    if ann<ans:
        ans=ann
    i+=1
    ls.append(-1)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int a,b,c;
int x,y;

int main(){
    cin >> a >> b >> c >> x >> y;

    int res = a * x + b * y;

    if(x >= y){
        res = min(res , c * y * 2 + a * (x - y));
    }
    else{
        res = min(res , c * x * 2 + b * (y - x));
    }

    res = min(res , c * max(x,y) * 2);
    cout << res << endl;

}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

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

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll a, b;
    cin >> a >> b;
    FOR(i, 10000)
    {
        if (i * 8 / 100 == a && i / 10 == b)
        {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}



Measured memory_bytes: 256
#include <cstdio>

#define SWAP(a,b) (a += b,b = a - b,a -= b)

int gcd(int a, int b){
    if(b<a)SWAP(a,b);
    int tmp;
    while(a!=0){
        tmp = b%a;
        b = a;
        a = tmp;
    }
    return b;
}

int main(void){
    int i,n;
    int a[100000];
    int gcd_array[100000];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",a+i);
    }

    gcd_array[0] = 0;
    int tmp = 0;
    for(i=1;i<n;i++){
        tmp = gcd(tmp,a[i-1]);
        gcd_array[i] = tmp;
    }

    tmp = 0;
    for(i=n-2;i>=0;i--){
        tmp = gcd(tmp,a[i+1]);
        gcd_array[i] = gcd(tmp,gcd_array[i]);
    }

    int max = gcd_array[0];
    for(i=1;i<n;i++){
        if(gcd_array[i]>max)max = gcd_array[i];
    }

    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}



void solve()
{
	int n, m;
	cin >> n >> m;
	bool good = 0;
	map<pii, bool> z;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		if(x > y) swap(x, y);
		if(x == 1 && z.count({y, n})) good = 1;
		if(y == n && z.count({1, x})) good = 1;
		z[{x, y}] = 1;
	}
	if(!good) cout << "IM";
	cout << "POSSIBLE";

}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 16160
#include <iostream>

using namespace std;

int N, A, mx;
int x[55];
long long dp[55][55][3000];

void solve() {
    for(int s = 0; s <= N*mx; s++) {
        for(int k = 0; k <= N; k++) {
            for(int j = 0; j <= N; j++) {
                if(j == 0 && s == 0 && k == 0 ) dp[j][k][s] = 1;
                else if(j >= 1 && s < x[j]) dp[j][k][s] = dp[j-1][k][s];
                else if(j >= 1 && k >= 1 && s >= x[j]) {
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
                }
                else dp[j][k][s] = 0;
            }
        }
    }
    long long sum = 0;
    for(int i = 1; i <= N; i++) sum += dp[N][i][i*A];
    cout << sum << endl; 
}

int main() {
    cin >> N >> A;
    mx = A;
    for(int i = 1; i <= N; i++) {
        cin >> x[i];
        mx = max(x[i], mx);
    }

    solve();
}

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

int main () {
  int N, K;
  int l[60];
  cin >> N >> K;
  for (int i = 0; i < N; ++i) cin >> l[i];

  sort(l, l + N, greater<int>());
  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
	int t;
	cin>>t;
	vector<int>v(t);
	for(int i=0;i<t;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	double sum=v[0];
	for(int i=1;i<t;i++){
		sum=(sum+v[i])/2;
	}
	printf("%.5f\n",sum);
	return 0;
}

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

using lint=long long;

lint get(lint l,lint r){ return r-l+1; }

int main()
{
   lint A,B; cin>>A>>B;
   if(A==B){ cout<<1<<endl; return 0; }

   const int LOG=60;
   lint X=0,Y=0;
   for(int i=LOG-1;i>=0;i--){
      if((A>>i&1)==(B>>i&1)){
         if(A>>i&1){
            A-=1LL<<i;
            B-=1LL<<i;
         }
      }else{
         X=Y=1LL<<i;
         bool flag=false;
         for(int j=i-1;j>=0;j--){
            if(B>>j&1) flag=true;
            if(flag) Y|=1LL<<j;
         }
         break;
      }
   }
   lint ans=get(A,X-1)+get(X,Y)+get(X+A,2*X-1);
   if(X+A<=Y) ans-=get(X+A,Y);
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
# coding: utf-8

N = int(input())
hi = [int(h) for h in input().split()]

def divide(l):
    div = []
    d = []
    for h in l:
        if (h == 0):
            div.append(d)
            d = []
        else:
            d.append(h)
    div.append(d)
    return div

def watering(l, n):
    div = divide(l)
    cnt = n
    for d in div:
        if not d:
            continue
        else:
            watered = [i - 1 for i in d]
            cnt += 1
            cnt = watering(watered, cnt)
    return cnt
    
print(watering(hi, 0))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


void solve()
{
    ll x;
    cin>>x;
    ll n=100;
    ll ans=0;
    while(n<x)
    {
        n+=(n/100);
        ans++;
    }
    cout<<ans<<"\n";

  
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;  // 从头结点后面的元素开始访问
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while ( 1 ) {
        if ( cur == nil ) break;
        if ( isf++ > 0 ) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if ( t == nil ) return;  // t为头结点时不做处理
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    // 删除搜索到的结点
    deleteNode(listSearch(key));
} 

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    // 在头结点后添加元素
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ) {
        scanf("%s%d", com, &key);
        if ( com[0] == 'i' ) { insert(key); np++; size++; }
        else if ( com[0] == 'd' ) {
            if ( strlen(com) > 6 ) {
                if ( com[6] == 'F' ) deleteFirst();
                else if ( com[6] == 'L' ) deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    
    printList();
    
    return 0;
}




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

#define ll long long

int main() {
	ll out, tkhs = 0, aok = 0;
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	vector<pair<int, int>> s(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i) >> b.at(i);
		s.at(i).first = a.at(i) + b.at(i);
		s.at(i).second = i;
	}

	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		if (i & 1)
			aok += b.at(s.at(n - 1 - i).second);
		else
			tkhs += a.at(s.at(n - 1 - i).second);
	}
	out = tkhs - aok;
	cout << out << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){
    int h,w;cin>>h>>w;
    fore(i,0,w+2){
        cout<<"#";
    }
    cout<<"\n";

    fore(i,0,h){
        string pixels;cin>>pixels;
        cout<<"#";
        cout<<pixels;
        cout<<"#\n";
    }

    fore(i,0,w+2){
        cout<<"#";
    }
    
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
a = []
b = []
c = []
N.times{|i|
    a[i], b[i], c[i] = gets.split(" ").map(&:to_i)
}
dp = Array.new(1, Array.new(3, 0))
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
(1...N).each{|i|
    ar = []
    ar[0] = [dp[i-1][1], dp[i-1][2]].max + a[i]
    ar[1] = [dp[i-1][0], dp[i-1][2]].max + b[i]
    ar[2] = [dp[i-1][0], dp[i-1][1]].max + c[i]
    dp.push(ar)
}
puts [dp[N-1][0], dp[N-1][1], dp[N-1][2]].max

Measured memory_bytes: 11948
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
ll dp[3001][3001];
ll  solve(int i,int j,ll a[]){
	if(i==j)
		return dp[i][j]=a[i];
	else if(j==i+1)
		return dp[i][j]=max(a[i],a[j]);
	else if(dp[i][j]!=0)
		return dp[i][j];
	return dp[i][j]=max(a[i]+min(solve(i+2,j,a),solve(i+1,j-1,a)),a[j]+min(solve(i,j-2,a),solve(i+1,j-1,a)));	
}
int main(){
	for(int i=0;i<101;i++)
	for(int j=0;j<101;j++)dp[i][j]=0;
	int n;
	cin>>n;
	ll a[n];
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll mx=solve(0,n-1,a);
	ll ans=2*mx-sum;
	cout<<ans<<endl;
}



Measured memory_bytes: 49844
#![allow(unused_imports, unused_variables, dead_code)]

use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;
use std::io::Write;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readvec<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readlines<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn idx(a: u8) -> usize {
    a as usize - 'A' as usize
}

fn main() {
    let n: usize = read();
    let s: Vec<String> = readlines(n);

    let mut v: Vec<u64> = vec![0; 26];
    for si in s {
        let a = si.into_bytes()[0];
        v[idx(a)] += 1;
    }

    let march = "MARCH".to_string().into_bytes();
    let mut sum: u64 = 0;
    for i in 0..5 {
        for j in i+1..5 {
            for k in j+1..5 {
                let ii = idx(march[i]);
                let jj = idx(march[j]);
                let kk = idx(march[k]);
                sum += v[ii] * v[jj] * v[kk];
            }
        }
    }
    println!("{}", sum);
}

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

int main(){
    string s;
    cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        int tmp = (int)(s[0] - '0');
        char op[3];
        for(int i=0; i<3; i++){
            if(bit & (1<<i)){
                tmp += (int)(s[i+1] - '0');
                op[i] = '+';
            }
            else{
                tmp -= (int)(s[i+1] - '0');
                op[i] = '-';
            }
        }
        if(tmp == 7){
            cout << s[0];
            for(int i=0; i<3; i++) cout << op[i] << s[i+1];
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
debug = False

def main():
    N = int(input())
    S = list(input())

    tmpCnt=S.count('E')
    if S[0]=='E':
        tmpCnt-=1

    minCnt=tmpCnt

    for i in range(1,N):
        if S[i]=='E':
            tmpCnt-=1
        if S[i-1]=='W':
            tmpCnt+=1
        minCnt=min(minCnt,tmpCnt)
        if debug:
            print(i,S[i],tmpCnt,minCnt)
        
    print(minCnt)
    return

if __name__ == "__main__":
    main()



Measured memory_bytes: 5792
#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>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll x = c-a-b;
    if(x < 0){
        puts("No");
        return 0;
    }
    if(4*a*b < x*x){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}
 



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    string S;cin>>S;
    int N=S.size();
    vector<vector<int>> next(N+1,vector<int>(26,-1));//i番目の次のアルファベットの位置(1-indexed)
    vector<int> canto(N+1,-1);
    for(int i=1;i<=N;i++){
        for(int j=i-1;j>=0;j--){
            if(next[j][S[i-1]-'a']!=-1) break;
            next[j][S[i-1]-'a']=i;
        }
    }
    
    for(int i=N;i>=0;i--){
        bool end=false;
        for(int j=0;j<26;j++){
            if(next[i][j]==-1) end=true;
        }
        if(end) canto[i]=0;
        else{
            int maxi=INF;
            for(int j=0;j<26;j++){
                maxi=min(maxi,canto[next[i][j]]);
            }
            canto[i]=maxi+1;
        }
    }
    
    int length=canto[0]+1,now=0;
    string T;
    
    for(int k=0;k<length;k++){
        int hozon=now;
        
        if(k==length-1){
            for(int j=0;j<26;j++){
                if(next[now][j]==-1){
                    T+=('a'+j);
                    cout<<T<<endl;
                    return 0;
                }
            }
        }
        
        for(int j=0;j<26;j++){
            now=next[now][j];
            if(canto[now]+k>=length-1){
                now=hozon;
                continue;
            }
            T+=('a'+j);
            break;
        }
    }
}



Measured memory_bytes: 27780