akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int cnt[10010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(x, 1, 100) {
        REP(y, 1, 100) {
            REP(z, 1, 100) {
                int num = x * x + y * y + z * z;
                num += x * y + y * z + z * x;
                if(num <= N) cnt[num]++;
            }
        }
    }
    REP(i, 1, N) {
        cout << cnt[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) output(x), output("\n")
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	OUTPUT(n);
	cout << n * n << endl;
	return 0;
}


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

int main() {
  int X,ans=0;
  cin >> X;
  if (X==2){
  cout << 2 << endl;
  }
  else{
  for (int j=X;j<100004;j++){
  for (int i=2;;i++){
  if (j%i==0){
  break;
  }
  else if (j%i!=0 && i==j-1){
  //X=prime
  cout << j << endl;
  ans=1;
  }
  }
  if (ans==1){
  break;
  }
  }
  }
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=200010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
struct edge{int to,cost;};
vector<int> dijkstra(int s,vector<edge> g[]){
    vector<int> d(MAX,INF);
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.push(P(0,s));
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        for(int i=0;i<g[v].size();i++){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}
vector<edge> G[200010];
int main(){
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back({b,1});
		G[b].push_back({a,1});
	}
	vector<int> d=dijkstra(0,G);
	if(d[n-1]==2){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
    return 0;
}


Measured memory_bytes: 15080
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int a[300100]={};
int b[300100]={};
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;

    REP(i,1,n+1){
      a[i] = a[i-1];
      b[i] = b[i-1];
      if(s[i-1]=='E') a[i]+=1;
      if(s[i-1]=='W') b[i]+=1;
    }
    int mi = inf;
    REP(i,1,n+1){
      mi = min(mi,a[n]-a[i]+b[i-1]);
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 2964
/*

*/
#include <bits/stdc++.h>

using namespace std;

#define ll          long long int
#define mp          make_pair
#define pb          push_back
#define fi          first
#define si          second
#define fastIO      ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n)      for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n)     for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n)      for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n)     for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m)  for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m)  for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e5 + 1;
const int mod = 1e9+7;



int main(){
fastIO
    ll n, capaciy;
    cin>>n>>capaciy;
    ll *weight = new ll[n+1];
    ll *cost = new ll[n+1];
    ll dp[101][nax];
    memset(dp, 0, sizeof(dp));
    for(ll i=1; i<=n; i++){
    	cin>>weight[i];
    	cin>>cost[i];
    }

    for(ll i=1; i<=n; i++){
    	for(ll j=0; j<=capaciy; j++){
    		ll op1 = dp[i - 1][j];
    		ll op2 = (weight[i] <= j) ? (cost[i] + dp[i-1][j - weight[i]]) : 0;
    		dp[i][j] = max(op1, op2);
    	}
    }

    cout<<dp[n][capaciy];
}

Measured memory_bytes: 82468
#include <iostream> 
using namespace std;
int N=1000000007;
int main()
{
	int n,i=1;
	long long x=3;
	char s[2][60];
	cin>>n;
	cin>>s[0];
	cin>>s[1];	
	if(s[0][0]!=s[1][0])
	{
		i=2;
		x=6; 
	} 		
	for(;i<n;i++)
	{
		if(s[0][i-1]==s[1][i-1])
			x=(x*2)%N;						
		else					
			if(s[0][i]!=s[1][i])
				x=(x*3)%N;
		if(s[0][i]!=s[1][i])
			i++;
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<set>
int n;std::set<int>s;
main()
{
	scanf("%d",&n);
	s.insert(n);
	for(register int i=2;;++i)
	{
		if(n&1)n=n*3+1;
		else n>>=1;
		if(s.count(n)){printf("%d",i);return 0;}
		s.insert(n);
	}
}/**/

Measured memory_bytes: 256
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var t = int.Parse(_[0]);
            var x = int.Parse(_[1]);

            var d = (1.0 * t) / x;
            Console.WriteLine(string.Format("{0:F9}",d));
        }
    }
}


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

int n;
ll k;
vector<ll> pos, neg;

ll check(ll mid) {
    ll cnt=0;
    if (mid>=0) { // product is positive
        // (+) * (+)
        for (int i=0; i<pos.size(); ++i) {
            if (!pos[i]) {
                cnt+=pos.size()-(i+1);
                continue;
            }

            // pos[i] * index <= mid
            // index <= mid / pos[i]
            ll need=mid/pos[i];

            int index=upper_bound(pos.begin(), pos.end(), need)-pos.begin();
            if (index>i) {
                cnt+=index-i-1;
            }
        }

        // (-) * (-)
        for (int i=0; i<neg.size(); ++i) {
            ll need=mid/neg[i];

            int index=upper_bound(neg.begin(), neg.end(), need)-neg.begin();
            if (index>i) {
                cnt+=index-i-1;
            }
        }

        // (+) * (-)
        cnt+=1LL*pos.size()*neg.size();
        return cnt;
    }

    mid*=-1;
    // (+) / (-)
    for (int i=0; i<pos.size(); ++i) {
        if (!pos[i]) {
            continue;
        }

        ll need=mid/pos[i]-(mid%pos[i]==0);

        cnt+=neg.end()-upper_bound(neg.begin(), neg.end(), need);
    }

    return cnt;
}

ll BSFind() {
    ll low=-1e18-18, high=1e18+18, res=0;
    while (low<=high) {
        ll mid=low+(high-low)/2;
        if (check(mid)>=k) {
            high=mid-1;
            res=mid;
        }
        else {
            low=mid+1;
        }
    }

    return res;
}

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

    cin >> n >> k;
    while (n--) {
        int a;
        cin >> a;

        if (a>=0)       pos.push_back(a);
        else            neg.push_back(-a);
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    cout << BSFind();

    return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define si set<int>
#define sll set<ll>
#define ins insert
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define mod 1000000007
using namespace std;
/*lli power(lli a,lli n)
{lli ans=0;
   while(n>0)
   {
      if(n%2)
       {
         ans=ans*a;
         n--; 
       }
      else
        {
         a=a*a;
         n=n/2; 
        }
  }
return ans;
 }*/
/*ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}*/ 
/*int is_prime[1000001];
void sieve(){
    int maxN=1000000;
    for(int i=1;i<=maxN;i++)
    is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i*i<=maxN;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=maxN;j+=i)
            is_prime[j]=0;
        }
    }
}*/
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
          int n;
          cin>>n;
         int a[n];
        for(int i=0;i<n;i++)
          cin>>a[i];
        int dp[n];
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
 
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   
  }
  cout<<dp[n-1];
return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
int main(void){
 
	int A, B, K;
	int i, j=1;
 
	scanf("%d", &K);
	scanf("%d", &A);
	scanf("%d", &B);
	
 
	for (i = A; i <= B; i++) {
		if (i % K == 0) {
			j *= 0;
		}
	}
	
	if (j == 0) {
		printf("OK");
	}
	else {
		printf("NG");
	}
 
	return 0;
}

Measured memory_bytes: 2152
#include <stdio.h>
#include <stdlib.h> 
typedef struct{
    int a,b,c;
}Node;
void insert(int, int);
void inParse(int);
void preParse(int);
Node A[500001];
int main(void)
{
    char s[8];
    int m;
    int num,count=0;
    int i;
  
    scanf("%d", &m);  
    for(i=0; i<m; i++){
        scanf("%s", &s);
        if(s[0]=='i'){ 
          scanf("%d", &num); 
          insert(count, num); 
          count++; 
        }
        if(s[0]=='p'){
          if(count>0) inParse(0);
            printf("\n");
            if(count>0) preParse(0);
            printf("\n");
        }
    }  
    return 0;  
}
  
void inParse(int p){
    if(A[p].b>=0) inParse( A[p].b);
    printf(" %d", A[p].a);
    if(A[p].c>=0) inParse( A[p].c);
}
  
void preParse(int p){
    printf(" %d", A[p].a);
    if(A[p].b>=0) preParse(A[p].b);
    if(A[p].c>=0) preParse(A[p].c);
}
  
void insert(int count, int z){
    int x=0, y;
    if(count<1) x=-1;
  
    A[count].a = z;
    A[count].b = -1;
    A[count].c = -1;
  
    while(x>=0){
        y = x; 
        if(z < A[x].a)x = A[x].b; 
        else x = A[x].c; 
    }
    if(count<1){}
    else if(z < A[y].a)A[y].b = count; 
    else A[y].c = count; 
}



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

using namespace std;

int main()
{
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; i++){
        for (int j = 20; j <= d; j++){
            int d1 = j % 10;
            int d10 = j / 10;
            if (d1 * d10 == i && d1 >= 2 && d10 >= 2){
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int x,t;
  cin>>x>>t;
  if(x-t<0) cout<<0<<endl;
  else cout<<x-t<<endl;

  return 0;
}





Measured memory_bytes: 256
n = int(input())
s_lst = [str(input()) for i in range(n)]
s_lst.sort()

count_lst = []
count = 1

if n==1:
    count_lst.append(1)
else:
    for i in range(1,n):
        s1 = s_lst[i-1]
        s2 = s_lst[i]

        if s1==s2:
            count += 1
            if i==n-1:
                count_lst.append(count)
        else:
            count_lst.append(count)
            count = 1

    if s_lst[-1]!=s_lst[-2]:
        count_lst.append(1)


new_slst = list(set(s_lst))
new_slst.sort()
max_count = max(count_lst)
answer_lst = []

for i in range(len(count_lst)):
    cou = count_lst[i]
    s = new_slst[i]
    if cou==max_count:
        answer_lst.append(s)

answer_lst.sort()
for i in range(len(answer_lst)):
    answer = answer_lst[i]
    print(answer)

Measured memory_bytes: 31172
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] ch=sc.next().toCharArray();
    StringBuffer sb=new StringBuffer();
    for(int i=0;i<12;i++){
      if(i==3){
        sb.append(ch[i]+" ");
      }else{
        sb.append(ch[i]);
      }
    }
    System.out.println(sb);
  }
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        int ans = 0;
        for(int i=0; i<h*w; ++i){
            int a;
            cin >> a;
            ans += a;
        }
        cout << ans << endl;
        return 0;
    }

    vector<vector<int> > a(h, vector<int>(w));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> a[y][x];
        }
    }

    vector<vector<int> > dp(w, vector<int>(w, 0));
    for(int y=0; y<h; ++y){
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1+1; x2<w; ++x2){
                dp[x1][x2] += a[y][x1] + a[y][x2];
            }
        }
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1+1; x2<w; ++x2){
                dp[x1+1][x2] = max(dp[x1+1][x2], dp[x1][x2] + a[y][x1+1]);
            }
        }
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1+1; x2<w-1; ++x2){
                dp[x1][x2+1] = max(dp[x1][x2+1], dp[x1][x2] + a[y][x2+1]);
            }
        }
    }
    cout << dp[w-2][w-1] << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int a,b,i,f,c=0;
  while(scanf("%d %d",&a,&b),a+b){
    f=1;
    if(c)
      putchar('\n');
    for(i=a;i<=b;i++){
      if(i%4==0){
	if(i%400==0){
	  printf("%d\n",i);
	  f=0;
	}
	else if(i%100==0)
	  continue;
	else{
	  printf("%d\n",i);
	  f=0;
	}
      }
    }
    if(f)
      puts("NA");
    c++;
  }
  return 0;
}

