akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 300500;
int sum[N], a[N], res, t, n;
bool check(int mid) {
    int k = 0;
    for (int i = 2;i <= n; i += 2) 
        if (sum[i-1] - k >= mid) Mn(k, sum[i]);
    return sum[n] - k >= mid;
}

int main() {
    read(n);
    for (int i = 1;i <= n; i++) {
        read(a[i]), sum[i] = i & 1 ? sum[i-1] + a[i] : sum[i-1] - a[i];
        res += a[i];
    }
    if (~n & 1) {
        t = max(sum[n], -sum[n]);
        write((res + t) / 2, ' '), write((res - t) / 2);
        return 0;
    }
    int l = 0, r = 1e9;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    t  = -sum[n] + 2 * r;
    write((res + t) / 2, ' '), write((res - t) / 2, ' ');
    return 0;
}

Measured memory_bytes: 5316
#include "bits/stdc++.h"
using namespace std;
int Xor[200005] , Array[200005];

void FindArray( int N ){
    int i , x = 0;

    for( i = 1 ; i <= N ; ++i )
        x ^= Xor[i];
    
    for( i = 1 ; i <= N ; ++i )
        Array[i] = Xor[i] ^ x;
}

int main(){
    int N , i;
    scanf( "%d" , &N );

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , Xor + i );
        
    FindArray( N );

    for( i = 1 ; i <= N ; ++i )
        printf( "%d " , Array[i] );
    
    puts( "" );
    return 0;
}

Measured memory_bytes: 5344
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7 ;

int main(){
  int a[3];
  rep(i,3)cin >> a[i];
  sort(a,a+3);
  bool flag=false;
  if(a[0]!=a[2]){
    if(a[0]==a[1] || a[1]==a[2])flag=true;
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;}

Measured memory_bytes: 256
import collections

class UnionFind:
    def __init__(self, n):
        self._id = list(range(n))
        self._sz = [1] * n

    def _root(self, i):
        j = i
        while (j != self._id[j]):
            self._id[j] = self._id[self._id[j]]
            j = self._id[j]
        return j

    def find(self, p, q):
        return self._root(p) == self._root(q)

    def union(self, p, q):
        i = self._root(p)
        j = self._root(q)
        if (self._sz[i] < self._sz[j]):
            self._id[i] = j
            self._sz[j] += self._sz[i]
        else:
            self._id[j] = i
            self._sz[i] += self._sz[j]

n, k, l = [int(x) for x in input().split()]
pqs = set(tuple(int(x) - 1 for x in input().split()) for _ in range(k))
rss = set(tuple(int(x) - 1 for x in input().split()) for _ in range(l))

road = UnionFind(n)
for pq in pqs:
    road.union(*pq)

rail = UnionFind(n)
for rs in rss:
    rail.union(*rs)

roadrail = [(road._root(i), rail._root(i)) for i in range(n)]
cnt = collections.Counter(roadrail)

print(' '.join([str(cnt[r]) for r in roadrail]))


Measured memory_bytes: 140288
#include<stdio.h>
int main(){
    int n;
    int ans=100000;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        ans=ans*1.05;
        if(ans%1000>1){
            ans=ans+1000-ans%1000;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll l = min(x,y);
  ll ans = 0;
  if(a+b>=2*c){
    ans += 2*c*l;
  }else{
    ans += (a+b)*l;
  }
  x -= l; y-=l;
  if(x>0){
    ans += x*(a>2*c ? 2*c:a);
  }else{
    ans += y*(b>2*c ? 2*c:b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var a, b, k int 
  fmt.Scan(&a, &b, &k)
  if a >= k {
    a -= k
  } else {
    k -= a
    a = 0
    b = maxInt(0, b - k)
  }
  fmt.Println(a, b)
  
}

Measured memory_bytes: 512
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let input: Vec<i32> = read_vec();
    let mut ans = 0;
    if input[0] == input[1] {
        ans = input[2];
    } else if input[0] == input[2] {
        ans = input[1];
    } else if input[1] == input[2] {
        ans = input[0];
    }
    println!("{}", ans);
}

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

int n, m, q;
ll a[4000][4000], f[4000][4000][4];

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

    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        int r, c;
        ll v;
        cin >> r >> c >> v;
        --r, --c;

        a[r][c] = v;
    }

    f[0][0][1] = a[0][0];
    for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
        if (i + 1 < n) {
            if (a[i + 1][j] != 0) {
                for (int k = 0; k <= 3; ++k) {
                    f[i + 1][j][0] = max(f[i + 1][j][0], f[i][j][k]);
                    f[i + 1][j][1] = max(f[i + 1][j][1], f[i][j][k] + a[i + 1][j]);
                }
            } else {                            
                for (int k = 0; k <= 3; ++k)
                    f[i + 1][j][0] = max(f[i + 1][j][0], f[i][j][k]);
            }
        }

        if (j + 1 < m) {
            if (a[i][j + 1] != 0) {
                f[i][j + 1][3] = max(f[i][j + 1][3], f[i][j][3]);
                for (int k = 0; k <= 2; ++k) {
                    f[i][j + 1][k] = max(f[i][j + 1][k], f[i][j][k]);
                    f[i][j + 1][k + 1] = max(f[i][j + 1][k + 1], f[i][j][k] + a[i][j + 1]);
                }
            } else {
                for (int k = 0; k <= 3; ++k)
                    f[i][j + 1][k] = max(f[i][j + 1][k], f[i][j][k]);
            }
        }
    }
                                    
    ll result = 0;
    for (int i = 0; i <= 3; ++i)
        result = max(result, f[n - 1][m - 1][i]);
    cout << result << "\n";
}

