akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
const int N=2005;
int n,sum=0,dia,dem[N],max1;
vector<int> adj[N];
void dfs(int x,int p,int dis){
	int now=0;
	for(int i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			if(dis+1<=dia/2){
				sum++;
				dfs(adj[x][i],x,dis+1);
				dem[x]+=dem[adj[x][i]];
			}
			else{
				if(dis+1==(dia+1)/2){
					dem[x]++;
					dem[adj[x][i]]++;
				}
			}
		}
	}
}
int main(){
	int i,j,k,ans;
	cin>>n>>dia;
	ans=n+1;
	for(i=1;i<n;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	for(i=1;i<=n;i++){
		memset(dem,0,sizeof(dem));
		sum=1;
		max1=0;
		dfs(i,i,0);
		for(j=0;j<adj[i].size();j++){
			max1=max(max1,dem[adj[i][j]]);
		}
		ans=min(ans,n-sum-max1);
	}
	cout<<ans;
}

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

int main(){
    //int freq[26] = {0};
    string s;
    cin>>s;
    int n = s.size();
    int count = 0;
    for(int i = 0; i<n/2; i++){
        if(s[i]!=s[n-1-i]) count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
import sys

S = input()

Slist = list(S)

Sset = set(Slist)

if not len(Sset) == 2:
    print("No")
    sys.exit()
    

counters = {}

for c in Slist:
    if not c in counters.keys():
        counters[c] = 1
    else:
        counters[c] += 1

for k in counters.keys():
    if not counters[k] == 2:
        print("No")
        sys.exit()
        
print("Yes")


Measured memory_bytes: 3060
import java.util.*;

import java.math.*;

public class Main {


	public static long solve(long[] arr1,long[] arr2, int k) {
 
		TreeMap<Long,Integer> map=new TreeMap<>();
		
		long ans=0;
		long count=0;
		map.put(0l, -1);
		for(int i=0;i<arr2.length;i++)
			map.put(arr2[i], i);
		for(int i=0;i<arr1.length;i++) {
			long rem=k-arr1[i];
			
			Long cc=map.floorKey(rem);
			if(cc!=null) {
				count=Math.max(count,i+1+map.get(cc)+1);
			}
			
		}
 
		return count;
	}
 
	public static void main(String[] args) throws Exception {
		Scanner s=new Scanner(System.in);
		int t=1;
		while(t-->0) {
			int n=s.nextInt();
			int m=s.nextInt();
			int k=s.nextInt();
			long[] arr1=new long[n];
			long[] arr2=new long[m];
			for (int i = 0; i < arr1.length; i++) {
				arr1[i]=s.nextLong();
				if(i>0)
					arr1[i]+=arr1[i-1];
			}
			for (int i = 0; i < arr2.length; i++) {
				arr2[i]=s.nextLong();
				if(i>0)
					arr2[i]+=arr2[i-1];
			}
			
			System.out.println(Math.max(solve(arr1,arr2,k),solve(arr2,arr1,k)));
			
				
			}
		}
 
 
	}




Measured memory_bytes: 92824
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	int a, b;
	long ans;
	scanf("%d%d%d", &n, &a, &b);

	int x[2];
	scanf("%d", &x[0]);
	for(i=1; i<n; i++){
		scanf("%d", &x[i&1]);
		long dx=x[i&1]-x[(i+1)&1];
		ans+=dx*a<b?dx*a:b;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

int n,k;
int res;
vector<vector<int> > d2t;

int dfs(int d, int from){
  int ret=0;
  for(int to : d2t[d]) if(to != from && to !=0) ret = max(ret, dfs(to, d));
  if(from>0 && ret==k-1){
    res++;
    return 0;
  } else if(from==0 && ret == k){
    res++;
    return 0;
  }
  return ret+1;
}

int main(){
  cin>>n>>k;
  vector<int> t2d(n);
  d2t = vector<vector<int> >(n, vector<int>());
  // town to dest, dest to town
  rep(i,n){
    scanf("%d", &t2d[i]);
    t2d[i]--;
    d2t[t2d[i]].pb(i);
  }

  res=0;
  if(t2d[0]!=0) res++;

  dfs(0,-1);

  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

const int dm = 1 << 22;
char dn[dm], * di = dn;
inline void putint(ll X, ll X2) {
	if (X == 0) {
		*di++ = '0';
	}
	else {
		if (X < 0) {
			*di++ = '-';
			X = -X;
		}
		int keta = 0;
		char C[20];
		while (X) {
			*(C + keta) = '0' + X % 10;
			X /= 10;
			keta++;
		}
		for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	}
	*di++ = ' ';
	if (X2 == 0) {
		*di++ = '0';
	}
	else {
		if (X2 < 0) {
			*di++ = '-';
			X2 = -X2;
		}
		int keta = 0;
		char C[20];
		while (X2) {
			*(C + keta) = '0' + X2 % 10;
			X2 /= 10;
			keta++;
		}
		for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	}
	*di++ = '\n';
}

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


	int Q = getint();

	ll X = 0;
	priority_queue<int> mae;
	priority_queue<int, vector<int>, greater<int>> ato;
	mae.push(-2e9);
	ato.push(2e9);
	int sa = 0;

	rep(i, Q) {
		if (getcha() == '1') {
			getcha();
			int a = getint();
			X += getint();

			if (sa) {
				int k = mae.top();
				if (a < k) {
					mae.pop();
					ato.push(k);
					mae.push(a);
					X += k + k;
					X -= a;
				}
				else {
					ato.push(a);
					X += a;
				}
				sa = 0;
			}
			else {
				int k = ato.top();
				if (a > k) {
					ato.pop();
					mae.push(k);
					ato.push(a);
					X += a;
					X -= k + k;
				}
				else {
					mae.push(a);
					X -= a;
				}
				sa = 1;
			}
		}
		else {
			getcha();
			int k = mae.top();
			ll ans = sa * k + X;
			putint(k, ans);
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 7676
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

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

    ll a, b, x;
    cin >> a >> b >> x;
    
    ll ano, bno;
    bno = b / x;
    
    if(a % x){
        ano = a / x;
    }else{
        ano = a / x - 1;
    }
    
    if(bno - ano < 0)   cout << 0 << endl;
    else    cout << bno - ano << endl;
    return 0;
}

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

int main() {
  long long K, X;
  cin >> K >> X;
  long long L = X - K + 1;
  long long R = X + K - 1;

  for (int i = L; i <= R; i++) {
    cout << i << " ";   
  }
  
  cout << endl;
}

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

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

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'


int n;
VI v(200010);
VI a(200010);

signed main()
{
    cin >> n;
    v.resize(n);
    a.resize(n);
    REP(i, n){
        cin >> v[i];
        a[i] = v[i];
    }

    sort(ALL(v));

    int left = v[n/2-1];
    int right = v[n/2];

    REP(i, n){
        if (a[i] <= left) {
            cout << right << endl;
        } else {
            cout << left <<endl;
        }
    }
}

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

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

using namespace std;

int main () {
   int s, w; cin >> s >> w;

   if(s <= w) {
      cout << "unsafe" << endl;
   } else {
      cout << "safe" << endl;
   }
}


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

using namespace std;

int main()
{
    int N;cin>>N;
    vector<int> d;
    for(int a = 0;a < N;a++){
        int b;cin>>b;
             d.push_back(b);
    }
    sort(d.begin(),d.end());
    d.erase(unique(d.begin(),d.end()),d.end());
    cout<<d.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
// #define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll mod=998244353;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }


int main()
{
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll r=0;
	while (1)
	{
		if (!r)
		{
			c-=b;
			if (c<=0)
			{
				cout<<"Yes";
				break;
			}
			r=!r;
		}
		else
		{
			a-=d;
			if (a<=0)
			{
				cout<<"No";
				break;
			}
			r=!r;
		}

	}
}



Measured memory_bytes: 3640
n=int(input())
h=list(map(int,input().split()))
ans='Yes'
for i in range(n-1,0,-1):
    if h[i]>=h[i-1]:
        continue
    elif h[i]+1==h[i-1]:
        h[i-1]-=1
    else:
        ans='No'
print(ans)


Measured memory_bytes: 14396
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
a=list(map(int,input().split()))
if n<sum(a):
    print(-1)
else:
    print(n-sum(a))

Measured memory_bytes: 68356
#include <stdio.h>

int main(void)
{
	int a,b,c,i,x = 0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(i = a;i <= b;i++){
		if(c % i == 0)
			x++;
	}
	printf("%d\n",x);
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v.at(i); 
    }

    sort(v.begin(), v.end(), greater<int>());
    int cnt = 0;
    for (int i = 0; i < v.size(); i++) {
        if (v.at(i) < k) {
            break;
        }
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

pi getPair(int n){
  int r = n % 10;
  int l = r;
  while(n){
    l = n%10;
    n /= 10;
  }
  return pi{l, r};
}

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

  map<pi, int> mp;
  rep(i, n){
    pi p = getPair(i+1);
    mp[p]++;
  }

  ll ans = 0;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      ans += mp[pi{i, j}] * mp[pi{j, i}];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define optimizator ios_base::sync_with_stdio(0);
#define ll long long
#define pb push_back
using namespace std;
int main(){
	optimizator;
	string a,b;
	int cnt=0;
	cin>>a>>b;
	for(int i=0; i<3; i++){	
		if(a[i]==b[i]){
			cnt++;
		}
	}
	cout<<cnt;
}

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

int main() {
	int n, input;
	long long sum = 0;
	int max, min;
	vector<int> v;
	cin >> n;
	/*
	for (auto i : v) {
		cin >> input;
		v.push_back(input);
		sum += v[i];
	}
	*/
	for (int i = 0; i < n; i++) {
		cin >> input;
		v.push_back(input);
		sum += input;
	}
	sort(v.begin(), v.end());
	min = v[0];
	max = v[n-1];
	cout << v[0] << " " << v[n-1] << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
const int N = 2e5 + 10, M = 20;
int n, a[N];
typedef struct node
{
    int b[M];
    node()
    {
        memset(b, 0, sizeof b);
    }
}Node;
Node v[N];
void add(int idx, int x)
{
    for(int i = 0;i < M;i ++)
    {
        if((x>>i) & 1) v[idx].b[i] = v[idx-1].b[i] + 1;
        else v[idx].b[i] = v[idx-1].b[i];
    }
}
bool check(int idx, int now)
{
    for(int i = 0;i < M;i ++)
    {
        if(v[idx].b[i] < v[now].b[i]-1) return false;    
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    memset(v[0].b, 0, sizeof v[0].b);
    for(int i = 1;i <= n;i ++)
    {
        cin >> a[i];
        add(i, a[i]);
    }
    LL ans = 0;
    for(int i = 1;i <= n;i ++)
    {
        int l = 0, r = i;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            if(check(mid, i))
            {
                r = mid - 1;
            }
            else l = mid + 1;
        }
        ans += i - l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}



int main() {
	int a, b;
	cin >> a >> b;

	int hai[16] = {};
	hai[0] = 1;
	a--;
	rep(i, 1, 16) {

		if (hai[i - 1] == 1) {
			if (b > 0) {
				b--;
				hai[i] = 2;
			}
		}

		else if (hai[i - 1] == 2) {
			if (a > 0) {
				a--;
				hai[i] = 1;
			}
		}
		else {
			if (a > 0) hai[i] = 1,a--;
			if (b > 0) hai[i] = 2,b--;
		}
	}

	if (hai[15] != 1 && a == 0 && b == 0) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def rot90(li):
    li2 = []
    for l in li:
        li2.append([l[0]*0+l[1]*(-1),l[0]*1+l[1]*0])
    return li2

while True:
    num_in = input()
    if num_in == 0:
        break
    pattern_list = []
    sam_li = []
    num = input()
    flagg = 1
    for j in range(num):
        x,y = map(int,raw_input().split())
        if flagg == 1:
            dxx,dyy = 0-x,0-y
        flagg = 0
        sam_li.append([x+dxx,y+dyy])
    dif_x = 0 -sam_li[num-1][0]
    dif_y = 0 -sam_li[num-1][1]
    sam_li2 = []
    for i in sam_li:
        sam_li2.append([i[0]+dif_x,i[1]+dif_y])
    sam_li2.reverse()
    pattern_list.append(sam_li)
    pattern_list.append(sam_li2)
    pattern_list.append(rot90(sam_li))
    pattern_list.append(rot90(sam_li2))
    pattern_list.append(rot90(rot90(sam_li)))
    pattern_list.append(rot90(rot90(sam_li2)))
    pattern_list.append(rot90(rot90(rot90(sam_li))))
    pattern_list.append(rot90(rot90(rot90(sam_li2))))
    for i in range(num_in):
        lis = []
        flag = 0
        for j in range(input()):
            x,y = map(int,raw_input().split())
            if flag == 0:
                xd, yd= 0-x,0-y
            flag = 1
            lis.append([x+xd,y+yd])
        if(lis in pattern_list):
            print i+1
    print "+++++"

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

int main(){
    int a;
    cin>>a;
    if(a<1200){
        cout<<"ABC"<<endl;
    }
    else if(a<2800){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"AGC"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int m, k;
	scanf("%d%d", &m, &k);

	int n = 1 << m;
	if (k >= n) {
		puts("-1");
		return 0;
	}

	if (m == 1) {
		if (k == 0) puts("0 1 1 0");
		else puts("-1");
		return 0;
	}

	for (int i = 0; i < n; i++) if (i != k)
		printf("%d ", i);
	printf("%d ", k);
	for (int i = n-1; i >= 0; i--) if (i != k)
		printf("%d ", i);
	printf("%d\n", k);
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
  int x=0,max=0;
  int n; cin >> n;
  string s; cin >> s;
  for(int i=0;i<n;i++){
    if(s[i]=='I') x++;
    else x--;
    if(x>=max) max = x;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
//#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


//namespace mp = boost::multiprecision;

//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int size(int n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}
int main() {
	int N, M;
	scanf("%d %d",&N ,& M);
	unordered_map<int,int>Y_Cnt;
	vector<pair<int, int>>P_Y(M);
	vector<pair<int, int>>P_Y_Copy(M);

	rep(i, M) {
		scanf("%d %d",& P_Y[i].first,& P_Y[i].second);
	}
	P_Y_Copy = P_Y;
	sort(all(P_Y), ps3);

	vector<int>cnt(N+1);
	FOR(i,0 ,M) {
		cnt[P_Y[i].F]++;
		Y_Cnt[P_Y[i].S] = cnt[P_Y[i].F];
	}

	rep(i, M) {
		int sizep = size(P_Y_Copy[i].F);
		int sizenum = size(Y_Cnt[P_Y_Copy[i].S]);
		rep(i, 6 - sizep) {
			printf("0");
		}
		printf("%d", P_Y_Copy[i].F);
		rep(i, 6 - sizenum) {
		printf("0");
		}
		printf("%d\n", Y_Cnt[P_Y_Copy[i].S]);

	}




}


Measured memory_bytes: 7588
# _*_ coding:utf-8 _*_
#  Atcoder_AiSingPrograming_Contest-A
#  TODO https://aising2019.contest.atcoder.jp/tasks/aising2019_a

def solveProblem(boardLength,Height,Width):
	lastHeight = boardLength+1-Height
	lastWidth = boardLength+1-Width

	if ( 0 < lastHeight ) and ( 0 < lastWidth): #この場合なら1枚以上は掲載できる
		papers = lastHeight * lastWidth
	else: # どちらかが0以下の場合貼ることすら出来ない(マイナスxマイナス＝プラスで勘違いされない)
		papers = 0
	answer = papers
	return answer


if __name__ == '__main__':
	N = int(input())
	H = int(input())
	W = int(input())
	solution = solveProblem(N,H,W)
	print("{}".format(solution))


Measured memory_bytes: 3060
declare function require(x: string): any;

var input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.split("\n");
const [h, w] = input[0].split(" ").map((x: string): number => +x);
const a = new Array<number>(26);
for (let i = 0; i < 26; i++) a[i] = 0;

for (let i = 0; i < h; i++) {
	for (let ii = 0; ii < w; ii++) {
		const index = input[i + 1][ii].charCodeAt() - "a".charCodeAt(0);
		a[index] += 1;
	}
}
a.sort().reverse();

let c4 = Math.floor(h / 2) * Math.floor(w / 2);
let c2 = 0;
let c1 = 0;
if (w % 2 != 0 && h % 2 != 0) {
	c2 = Math.floor(w / 2) + Math.floor(h / 2);
	c1 = 1;
}
else if (w % 2 != 0) {
	c2 = Math.floor(h / 2);
}
else if (h % 2 != 0) {
	c2 = Math.floor(w / 2);
}

// 貪欲
let index = 0;
while (c4 > 0 && index < 26) {
	if (a[index] >= 4) {
		a[index] -= 4;
		c4 -= 1;
	}
	else {
		index += 1;
	}
}
if(c4>0){
	console.log("No");
}
else{
	let index = 0;
	while (c2 > 0 && index < 26) {
		if (a[index] >= 2) {
			a[index] -= 2;
			c2 -= 1;
		}
		else {
			index += 1;
		}
	}
	if(c2>0){
		console.log("No");
	}
	else{
		let index = 0;
		while (c1 > 0 && index < 26) {
			if (a[index] >= 1) {
				a[index] -= 1;
				c1 -= 1;
			}
			else {
				index += 1;
			}
		}
		if(c2>0){
			console.log("No");
		}
		else{
			let flg_yes = true;
			for(let i=0; i<26; i++){
				if(a[i]!=0) {
					flg_yes = false;
					break;
				}
			}
			if(flg_yes) console.log("Yes");
			else console.log("No");
		}
	}
}



Measured memory_bytes: 7500
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end
  # [2,4,6].each_with_index.sort

n = gets.to_i
array = n.times.map { gets.split.map(&:to_i) }

# pp array
flag = false
count = 0
array.each do |ele|
  if ele[0] == ele[1]
    count += 1
    flag = true if count >= 3
  else
    count = 0
  end
end

puts flag ? "Yes" : "No"

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

void main_()
{
    string S;
    cin >> S;

    vector<ll> v(S.size() + 1, -1);

    size_t next_pos = 0;

    while (true) {
        auto pos_s = S.find('<', next_pos);
        pos_s = (pos_s != string::npos) ? pos_s : v.size();
        auto pos_e = S.find('>', pos_s);
        pos_e = (pos_e != string::npos) ? pos_e : v.size();
        iota(begin(v) + next_pos, begin(v) + pos_s, pos_s < v.size() ? 1LL : 0LL);
        reverse(begin(v) + next_pos, begin(v) + pos_s);
        iota(begin(v) + pos_s, begin(v) + pos_e, 0LL);
        if (pos_e == v.size()) {
            break;
        }
        next_pos = pos_e + 1;
    }

    for (int i = 0; i < v.size(); ++i) {
        if (v[i] == -1) {
            v[i] = max(v[i - 1], v[i + 1]) + 1;
        }
    }

    auto ans = accumulate(begin(v), end(v), 0LL);
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

ll BinarySearch(ll ng, ll ok, function<bool(ll)> judge){
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(judge(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}


signed main(){
    ll s;
    cin >> s;

    vector<ll> x(3,0), y(3,0);

    auto fn = [s](ll a){return a*a >= s;};

    ll n = BinarySearch(0, 1e9, fn);

    debug(n);

    x[1] = n;
    y[2] = n;
    y[1] = 1;
    x[2] = n*n - s;

    REP(i, 3){
        cout << x[i] << " " << y[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char prime[1000000]={};

int isprime(unsigned long n)
{
	unsigned long i, n1=n-1;
	if(n < 2){
		return 0;
	}else if(n == 2){
		return 1;
	}else if(n%2){
		for(i=3; i*i<=n; i+=2){
			if(n%i == 0){ return 0; }
		}
		return 1;
	}
	return 0;
}


int main(void)
{
	unsigned long i, j, n, cnt=0;

	//initialize
	for(i=0; i<1000000; i++){
		prime[i]--;
	}

	while(scanf("%ld", &n) != EOF){
		cnt = 0;
		for(i=1; i<=n; i++){
			if(prime[i-1] == -1){
				prime[i-1] = isprime(i);
			}
			cnt += prime[i-1];
		}
		printf("%ld\n", cnt);
	}
    return 0;
}

Measured memory_bytes: 1572
#include<bits/stdc++.h>
#define inf 100000000
using namespace std;

long long int cst[500][500],a[500],b[500],c[500],ans=inf;

int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	for(int i=0;i<=490;i++){
		for(int j=0;j<=490;j++){
			cst[i][j]=inf;
		}
	}
	cst[0][0]=0;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<n;i++){
		for(int p=480;p>=1;p--){
			for(int q=480;q>=1;q--){
				if(p>=a[i] && q>=b[i]){
					cst[p][q]=min(cst[p][q],cst[p-a[i]][q-b[i]]+c[i]);
				}
			}
		}
	}
	for(int i=1;i<=45;i++){
		ans=min(ans,cst[ma*i][mb*i]);
	}
	if(ans>=inf)
		cout<<"-1"<<endl;
	else 
		cout<<ans<<endl;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
char Map[1005][1005];
int n,m,turn[4][2]={1,0,0,1,-1,0,0,-1};
void judge(int _x,int _y) {
    if(_x<0||_x>=n) return;
    if(_y<0||_y>=m) return;
    if(Map[_x][_y]=='.') Map[_x][_y]='*';
}
struct node {
    int a,b;
    node (int x,int y) {
        a=x,b=y;
    }
    node(){}
}point[1005];
int dis(int a,int b,int c,int d) {
    return abs(a-c)+abs(b-d);
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) {
        scanf("%s",Map[i]);
    }
    int cn=0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            if(Map[i][j]=='#') {
                if(cn<=1005) {
                    point[cn++]=node(i,j);
                }
                else {
                    break;
                }
            }
        }
    }
    if(cn<1000) {
        int ans=0;

        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                int Min=0x3f3f3f3f;
                if(Map[i][j]=='.') {
                    for(int k=0;k<cn;k++) {
                        Min=min(Min,dis(i,j,point[k].a,point[k].b));
                    }
                    ans=max(ans,Min);
                }
            }
        }
        printf("%d\n",ans);
        return 0;
    }
    int ans=0;
    while(true) {
        bool falg=false;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(Map[i][j]=='#') {
                    for(int k=0;k<4;k++) {
                        int _x=i+turn[k][0];
                        int _y=j+turn[k][1];
                        judge(_x,_y);
                    }
                }
                else {
                    falg=true;
                }
            }
        }

        if(!falg) break;
        ans++;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(Map[i][j]=='*') Map[i][j]='#';
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int n;
  while(cin >> n){
    vector<int> a(n); cin >> a;

    sort(ALL(a));
    UNIQ(a);

    if(a.size() == n){
      puts_all("YES");
    }else{
      puts_all("NO");
    }
    
  }

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>

#include <string>
 
using namespace std;
 
int main(void) {
    int h, w;
    cin >> h >> w;
    string str[h];
    string check(w, '.');
    int line = 0;
    for(int i = 0; i < h; i++){
        cin >> str[line];
        if(str[line] != check){
            line++;
        }
    }
    int out[w] = {};
    for(int i = 0; i < w; i++){
        if(str[0][i] == '.'){
            int a = 0;
            for(int j = 0; j < line; j++){
                if(str[j][i] == '#'){
                    a++;
                    break;
                }
            }
            if(a == 0){
                out[i] = 1;
            }
        }
    }
    for(int i = 0; i < line; i++){
        for(int j = 0; j < w; j++){
            if(out[j] == 0){
                cout << str[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  REP(i, N) cin >> w[i] >> v[i];
  vector<vector<ll>> a(4), b(4);
  REP(i, N) a[w[i]-w[0]].emplace_back(v[i]);
  REP(i, 4){
    b[i].emplace_back(0);
    sort(ALLr(a[i]));
    REP(j, a[i].size()){
      b[i].emplace_back(b[i].back() + a[i][j]);
    }
  }

  ll ans = 0;
  REP(i, b[0].size()) REP(j, b[1].size()){
    REP(k, b[2].size()) REP(l, b[3].size()){
      if(w[0]*i + (w[0]+1)*j + (w[0]+2)*k + (w[0]+3)*l <= W){
        chmax(ans, b[0][i]+b[1][j]+b[2][k]+b[3][l]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

typedef pair<int,int> Pii;

#define SUPhl 1502
#define SUPgl 1502
#define SUPx 1500002
#define SUPy 1500002
int hl,gl;
int hs[SUPhl],gs[SUPgl];
int shs[SUPhl],sgs[SUPgl];
int xcn[SUPx],ycn[SUPy];



int solve(){
	shs[0]=0;
	FOR(hi,0,hl){shs[hi+1]=shs[hi]+hs[hi];}
	FOR(x,0,SUPx){xcn[x]=0;}
	FOR(ahi,0,hl){
		FOR(bhi,ahi+1,hl+1){
			int x=shs[bhi]-shs[ahi];
			xcn[x]++;
		}
	}

	sgs[0]=0;
	FOR(gi,0,gl){sgs[gi+1]=sgs[gi]+gs[gi];}
	FOR(y,0,SUPy){ycn[y]=0;}
	FOR(agi,0,gl){
		FOR(bgi,agi+1,gl+1){
			int y=sgs[bgi]-sgs[agi];
			ycn[y]++;
		}
	}

	int re=0;
	FOR(x,1,SUPx){
		re += xcn[x]*ycn[x];
	}

	return re;
}



int main(){
	while(true){
		cin >> hl >> gl;			if(!hl) return 0;
		REP(hi,hl){cin>>hs[hi];}
		REP(gi,gl){cin>>gs[gi];}

		cout<<solve()<<endl;

	}
}

Measured memory_bytes: 12900
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}

bool sign(ll a){
    return a>=0;
}

int main(){
    ll ans=0,ans2=0;
    dcl(n);
    vector<ll> in(n+1,0ll);
    range(i,1,n+1){
        cin>>in[i];
    }
    auto a=in,b=in;
    if(a[1]==0){
        ans++;
        a[1]=1;
    }
    partial_sum(all(a),a.begin());
    ll d=0;
    range(i,2,n+1){
        a[i]+=d;
        if(a[i]==0){
            ans++;
            a[i]=sign(a[i-1])?-1:1;
            d+=sign(a[i-1])?-1:1;
        }else if(sign(a[i])==sign(a[i-1])){
            ans+=abs(a[i])+1;
            d+=a[i]*-1+(sign(a[i])?-1:1);
            if(sign(a[i])){
                a[i]=-1;
            }else{
                a[i]=1;
            }
        }
        //cout<<a[i]<<"("<<d<<"), ";
    }

    if(b[1]==0){
        ans2++;
        b[1]=-1;
    }else{
        ans2=abs(b[1])+1;
        b[1]=(sign(b[1])?-1:1);
    }
    partial_sum(all(b),a.begin());
    d=0;
    range(i,2,n+1){
        a[i]+=d;
        if(a[i]==0){
            ans2++;
            a[i]=sign(a[i-1])?-1:1;
            d+=sign(a[i-1])?-1:1;
        }else if(sign(a[i])==sign(a[i-1])){
            ans2+=abs(a[i])+1;
            d+=a[i]*-1+(sign(a[i])?-1:1);
            if(sign(a[i])){
                a[i]=-1;
            }else{
                a[i]=1;
            }
        }
        //cout<<a[i]<<"("<<d<<"), ";
    }
    cout<<min(ans,ans2)<<endl;
}


Measured memory_bytes: 2560
/*
    Author: DurJoy
*/

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin() , v.end());
    int temp = v[n - 1] , sum = 0;
    for(int i = 0; i + 1 < n; i++){
        sum += v[i];
    }
    if(sum > temp){
        cout <<"Yes"<< endl;
    }
    else{
        cout <<"No"<< endl;
    }
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n ; cin >> n;
    cout << (n+1)/2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			Point p[]=new Point[n];
			for(int i=0;i<n;i++)
				p[i]=new Point(in.nextDouble(), in.nextDouble());
			int max=1;
			int dir[]={1,-1};
			for(int i=0;i<n;i++)
				for(int j=i+1;j<n;j++)
				{
					double d=Point.point_distance(p[i],p[j]);
					if(d>2)
						continue;
					//中点
					double mx=(p[i].x+p[j].x)/2;
					double my=(p[i].y+p[j].y)/2;
					//i->jの単位ベクトル
					double vx=(p[j].x-p[i].x)/d;
					double vy=(p[j].y-p[i].y)/d;
					//m->cの距離
					double e=Math.sqrt(1-d*d/4);
					for(int s=0;s<2;s++)
					{
						//円の中心座標
						Point pc=new Point(mx-e*vy*dir[s],my+e*vx*dir[s]);
						int cnt=2;
						for(int k=0;k<n;k++)
						{
							if(k!=i&&k!=j)
							{
								//hypotを使わずに距離を比較し計算時間が1/10になった
								double tmp_dis=(pc.x-p[k].x)*(pc.x-p[k].x)+(pc.y-p[k].y)*(pc.y-p[k].y);
								if(tmp_dis<=1)
									cnt++;
							}
						}
						max=Math.max(max,cnt);
					}
				}
			System.out.println(max);
		}
	}
}

class Point
{
	double x;
	double y;
	Point(double x,double y)
	{
		this.x=x;
		this.y=y;
	}
	//クラスメソッド
	static double point_distance(Point p1,Point p2)
	{
		return Math.hypot(p1.x-p2.x, p1.y-p2.y);
	}
}

Measured memory_bytes: 58252
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    int w = 0;
    int min=1001;
    bool end = false;
    while(!end){
        min =1001;
    for(int i=0;i<n;i++){
        if(i==n-1 && min == 1001){ //全部0になった
            end = true;
            w+=h[i];
            h[i] =0;
            break;
        }
        if(h[i]==0 && min != 1001){ //今までに1以上あってh[i]が0
            w+=min;
            for(int j=0;j<i;j++){
                if(h[j]==0){}
                else{
                h[j] -= min;
                }
            }
            break;
        }
        if(h[i]<min && h[i]!=0){ //最小値の更新(0以外)
            min = h[i];
        }
        if(i==n-1){ //配列に0がない
            w += min; //最小値分だけ水をあげる
            for(int j=0;j<n;j++){
                if(h[j]==0){}
                else{
                h[j] -= min;
                }
            }
        }
    }
    /*for(int i=0;i<n;i++){
        cout << h[i] <<" ";
    }
    cout <<endl;
    */
    }
    cout << w <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define mod (1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  ll d=c-a-b;
  if(d>0 && 4*a*b<d*d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int[][] m = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    // create square map
    Set<Integer> squares = new HashSet<>();
    for (int i = 0; i*i <= 16000; i++) {
      squares.add(i*i);
    }
    
    // combination(10,2)
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
      for (int j = i+1; j < N; j++) {
        int dist = calc(m, i, j);
        if (squares.contains(dist)) {
          ans++;
        }
      }
    }

    System.out.println(ans);
  }
  
  private static int calc(int[][] m, int a, int b) {

    int ret = 0;
    for (int i = 0; i < m[0].length; i++) {
      int t = Math.abs(m[a][i] - m[b][i]);
      ret += t*t;
    }
    
    return ret;
  }
}


Measured memory_bytes: 23892
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

n, k = getis
d = getis
b = []; d.each{|i|b[i]=true}

p (n..n+100000).find{|x| x.to_s.chars.all?{|c| not b[c.to_i] }}

__END__
s = gets.chomp
t = gets.chomp

puts s.chars.sort.join < t.chars.sort.reverse.join ?  "Yes" : "No"

a,b=getis
p (a+b+1)/2

n,a,b=getis
puts (1..n).select{|s| c=s.to_s.chars.map(&:to_i).reduce(:+); a<=c&&c<=b }.reduce(:+)

a,b,c,d=getis
puts %w(Balanced Left Right)[a+b<=>c+d]

puts (gets.sub(?\s,'').to_i**0.5)%1==0? "Yes" : "No"

a,b=getis
puts a*b%2==0? "Even" : "Odd"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N, X, T;
	cin >> N >> X >> T;
	cout << (N+X-1)/X*T << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define vll vector<ll>
#define fl(i,a,b) for(ll i=a;i<=b;i++)
#define flr(i,a,b) for(ll i=a;i>=b;i--)
#define print(v) for(auto x: v) {cout<<x<<" ";} cout<<"\n";
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define test() ll te; cin >> te; while(te--)
#define MOD 998244353 //1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const int N=1e6;

ll n,ans;
vll h(N),a(N),dp(N);

ll t[2 * N];

void build() {
  for (ll i = n - 1; i > 0; --i) t[i] = max(t[i<<1] , t[i<<1|1]);
}

void modify(ll p, ll value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = max(t[p] , t[p^1]);
}

ll query(ll l, ll r) {
  ll res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res =max(res, t[l++]);
    if (r&1) res =max(res, t[--r]);
  }
  return res;
}

int main()
{
	cin>>n;
	fl(i,0,n-1) cin>>h[i];
	fl(i,0,n-1) cin>>a[i];
	n++;
	build();
	fl(i,0,n-1)
	{
		ll ht=h[i];
		ll x=query(0,ht);
		dp[i]=x+a[i];
		modify(h[i],dp[i]);
		ans=max((ll)ans,dp[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 29900
#include <iostream>
using namespace std;
typedef unsigned long long Int;

int main(void){
  Int n, x;
  cin >> n >> x;
  if(x % 1000 != 0){
    cout << "-1 -1 -1";
    return 0;
  }
  x /= 1000;

  for(Int i=0;i<=n;i++){
    for(Int j=0;j+i<=n;j++){
      Int k = n - i - j;
      if(10*i+5*j+k==x){
        cout << i << " " << j << " " << k;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
}

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

using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;

    a += b;
    int num = atoi(a.c_str());
    for (int i = 2; i <= 100100; ++i)
    {
        if (i*i == num)
        {
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
    return 0;

    return 0;
}

Measured memory_bytes: 256