Measured memory_bytes: 616
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>

const int kMaxTown = 10;
const int kInf = 1 << 16;

int cost[kMaxTown][kMaxTown];

int main(){

	while (1){
		int n;
		scanf(" %d", &n);
		if (n == 0) break;

		for (int i = 0; i < kMaxTown; i++)
			for (int j = 0; j < kMaxTown; j++)
				cost[i][j] = (i == j) ? 0 : kInf;

		for (int i = 0; i < n; i++){
			int a, b, c;
			scanf(" %d %d %d", &a, &b, &c);
			cost[a][b] = cost[b][a] = c;
		}

		for (int k = 0; k < kMaxTown; k++)
			for (int i = 0; i < kMaxTown; i++)
				for (int j = 0; j < kMaxTown; j++)
					cost[i][j] = std::min(cost[i][j], cost[i][k] + cost[k][j]);

		int best = 0;
		int bestSum = kInf;
		for (int i = 0; i < kMaxTown; i++){
			int sum = 0;
			for (int j = 0; j < kMaxTown; j++)
				if (cost[i][j] != kInf)
					sum += cost[i][j];
			if (sum == 0) continue;
			if (sum < bestSum){
				bestSum = sum;
				best = i;
			}
		}

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

Measured memory_bytes: 1028
import queue

n = int(input())

Graph = [[x-1 for x in list(map(int, input().split()))[2:]] for i in range(n)]


# for i in range(n):
#     li = list(map(int, input().split()))
#     a = li[0]
#     a-=1
#     b = li[2:]
#     Graph[a].append(b)


dist = [-1]*n
q = queue.Queue()

dist[0] = 0
q.put(0)

while not q.empty():
    v = q.get()

    for nv in Graph[v]:
        if dist[nv] != -1: continue

        dist[nv] = dist[v] + 1
        q.put(nv)


for v in range(n):
    print(v+1, dist[v])


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

int main(){
  ll A,B,N;
  cin>>A>>B>>N;
  
  ll ans=1000000000001LL;
  for(ll i=1;i<=N;i++){
    for(ll j=1;j<=N;j++){
      if(B*i%j)continue;
      ans=min(ans,abs(A-B*i/j));
    }
  }
  cout <<ans<<endl;
  return 0;
}

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

int main(){

  int n,x=0;
  string s;
  cin >> n >> s;
  int m=0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'I') {
      x++;
      m = max(m,x);
    } else if (s[i] == 'D') {
      x--;
    }
  }

  cout << m << endl;

}