Measured memory_bytes: 377644
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int x,cnt=0;
    cin>>x;
    int a[x];
    for(int i=0;i<x;i++)
    {
      cin>>a[i];
    }
    SRT(a,x);
    for(int i=0;i<x;i++)
    {
        if(a[i]==a[i+1])
        {
            i++;
        }
        else
        {
            cnt++;
        }
    }
    cout<<cnt<<NL;
    return 0;
}


Measured memory_bytes: 640
l = []

for _ in range(5):
  l.append(int(input()))

ans = float('inf')

def std_num(num):
  r = num % 10
  return num if r == 0 else num + (10 - r)

for i in range(5):
  total = 0

  for j in range(5):
    if i == j:
      total += l[j]
    else:
      total += std_num(l[j])

  ans = min(total,ans)

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<stack>
#include<ctime>
using namespace std;
#define N 1050
#define M 200500
int head[N],cnt,scc[N],dfn[N],low[N],f[N][13],s[M][2],as[M],vl[N],ct,ct2,vis[N][N],id[N],ct1,dep[N],is[N],n,m,ct3;
struct edge{int t,next,id;}ed[M];
void adde(int f,int t,int id){ed[++cnt]=(edge){t,head[f],id};head[f]=cnt;}
stack<int> tp,tp2,v[N],tp3;
void dfs1(int u)
{
	dfn[u]=low[u]=++ct1;
	tp.push(u);
	for(int i=head[u];i;i=ed[i].next)
	{
		if(!dfn[ed[i].t])dfs1(ed[i].t),low[u]=min(low[u],low[ed[i].t]);
		else if(!scc[ed[i].t])low[u]=min(low[u],dfn[ed[i].t]);
	}
	if(dfn[u]==low[u])
	{
		int s=tp.top(),id=++ct2;tp.pop();
		scc[s]=id;
		while(s!=u)
		s=tp.top(),tp.pop(),scc[s]=id;
	}
}
void dfs2(int u,int s){for(int i=head[u];i;i=ed[i].next)if(!vis[s][ed[i].t])vis[s][ed[i].t]=1,dfs2(ed[i].t,s);else vis[s][ed[i].t]++;}
int LCA(int x,int y){if(dep[x]<dep[y])x^=y^=x^=y;for(int i=10;i>=0;i--)if(dep[x]-dep[y]>=(1<<i))x=f[x][i];if(x==y)return x;for(int i=10;i>=0;i--)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];return f[x][0];}
void dfs3(int u,int fa)
{
	dfn[u]=1;dep[u]=dep[fa]+1;f[u][0]=fa;vl[u]=0;for(int i=1;i<=10;i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int i=head[u];i;i=ed[i].next)
	if(!dfn[ed[i].t])tp.push(ed[i].id),dfs3(ed[i].t,u),vl[u]+=vl[ed[i].t];
	else{int s=LCA(u,ed[i].t);vl[u]++;vl[s]--;tp2.push(ed[i].id);}
}
void dfs4(int u)
{
	dfn[u]=low[u]=++ct1;
	for(int i=head[u];i;i=ed[i].next)
	{
		if(!dfn[ed[i].t])dfs1(ed[i].t),low[u]=min(low[u],low[ed[i].t]);
		else if(!scc[ed[i].t])low[u]=min(low[u],dfn[ed[i].t]);
	}
	if(dfn[u]==low[u])ct2++;
}
bool check(int x)
{
	for(int i=1;i<=n;i++)dfn[i]=scc[i]=head[i]=0;
	cnt=0;ct2=0;
	for(int i=1;i<=m;i++)if(i!=x)adde(s[i][0],s[i][1],-1);else adde(s[i][1],s[i][0],-2);
	for(int i=1;i<=n;i++)if(!dfn[i])dfs1(i);
	return ct2!=ct3;
}
int main()
{
//	freopen("12.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&s[i][0],&s[i][1]),adde(s[i][0],s[i][1],1);
	for(int i=1;i<=n;i++)if(!dfn[i])dfs1(i);ct3=ct2;
	for(int i=1;i<=n;i++)head[i]=0;cnt=0;
	for(int i=1;i<=m;i++)if(scc[s[i][0]]!=scc[s[i][1]])adde(scc[s[i][0]],scc[s[i][1]],-3);
	for(int i=1;i<=ct2;i++)dfs2(i,i);
	for(int i=1;i<=n;i++)head[i]=0;cnt=0;
	for(int i=1;i<=m;i++)if(scc[s[i][0]]!=scc[s[i][1]])as[i]=vis[scc[s[i][0]]][scc[s[i][1]]]>1;else v[scc[s[i][0]]].push(i);
	for(int i=1;i<=ct2;i++)
	{
		for(int j=1;j<=n;j++)dfn[j]=0,head[j]=0;
		ct1=0;cnt=0;
		for(int j=1;j<=n;j++)if(scc[j]==i)id[j]=++ct1;
		while(!v[i].empty())
		{
			int q=v[i].top();v[i].pop();
			adde(id[s[q][0]],id[s[q][1]],q);
		}
		dfs3(1,0);
		while(!tp2.empty())
		{
			int st=tp2.top();tp2.pop();
			int l=id[s[st][0]],r=id[s[st][1]];
			r=LCA(l,r);
			int fg=0;
			while(l!=r)fg|=(vl[l]==1),l=f[l][0];
			as[st]=fg;
		}
	}
	while(!tp.empty()){int st=tp.top();tp.pop();as[st]=check(st);}
	for(int i=1;i<=m;i++)printf("%s\n",as[i]?"diff":"same");
//	printf("time : %dms",clock());
}

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

