akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
inline int gi() { 
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 1e5 + 5; 
int N, L, a[MAX_N], f[17][MAX_N]; 

int main () { 
	N = gi(); for (int i = 1; i <= N; i++) a[i] = gi();
	L = gi(); 
	for (int i = 1; i <= N; i++) f[0][i] = upper_bound(&a[i + 1], &a[N + 1], a[i] + L) - a - 1; 
	for (int i = 1; i < 17; i++) 
		for (int j = 1; j <= N; j++) f[i][j] = f[i - 1][f[i - 1][j]]; 
	int Q = gi(); 
	while (Q--) { 
		int l = gi(), r = gi(); 
		if (l > r) swap(l, r); 
		int ans = 0; 
		for (int i = 16; ~i; i--) if (f[i][l] < r) l = f[i][l], ans |= (1 << i); 
		printf("%d\n", ans + 1); 
	} 
    return 0; 
} 

Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
char table(char a){
  string x = "({[]})";
  for(int i = 0 ; i < 6 ; ++i){
    if( a == x[i]) return x[5-i];
  }
  return a;
}
bool same(int a,int b){
  return b == table(a);
}
int Maxcnt(int l,int r){
  int rec = 0;
  for(int i = l ; s[i] != 'i' ; ++i ){
    for(int j = r ; s[j] != 'i' ; --j ){
      if(same(s[i],s[j])) rec = max(rec,Maxcnt(i+1,j-1)+2);
    }
  }
  return rec;
}
int main(){
  cin >> s;
  cout << Maxcnt(0,s.size()-1) + 3 << endl;
}

Measured memory_bytes: 1188
N,K= map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -1000000000

for i in range(N):
    S = []
    j = P[i]-1
    S.append(C[j])

    while i != j:
        j = P[j]-1
        S.append(S[-1] + C[j])

    if K <= len(S):
        score = max(S[:K])

    elif S[-1] <= 0:
        score = max(S)
    
    else:
        score1 = K//len(S) * S[-1]
        r = K%len(S)
        if r != 0:
            score1 += max(0, max(S[:r]))
        score2 = (K//len(S)-1)*S[-1] + max(S)
        score = max(score1, score2)
    ans = max(ans, score)
print(ans)

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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int x,y;
  cin >> x >> y;
  int a[] = {0,1,2,1,3,1,3,1,1,3,1,3,1};

  if(a[x] == a[y]){
    printf("Yes\n");
  }
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
S=input()
A='abcdefghijklmnopqrstuvwxyz'
N=len(S)

ans='-1'
if N<26:
    for a in A:
        if a not in S:
            ans=S+a
            break
else:
    rs=S[::-1]
    i=1
    while i<26:
        srt=sorted(rs[:i+1])
        if srt[-1]!=rs[i]:
            ans=rs[i+1:][::-1]+srt[srt.index(rs[i])+1]
            break
        i+=1

print(ans)

Measured memory_bytes: 9148
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main() {
  int a,b,c; cin>>a>>b>>c;
  if ((10*b+c)%4==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    ans=1
    N=I()
    for i in range(10):
        ans*=2
        if ans>N:
            break
    print(ans//2)

main()


Measured memory_bytes: 38384
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int solve() {
    cins(s);
    if(s=="SUN")
        return 7;
    else if(s=="MON")
        return 6;
    else if(s=="TUE")
        return 5;
    else if(s=="WED")
        return 4;
    else if(s=="THU")
        return 3;
    else if(s=="FRI")
        return 2;
    else if(s=="SAT")
        return 1;

    assert(false);

}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int t=1;
    while(t--) {
        int ans=solve();
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    c = [str(input().rstrip('\n')) for _ in range(h)]
    for i in range(h):
        print(c[i])
        print(c[i])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

lint gcd(lint p, lint q){
    if(p < q) swap(p, q);
    while(q){
        lint r = p % q;
        p = q;
        q = r;
    }
    return p;
}

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


const int MAX = 1000010;
bool sieve[MAX];

void getsieve(){
    rep(i, MAX) sieve[i] = true;
    for(int i=2; i<MAX; ++i)if(sieve[i]){
            for(int j=i*2; j<MAX; j+=i) sieve[j] = false;
        }
    return;
}

lint getdiv(lint n){
    lint ret = 0;
    for(lint i=1; i*i<=n; ++i){
        if(n % i == 0){
            if((i < MAX && sieve[i]) || is_prime(i)) ++ret;
            if(i*i != n){
                lint t = n / i;
                if((t < MAX && sieve[t]) || is_prime(t)) ++ret;
            }
        }
    }
    return ret;
}

int main(){
    lint a, b;
    scanf("%lld%lld", &a, &b);
    lint g = gcd(a, b);
    getsieve();
    printf("%d\n", getdiv(g));
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n,k;
  cin >> n >> k;
  ll a[n];
  ll s[n+1];

  rep(i,n){
    cin >> a[i];
  }
  s[0]=0;
  rep(i,n){
    s[i+1] = s[i] + a[i];
    s[i+1] %=k;
  }
  ll ans=0;
  //  multiset<ll> cou;
  map<ll, ll> cou;
    rep(i,n+1){
    s[i] -= (i%k);
    s[i] = (s[i]+k)%k;
    if(i-k>=0){
      --cou[s[i-k]];
    }
    ans += cou[s[i]];
    cou[s[i]]++;
    //    cout << "sum ans " << s[i] << " " << ans << endl;    
  }
  
  cout << ans << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 15872
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

prev = -99
ans = 0
for i in range(n):
  ans += b[a[i]-1]
  if a[i]-1 == prev:
    ans += c[a[i]-2]
  prev = a[i]

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  int l,m,f,i,ans=0;
  cin>>n;
  l=n.length();
  f=0;
  for(i=l-1;i>=0;i--){
    m=n.at(i)-'0'+f;
    if(m<=4){
      ans+=m;
      f=0;
    }
    else if(6<=m){
      ans+=10-m;
      f=1;
    }
    else if(m==5){
      if(i>0 && n.at(i-1)-'0'>=5){
        ans+=10-m;
        f=1;
      }
      else{
        ans+=m;
        f=0;
      }
    }
  }
  ans+=f;
  cout<<ans<<endl;
}

Measured memory_bytes: 1412
# D

N = int(input())

d = [0] * (10**6 + 1) 

for a in map(int, input().split()):
  d[a] += 1

ans = 0

for i in range(1,10**6+1):
  if d[i] == 1:
    ans += 1

  if d[i] > 0:
    # d[i]の倍数は含めない
    for j in range(i*2,10**6+1,i):
      d[j] = 0

print(ans)



Measured memory_bytes: 32516
<?php
fscanf(STDIN, "%d%d%d%d", $a, $b, $c, $d);
fscanf(STDIN, "%d", $n);
$c = min($a*4, $b*2, $c);
$d = min($c*2, $d);
printf("%d", ($n%2)*$c+intdiv($n,2)*$d);


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr first
#define sc second
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=3e5+10;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    for (char a='a';a<='z';a++){
        if (s.find(a)==-1)
        {
            cout<<a<<endl;
            return 0;
        }
    }
    cout<<"None\n";
    return 0;
}


Measured memory_bytes: 512
let min_with f x y = if f x <= f y then x else y
 
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let ai = Array.fold_left max min_int as_ in
  let aj = Array.fold_left (min_with (fun a ->
    if a = ai then max_int
    else if ai mod 2 = 0 then abs (a - ai / 2)
    else if a <= ai / 2 then ai / 2 - a
    else a - (ai + 1) / 2)) ai as_ in
  Printf.printf "%d %d\n" ai aj

Measured memory_bytes: 5248
def f(s):
  u = 0
  for c in s:
    if c.isupper():
      u += 1
  return u == 1
s = input()
if s[0] == 'A' and s[2:-1].count('C') == 1 and f(s[1:]):
  print('AC')
else:
  print('WA')


Measured memory_bytes: 2940
n,p = map(int,input().split())
A = list(map(int,input().split()))
A = [_ % 2 for _ in A ]
k = A.count(1)
if k == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))


Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
struct temp
{
    int xian,id,year;
    temp(int x=0,int y=0,int z=0) {xian=x;id=y;year=z;}
}a[100000+5];
bool cmp(temp a,temp b){
    if(a.xian!=b.xian)
        return a.xian<b.xian;
    else
       return a.year<b.year;
}
pair<int,int> p[100000+5];
int n,m;
int t1,t2;
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&t1,&t2);
        a[i].id=i;
        a[i].xian=t1;
        a[i].year=t2;
    }
    sort(a+1,a+m+1,cmp);
    int no=0;
    for(int i=1;i<=m;i++){
        if(i>1&&a[i].xian!=a[i-1].xian)
            no=1;
        else
            no++;
        p[a[i].id]=make_pair(a[i].xian,no);
    }
    for(int i=1;i<=m;i++)
        printf("%06d%06d\n",p[i].first,p[i].second);

}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

