akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
#define M_PI 3.14159265358979

struct Point {
  double x;
  double y;
};

void koch(int,struct Point,struct Point);

void koch(int n,struct Point a,struct Point b) {
  if(n == 0) return;

  struct Point s,t,u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);

  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);

  koch(n-1,u,t);
  printf(" %.8f %.8f\n",t.x,t.y);

  koch(n-1,t,b);
}


int main() {
  struct Point a,b;
  int n;

  scanf("%d",&n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

Measured memory_bytes: 640
unittest
{
	assert( [ "5", "2 4 4 0 2" ].parse.expand.solve == 4 );
	assert( [ "7", "6 4 0 2 4 0 2" ].parse.expand.solve == 0 );
	assert( [ "8", "7 5 1 1 7 3 5 3" ].parse.expand.solve == 16 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

const MOD = 10L ^^ 9 + 7;

auto solve( long[] as )
{
	// 奇数人の場合 = 0が1人、1以上の偶数が2人ずつ じゃないと成り立たない
	// 偶数人の場合 = 1以上の奇数が2人ずつ じゃないと成り立たない
	
	as.sort();
	
	auto ans = 1L;
	auto d = 0L;
	if( as.length % 2 == 1 )
	{
		if( as[ 0 ] != 0 ) return 0L;
		as.popFront;
		d = 2;
	}
	else
	{
		d = 1;
	}
	
	for( auto i = 0L; i < as.length; i += 2 )
	{
		if( as[ i ] != d || as[ i + 1 ] != d ) return 0L;
		ans = ( ans * 2 ) % MOD;
		d += 2;
	}

	return ans;
}


Measured memory_bytes: 4540
n,m,x,y = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))

x_max = max(X)
y_min = min(Y)

for i in range(x+1,y+1):
  if x_max < i and y_min >= i:
    print("No War")
    exit()

print("War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> v;
    vector<pair<int, int> > pr;
    for (int i=0; i < n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        v.push_back(a);
        pr.push_back({b, c});
    }
    int profit = 0;
    for (int i=0;i<n;i++) profit += v[i] * pr[i].first;
    int L = -1, R = x*n;
    while (R-L>1){
        int M = (L+R)/2;
        int full = M/x, prt = M%x;
        vector<pair<int, int> > poss;
        for (int i=0; i < n; i++){
            int F = v[i]*pr[i].first + (x-v[i])*pr[i].second;
            int T;
            if (v[i] >= prt){
                T = prt*pr[i].first;
            }
            else{
                T = v[i]*pr[i].first + (prt-v[i])*pr[i].second;
            }
            poss.push_back({F, T});
        }
        sort(poss.begin(), poss.end(), greater<pair<int, int> > ());
        int A = 0, B = 0;
        for (int i=0; i < full; i++) A += poss[i].first;
        B = A + poss[full].first;
        bool can = false;
        for (int i=0; i < n; i++){
            int var = 0;
            if (i < full){
                var = poss[i].second + B - poss[i].first;
            }
            else{
                var = A + poss[i].second;
            }
            if (var >= profit) can = true;
        }
        if (can) R = M;
        else L = M;
    }
    cout << R;
}


Measured memory_bytes: 6876
#include <stdio.h>
using namespace std;

int main()
{
  int i = 1;
  while (1)
  {
    int x;
    scanf("%d", &x);
    if (x == 0)
      break;
    printf("Case %d: %d\n", i, x);
    i++;
  }

  return 0;
}


Measured memory_bytes: 2576
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}


void solve()
{
    const ll mod = 1000000007;
    ll N,M;
    cin >> N >> M;
    vll S(N);
    vll T(M);
    for1(i,N) {
        cin >> S[i];
    }
    for1(i,M) {
        cin >> T[i];
    }
    vvvll dp(N+1, vvll(M+1, vll(2)));
    dp[0][0][0] = 1;
    for1(i,N+1) {
        for1(j,M+1) {
            if (i >= 1 && j >= 1) {
                if (S[i-1]==T[j-1]) {
                    dp[i][j][0] += dp[i-1][j-1][0];
                    dp[i][j][0] %= mod;
                    dp[i][j][0] += dp[i-1][j-1][1];
                    dp[i][j][0] %= mod;
                }
            }
            if (i >= 1) {
                dp[i][j][0] += dp[i-1][j][0];
                dp[i][j][0] %= mod;
            }
            if (j >= 1) {
                dp[i][j][1] += dp[i][j-1][0];
                dp[i][j][1] %= mod;
                dp[i][j][1] += dp[i][j-1][1];
                dp[i][j][1] %= mod;
            }
        }
        /*
        for1(j,N+1) {
            dumplist(dp[j]);
        }
        cout << endl;
        */
    }
    cout << (dp[N][M][0]+dp[N][M][1]) % mod << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 219392
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>



const int MAX_N = 100050;
int N;
long long L, T;
long long X[MAX_N], W[MAX_N];

long long tmp[MAX_N];
long long ret[MAX_N];

long long mod(long long loc) {
    if (0 <= loc) {
        return loc % L;
    } else {
        long long tmp = -loc / L;
        return (loc + (tmp + 1) * L) % L;
    }
}

int main(int argc, char **argv) {
    std::cin >> N >> L >> T;

    for (int i = 0; i < N; i++) {
        std::cin >> X[i] >> W[i];
    }

    int num_cc = 0;

    for (int i = 0; i < N; i++) {
        if (W[i] == 2) {
            num_cc++;
        }
    }

    if (num_cc == 0 || num_cc == N) {

        for (int i = 0; i < N; i++) {
            ret[i] = W[i] == 1 ? mod(X[i] + T) : mod(X[i] - T);
        }

    } else {
        int first_c = 0;

        for (int i = 0; i < N; i++) {
            if (W[i] == 1) {
                first_c = i;
                break;
            }
        }

        std::vector<long long> loc;

        for (int i = 0; i < N; i++) {
            loc.push_back(W[i] == 1 ? mod(X[i] + T) : mod(X[i] - T));
        }
        std::sort(loc.begin(), loc.end());

        long long pass_num = (T / L) * num_cc * 2;

        for (int i = 0; i < N; i++) {
            if (W[i] == 2) {
                if (L + mod(X[i] - X[first_c]) < (T % L) * 2) {
                    pass_num += 2;
                } else if (mod(X[i] - X[first_c]) < (T % L) * 2) {
                    pass_num += 1;
                }
            }
        }

        long long st = (first_c + pass_num) % N; // 基準点のアリID (mod N)

        long long st_tmp_idx = 0; // 基準点のアリIDのloc上のID
        for (int i = 0; i < N; i++) {
            if (loc[i] == mod(X[first_c] + T)) {
                st_tmp_idx = i;
                break;
            }
        }

        //std::cout << "check:" << st << " " << st_tmp_idx << std::endl;

        for (int i = 0; i < N; i++) {
            ret[i] = loc[(i - st + st_tmp_idx + N) % N];
        }
    }

    for (int i = 0; i < N; i++) {
        std::cout << ret[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{ int N; cin >> N;
  vector<int> A(N);
 for(int i = 0; i < N; i++)
 {cin >> A[i];}
 
 sort(A.begin(),A.end());
 
 int count = 0; int res = 0;
   
 while(count < N)
  { 
   int cc = A[count] ; int f = 0;
    while( count < N && A[count] == cc){ f++; count++;}
   
   res += f%2;
 }

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

Measured memory_bytes: 640
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846

int main(){
	FASTIO;
	ll n; cin >> n;
	set<ll> div;
	for ( ll k = 2; k * k <= n; k++ ){
		if (n % k == 0) {
			div.insert(k);
			div.insert(n / k);
		}
	}
	div.insert(n);
	ll ans = 0;
	set<ll> tmp;
	for (ll d: div) {
		ll x = n;
		while (x % d == 0)
			x /= d;
		if (x % d == 1 || x == 1) {
			ans++;
			tmp.insert(d);
		}
	}
	ll nn = n - 1;
	set<ll> divv;
	divv.insert(nn);
	for ( ll k = 2; k * k <= nn; k++ ){
		if (nn % k == 0) {
			if (!tmp.count(k))
				divv.insert(k);
			if (!tmp.count(nn / k))
				divv.insert(nn / k);
		}
	}
	ans += sz(divv);
	if (n == 2)
		ans = 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int m;
  while( cin>>m, m ){
    int a[7],b[7];
    REP(i,m){
      int aa,bb;
      cin >>aa>>bb;
      a[i] = aa;
      b[i] = bb;
    }

    int dp[m+1][1000+1];
    memset( dp, 0, sizeof(dp) );
    dp[0][0] = 1;

    REP(i,m){
      REP(j,1001){
	REP(k,b[i]+1){
	  if( j+a[i]*k <= 1000 )
	    dp[i+1][j+a[i]*k] += dp[i][j];
	}
      }
    }

    int g;
    cin >> g;
    REP(_t,g){
      int n;
      cin >> n;
      cout << dp[m][n] << endl;
    }


  }

  return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <string.h>

int main(void) {
	int n;
	int a[100000];
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int button = 1;
	int count = 0;
	for (int i = 1; i < n; i++) {
		button = a[button - 1];
		++count;
		if (button == 2) {
			printf("%d", count);
			return 0;
		}
	}

	printf("%d", -1);
	return 0;
}

Measured memory_bytes: 512
s = str(input())
top = int(s[:2])
bottom = int(s[2:])

if 1 <= top <= 12 and 1 <= bottom <= 12:
    print('AMBIGUOUS')
elif top > 12 and bottom > 12:
    print('NA')
elif 1 <= top <= 12:
    print('MMYY')
elif 1 <= bottom <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stack>
#include <deque>

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(__typeof(v.begin()) it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " <<x<<endl;

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 1e4 + 6.66;
const int MAXM = 1e6 + 6.66;
vi g[MAXN];
int d[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
  int n,m;
  cin >> n >> m;
  FOR(i,0,m) {
    int x,y;cin >> x >> y;
    d[x]++;
    g[y].pb(x);
  }
//  F0R(i,1,n) {
//    sort(g[i].begin(),g[i].end());
//    reverse(g[i].begin(),g[i].end());
//  }
  queue<int> q;
  stack<int> ans;
  RFOR(i,0,n) if( d[i]==0 ) q.push(i);
  while(q.size()) {
    ans.push(q.front());
    int i = q.front();q.pop();
    for(auto x : g[i])
    {
      d[x]--;
      if(!d[x]) q.push(x);
    }
  }
  if(ans.size()!=n) cout << "Sandro fails." << endl;
  else
    while(ans.size()) cout << ans.top() << "\n",ans.pop();
  cout << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());

  map<long long, long long> mp;
  mp[0] = 1;
  long long now = 0, ten = 1;

  for(auto e:s){
    now = (now + (e - '0') * ten) % 2019;
    ten *= 10;
    ten %= 2019;
    mp[now]++;
//    cout << now << endl;
  }

  long long ans = 0;
  for(auto e:mp){
    ans += e.second * (e.second - 1) / 2;
//    cout << e.first << " : " <<  e.second << " : " << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main(){
  int n;
  cin >> n;
  map<P,int> mp;
  for(int i=1; i<=n; ++i){
    int a, b;
    a = i%10;
    b = i;
    while(b>=10) b /= 10;
    ++mp[make_pair(a,b)];
  }
  ll ans=0;
  for(auto pi: mp){
    int a, b;
    a = pi.first.first;
    b = pi.first.second;
    ans += (ll)pi.second * (ll)mp[make_pair(b,a)];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;
const int MOD=1e9+7;
const int maxn=400000+10;

int a[maxn];
ll c2[maxn];

ll Pow(ll x,int p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%MOD) if(p&1) ret=ret*x%MOD;
	return ret;	
}

int main()
{
//	freopen("std.in","r",stdin);
	int n;cin>>n;
	ll inv2=Pow(2,MOD-2);
	
	c2[0]=1;
	rep(i,1,n*2) c2[i]=c2[i-1]*2%MOD;
	rep(i,1,n) cin>>a[i];
	sort(a+1,a+n+1);
	
	ll ans=0;
	rep(i,1,n)
	{
		ans+=c2[n+i-1]*a[i]%MOD*c2[n-i]%MOD*(n-i+2)%MOD*inv2%MOD;
	}
	cout<<ans%MOD<<endl;
	return 0;
}


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

int main(){
	int n; 
  ll ans = 0;
  cin >> n;
    for(int i=1; i<=n; i++){
      if((i%3)!= 0 && (i%5) != 0){
      ans +=i;
      }
    }
      cout << ans << endl;
}

Measured memory_bytes: 3632
ans=0
def dfs(x,len_x,i=0):
        global ans
        if i < len_x:
                dfs(x,len_x,i=i+1)
        if i < len_x:
                x=x[:i+1] + "+" + x[i+1:]
                dfs(x,len_x + 1,i=i+2)
                ans+=sum([int(k) for k in x.split("+")])
        
s = input()
dfs(s,len(s)-1)
print(ans+int(s))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int mo=924844033;
const int N=4005;
int n,k,tot;
int ed[N],vis[N][2];
int f[N][N][2];
int g[N],fac[N];
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
		for (int j=0;j<=1;j++)
			if (!vis[i][j]){
				int len=0;
				for (int x=i,y=j;x<=n;x+=k,y^=1)
					vis[x][y]=1,++len;
				ed[tot+=len]=1;
			}
	f[1][0][0]=1;
	for (int i=1;i<=tot;i++)
		for (int j=0;j<=n;j++){
			f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%mo;
			if (!ed[i]) f[i+1][j+1][1]=f[i][j][0];
		}
	for (int i=0;i<=n;i++)
		g[i]=(f[tot][i][0]+f[tot][i][1])%mo;
	fac[0]=1;
	for (int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%mo;
	int ans=fac[n];
	for (int i=1,j=mo-1;i<=n;i++,j=mo-j)
		ans=(ans+1ll*j*fac[n-i]%mo*g[i]%mo)%mo;
	printf("%d",ans);
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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

string s;

signed main(){
    cin>>s;
    if(s[s.size()-1]!='s')s+='s';
    else s+="es";
    cout<<s<<endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main() {
  int a, b;
  char op;
  while (cin >> a >> op >> b) {
    if (op == '?') return 0;
    if (op == '+') cout << a + b << endl;
    if (op == '-') cout << a - b << endl;
    if (op == '*') cout << a * b << endl;
    if (op == '/') cout << a / b << endl;
  }
}


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

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

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    int ans;
    ans = 1e9;
    FOR(i, -100, 101) {
        int tmp = 0;
        rep(j, N) tmp += ((A[j] - i) * (A[j] - i));
        // if (5 <= i <= 9) {
        //     cout << i << " " << tmp << endl;
        // }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//=====================================================
// 
// (setq backup-inhibited t)
// (setq auto-save-default nil)
// 
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
// 
// (global-set-key "\C-h" 'delete-backward-char)
// 
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\C-m" 'newline-and-indent)
// 
//=====================================================

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <complex>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef complex<long double> P;
typedef vector<P> L;

const long double EPS=1e-9;
const long double INF=1e+12; 

double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
}

bool intersectSS(const L &s, const L &t) {
    return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
           ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

long double dijkstra(const vector<vector<pair<int,long double>>>& g){
  priority_queue<pair<long double,int>,vector<pair<long double,int>>,greater<pair<long double,int>>> q;
  q.push(pair<long double,int>(0.0,0));
  vector<long double> dist(g.size(),INF);
  dist[0]=0.0;
  while(!q.empty()){
    auto p=q.top();
    q.pop();
    long double d=p.first;
    int i=p.second;
    if(d > dist[i])continue;
    for(auto e:g[i]){
      int j=e.first;
      long double l=e.second;
      if(dist[j] > dist[i]+l){
        dist[j] = dist[i]+l;
        q.push(make_pair(dist[j],j));
      }
    }
  }
  return dist[1];
}

int main() {
  int na,nb;
  cin>>na>>nb;
  vector<P> a(na);
  vector<P> b(nb);
  REP(i,na){
    int x,y;
    cin>>x>>y;
    a[i] = P(x,y);
  }
  REP(i,nb){
    int x,y;
    cin>>x>>y;
    b[i] = P(x,y);
  }
  vector<vector<pair<int,long double>>> ea(na);
  vector<vector<pair<int,long double>>> eb(nb);
  L la={a[0],a[1]};
  L lb={b[0],b[1]};
  REP(i,na){
    REP(j,na){
      if(i==j)continue;
      L l = {a[i],a[j]};
      if(!intersectSS(lb,l)){
        ea[i].push_back(make_pair(j,abs(a[i]-a[j])));
      }
    }
  }
  REP(i,nb){
    REP(j,nb){
      if(i==j)continue;
      L l = {b[i],b[j]};
      if(!intersectSS(la,l)){
        eb[i].push_back(make_pair(j,abs(b[i]-b[j])));
      }
    }
  }
  double dist1 = dijkstra(ea) + abs(b[0]-b[1]);
  double dist2 = dijkstra(eb) + abs(a[0]-a[1]);
  long double d = min(dist1,dist2);
  if(d<INF)
    cout<<fixed<<setprecision(12)<<d<<endl;
  else
    cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 63560
import sys
import math

N,Y = list(map(int,input().split()))

for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if Y == 10000*i + 5000*j + 1000*k and k >= 0:
            print("{0} {1} {2}".format(i,j,k))
            break
        if i == N and j== N:
            print("-1 -1 -1")
            break
    else:
        continue
    break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    //write code  here
    ll X;
    cin >> X;

    ll A,B;
    bool is=false;
    for (ll a = 0; a < 100000; ++a) {
        for (ll b = -100; b < 10000; ++b) {
            if(X == (a*a*a*a*a - b*b*b*b*b)){
//                cout << (a ^ 5 - b ^ 5) << endl;
                A=a;
                B=b;
                is=true;
                break;
            }
        }
        if (is)break;
    }

    cout << A << " " << B << endl;


    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	int i=0;
	int size=0;
	int ans=1;
	
	cin>>s;
	size=s.size();
	if(size<4){
		cout<<"No";
	}else{
		if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
			cout<<"Yes";
		}else{
			cout<<"No";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#define ll long long
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define sort(s) sort(s.begin(),s.end())
constexpr auto INF = 1000000000;
using namespace std;
void press(vector<int> & v) { v.erase(unique((v).begin(), (v).end()), v.end()); }

int main() {
	int n;
	cin >> n;
	vector<int> k = {}, g = {};
	rep(i, 0, n) {
		int a;
		cin >> a;
		if (i % 2 == 0)k.push_back(a);
		else g.push_back(a);
	}
	sort(k);
	sort(g);
	k.push_back(INF);
	g.push_back(INF);
	int t = 1;
	int ksum = 0,kj=0;
	rep(i, 0, n / 2) {
		if (k[i] == k[i + 1])t++;
		else {
			if (ksum < t) {
				ksum = t;
				kj = k[i];
			}
			t = 1;
		}
	}
	t = 1;
	int ksecond = 0;
	rep(i, 0, n / 2) {
		if (k[i] != kj && k[i] == k[i + 1])t++;
		else {
			ksecond = max(ksecond, t);
			t = 1;
		}
	}
	t = 1;
	int gsum = 0,gj=0;
	rep(i, 0, n / 2) {
		if (g[i] == g[i + 1])t++;
		else {
			if (gsum < t) {
				gsum = t;
				gj = g[i];
			}
			t = 1;
		}
	}
	int gsecond = 0;
	t = 1;
	rep(i, 0, n / 2) {
		if (gj != g[i] && g[i] == g[i + 1])t++;
		else {
			gsecond = max(gsecond, t);
			t=1;
		}
	}
	k.erase(k.begin()+n/2);
	g.erase(g.begin() + n / 2);
	press(k);
	press(g);
	if (g.size()==1)gsecond--;
	if (k.size() == 1)ksecond--;
	int ans;
	if (gj != kj)ans = n - ksum - gsum;
	else ans = n - max(ksum + gsecond, gsum + ksecond);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

ll sum(ll x) {
	ll ret = 0;
	while (x) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

double f(ll n) {
	return double(n) / sum(n);
}

int main() {
	// 최대유량, 앳코더, (종만북(?) 생각) - 기하 잘하고 싶다!
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// 1 2 3 4 5 6 7 8 9 19 29 39 49 59 69 79 89 99 109 ... 
	ll k;
	cin >> k;
	ll n = 1, a = 1;
	while (k--) {
		cout << n << endl;
		while (f(n + a) > f(n + 2 * a)) {
			a *= 10;
		}// 99 + 10 , 99 + 20  10.9 , 119 // 11
		n += a;
	}

}


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

int n;
vector<long long> a;

int main(int argc, char *argv[])
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        long long num;
        cin >> num;
        a.emplace_back(num);
    }
    bool mark = false;
    long long sum = 0;
    long long maxItem = INT64_MAX;
    for (long long num : a)
    {
        if (num < 0)
        {
            mark = !mark;
        }
        sum += abs(num);
        maxItem = min(maxItem, abs(num));
    }
    cout << (mark ? sum - 2 * maxItem : sum) << endl;
}

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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie 📝

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::string str;
    cin>>str;

    map<char, int> m;
    for(char c: str)
    {
        if(m.count(c))
            m[c]++;
        else
            m[c] = 1;
    }
    bool ok = true;
    for(auto& pair: m)
    {
        if(pair.second != 2)
            ok = false;
    }
    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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 st, sx, sy, et, ex, ey;
		et = 0;
		ex = 0;
		ey = 0;
		for (int i = 0; i < n; i++) {
			st = et;
			sx = ex;
			sy = ey;

			et = sc.nextInt();
			ex = sc.nextInt();
			ey = sc.nextInt();

			if (!can(et - st, ex - sx, ey - sy)) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

	public static boolean can(int t, int x, int y) {
		int d = Math.abs(x) + Math.abs(y);
		return (d <= t) && (t % 2 == d % 2);
	}
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int n,a,b;

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

	cin>>n>>a>>b;
	if(a+b>n+1||(ll)a*b<(ll)n) {
		cout<<-1<<endl;
		return 0;
	}
	for(int i=n-a+1;i<=n;i++) cout<<i<<' ';
	if(b==1) {
		cout<<endl;
		return 0;
	}
	int times=(n-a)/(b-1);
	int amari=(n-a)%(b-1);
	int cur=n-a;

	//cout<<times<<' '<<amari<<endl;
	for(int i=1;i<b;i++) {
		if(amari>0) {
			for(int i=times;i>=0;i--) {
				cout<<cur-i<<' ';
			}
			cur-=times+1;
			amari--;
		}
		else {
			for(int i=times-1;i>=0;i--) {
				cout<<cur-i<<' ';
			}
			cur-=times;
		}
	}
	cout<<endl;


	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){
    ll n,C;cin>>n>>C;
    ll s[n],t[n],c[n];rep(i,0,n-1)cin>>s[i]>>t[i]>>c[i];
    bool b[C+1][200010];
    rep(i,1,C)rep(j,0,200005)b[i][j]=false;
    rep(i,0,n-1){
        rep(j,2*s[i]-1,2*t[i]){
            b[c[i]][j]=true;
        }
    }
    ll ans=0;
    ll sum;
    rep(i,0,200000){
        sum=0;
        rep(j,1,C){
            if(b[j][i]){
                sum++;
            }
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

// <expr>   ::= <term> [ ('+'|'-') <term> ]*
// <term>   ::= <factor> [ ('*'|'/') <factor> ]*
// <factor> ::= <number> | '(' <expr> ')'
// <number> :== ???????????°

int expr(int& pos);
int term(int& pos);
int factor(int& pos);
int number(int& pos);

string s;

int expr(int& pos){
    int res = term(pos);
    while(s[pos] == '+' || s[pos] == '-'){
        if(s[pos] == '+'){
            res += term(++pos);
        }else{
            res -= term(++pos);
        }
    }
    return res;
}

int term(int& pos){
    int res = factor(pos);
    while(s[pos] == '*' || s[pos] == '/'){
        if(s[pos] == '*'){
            res *= factor(++pos);
        }else{
            res /= factor(++pos);
        }
    }
    return res;
}

int factor(int& pos){
    if(isdigit(s[pos])) return number(pos);
    pos++;  //'('?????¨??°???
    int res = expr(pos);
    pos++;  //')'?????¨??°???
    return res;
}

int number(int& pos){
    string res;
    while(isdigit(s[pos])){
        res.pb(s[pos++]);
    }
    return stoi(res);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        cin >> s;
        int pos = 0;
        cout << expr(pos) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3148
S = input()

yymm = 0
mmyy = 0

kami2 = int(S[0]) * 10 + int(S[1])
simo2 = int(S[2]) * 10 + int(S[3])


if simo2 > 0 and simo2 <= 12:
    yymm=1
if kami2 <= 12 and kami2 >0:
    mmyy=1


if yymm:

 if mmyy:
    print("AMBIGUOUS")
 else:
     print("YYMM")
           
elif mmyy:
     print("MMYY")
else:
    print("NA")

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  
  int da = abs(x - a), db = abs(x - b);
  if (da < db) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
}


Measured memory_bytes: 3564
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nw = Input.ar;
        var vw = Input.twodim(nw[0]);
        var dp = new long[nw[0] + 1, nw[1] + 1];
        for (var i = 1; i <= nw[0]; i++)
            for (var j = 0; j <= nw[1]; j++)
                if (j - vw[i - 1][1] >= 0)
                    dp[i, j] = Max(dp[i - 1, j], dp[i - 1, j - vw[i - 1][1]] + vw[i - 1][0]);
                else dp[i, j] = dp[i - 1, j];
        var max = 0L;
        for (var i = 0; i <= nw[1]; i++)
            max = Max(max, dp[nw[0], i]);
        WriteLine(max);
    } 
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}



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

const int size = 50;
int n, m;
bool graph[size][size];
bool visited[size];

void dfs(int v) {
    visited[v] = true;
    for (int i = 0; i < n; i++) {
        if (graph[v][i] == true && visited[i] == false) {
            dfs(i);
        }
    }
}

int main() {
    cin >> n >> m;
    int a[m], b[m];

    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;
    for (int i = 0; i < m; i++) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        fill(visited, visited+n, false);

        dfs(0);

        bool bridge = false;
        for (int j = 0; j < n; j++) {
            if (visited[j] == false) {
                bridge = true;
            }
        }

        if (bridge) {
            ans++;
        }

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

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

Measured memory_bytes: 256
def _rotN(c,N):
    if 'A' <= c and c <= 'Z':
        # 13 文字分ずらす
        return chr((ord(c) - ord('A') + N) % 26 + ord('A'))

    if 'a' <= c and c <= 'z':
        # 13 文字分ずらす
        return chr((ord(c) - ord('a') + N) % 26 + ord('a'))

    # その他の文字は対象外
    return c

N=int(input())
S=str(input())
print(''.join((_rotN(c,N) for c in S)))

Measured memory_bytes: 3060
#include<stdio.h>
int R,S,P;
int cnt(char c)
{
  if(c=='r') return P;
  else if(c=='p') return S;
  else if(c=='s') return R;
}
int main(void)
{
  int n,k,ans=0;
  scanf("%d%d",&n,&k);
  scanf("%d%d%d",&R,&S,&P);
  char tmp='t';
  char t_tmp[n+1];
  scanf("%s",t_tmp);
  char str[k+1][n/k+2];
  for(int i=1;i<=n;i++){
    str[(i-1)%k+1][i/k+1]=t_tmp[i-1];
    ans+=cnt(t_tmp[i-1]);
    if(i>k){
      if(t_tmp[i-1]==t_tmp[i-1-k]){
        ans-=cnt(t_tmp[i-1]);
        t_tmp[i-1]=tmp;
      }
    }
  }
  printf("%d",ans);
  return 0;
}

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

#define Bye return 0
#define ll long long
const int SIZE = 51;
char a[SIZE][SIZE];
char b[SIZE][SIZE];
int n, m; 

bool isContained(){

    for (int i=0;i<=n-m; i++)
        for (int j=0; j<=n-m; j++){
            int isEqual = true;  
            for (int x=0; x<m; x++)
                for (int y=0; y<m; y++)
                    if(a[i+x][j+y]!=b[x][y])
                        isEqual = false;
            if(isEqual) return true;
        }
     return false;
}

void solve(){
   cin>>n>>m;

    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++) cin>>a[i][j];

    for (int i=0; i<m; i++)
        for (int j=0; j<m; j++) cin>>b[i][j];

    cout<<(isContained()?"Yes":"No")<<endl;
}

int main(){
    solve();
    Bye;
}

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

int main(){
    string S; cin >> S;
    int K; cin >> K;
    int N = S.size();
    vector<string> SDP;
    for(int i = 0; i < N; i++){
        for(int j = i; j < i + 5; j++){
            if(j >= N) break;

            string sub = S.substr(i, j + 1 - i);
            SDP.push_back(sub);
        }
    }
    sort(SDP.begin(), SDP.end());
    auto itr = unique(SDP.begin(), SDP.end());
    SDP.erase(itr, SDP.end());
    cout << SDP[K-1] << endl;

}

Measured memory_bytes: 1660
n = int(input())
a = sorted(list(map(int, input().split())))

ans = a[0]
ans_l = []
ans_e = a[-1]

if ans_e >= 0:
    for i in range(1,n-1):
        if a[i] < 0:
            ans_l += [(ans_e, a[i])]
            ans_e -= a[i]
        else:
            ans_l += [(ans, a[i])]
            ans -= a[i]

    ans_l += [(ans_e,ans)]
    ans = ans_e - ans

else:
    ans = ans_e
    for i in range(0,n-1):
        ans_l += [(ans, a[i])]
        ans -= a[i]

print(ans)

for x, y in ans_l:
    print(x,y)


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

#define ll long long
#define ff(i,c,n) for(ll i=c;i<n;i++)

int main(){
    ll n,W;
    cin>>n>>W;
    ll w[n],v[n];
    ff(i,0,n) cin>>w[i]>>v[i];
    ll dp[n+1][W+1]={0};
    ff(i,0,n+1){
        ff(j,0,W+1){
            if(i==0||j==0) dp[i][j]=0;
            else if(w[i-1]<=j){
                dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
            }
            else dp[i][j]=dp[i-1][j];
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
    cout<<dp[n][W]<<endl;
}

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

int main(){
	int N;
  	int colors[8] = {};
  	int other = 0;
    int a;
  	int cnt = 0;
  
    cin >> N;
  
	for(int i=0; i<N; i++){
      cin >> a;
      if(a < 3200){
           colors[a/400] = 1;
      }
      else{
           other++;
      }           
    }

    for(int i=0; i<8; i++){
        cnt += colors[i];
    }
  
    cout << max(1, cnt) << ' ' << cnt+other;
  
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

ll gpow(ll i){
	ll ans = 1;
	for(ll j = 0; j < 5; j++)
		ans *= i;
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	ll x;
	cin >> x;
	vll v;
	for(ll i = 0; ;i++){
		ll h = gpow(i);
		if(h > 1e18)
			break;
		v.pb(h);
	}
	for(ll i = 0; i < v.size(); i++){
		for(ll j = 0; j < v.size(); j++){
			if(v[i] + v[j] == x){
				cout << i << ' ' << -j << endl;
				return 0;
			}
			if(v[i] - v[j] == x){
				cout << i << ' ' << j << endl;
				return 0;
			}
		}
	}
}

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

int main() {
  int n,k;
  cin>>n;
  vector<int> d;
  for(int i=0; i<n; i++){
    int x;
    cin>>x;
    d.push_back(x);
  }
  sort(d.begin(),d.end());
  k = d[n/2] - d[(n/2)-1];
  cout<<k;
}


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

#define ll long long 

using namespace std;
int main(){
	int n,m;
	priority_queue<int>q;
	cin>>n>>m;
	ll w;
	while(n--){
		cin>>w;
		q.push(w);
	}
	ll ans = 0;
	while(m){
		w = q.top()/2;
		q.pop();
		q.push(w);
		m--;
	}
	while(!q.empty()){
		ans += q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 892
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]


dice = Dice(list(map(int, input().split())))
n = int(input())
for i in range(n):
    (face1, face2) = map(int, input().split())
    if face2 == dice.number(3) or face2 == dice.number(4):
        dice.roll_west()
    while dice.number(2) != face2:
        dice.roll_north()
    while dice.number(1) != face1:
        dice.roll_west()
    print(dice.number(3))

Measured memory_bytes: 6764
#include <iostream>
#include <string>
using namespace std;
  
int main () {
    int a;
    string p,s;
    cin >> p >> s;
    p += p;
 
    a=p.find(s);
    if(a==-1)cout <<"No"<<endl;
    else cout << "Yes"<<endl;
}

Measured memory_bytes: 3212
str = gets.split
A,B,M = str[0].to_i, str[1].to_i, str[2].to_i

a = Array.new(A)
amin = 10**5
str = gets.split
for i in 0...A do
    a[i] = str[i].to_i
    if a[i] < amin
        amin = a[i]
    end
end

b = Array.new(B)
bmin = 10**5
str = gets.split
for i in 0...B do
    b[i] = str[i].to_i
    if b[i] < bmin
        bmin = b[i]
    end
end
answer = amin + bmin

for i in 0...M do
    str = gets.split
    x,y,c = (str[0].to_i)-1, (str[1].to_i)-1, str[2].to_i
    d = a[x] + b[y] - c
    if answer > d
        answer = d
    end
end

puts answer

Measured memory_bytes: 18836
#include <iostream>

using namespace std;

int main(void) {
    int N, K, x, res =0, ax, bx;

    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> x;
        ax = x * 2;
        bx = (K - x) * 2;
        if (ax >= bx) {
            res += bx;
        }
        else {
            res += ax;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define rep(i,n) for(int i=0; i<(n);++i)

int main(){
    int N;ll W;
    cin>>N>>W;
    vector<ll> v(N),w(N);
   rep(i,N)cin>>w[i]>>v[i];
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,0LL));
    rep(i,N){
      rep(j,W+1){
        if(j-w[i]<0)dp[i+1][j]=dp[i][j];
        else{
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
        }
      }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

Measured memory_bytes: 80256
#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)

def main(N, L):
    min_val = 1000
    apples = list(range(L, L+N))
    for apple in apples:
        if abs(apple) < abs(min_val):
            min_val = apple
    ans = (apples[0] + apples[N-1]) * N / 2 - min_val
    return ans

if __name__ == '__main__':
    N, L = list(map(int, input().split()))
    print(int(main(N, L)))




Measured memory_bytes: 43500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
    string s;cin>>s;
    int n=s.size();
    int flag=1;
    for(int i=0;i<(n-1)/2;i++){
        if(s[i]==s[(n-1)/2-1-i]) continue;
        flag=0;
    }
    for(int i=(n+3)/2-1;i<n;i++){
        if(s[i]==s[n-1-i]) continue;
        flag=0;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int w, h, cnt = 0;

void srch(int x, int y, vector<vector<int>> &inp, vector < vector <bool>> &hit)
{
	if (x < 0 || w <= x || y < 0 || h <= y || inp[y][x] == 0) { return; }
	if (hit[y][x]) return;
	hit[y][x] = true;
	cnt += 1;
	srch(x + 1, y, inp, hit);
	srch(x - 1, y, inp, hit);
	srch(x, y + 1, inp, hit);
	srch(x, y - 1, inp, hit);
	srch(x + 1, y + 1, inp, hit);
	srch(x + 1, y - 1, inp, hit);
	srch(x - 1, y + 1, inp, hit);
	srch(x - 1, y - 1, inp, hit);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> w >> h && w != 0 && h != 0)
	{
		vector<vector<int>> inp(h, vector<int>(w, 0));
		vector<vector<bool>> hit(h, vector<bool>(w, false));
		int ans = 0;
		rep(y, h) rep(x, w){ cin >> inp[y][x]; }
		rep(y, h) rep(x, w)
		{
			srch(x, y, inp, hit);
			if (cnt > 0) { ans += 1; }
			cnt = 0;
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 3552