int main() {
  string s;
  cin >> s;
  int ans;
  if(s == "SUN")ans = 7;
  else if(s == "MON")ans = 6;
  else if(s == "TUE")ans = 5;
  else if(s == "WED")ans = 4;
  else if(s == "THU")ans = 3;
  else if(s == "FRI")ans = 2;
  else if(s == "SAT")ans = 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node {
	int a, b, id;
	bool operator<(const node& x)const { return 1LL * a* x.b < 1LL * b* x.a; }
};
int n, fa[200007], num[200007], f[200007], cnt[200007][2];
long long res;
priority_queue<node>q;
int read()
{
	int num = 0;
	char c = getchar();
	while (c<'0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int find(int x)
{
	if (f[x] == x)return x;
	else return f[x] = find(f[x]);
}
int main()
{
	n = read();
	for (int i = 2; i <= n; i++)
		fa[i] = read();
	for (int i = 1; i <= n; i++)
		cnt[i][num[i] = read()]++;
	for (int i = 1; i <= n; i++)
		f[i] = i;
	for (int i = 2; i <= n; i++)
		q.push(node{ cnt[i][0],cnt[i][1],i });
	while (!q.empty())
	{
		node d = q.top();
		q.pop();
		int x = find(d.id);
		if (d.a == cnt[x][0] && d.b == cnt[x][1])
		{
			int y = find(fa[x]);
			res += 1LL * cnt[y][1] * cnt[x][0];
			cnt[y][0] += cnt[x][0];
			cnt[y][1] += cnt[x][1];
			f[find(x)] = find(y);
			if (y != 1)q.push(node{ cnt[y][0],cnt[y][1],y });
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8820
import sys
sys.setrecursionlimit(100000000)
n,q= map(int,input().split())
nodes = [[]for _ in range(n+1)]
value = [0 for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int,sys.stdin.readline().split())
    nodes[a].append(b)
    nodes[b].append(a)
query = []
for i in range(q):
    a, b = map(int, sys.stdin.readline().split())
    value[a]+=b
def dfs(node,p,score):
    for v in nodes[node]:
        if v !=p:
            value[v]+=score
            dfs(v,node,value[v])

dfs(1,-1,value[1])
for i in range(1,n+1):
    sys.stdout.write('{} '.format(int(value[i])))



Measured memory_bytes: 227760
S = input()
N = len(S) 

left_S = S[:int(N // 2)]
right_S = S[int((N + 1) // 2):]

right_S = ''.join(list(reversed(right_S)))

count = 0

for i in range(len(left_S)):
    if left_S[i] != right_S[i]:
        count += 1
        
print(count)

Measured memory_bytes: 3064
#include<cstdio>


long long count[5];
int combine[10][3] = {
	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}
};
int main()
{
	int n;
	long long ans;
	char str[15];
	while(~scanf("%d",&n)){
		ans = 0;
		for(int i = 0; i<5; i++)count[i] = 0;
		for(int i = 0; i<n; i++){
			scanf("%s",str);
			if(str[0] == 'M') count[0]++;//M
			else if(str[0] == 'A') count[1]++;//A
			else if(str[0] == 'R') count[2]++;//R
			else if(str[0] == 'C') count[3]++;//C
			else if(str[0] == 'H') count[4]++;//H
			else continue;
		}
		for(int i = 0; i<10; i++){
			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] a = new int[h+2][w+2];
		String s;
		boolean flag = true;
		int x = 1;
		int y = 1;
		
		for (int i=1; i<=h; i++) {
			s = sc.next();
			for (int j=1; j<=w; j++) {
				if (s.charAt(j-1) == '#') {
					a[i][j] = 1;
				} else {
					a[i][j] = 0;
				}
			}
		}
		
		while (flag) {
			if (a[x][y+1] == 1) {
				if (a[x+1][y] == 1) {
					flag = false;
				}
				y++;
				if (a[x-1][y] == 1) {
					flag = false;
				}
			} else {
				if (a[x+1][y] == 1) {
					x++;
				} else {
					flag = false;
				}
				if (a[x][y-1] == 1) {
					flag = false;
				}
			}
			
			if (x == h && y == w && flag) {
				break;
			}
		}
		
		System.out.println(flag ? "Possible" : "Impossible");
	}
}


Measured memory_bytes: 9812
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

pair<ll, ll> ab[100001];
pair<ll, ll> sum[100001];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    cin >> ab[i].first >> ab[i].second;
    sum[i].first = (ll)ab[i].first+(ll)ab[i].second;
    sum[i].second = i;
  }
  sort(sum, sum+n, greater<pair<ll, ll>>());

  //cout << sum[0].first << " " << sum[0].second << endl;
  

  int ii=0;
  ll tkhs = 0LL, aoki = 0LL;
  while(ii<n){
    //cout << "tkhs: " << tkhs << " aoki: " << aoki << " ii: " << ii << endl;    
    tkhs += ab[sum[ii].second].first;
    ii++;
    if(ii >= n) break;
    aoki += ab[sum[ii].second].second;
    ii++;
  }

  cout << tkhs-aoki << endl;
  
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;
    int a[n]; for(int i = 0; i < n; ++i) cin >> a[i];
    bool flag = true;
    int cnt = 0;
    while(flag){
        flag = false;
        for(int j = n-1; j != 0; --j){
            if(a[j] < a[j-1]){
                cnt++;
                swap(a[j], a[j-1]);
                flag = true;
            }
        }
    }
    for(int i = 0; i < n; ++i){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3092
process.stdin.resume();
process.stdin.setEncoding("utf-8");

process.stdin.on("data", function(chunk){
  var array = chunk.replace("\n", "").split(" "), i;
  var a = array[0];
  var b = array[1];
  var c = array[2];
  if(a !== b && a !== c && b !== c) process.stdout.write("3")
  if(a === b && a !== c) process.stdout.write("2")
  if(b === c && a !== c) process.stdout.write("2")
  if(c === a && a !== b) process.stdout.write("2")
  if(a === b && a === c) process.stdout.write("1")
});


Measured memory_bytes: 6904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int h[200000];
ll dp[100008];
int n;
ll recurs(int pos)
{
	if(pos==n) return 0;
	if(pos>n) return (1e5);
	if(dp[pos]!=-1) return dp[pos];
	dp[pos]=min(abs(h[pos+1]-h[pos])+recurs(pos+1),abs(h[pos+2]-h[pos])+recurs(pos+2));
	//cout<<pos<<" "<<dp[pos]<<"\n";
	return dp[pos];
}
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
    cin>>n;
    for (int i = 1; i <=n; ++i)
    {
    	cin>>h[i];
    }
    memset(dp,-1,sizeof(dp));
    ll ans=recurs(1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int N,H,W;
int X1[1000],X2[1000],Y1[1000],Y2[1000];
int fld[2002][2002],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};

int compress(int *x1,int *x2,int w){
  vector<int>xs;

  for(int i=0;i<N;i++){
      int tx1=x1[i],tx2=x2[i];
      if(1<=tx1 && tx1<w)xs.push_back(tx1);
      if(1<=tx2 && tx2<w)xs.push_back(tx2);
  }
  xs.push_back(0);
  xs.push_back(w);
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i=0;i<N;i++){
    x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
    x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
  }
  return xs.size()-1;
}

int bfs(void){

  int ans=0;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(fld[i][j])continue;
      ans++;
      queue<pair<int,int> >que;
      que.push(make_pair(j,i));
      while(!que.empty()){
	int nx=que.front().first,ny=que.front().second;
	que.pop();

	for(int i=0;i<4;i++){
	  int tx=nx+dx[i],ty=ny+dy[i];
	  if(tx<0 || W<tx || ty<0 || H<ty || fld[ty][tx]>0)continue;
	  que.push(make_pair(tx,ty));
	  fld[ty][tx]=1;
	}
      }
    }
  }
  return ans;
}

int main(void){

  while(cin >> W >> H,W|H){
    cin >> N;
    for(int i=0;i<N;i++)
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    
    fill(fld[0],fld[2002],0);
    
    W=compress(X1,X2,W);
    H=compress(Y1,Y2,H);
    
    for(int i=0;i<N;i++){
      fld[Y1[i]][X1[i]]++;
      fld[Y1[i]][X2[i]]--;
      fld[Y2[i]][X1[i]]--;
      fld[Y2[i]][X2[i]]++;
    }
    
    for(int i=0;i<H;i++){
      for(int j=1;j<W;j++){
	fld[i][j]+=fld[i][j-1];      
      }
    }
    
    for(int i=1;i<H;i++){
      for(int j=0;j<W;j++){
	fld[i][j]+=fld[i-1][j];
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 16904
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

int main (){

    string ans = "No";
    char a,b,c;
    cin >> a >> b >> c;

    int d = a-'0';
    int e = b-'0';
    int f = c-'0';
    if(d == 7) ans = "Yes";
    if(e == 7) ans = "Yes";
    if(f == 7) ans = "Yes";

    cout << ans ;

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;
 
typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;
 
int main() {
 
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll sum = 0;
    rep(i,N) sum ^= A[i];
    rep(i,N) {
        cout << (sum ^ A[i]);
        if (i < N - 1) cout << " ";
        else cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4848
import java.io.*;
import java.util.Scanner;

public class Main {
	public static int area (int a, int b) {
		return a * b;
	}

	public static int perimeter (int a, int b) {
		return (a + b) * 2;
	}

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = area(a, b);
        int peri = perimeter(a, b);
        System.out.println(area + " " + peri);
	}
}


Measured memory_bytes: 26308
#include <stdio.h>
int main()
{
  int A[100];
  int N,i,j,v,m;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    A[j+1]=v;  
    }

    for(m=0;m<N;m++){
      if(m>0) printf(" ");
      printf("%d",A[m]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}

int main(){
    ll N, L, T;
    cin>>N>>L>>T;
    ll X[N], W[N];
    ll a;
    rep(i, N){
        cin>>X[i]>>W[i];
        if(i==0){
            a=X[i];
            X[i]=0;
        }
        else{
            X[i]-=a;
        }
    }
    ll cnt=0;
    if(W[0]==1){
        rep(i,N){
            if(W[i]==2){
                if(X[i]-2*T>0){
                    X[i]=(X[i]-2*T)%L;
                }
                else{
                    cnt+=(2*T-X[i])/L+1;
                    X[i]=L+(X[i]-2*T)%L;
                }
            }
        }
        sort(X, X+N);
        cnt%=N;
        rep(i, N){
            cout<<(X[(N-cnt+i)%N]+T+a)%L<<endl;
        }
    }
    else{
        rep(i, N){
            if(W[i]==1){
                cnt+=(X[i]+2*T)/L;
                X[i]=(X[i]+2*T)%L;
            }
        }
        sort(X, X+N);
        cnt%=N;
        rep(i, N){
            if(X[(cnt+i)%N]-T+a>=0)
            cout<<(X[(cnt+i)%N]-T+a)%L<<endl;
            else{
                if((X[(cnt+i)%N]-T+a)%L==0){
                    cout<<0<<endl;
                }
                else{
                cout<<L+(X[(cnt+i)%N]-T+a)%L<<endl;
                }
            }
        }
    }
}

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

using namespace std;

using ll = long long;
const ll INF = 2e9, N = 1e5 + 15;

ll n, a[ N ][ 3 ], dp[ N ][ 4 ];

ll dfs(ll pos = 1, ll pre = 3) {
    if( pos == n + 1 ) return 0LL;
    ll &ret = dp[ pos ][ pre ];
    if( ~ret ) return ret;
    ret = 0;
    for(ll i = 0; i < 3; i += 1) {
        if( pre == i ) continue;
        ret = max(ret, a[ pos ][ i ] + dfs(pos + 1, i));
    }
    return ret;
}

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

    cin >> n;
    for(ll i = 1; i <= n; i += 1) {
        cin >> a[ i ][ 0 ] >> a[ i ][ 1 ] >> a[ i ][ 2 ];
    }
    memset(dp, -1, sizeof dp);
    cout << dfs() << '\n';
    return 0;
}


Measured memory_bytes: 13568
def LI():
    return list(map(int, input().split()))


pu = []
mi = []
N = int(input())
for _ in range(N):
    x, y = LI()
    pu.append(x+y)
    mi.append(x-y)
P = max(pu)
p = min(pu)
M = max(mi)
m = min(mi)
print(max(P-p, M-m))


Measured memory_bytes: 24896
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
ll mod=1e9+7;
ll modn(ll a,ll mod)
{
  a%=mod;
  if(a<0)a+=mod;
  return a;
}
ll dp[200000][50];
ll c(ll num,ll d)
{
  if(num==1 || num==d || d==0)return 1;
  if(dp[num][d]>0)return dp[num][d];
  dp[num][d]=modn(c(num-1,d)+c(num-1,d-1),mod);
  return dp[num][d];
}

int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  ll n,m;
  cin>>n>>m;
  map<ll,ll> pd;
  ll sqrtm=sqrt(m)+1;
  ll tm=m;
  repi(i,2,sqrtm+1000)
  {
    while(tm%i==0){pd[i]++;tm/=i;}
    if(tm==1)break;
  }
  if(tm>1)pd[m]++;
  ll res=1;
  for ( auto p : pd)
  {
    //cout<<p.first<<" "<<p.second<<endl;
    res=modn((ll)res*c(p.second+n-1,p.second),mod);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 45952
import java.util.*;
import java.util.Collections;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double total = 0;
    for (int i = 0; i < N; i++) {
      total += 1 / sc.nextDouble();
    }
    System.out.println(1 / total);
  }

  public static void primeFactorization(int num) {
    int Z = 0;
    for (int i = 2; num > i; i++) {
      while (num % i == 0) {
        System.out.println(i);
        num /= i;
        Z = num;
      }
    }
    System.out.println(Z);
  }

  public static boolean isPrime(int num) {
    if (num < 2)
      return false;
    else if (num == 2)
      return true;
    else if (num % 2 == 0)
      return false;

    for (int i = 3; i < num; i += 2) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll N, x=100;
  cin >> N;
  int y = 0;
  while(x < N){
    x += x/100;
    y++;
  }
  print(y);

}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b) {
    if( *(long long*)a - *(long long*)b < 0 )
        return 1;
    if( *(long long*)a - *(long long*)b > 0 )
        return -1;
    return 0;
}

int main(int argc, char *argv[])
{
    long long N, A[(int)1e5], B[(int)1e5];
    long long sub[(int)1e5];
    long long i, minus = 0, ans = 0;

    scanf("%lld", &N);
    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    for (i = 0; i < N; i++) {
        scanf("%lld", &B[i]);
        sub[i] = A[i] - B[i];
    }

    qsort(sub, N, sizeof(long long), compare);

    for (i = 0; i < N; i++) {
        if (sub[i] >= 0) continue;
        minus += sub[i];
        ans++;
    }

    for (i = 0; i < N; i++) {
        if (minus >= 0) break;
        if (sub[i] <= 0) {
            puts("-1");
            return 0;
        }
        minus += sub[i];
        ans++;
    }

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

    return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

    ll  N,A,B;
    cin >> N >> A >> B;

    ll ans = 0;

    ans += (N/(A+B)) * B;


    ll amari = N%(A+B);
    if(amari > A){
        ans += amari - A;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
int n;
vector<int> g[N];
int dist[N];
int q[N];
int topQ;

void BFS(int v) {
	topQ = 0;
	for (int i = 0; i < n; i++)
		dist[i] = N;
	dist[v] = 0;
	q[topQ++] = v;
	for (int i = 0; i < topQ; i++) {
		v = q[i];
		for (int u : g[v]) {
			if (dist[u] <= dist[v] + 1) continue;
			dist[u] = dist[v] + 1;
			q[topQ++] = u;
		}
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	BFS(0);
	BFS(q[topQ - 1]);
	int x = 1 + dist[q[topQ - 1]];
	if (x >= 2) {
		x -= 2;
		x %= 3;
	}
	if (x == 0)
		printf("Second\n");
	else
		printf("First\n");

	return 0;
}


Measured memory_bytes: 13556
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> pList = new ArrayList<>();
        for (int i = 0; i < n; i++){
            int p = sc.nextInt();
            pList.add(p);
        }

        Collections.sort(pList, Comparator.reverseOrder());
        pList.set(0, pList.get(0) / 2);

        int answer = 0;
        for (int i : pList){
            answer += i;
        }

        System.out.println(answer);
    }

}


Measured memory_bytes: 21844
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"

const int INF = 10000000;

using namespace std;

int main(){
    long N; cin >> N;
    vector<long> A;
    map<long,long> num;
    map<long,long> sum_combination;
    
    for(long i=0;i<N;i++){
        long temp; cin >> temp;
        A.push_back(temp);
    }
    
    for(long i=0;i<N;i++){
        if(num.count(A[i])==0){
            num[A[i]] = 1;
        }
        else{
            num[A[i]]++;
        }
    }
    long sum=0;
    for(auto iter=num.begin();iter!=num.end();iter++){
        long key=iter->first;
        long value=iter->second;
        sum_combination[key] = (value*(value-1))/2;
        sum += sum_combination[key];
    }
    
    for(long i=0;i<N;i++){
        long save_sum = sum;
        sum += -sum_combination[A[i]] + ((num[A[i]]-1)*(num[A[i]]-2))/2;
        cout << sum << endl;
        sum = save_sum;
     }


//    for(long i=0;i<N;i++){
//        long sum2=0;
//        for(auto iter=num.begin();iter!=num.end();iter++){
//            long key=iter->first;
//            long value=iter->second;
//
//            if(key==A[i]){
//                value--;
//                sum2+=(value*(value-1))/2;
//                value++;
//            }else{
//                sum2+=(value*(value-1))/2;
//            }
//        }
//        cout << sum2 << endl;
//     }
    
    return 0;
 
}


Measured memory_bytes: 18928
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <utility>

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cerr << #x << "=" << x << endl

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<bool> bv;

int main(void) {

    int n, x;
    cin >> n >> x;
    vi m(n);
    rep(i, n) cin >> m[i];

    //int sum = accumulate(all(m));
    int sum=0;
    rep(i, n) {
        sum += m[i];
    }
    int m_min = *min_element(all(m));

    int num = n+(x-sum)/m_min;

    cout << num << endl;
}


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

int main() {
	int x,y;
	int sum,i;
	int tmp;
	char c;
	sum=i=0;
	tmp=0;
	
	while(cin>>x>>c>>y){
		sum+=x*y;
		tmp+=y;
		i++;
	}
	
	cout<<sum<<endl;
	cout<<(int)(1.0*tmp/i+0.5)<<endl;
	return 0;
}

Measured memory_bytes: 1160
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line.split(" "));
});
reader.on('close', solve);

function getInt(strArr){
  var rtn = [];
  for(elem of strArr)rtn.push(parseInt(elem));
  return rtn;
}

function getFloat(strArr){
  var rtn = [];
  for(elem of strArr)rtn.push(parseFloat(elem));
  return rtn;
}

function solve(){
  var [N] = getInt(lines[0]);
  var P = getInt(lines[1]);
  var m=200001, ans=0;
  for(i=0; i<N; i++){
    if(P[i]<m)ans++;
    m = Math.min(m, P[i]);
  }
  console.log(ans);
}

Measured memory_bytes: 57612
import java.math.*;
import java.util.*;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int L = sc.nextInt();
			double a= L/3.0;
			double b= L/3.0;
			double v = a*b*(L-a-b);
			
			System.out.println(v);
			
		}

	}

Measured memory_bytes: 21716
/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 29 August 2020 06:09:03 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

const int N = 1e6+5;

map< int, int > factors;
bool factorisation(int n) {
	if (n % 2 == 0) {
        if(factors.count(2)){
            return false;
        }
        factors[2]++;
        while(n!=1 and n%2 == 0) n /= 2;
	}
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) {
			while (n!=1 and n % i == 0) {
				n /= i;
			}
		    if(factors.count(i)){
                return false;
            }
            factors[i]++;
        }
	}
	if (n > 1) {
        if(factors.count(n)){
            return false;
        }
		factors[n]++;
	}
    return true;
}

class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int n;
            cin>>n;
            vector < int > v(n);
            bool all_one = 1;
            bool one = 0;
            for(int i=0; i<n; ++i){
                cin>>v[i];
                if(v[i] != 1){
                    all_one=0;
                }
                if(v[i] == 1){
                    one = 1;
                }
            }
            if(all_one){
                cout<<"pairwise coprime"<<endl;
                return;
            }
            bool ok = true;
            for(auto x: v){
                if(!factorisation(x)){
                    ok = false;
                    break;
                }
            }
            if(ok){
                cout<<"pairwise coprime"<<endl;
                return;
            }
            int gc = v[0];
            for(int i=1; i<n; ++i){
                gc = __gcd(gc,v[i]);
            }
            if(gc == 1){
                cout<<"setwise coprime"<<endl;
                return;
            }
            cout<<"not coprime"<<endl;
        }
};


int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}



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

int main(void)
{
  int k, s;
  int x, y, z;
  int n = 0;
  cin >> k >> s;
  for ( x=0; x<=k; x++ ) {
    for ( y=x; y<=k; y++ ) {
      for ( z=y; z<=k; z++ ) {
        if ( x + y + z == s ) {
          if ( x == y && y == z ) {
            n++;
          } else if ( x == y || y == z || x == z ) {
            n = n + 3;
          } else {
            n = n + 6;
          }
        }
      }
    }
  }
  
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
using namespace std;

int pqr[3];
char *pt;
int parse() {
  int ret;
  if('0' <= *pt && *pt <= '2') {
    ret = *pt-'0';
    pt++;
  } else if('P' <= *pt && *pt <= 'R') {
    ret = pqr[*pt-'P'];
    pt++;
  } else if('-' == *pt) {
    pt++;
    ret = 2-parse();
  } else if('(') {
    pt++;
    int x = parse();
    char op = *pt; pt++;
    int y = parse();
    if(op == '*') {
      ret = min(x,y);
    } else if(op == '+') {
      ret = max(x,y);
    } else assert(false);
    assert(*pt==')');
    pt++;
  } else assert(false);
  return ret;
}

int main() {
  for(int tci = 0; ; tci++) {
    char pr[100]; scanf(" %s", pr);
    if(*pr=='.') break;
    int cnt=0;
    for(pqr[0]=0;pqr[0]<3;pqr[0]++)
      for(pqr[1]=0;pqr[1]<3;pqr[1]++)
        for(pqr[2]=0;pqr[2]<3;pqr[2]++) {
          pt=pr;
          if(parse()==2)cnt++;
        }
    printf("%d\n", cnt);
  }
  return 0;
}

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

int X;

bool isExp(int n) {
    bool ret = false;
    if (n == 1) {
        ret = true;
    }
    else {
        for (int i = 2; i*i <= n; i++) {
            int now = n;
            while (now % i == 0) {
                now /= i;
            }
            if (now == 1) {
                ret = true;
                break;
            }
        }
    }

    return ret;
}

int main() {
    cin >> X;

    int ans = 0;
    for (int i = 1; i <= X; i++) {
        if (isExp(i)) ans = i;
    }

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int min,max;
    cin >> min;
    max = -2147483648;
    for(int i=1;i<n;i++){
        int r;
        cin >> r;
        if(max < r - min) max = r - min;
        if(r < min) min = r;
    }
    
    cout << max << endl;
    
}



Measured memory_bytes: 3092
s = input()
s1 = int(s[0]+s[1])
s2 = int(s[2]+s[3])

if(s1 >= 1 and s1 <=12):
  if(s2 >= 1 and s2 <=12):
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if(s2 >= 1 and s2 <=12):
    print('YYMM')
  else:
    print('NA')


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int a, b, c, i;
	int count = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a; i <= b; i++)
	{
		if (c%i == 0)
		{
			count++;
		}
	}
	printf("%d\n", count);
}


Measured memory_bytes: 2736
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    s = S()
    c = collections.Counter(s)
    if c['o'] >= 8 - (15-len(s)):
        return 'YES'

    return 'NO'


print(main())



Measured memory_bytes: 7748
# dpC - Vacation
# 3 variables
def main():
    n = int(input())
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    a, b, c = A[0]
    for x, y, z in A[1:]:
        a, b, c = x + max(b, c), y + max(a, c), z + max(a, b)
    print(max(a, b, c))


if __name__ == "__main__":
    main()

Measured memory_bytes: 21308
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut a: Vec<usize> = (0..n).map(|_| read()).collect();
    a.sort_by(|x,y|y.cmp(x));

    let max_a = a[0];
    let mut table = vec![0;max_a+1];
    let mut already_visited = HashSet::new();

    for i in 0..n{
        let mut x = a[i];
        let dx = a[i];
        if already_visited.get(&x) != None{
            table[x] = 0;
            continue;
        }
        already_visited.insert(x);
        
        table[x] = 1;
        loop{
            x += dx;
            if x > max_a{
                break;
            }
            table[x] = 0;
        }
    }

    let ans = table.iter().filter(|x| **x == 1).count();
    println!("{}",ans);
}