ll mod=1e8+7;
ll dp[100100];
ll dp1[100100];

int main(){
	for(int i=1;i<=6;i++){
		dp[i]=pow(2,i-1);
	}
	for(int i=7;i<=100000;i++){
		(dp[i]+=dp[i-1]+dp[i-2]+dp[i-3]+dp[i-4]+dp[i-5]+1)%=mod;
	}
	for(int i=1;i<=4;i++){
		dp1[i]=pow(2,i-1);
	}
	for(int i=5;i<=100000;i++){
		(dp1[i]+=dp1[i-1]+dp1[i-2]+dp1[i-3]+1)%=mod;
	}
	while(1){
		string s; cin >> s;
		if(s=="#")break;
		int n=s.size();
		ll ans=1;
		for(int i=0;i<n;i++){
			char c=s[i];
			int cnt=0;
			while(i<n&&s[i]==c){
				i++;
				cnt++;
			}
			i--;
			if(c=='8'||c=='0')(ans*=dp1[cnt])%=mod;
			else (ans*=dp[cnt])%=mod;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 5040
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n, d;
	cin >> n >> d;
	int x = d * 2 + 1;
	if (n % x == 0) cout << n / x;
	else cout << n / x + 1;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(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;}
const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    set<ll> s;
    s.insert(A);
    s.insert(B);
    s.insert(C);
    cout<<(s.size()==2?YES:NO)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    S = input()
    print("Yes" if S.startswith("YAKI") else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include<cstdio>

struct card
{
    int value;
    char name;
    int num;
    int sc;
};

int i,j;
card a[120],b[120];

void bubblesort(int n)
{
   for(i=0;i<n;i++)
    for(j=n-1;j>=i+1;j--)
   {
       if(a[j-1].value>a[j].value)
       {
           card temp;
           temp=a[j-1];
           a[j-1]=a[j];
           a[j]=temp;
       }
   }
}

void selectionSort(int n)
{
    int m;
    for(i=0;i<n;i++)
    {
        m=i;
        for(j=i;j<n;j++) if(b[j].value<b[m].value) m=j;
        if(m!=i){
           card temp;
           temp=b[m];
           b[m]=b[i];
           b[i]=temp;
        }
    }
}

int main()
{
    int n;

    while(~scanf("%d",&n))
    {
        getchar();
        for(i=0;i<n;i++)
        {
            a[i].sc=0;a[i].num=0;
            b[i].sc=0;b[i].num=0;
        }
        int l=0,flag1=0,flag2=0;
        while(n--) {scanf("%c%d",&a[l].name,&a[l].value);l++;b[l-1].value=a[l-1].value;b[l-1].name=a[l-1].name;getchar();}
        for(i=0;i<l;i++)
            for(j=i+1;j<l;j++)
            {
                if(a[j].value==a[i].value)
                a[i].num++;
                if(b[j].value==b[i].value)
                    b[i].num++;
            }
        bubblesort(l);
        selectionSort(l);
        for(i=0;i<l;i++) for(j=i+1;j<l;j++) {if(a[j].value==a[i].value) a[i].sc++;if(b[j].value==b[i].value) b[i].sc++;}
        for(i=0;i<l;i++)
        {
            if(a[i].num!=a[i].sc) flag1=1;if(b[i].num!=b[i].sc) flag2=1;
        }
        for(i=0;i<l;i++) printf("%c%d%c",a[i].name,a[i].value,(i==l-1)?'\n':' ');
         if(!flag1) printf("Stable\n"); else printf("Not stable\n");
        for(i=0;i<l;i++) printf("%c%d%c",b[i].name,b[i].value,(i==l-1)?'\n':' ');
         if(!flag2) printf("Stable\n"); else printf("Not stable\n");

    }

    return 0;
}
/*5
H4 C9 S4 D2 C3
2
S1 H1
*/

Measured memory_bytes: 1044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		int s = -1;
		for(int i=1; i<=1009; i++) {
			if((int)(i*0.08)==A && (int)(i*0.1)==B) {
				s = i;
				break;
			}
		}
		System.out.println(s);
	}

}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define all(v)	((v).begin()), ((v).end())
#define pb	push_back
#define mp	make_pair
#define mod 1000000007
#define debug(x)  cout<<#x<<" = "<<x<<" \n"
typedef long long ll;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

// int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
// inline bool valid(int x, int y, int v) {
//     return x >= 0 && x < n && y >= 0 && y < m && !visited[x][y] && grid[x][y] == v;
// }

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

    string n;
    getline(cin,n);

    ll sum = 0;
    for(int i=0;i<n.length();i++)
    {
        sum += (n[i]-48);
    }
    if(sum % 9 == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

   
}
    

Measured memory_bytes: 3708
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll spf[N], f[N];
void sieve()
{
    spf[1] = 1;
    for (ll i = 2; i < N; i++)
        spf[i] = i;
    for (ll i = 4; i < N; i += 2)
        spf[i] = 2;
    for (ll i = 3; i * i < N; i++)
    {
        if (spf[i] == i)
        {
            for (ll j = i * i; j < N; j += i)
                if (spf[j] == j)
                    spf[j] = i;
        }
    }
}
unordered_map<ll, ll> factorize(ll x)
{
    unordered_map<ll, ll> ret;
    while (x != 1)
    {
        ret[spf[x]]++;
        x = x / spf[x];
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, g = 0;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, g = gcd(g, e);
    if (g > 1)
        return cout << "not coprime", 0;
    sort(a.begin(), a.end());
    sieve();
    for (ll e : a)
    {
        auto p = factorize(e);
        for (auto [e, _] : p)
            if (f[e])
                return cout << "setwise coprime", 0;
            else
                f[e]++;
    }
    cout << "pairwise coprime";
}

Measured memory_bytes: 19428
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] yakusuu = new int[n + 1];
            for (int i = 2; i <= n; i++)
            {
                int x = i;
                for (int j = 2; j <= n; j++)
                {
                    int k = 0;
                    if (x % j == 0)
                    {
                        for (k = 0; x % j == 0; x /= j) k++;
                    }
                    yakusuu[j] += k;
                }
            }
            long ret = 1;
            for (int i = 2; i <= n; i++)
            {
                ret *= yakusuu[i] + 1;
                ret %= 1000000007;
            }
            Console.WriteLine(ret);
        }
    }
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    string s;
    cin >> s;

    int L = s.size(), ans = 0;
    stack<char> st;

    for(int i = 0; i < L; i++){
        if(!st.size()){
            st.push(s[i]);
            continue;
        }

        char c = st.top();
        if((c == '0' && s[i] == '1') || (c == '1' && s[i] == '0'))
            st.pop(), ans += 2;
        else
            st.push(s[i]);
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i <(b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a,value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<LL> VI;
typedef pair<int, LL> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;

int A[MAX];

int main()
{
    //freopen("input.txt", "r", stdin);
    //ios::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin >> n;
    n *= 2;
    FOR(i, 0, n)
    cin >> A[i];
    
    sort(A, A + n);
    int res = 0;
    for(int i = n - 2; i >= 0; i -= 2)
        res += A[i];
    
    cout << res << endl;
    
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	int curr=a[0];
	ll ans=0;
	for(int i=1;i<n;i++)
	{
		ans+=max(0,curr-a[i]);
		curr=max(curr,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4052
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    ll a,b,c;
    cin>>a>>b>>c;
    a=abs(a);
    ll x=min(a/c,b);
    a-=x*c;
    b-=x;
    if(b&1) cout<<abs(a-c);
    else cout<<a;
    return 0;
}


Measured memory_bytes: 3660
x, n = map(int, input(). split())
p = list(map(int, input(). split()))
if x not in p:
  print(x)
else:
  d = 1
  for i in range(1, 100):
    if x-d not in p:
      print(x-d)
      break
    if x+d not in p:
      print(x+d)
      break
    d += 1

Measured memory_bytes: 61924
#https://atcoder.jp/contests/abc175/tasks/abc175_a

a= []
a= input(" ")
#print(a[0:3])
if(a[0]==a[1] and a[1]==a[2]):
    if(a[0]=="R"):
        print(3)
    else:
        print(0)
elif(a[1]=="S"):
    if(a[0]=="R" or a[2]=="R"):
        print(1)
elif(a[1]=="R"):
    if (a[0]==a[1] or a[1]==a[2]):
        print(2)
    else:
        print(1)

Measured memory_bytes: 8900
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        Map<Integer, Integer> H = new HashMap<>();
        Map<Integer, Boolean> check = new HashMap<>();

        for (int i = 0; i < N; i++) {
            H.put(i + 1, scanner.nextInt());
            check.put(i + 1, true);
        }

        for (int i = 0; i < M; i++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();

            if (H.get(A) > H.get(B)) {
                check.put(B, false);
            } else if (H.get(A) < H.get(B)) {
                check.put(A, false);
            } else {
                check.put(A, false);
                check.put(B, false);
            }
        }

        int result = 0;
        for (Integer integer : check.keySet()) {
            if (check.get(integer).equals(true)) {
                result += 1;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 68376
#!/usr/bin/perl
use Data::Dumper;

my ($X,$N) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @p = map { $_ - 0 } split(/\s+/,<STDIN>);

my %pp = ();
for(my $i=0;$i<$N;$i++){
  $pp{"" . $p[$i]} = 1;
}

my $tgt = 400;
my $val = 400;

for(my $x1=-10;$x1<110;$x1++){
  next if $pp{"" . $x1};
  if( abs($X - $x1) <= $tgt ){
    $val = $x1 if( $x1 <= $val or abs($X - $x1) < $tgt );
    $tgt = abs($X - $x1);
  }
}

print "$val\n";







Measured memory_bytes: 6380
#include<cstdio>
#include<algorithm>
using namespace std;
namespace io {
	const int SIZE=(1<<21)+1;
	char ibuf[SIZE],*iS,*iT,c; int f;
#define gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
	template <class I>
	inline void gi (I &x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc()) if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc()) x=(x<<1)+(x<<3)+(c&15); x*=f;
	}
}
using io::gi;
const int N=500005,Mod=1000000007;
int n,pre[N],suf[N],f[N],sf[N],lst[N];
struct node {
	int k,b;
} a[N];
bool operator < (node x, node y) {
	if(x.k==y.k) return x.b<y.b;
	return x.k<y.k;
}
int main()
{
#ifdef lc
	freopen("river.in","r",stdin);
#endif
	gi(n);
	for(int i=1;i<=n;++i) gi(a[i].k),gi(a[i].b);
	sort(a+1,a+1+n);
	pre[0]=-1<<30;
	for(int i=1;i<=n;++i) pre[i]=max(pre[i-1],a[i].b);
	suf[n+1]=1<<30;
	for(int i=n;i>=1;--i) suf[i]=min(suf[i+1],a[i].b);
	for(int i=1;i<=n;++i)
	{
		int l=upper_bound(pre+1,pre+i,a[i].b)-pre,
			r=lower_bound(suf+i+1,suf+n+1,a[i].b)-suf-1;
		lst[r]=max(lst[r],l);
	}
	f[0]=sf[0]=1;
	for(int i=1;i<=n+1;++i)
	{
		if(lst[i-1]) f[i]=((sf[i-1]-sf[lst[i-1]-1])%Mod+Mod)%Mod;
		else f[i]=sf[i-1];
		lst[i]=max(lst[i],lst[i-1]);
		sf[i]=(sf[i-1]+f[i])%Mod;
	}
	printf("%d",f[n+1]);
}

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

int main(){
    int a, b, c, d;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    a=a-b;
    d=a/c;
    a=a-c*d;
    printf("%d", a);
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
if n%2 == 0:
  for i in range(n//2):
    print(L[2*(n//2-i-1)+1],end = ' ')
  for j in range(n//2):  
    print(L[2*j],end = ' ')
else:
  for k in range(n//2+1):
    print(L[2*(n//2-k)],end = ' ')
  for l in range(n//2):
    print(L[2*(l+1)-1],end = ' ')

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

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int m = std.nextInt();
        int x = std.nextInt();
        int y = std.nextInt();

        int[] xs = new int[n + 1];
        int[] ys = new int[m + 1];

        for (int i = 0; i < n; i++) {
            xs[i] = std.nextInt();
        }
        xs[n] = x;

        for (int i = 0; i < m; i++) {
            ys[i] = std.nextInt();
        }
        
        ys[m] = y;

        int maxX = Arrays.stream(xs).max().getAsInt();
        int minY = Arrays.stream(ys).min().getAsInt();
        if (maxX < minY) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
}


Measured memory_bytes: 27092
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] lines = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Console.WriteLine("{0} {1}", lines[0] * lines[1], 2 * lines[0] + 2 * lines[1]);
    }
}

Measured memory_bytes: 9436
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(new Main().solve());
    }
    
    int solve() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        
        List<Integer> divA = IntStream.rangeClosed(1, a).filter(i -> a % i == 0).boxed()
                        .sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        List<Integer> divB = IntStream.rangeClosed(1, b).filter(i -> b % i == 0).boxed()
                        .sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        divA.retainAll(divB);
        
        return divA.get(k - 1);
    }
}


Measured memory_bytes: 28372
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


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

  int l = 0, r = n-1;
  string l_str, r_str;
  cout << l << endl;
  cin >> l_str;
  if(l_str == "Vacant") return 0;
  
  cout << r << endl;
  cin >> r_str;
  if(r_str == "Vacant") return 0;

  while(true){
    int mid = (r+l)/2;
    string mids;
    cout << mid << endl;
    cin >> mids;
    if(mids == "Vacant") return 0;

    if((l%2 == mid%2) == (l_str == mids)){
      l = mid;
      l_str = mids;
    }
    else{
      r = mid;
      r_str = mids;
    }
  }
}

Measured memory_bytes: 852
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,k,x,y;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);in(k);in(x);in(y);
	if(k>=n)printf("%d\n",n*x);
	else printf("%d\n",k*x+(n-k)*y);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int t[N+1],x[N+1],y[N+1];
    t[0]=x[0]=y[0]=0;
    for(int i=1;i<N+1;i++)cin>>t[i]>>x[i]>>y[i];
    bool can=true;
    for(int i=0;i<N;i++){
           int dt=t[i+1]-t[i];
           int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
           if(dist>dt||dist%2!=dt%2){
               can=false;
           }
    }
    if(can) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int h,w,q;
    cin >> h >> w >> q;

    string s[h];
    rep(i,h)cin >> s[i];
    int a[h+1][w+1];
    int b[h+1][w+1];
    int c[h+1][w+1];
    rep(i,h+1){
        rep(j,w+1){
            if(i == 0 || j == 0)a[i][j] = 0;
            else{
                a[i][j] = a[i][j-1] + a[i-1][j] - a[i-1][j-1] + s[i-1][j-1] - '0';
            }
            b[i][j] = 0;
            c[i][j] = 0;
            if(j >= 2 && i >= 1){
                b[i][j] += b[i-1][j] + b[i][j-1] - b[i-1][j-1];
                if(s[i-1][j-2] == '1' && s[i-1][j-1] == '1')b[i][j]++;
            }
            if(i >= 2 && j >= 1){
                c[i][j] += c[i-1][j] + c[i][j-1] - c[i-1][j-1];
                if(s[i-2][j-1] == '1' && s[i-1][j-1] == '1')c[i][j]++;
            }
        }
    }
    /*
    rep(i,h+1){
        rep(j,w+1){
            cout << a[i][j];
        }
        cout << endl;
    }
    cout << endl;
    rep(i,h+1){
        rep(j,w+1){
            cout << b[i][j];
        }
        cout << endl;
    }
    cout << endl;
    rep(i,h+1){
        rep(j,w+1){
            cout << c[i][j];
        }
        cout << endl;
    }
    cout << endl;
    */

    rep(loop, q){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int ans = a[x2][y2] - a[x1-1][y2] - a[x2][y1-1] + a[x1-1][y1-1];
        ans -= b[x2][y2] - b[x1-1][y2] - b[x2][y1] + b[x1-1][y1];
        ans -= c[x2][y2] - c[x1][y2] - c[x2][y1-1] + c[x1][y1-1];
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 52864
#include <bits/stdc++.h>
#define N 16
#define P 40000
#define M 15000000
using namespace std;

int n,m;
int inf=1000000000;
vector <int> bi[N], ci[N];
int L[P],f[P][N], g[M], h[P][N];
int merge(int a, int b)
{
    int s=0, k=1;
    for (int i=0; i<n; ++i, k*=3)
        if (a & (1 << i)) s += k;
        else if (b & (1 << i)) s += k * 2;
    return s;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++ i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        bi[a].push_back(b); ci[a].push_back(c);
        bi[b].push_back(a); ci[b].push_back(c);
    }
    for (int i = 1; i <= n; ++ i) L[1 << (i - 1)] = i;
    for (int i = 1; i < (1 << n); ++ i)
        for (int j = 1; j <= n; ++ j)
            if (((1 << (j - 1)) & i) == 0)
                for (int k = 0; k < bi[j].size(); ++ k)
                    if ((1 << (bi[j][k] - 1)) & i)
                        f[i][j] += ci[j][k];
    for (int i = 1; i < (1 << n); ++ i)
        for (int j = i & (i - 1); j; j = i & (j - 1))
        {
            int p = L[j & (-j)];
            g[merge(i ^ j, j)] = g[merge(i ^ j, j ^ (1 << (p - 1)))] + f[i ^ j][p];
        }
    for (int i = 0; i < (1 << n); ++ i)
        for (int j = 1; j <= n; ++ j)
            h[i][j]=inf;
    h[1][1] = 0;
    for (int i = 1; i < (1 << n); ++ i)
        for (int j = 1; j <= n; ++ j)
            if (h[i][j] != inf)
            {
                for (int k = 0; k < bi[j].size(); ++ k)
                    if (((1 << (bi[j][k] - 1)) & i) == 0)
                        h[i | (1 << (bi[j][k] - 1))][bi[j][k]] = min(h[i | (1 << (bi[j][k] - 1))][bi[j][k]], h[i][j] + f[i][bi[j][k]] - ci[j][k]);
                int o = ((1 << n) - 1) ^ i;
                for (int k = o; k; k = (k - 1) & o)
                    h[i | k][j] = min(h[i | k][j], h[i][j] + g[merge(i ^ (1 << (j - 1)), k)]);
            }
    cout << h[(1 << n) - 1][n] << endl;
}

Measured memory_bytes: 63872
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()

    val par = new Array[Int](n)
    init(par)

    for (i <- 0 until m) {
      val x, y, z = sc.nextInt()
      unite(par, x - 1, y - 1)
    }

    var ans = 0

    for (i <- par.indices) {
      if (isParent(par, i)) {
        ans += 1
      }
    }

    println(ans)
  }

  def isParent(par: Array[Int], x: Int): Boolean = {
    par(x) == x
  }

  def init(par: Array[Int]): Unit = {
    for (i <- par.indices) {
      par(i) = i
    }
  }


  def root(par: Array[Int], x: Int): Int = {
    if (par(x) == x) {
      x
    } else {
      par(x) = root(par, par(x))
      par(x)
    }
  }

  def same(par: Array[Int], x: Int, y: Int): Boolean = {
    root(par, x) == root(par, y)
  }

  def unite(par: Array[Int], x: Int, y: Int): Unit = {
    var (xx, yy) = (root(par, x), root(par, y))
    if (!(xx == yy))
      par(xx) = yy
  }
}


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

using namespace std;

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

int in() { int x; scanf("%d", &x); return x; }
template<typename T> void pv(T a, T b) { for (T i = a; i < b; i++) cout << *i << ' '; cout << endl; }
template<typename T, typename U> void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void chmax(T &x, U y) { if (x < y) x = y; }

int main() {
  int A,B,C,X,Y;

  cin >> A >> B >> C >> X >> Y;

  int cost = (1<<30);
  REP(c,200010) {
    int a = max(X - c / 2, 0);
    int b = max(Y - c / 2, 0);
    int x = a * A + b * B + c * C;
    chmin(cost, x);
  }

  cout << cost << endl;

  return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  // ll ans = 0;
  // bool ok = false;

  cout << (10000-N)%1000 << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION


void solve(void)
{
  int N;
  cin>>N;
  vector<int>A(N),B(N);
  vector<pair<int,int> > vp(N);
  for (int i = 0; i < N; i++)
  {
    cin>>A[i]>>B[i];
    vp[i].first = A[i] + B[i];
    vp[i].second = i;
  }
  sort(ALL(vp));
  reverse(ALL(vp));
  int ST = 0, SA = 0;
  for (int i = 0; i < N; i++)
  {
    if(i%2 == 0)
    {
      ST += A[vp[i].second];
    }
    else
    {
      SA += B[vp[i].second];
    }
    
  }
  cout<<ST - SA<<endl;
  
 
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 3456
a,b=map(int,input().split())
if b//100==1:
    s=1000*a+b
elif b//10==0:
    s=10*a+b
else:
    s=100*a+b
c=1
while s>=c**2:
    if s==c**2:
        print("Yes")
        break
    else:
        c+=1
if not s==c**2:
    print("No")

Measured memory_bytes: 3060
n = int(input())
c = [int(input()) for _ in range(n)]
mod = 10 ** 9 + 7

# 解説AC
dp = [1] * n
color = [-1] * max(c)
for i, ci in enumerate(c):
    dp[i] = dp[i - 1]
    if 0 <= color[ci - 1] < i - 1:
        dp[i] += dp[color[ci - 1]]
    color[ci - 1] = i
print(dp[-1] % mod)


Measured memory_bytes: 789364
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

f n s = length . filter ((==s) . sum) . filter ((==n) . length) $ subsequences [0..9]

main = do
    [n, s] <- getInts
    when (n/=0 || s/=0) $ do
        print $ f n s
        main

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
//26

int a[100000];
signed main(){
	int n, ans = 0;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n){
		int cnt = 0;
		while(a[i]%2 == 0){a[i]/=2;cnt++;}
		a[i] = cnt;ans += cnt;
	}
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;
int main(void){
  int N,K;
  cin >>N>>K;
  int h[N];
  for (int i=0;i<N;i++) cin >>h[i];
  sort(h,h+N);
  int d[N-K+1];
  for (int i=0;i<N-K+1;i++) d[i]=h[i+K-1]-h[i];
  sort(d,d+N-K+1);
  
  cout <<d[0]<<endl;
  return 0;
}


Measured memory_bytes: 1024
fun main (args : Array<String>) {
	val n = readLine()
	val N : Int = n!!.toInt()
	val l = readLine()!!.split(" ")
	var list : MutableList<Int> = mutableListOf()
	var rlist : MutableList<Int> = mutableListOf()
	var count1 : Int = 0
	var count2 : Int = 0
	var result : Int = 0
	for (i in l) {
		list.add(i.toInt())
		rlist.add(i.toInt())
	}
	rlist.sort()
	result = rlist[N / 2] - rlist[(N / 2) - 1]
	println("${result}")
}

Measured memory_bytes: 62240
fn main() {
  let s: String = get::val();
  let t: String = get::val();

  let s = s.chars().collect::<Vec<_>>();
  let t = t.chars().collect::<Vec<_>>();
  let pos = s.windows(t.len()).enumerate().filter(|&(_,w)|smatch(w,&t)).map(|(i,_)|i).max();
  if pos == None {
    println!("UNRESTORABLE");
    return
  }

  let pos = pos.unwrap();
  let ans = s.iter().enumerate().map(|(i,&c)|if pos<=i&&i<=pos+t.len()-1&&c=='?' {t[i-pos]} else if c=='?' {'a'} else {c}).collect::<String>();
  println!("{}", ans);
}

fn smatch(s: &[char], t: &[char]) -> bool {
  if s.len() != t.len() {return false}
  s.iter().zip(t.iter()).all(|(&c,&d)|c==d||c=='?')
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }
}


Measured memory_bytes: 4352