Measured memory_bytes: 256
s = input()
a, b = (s[0], s[1])
N = len(s)
l = s[N-1]
for c in s:
    if c not in (a, b):
        if a == l:
            if N%2 == 0:
                print("First")
            else:
                print("Second")
        else:
            if N%2 == 0:
                print("Second")
            else:
                print("First")
        break
else:
    print("Second")   

Measured memory_bytes: 3316
#include <stdio.h>

int main(void)
 {
   int a[10], n[10], max = 0;
    int i, s, j;
    int ans[3];

    for (i = 0; i < 10; i++){
      a[i] = 0;
    }

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


    for (j = 0; j < 3; j++){
      for (i = 0; i < 10; i++){
        if (max < n[i]){
          max = n[i];
          s = i;
        }
      }
      ans[j] = max;
      max = 0;
      a[s] = j + 1;
      n[s] = 0;
    }

    for (i = 0; i < 10; i++){
    }

    for (i = 0; i < 3; i++){
      printf("%d\n", ans[i]);
    }

    return (0);

 }

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a.push_back(1e10);
  int l;
  cin >> l;
  vector<vector<int>> table(n, vector<int>(20));
  for (int i = 0; i < n; i++) {
    int idx = prev(upper_bound(a.begin(), a.end(), a[i] + l)) - a.begin();
    table[i][0] = idx;
  }
  for (int j = 1; j < 20; j++) {
    for (int i = 0; i < n; i++) {
      table[i][j] = table[table[i][j - 1]][j - 1];
    }
  }
  int q;
  cin >> q;
  for (int u = 0; u < q; u++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (a > b) swap(a, b);
    int ans = 0;
    int cur = a;
    for (int j = 19; j >= 0; j--) {
      if (table[cur][j] < b) {
        cur = table[cur][j];
        ans += 1 << j;
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}

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

int main(void){
  int K;
  string S;
  cin>>K;
  cin>>S;
  
  if(S.size()<=K){
    cout<<S<<endl;
  }else{
    string result="";
    for(int i=0;i<K;i++){
      result+=S.at(i);
    }
    cout<<result+"..."<<endl;
  }
}

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

int Egcd(int x, int y) {
	if (x < y) swap(x, y);
	if (y == 0) return x;
	return Egcd(y, x % y);
}

int main() {
	int a, b;
	while (cin >> a >> b) cout << Egcd(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3064
use std::cmp::max;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    s: chars
    }
    let acgt = ['A', 'C', 'G', 'T'];
    let mut ans = 0;
    let mut c = 0;
    for i in s{
        if acgt.contains(&i){
            c += 1;
        } else {
            ans = max(ans, c);
            c = 0;
        }
    }
    ans = max(ans, c);
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include<stdio.h>
#define N 100

int main()
{
  int i,j,k,xu;
  int fan,malong=0;
  int tum[N][N],sum[N],num[N];

  scanf("%d",&xu);
  for(i=0;i<xu;i++)
    {
      for(j=0;j<xu;j++)scanf("%d",&tum[i][j]);
    }
  for(i=0;i<xu;i++){
    sum[i]=0;
    num[i]=2000;
  }
  num[0]=0;
  for(i=0;i<xu-1;i++)
    {
      k=2000;
  for(j=0;j<xu;j++)
    {
      if(num[j]<k && sum[j]==0)
	{
	  k=num[j];
	  fan=j;
	}
    }
  sum[fan]=1;

  for(j=0;j<xu;j++)
    {
      if(tum[fan][j] !=-1 && tum[fan][j]<num[j] && sum[j] ==0)num[j]=tum[fan][j];
    }
    }
  for(i=0;i<xu;i++)malong=malong+num[i];

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

}



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

int main() {
  ll MOD = 1e9 + 7;
  ll N;
  ll sum = 0;
  ll ans = 0;
  cin >> N;

  for (ll i = 0; i < N; i++) {
    ll temp;
    cin >> temp;
    ans = (ans + temp * sum) % MOD;
    sum = (sum + temp) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;


int main(){
    int k, s;
    int counter = 0;
    cin >> k >> s;
    for(size_t i = 0; i <= k; i++)
    {
        for(size_t j = 0; j <= k; j++)
        {
            if(0<=s-i-j && s-i-j<=k) counter ++;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(2e4+5)
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
struct node{
	int w,s,v;
	bool operator<(const node &a) const{
		return w+s<a.w+a.s;
	}
};
int main(){
	int n,i,j;cin>>n;vector<node>v(n);for(i=0;i<n;i++) cin>>v[i].w>>v[i].s>>v[i].v;
	sort(all(v));vvi d(n+1,vi(mxn,-1));d[0][0]=0;
	for(i=1;i<=n;i++){
		for(j=0;j<mxn;j++){
			if(d[i-1][j]==-1) continue;
			d[i][j]=max(d[i-1][j],d[i][j]);
			if(j+v[i-1].w<mxn&&j<=v[i-1].s) d[i][j+v[i-1].w]=max(d[i][j+v[i-1].w],d[i-1][j]+v[i-1].v);
		}
	}
	//for(i=0;i<n;i++) cout<<v[i].w<<" "<<v[i].s<<" "<<v[i].v<<endl;
	cout<<*max_element(all(d[n]))<<endl;
}


Measured memory_bytes: 163592
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100002];
bool used[100002];
int ct;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
}
int main()
{
	int n; cin>>n;
	int a[100002], b[100002], as[100002], bs[100002], s=0;
	map<int, int> mp;
	for(int i=0; i<n; i++){
		cin>>a[i]; as[i]=a[i];
		s^=a[i];
	}
	as[n]=a[n]=s;
	sort(as, as+n+1);
	s=0;
	int ans=0;
	for(int i=0; i<n; i++){
		cin>>b[i]; bs[i]=b[i];
		s^=b[i];
		if(a[i]!=b[i]) mp[b[i]]=0, ans++;
	}
	bs[n]=b[n]=s;
	mp[a[n]]=mp[b[n]]=0;
	sort(bs, bs+n+1);
	for(int i=0; i<=n; i++){
		if(as[i]!=bs[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(mp.empty()){
		cout<<0<<endl;
		return 0;
	}
	int c=0;
	for(auto& p:mp){
		p.second=c; c++;
	}
	for(int i=0; i<n; i++){
		int x=mp[a[i]], y=mp[b[i]];
		g[x].push_back(y); g[y].push_back(x);
	}
	for(int i=0; i<c; i++){
		if(!used[i]){
			dfs(i); ct++;
		}
	}
	ans+=(ct-1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main(){
    int ac=0,wa=0,tle=0,re=0,n;
    string str;
    vector<string>ans;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>str;
        ans.push_back(str);
        if(ans[i] == "AC")ac++;
        if(ans[i] == "WA")wa++;
        if(ans[i] == "TLE")tle++;
        if(ans[i] == "RE")re++;
    }
    cout << "AC x "<< ac << endl;
    cout << "WA x "<< wa << endl;
    cout << "TLE x "<< tle << endl;
    cout << "RE x "<< re << endl;

}

Measured memory_bytes: 7464
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Measured memory_bytes: 26840
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c;
	else if(b==c)cout<<a;
	else cout<<b;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
H,W = map(int,input().split())
a = [["."]*(W+2)]*(H+1)
f = True
for i in range(H):
    a[i+1] = ["."]
    a[i+1].extend([x for x in input()])
    a[i+1].append(".")
a.append(["."]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if a[i][j] == "#":
            if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                f = False
                break
                break
if f:
    print("Yes")
else:
    print("No")

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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  ll n,a,b; cin >> n >> a >> b;
  if(a > b){
    std::cout << 0 << '\n';
    return 0;
  }
  if(n == 1){
    if(a == b) std::cout << 1 << '\n';
    else std::cout << 0 << '\n';
    return 0;
  }

  ll sum1 = a*(n-2);
  ll sum2 = b*(n-2);

  std::cout << sum2 - sum1 + 1 << '\n';
}


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

int main(){
  ll a;
  cin>>a;
  ll ans=a-1;
  for(int i=2;i<=sqrt(a)+1;i++){
    if(a%i==0){
      ans=a/i+i-2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    ll ans = 0;
    ll amx,amn,bmx,bmn;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        ll a = x + y;
        ll b = x - y;
        if(i==0){
            amx = amn = a;
            bmx = bmn = b;
        }
        chmax(ans,max(abs(amx - a),abs(amn - a)));
        chmax(ans,max(abs(bmx - b),abs(bmn - b)));
        chmax(amx,a);
        chmin(amn,a);
        chmax(bmx,b);
        chmin(bmn,b);
    }
    cout << ans << endl;
}

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


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

  if (a + b >= 10) {
    cout << "error" << endl;
  } else {
    cout << a + b << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3596
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A < 10 && B < 10) {
			System.out.println(A * B);
			return;
		}
		System.out.println(-1);
		return;

	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 22484
#include<stdio.h>

int main(){
  int n, i, j, u, k, v, Adj[101][101];
  
  scanf("%d", &n);

  for(i = 1; i < n + 1; i++){
    for(j = 1; j < n + 1; j++)
      Adj[i][j] = 0;
  }
  
  for(i = 1; i < n + 1; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      Adj[i][v] = 1;
    }
  }
  
  for(i = 1; i < n + 1; i++){
    for(j = 1; j < n + 1; j++){
      if(j == n)
	printf("%d\n", Adj[i][j]);
      else
	printf("%d ", Adj[i][j]);
    }
  }

  return 0;
}



Measured memory_bytes: 2108
package main

import "fmt"

func main() {
	var d1, d2, d3 int
	var sum int
	const jNum = 22
	fmt.Scanf("%d %d %d", &d1, &d2, &d3)

	sum = d1 + d2 + d3
	if sum >= jNum {
		fmt.Print("bust")
	} else {
		fmt.Print("win")
	}
}


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

const int N = 3001;
vector<int> arr(N); 
int n; 
vector< vector<long int> > memo(3001, vector<long int> (3001,-1)); 


long int find(int i, int j)
{  
    if( i > j ) return 0 ;
    
    long int &res = memo[i][j];
    if(res != -1) return res;
    
    res = arr[i] - find(i+1,j);
    res = max(res,arr[j]-find(i,j-1));
    
    return res; 
}
void solve( )
{
    
   cin >> n ;
   for(int i = 0 ; i < n ; i ++) cin >> arr[i];
   
   cout <<  find(0,n-1); 
  

}

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


    solve(); 
    return 0;
}




Measured memory_bytes: 74288
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535
int main(void){
     int a, b, c;
     double S, L, h;
     scanf("%d %d %d", &a, &b, &c);
     S = 0.5*a*b*sin(c*PI/180);
     L = a + b + sqrt(a*a + b*b - 2*a*b*cos(c*PI/180));
     h = (2*S)/a;
     printf("%lf\n", S);
     printf("%lf\n", L);
     printf("%lf\n", h);
     return 0;
}


Measured memory_bytes: 2108
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
    #define REP(i,n)   FOR(i,0,n)
     
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
      int a,b,c,d,e;
      cin>>a>>b>>c;
      e=a-b;
      d=e%c;
      cout<<d<<"\n";
    return 0;
    }  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

int A, B;

int main() {
	cin >> A >> B;
	cout << max(A + B, max(A - B, A * B)) << endl;
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())

inf = float("inf")

max_v = 1000 * N + 1
dp = [inf for _ in range(max_v)]
dp[0] = 0
sum_v = 0

for i in range(N):
    w, v = map(int, input().split())
    for j in range(max_v, v-1, -1):
        new = dp[j-v] + w
        if new > W:
            continue
        if dp[j] > new:
            dp[j] = new

ans = 0
for sum_v in range(max_v):
    if dp[sum_v] <= W:
        ans = sum_v
print(ans)

Measured memory_bytes: 52016
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h){
        cin >> s[i];
    }
    rep(i,h){
        rep(j,2){
            cout << s[i] << endl;
        }
        
    }
    return 0;
}


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

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

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

int main()
{
  int n;
  
  scanf("%d",&n);
  
  int a[n],b[n];
  int i;
  int ans;
  
  for(i=0;i<n;i++)
  {
    scanf("%d%d",&a[i],&b[i]);
  }
  
  qsort(a,n,sizeof(int),cmp_1);
  qsort(b,n,sizeof(int),cmp_2);
  
  ans=a[0]-1;
  for(i=1;i<n;i++)
  {
    ans+=a[i]-a[i-1]-1;
  }  
  ans+=b[n-1];

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

Measured memory_bytes: 1396
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N, X, T = map(int, input().split())

q = N // X
r = N % X

if r == 0:
    print(q * T)
else:
    print(q * T + T)


Measured memory_bytes: 68488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[] a = new int[n];
		int max = -101;
		int min = 101;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
			min = Math.min(min, a[i]);
		}
		int ans = Integer.MAX_VALUE;
		int t;
		for (int i = min; i <= max; i++) {
			t = 0;
			for (int j = 0; j < n; j++) {
				t += (a[j] - i) * (a[j] - i);
			}
			ans = Math.min(ans, t);
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

vector<ll> v;
ll n,q;

void f(ll &a,ll b)
{
	if(v[2] > a)
	{
		a = 1;
		return;
	}
	vector<ll>::iterator it = upper_bound(ALL(v),a);
	
	while(a > b && it > v.begin()+1)
	{
		it--;
		a = *(it-1) + ((a - *it) / n);
	}
	return;
}

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

	ll k = 1;
	if(n == 1)
	{
		REP(i,q)
		{
			int a,b;cin >> a >> b;
			cout << min(a,b) << endl;
		}
		return 0;
	}

	
	for(ll i = 1 ;i <= 10000000000;)
	{
		v.PB(i);
		i += k;
		k *= n;
	}
	
	
	REP(i,q)
	{
		ll a,b;cin >> a >> b;
		
		while(1)
		{
			if(a == b)
			{
				cout << a << endl;
				break;
			}
			if(a > b)
				f(a,b);
			else
				f(b,a);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<sstream>
#include<cstdlib>
using namespace std;

set<int> S;

void cal(vector<string> V){
  
  for(int i=1;i<V.size()-1;i++){
    if(V[i-1]=="(" && V[i+1]==")"){
      V.erase(V.begin()+i+1);
      V.erase(V.begin()+i-1);
      i=max(0,i-2);
    }
    }
  if(V.size()==1){
    S.insert(atoi(V[0].c_str()));
  }
  else {
    for(int i=0;i<V.size();i++){
      if(V[i]=="+"){
        if(V[i+1]=="(" || V[i-1]==")")continue;
        int a=atoi(V[i-1].c_str())+atoi(V[i+1].c_str());
	stringstream ss;
	ss << a;
	string s=ss.str();
        vector<string> v=V;
        v.erase(v.begin()+i+1);
        v.erase(v.begin()+i);
	v.erase(v.begin()+i-1);
	v.insert(v.begin()+i-1,s);
	cal(v);
      }
      if(V[i]=="-"){
	if(V[i+1]=="(" || V[i-1]==")")continue;
        int a=atoi(V[i-1].c_str())-atoi(V[i+1].c_str());
	stringstream ss;
	ss << a;
	string s=ss.str();
        vector<string> v=V;
        v.erase(v.begin()+i+1);
        v.erase(v.begin()+i);
	v.erase(v.begin()+i-1);
	v.insert(v.begin()+i-1,s);
	cal(v);
      }
      if(V[i]=="*"){
	if(V[i+1]=="(" || V[i-1]==")")continue;
        int a=atoi(V[i-1].c_str())*atoi(V[i+1].c_str());
	stringstream ss;
	ss << a;
	string s=ss.str();
        vector<string> v=V;
        v.erase(v.begin()+i+1);
        v.erase(v.begin()+i);
	v.erase(v.begin()+i-1);
	v.insert(v.begin()+i-1,s);
	cal(v);
      }
      if(V[i]=="/"){
	if(V[i+1]=="(" || V[i-1]==")")continue;
	if(V[i+1]=="0")continue;
        int a=atoi(V[i-1].c_str())/atoi(V[i+1].c_str());
	stringstream ss;
	ss << a;
	string s=ss.str();
        vector<string> v=V;
        v.erase(v.begin()+i+1);
        v.erase(v.begin()+i);
	v.erase(v.begin()+i-1);
	v.insert(v.begin()+i-1,s);
	cal(v);
      }
    }
  }
}

int main()
{
  string s;
  while(1){
    cin>>s;
    if(s[0]=='#')break;
    vector<string> V;
    string samp;
    for(int i=0;i<s.length();i++){
      if('0'<=s[i] && s[i]<='9'){
	samp+=s[i];
	if(i==s.length()-1)V.push_back(samp);
      }
      else {
	if(!samp.empty()){
	  V.push_back(samp);
	  samp="";
	}
	samp=s[i];
	V.push_back(samp);
	samp="";
      }
    }
    S.clear();
    cal(V);
    cout<<S.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<bool> vecbool;
typedef vector<vector<int>> vec2int;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  ll a, b, n;
  cin >> a >> b >> n;
  cout << (a * min(b - 1, n)) / b << endl;
}

Measured memory_bytes: 3612
N = int(input())
t = [0] * N
for i in range(N):
    t[i] = list(map(int, input().split()))

t = sorted(t, key = lambda x: x[1])

n = 0
d = 0
f = 0
for i in range(N):
    n += t[i][0]
    if n > t[i][1]:
        f = 1
        break

if f == 0:
    print("Yes")
else:
    print("No")

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


int main(){
    int x,y,t;
    while (1){
        cin >> x >> y;
        
        if (x > y){
            t = x, x = y, y = t;
        }
    if ( x == 0 && y == 0 )break;
    cout << x << " " << y << endl;
    }
    
    return 0;
    
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int a, b;
  cin >> a >> b;
  cout << ((a * b) % 2 == 0 ? "Even" : "Odd") << endl;
}

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

using namespace std;

int main()
{
    bool adj[128][128] = {0};
    adj['A']['B'] = 1; adj['A']['D'] = 1; adj['B']['C'] = 1;
    adj['B']['E'] = 1; adj['D']['E'] = 1; adj['D']['G'] = 1;
    adj['E']['H'] = 1; adj['E']['F'] = 1; adj['C']['F'] = 1;
    adj['F']['I'] = 1; adj['G']['H'] = 1; adj['H']['I'] = 1;
    
    for (int i = 0; i < 1000; i++){
        char s[16];
        
        scanf("%s", s);
        
        bool ok = true;
        for (int i = 1; s[i]; i++){
            if (!(adj[s[i]][s[i - 1]] || adj[s[i - 1]][s[i]])){
                ok = false;
            }
        }
        if (ok) printf("%s\n", s);
    }
    
    return (0);
}

Measured memory_bytes: 1136
#include <stdio.h>

int main(void){
  int n,x,y,z,k;
  long long Y;
  scanf("%d %lld",&n,&Y);
  for(int i=0;i<=2000;i++){
    for(int j=0;j<=2000;j++){
      k=n-i-j;
      if(k<0) continue;
      if(10000*i+5000*j+1000*k==Y){
        printf("%d %d %d",i,j,k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1");

  return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define P pair<ll, int> // <Minimum distance, Vertex number>

struct edge {
    int to, cost;
};

vector<ll> getDist(int s, vector<vector<edge>> E, int N) {
    vector<ll> dist(N, 1e18);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    while (!que.empty()) {
        int u = que.top().second;
        int d = que.top().first;
        que.pop();
        if (dist[u] < d) {
            continue;
        }

        for (edge e : E[u]) {
            int v = e.to;
            if (dist[v] > dist[u] + e.cost) {
                dist[v] = dist[u] + e.cost;
                que.push(P(dist[v], v));
            }
        }
    }

    return dist;
}

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    vector<vector<edge>> E(N);
    for (int i = 0; i < N - 1; i++) {
        E[i].push_back(edge({i + 1, 1}));
        E[i + 1].push_back(edge({i, 1}));
    }
    E[X].push_back(edge({Y, 1}));
    E[Y].push_back(edge({X, 1}));

    vector<vector<ll>> dist(N);
    for (int i = 0; i < N; i++) {
        dist[i] = getDist(i, E, N);
    }

    vector<int> ans(N, 0);
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ans[dist[i][j]]++;
        }
    }

    for (int i = 1; i <= N - 1; i++) {
        cout << ans[i] << endl;
    }
}


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

int main() {
  int N; cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }
  int border = N / 2;
  int K_min, K_max;
  int cnt;
  
  sort(d.begin(), d.end());
  
  K_min = d[border-1] + 1;
  K_max = d[border];
  cnt = K_max - K_min + 1;
  
  if (d[border-1] == d[border]) cnt = 0;
  
  cout << cnt << endl;
  
  return 0;
}
  

Measured memory_bytes: 640