Measured memory_bytes: 10864
num_town, num_move = map(int, input().split())
teleports = list(map(lambda x: int(x) - 1, input().split()))

current = 0
memo = {}
for i in range(num_move):
    if memo.get(current) == 2:
        break
    if not memo.get(current):
        memo[current] = 1
    else:
        memo[current] += 1
    destination = teleports[current]
    current = destination

loop = {k:v for k,v in memo.items() if v==2}
minus = {k:v for k,v in memo.items() if v==1}

new_move_count = 0
if len(loop) == 0:
    current = 0
    new_move_count = num_move
else:
    new_move_count = (num_move - len(minus)) % len(loop)

for i in range(new_move_count):
    destination = teleports[current]
    current = destination

print(current + 1)


Measured memory_bytes: 34248
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
ans = (sum(d)**2 - sum(item**2 for item in d))//2
print(ans)

Measured memory_bytes: 61800
import java.util.Scanner;
//0593
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt(),l[]=new int[n],r[]=new int[n],max=0,a=0;
        for(int i=0;i<n;i++) {
            l[i]=sc.nextInt();
        }
        for(int i=0;i<m;i++) {
            int t=sc.nextInt();
            for(int j=0;j<n;j++) {
                if(l[j]<=t) {
                    r[j]++;
                    if(max<r[j]) {
                        max=r[j];
                        a=j;
                    }
                    break;
                }
            }
        }
        System.out.println(a+1);
    }
}


Measured memory_bytes: 32584