akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String args[]) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int n = Integer.parseInt(br.readLine());
            char[] s = br.readLine().toCharArray(), t = br.readLine().toCharArray();
            for(int i = 0; i <= n; ++i){
                boolean ok = true;
                for(int j = 0; j < n - i; ++j){
                    if(s[i + j] != t[j]){
                        ok = false;
                        break;
                    }
                }
                if(ok){
                    System.out.println(n + i);
                    return;
                }
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 21204
#include<stdio.h>

int main(void) {
    int a,b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while(op != '?') {
        switch(op) {
            case '+' :
            printf("%d\n", a + b);
            break;

            case '-' :
            printf("%d\n", a - b);
            break;

            case '*' :
            printf("%d\n", a * b);
            break;

            case '/' :
            printf("%d\n", a / b);
            break;

            default :
            break;
        }
        scanf("%d %c %d", &a, &op, &b);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a;
	return 0;
}

Measured memory_bytes: 3592
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[500][500],b[500],m,n,p,q;
  int ct;
  while(cin>>n>>m&&n+m){
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=0;i<m;i++){
      cin>>p>>q;
      a[p-1][q-1]=1;
      a[q-1][p-1]=1;
      if(p-1==0)
	b[q-1]=1;
      if(q-1==0)
	b[p-1]=1;
    }
    for(i=0;i<n;i++){
      if(b[i]==1){
	for(j=0;j<n;j++){
	  if(a[i][j]&&b[j]==0)
	    b[j]=2;
	}
      }
    }
    ct=0;
    for(i=1;i<n;i++){
      if(b[i])
	ct++;
    }
    cout<<ct<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin>>n>>k;
  ll tmp=(n/k);
  if(n%k!=0){
    tmp+=1;
  }
  ll ans=n;
  ans=min(ans,abs(n-(k*tmp)));
  cout<<ans<<endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int n, i, g, tmp;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	cin >> g;
	for (i = 1; i < n; i++){
		cin >> tmp;
		g = gcd(g, tmp);
	}
	cout << g << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

char grid[110][110];
int dp[110][110];
signed main()
{
    int h,w;
    cin>>h>>w;
    REP(i,h) REP(j,w) cin>>grid[i][j];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            dp[i][j]=INF;
        }
        
    }
    
    if(grid[0][0]=='.') dp[0][0]=0;
    else dp[0][0]=1;
    for (int i = 1; i < w; i++)
    {
        if(grid[0][i]=='.') dp[0][i]=dp[0][i-1];
        else{
            if(grid[0][i-1]=='.') dp[0][i]=dp[0][i-1]+1;
            else dp[0][i]=dp[0][i-1];
        }
    }
    for (int i = 1; i < h; i++)
    {
        if (grid[i][0] == '.')
            dp[i][0] = dp[i-1][0];
        else
        {
            if (grid[i-1][0] == '.')
                dp[i][0] = dp[i-1][0] + 1;
            else
                dp[i][0] = dp[i-1][0];
        }
    }
    for (int i = 1; i < h; i++)
    {
        for (int j = 1; j < w; j++)
        {
            
                if(grid[i][j] == '.') chmin(dp[i][j],dp[i][j-1]);
                else {
                    if(grid[i][j-1]=='#')
                        chmin(dp[i][j], dp[i][j-1]);
                    else chmin(dp[i][j],dp[i][j-1]+1);
                }
            
           
                if (grid[i][j] == '.')
                    chmin(dp[i][j], dp[i-1][j]);
                else
                {
                    if (grid[i-1][j] == '#')
                        chmin(dp[i][j], dp[i-1][j]);
                    else
                        chmin(dp[i][j], dp[i-1][j]+1);
                }
            
        }
    }
  /*  for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cerr<<dp[i][j]<<" ";
        }
        cerr<<endl;
    }
    */
    cout<<dp[h-1][w-1]<<endl;

    return 0;
}

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

int main ()
{
    long long int  k; cin>>k;
     long long int cnt =1;
     long long int x= 7;
     if (k%2==0 || k%5==0) {
            cout <<"-1"<<endl;
            return 0;
         }
     while (true)
     {
         if (x%k==0) {
            cout <<cnt <<endl;
            return 0;
         }
         if (cnt>k) {
            cout <<"-1"<<endl;
            return 0;
         }
         x= ((x%k)*10)+7;
         cnt++;
     }
     return 0;
}


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

template< unsigned mod >
struct RollingHash2 {
  vector< unsigned > hashed, power;

  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }

  RollingHash2(const vector<ll> &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }
  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }
};




template<long long mod >
struct RollingHash {
  vector<long long> hashed, power;
  inline long long mul(long long a, long long b) const {
    long long x = (long long) (a * b);
    long long xh = (long long) (x >> 32LL), xl = (long long) x, d, m;
    return m;
  }

  RollingHash(const vector<ll> &s,long long base = 10007) {
    ll sz = (ll) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(ll i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }

  long long get(ll l, ll r) const {
    long long ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }

};

//using RH = RollingHash< 1000000007 >;

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

  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  vector<ll> c(n),d(n);
  rep(i,n){
    c[i] = a[i]^a[(i+1)%n];
    d[i] = b[i]^b[(i+1)%n];
  }
  rep(i,n) c.pb(c[i]);
  
  const int mod2 = 1e9+7;
  const int mod4 = 1e5+7;
  RollingHash2<mod2> rh2c(c);
  RollingHash2<mod2> rh2d(d);
  RollingHash2<mod4> rh4c(c);
  RollingHash2<mod4> rh4d(d);
  



  
  const ll mod1 = 1e9+7;
  //  const ll mod2 = 9999991;
  //  const ll mod3 = 9273703;
  const ll mod3 = 1000000009;
  //  const ll mod4 = 1000003;
  RollingHash<mod1> rh1c(c,1007);
  RollingHash<mod1> rh1d(d,1007);
  //RollingHash<mod2> rh2c(c);
  //  RollingHash<mod2> rh2d(d);
  RollingHash<mod3> rh3c(c,2009);
  RollingHash<mod3> rh3d(d,2009);
  //  RollingHash<mod4> rh4c(c,100000007);
  //  RollingHash<mod4> rh4d(d,100000007);

  rep(k,n){
    //    cout << rh1c.get(k,k+n) <<" " <<  rh1d.get(0,n) << endl;
    if(rh1c.get(k,k+n) == rh1d.get(0,n) && rh3c.get(k,k+n) == rh3d.get(0,n)){
      if(n!=200000 || (rh2c.get(k,k+n) == rh2d.get(0,n) && rh4c.get(k,k+n) == rh4d.get(0,n))) {     
	ll x = b[0]^a[k];
	cout << k << " " << x << endl;
      }
    }
  }

  

  return 0;
    

}


Measured memory_bytes: 39396
import collections
N = int(input())
xy = [0] * N
for i in range(N):
  xy[i] = list(map(int, input().split()))
#print(xy)

ans = [[0, 0] for i in range(N ** 2)]
x = [1] * (N ** 2)
y = 0
for i in range(N):
  for j in range(N):
    if i != j:
      p = xy[i][0] - xy[j][0]
      q = xy[i][1] - xy[j][1]
      if [p, q] not in ans:
        ans[y][0], ans[y][1] = p, q 
        y += 1
      else:
        lnum = ans.index([p, q])
        x[lnum] += 1
        
x_max = x.index(max(x))
pq = ans[x_max]
#print(pq)

ans2 = N - max(x)
print(max(ans2, 1))
  

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

int main() {
  int n;
  vector<int> items(100, 0);
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> items[i];
  }

  //vector<vector<int> > dp(n, vector<int>(21, 0));                          
  unsigned long long dp[101][21] = {0};

  dp[0][items[0]] = 1;
  for(int i = 1; i < n-1; i++) {
    //cout << n << endl;                                                     
    //cout << items[i] << endl;                                              
    for(int j = 0; j <= 20; j++) {
      //cout << i-1 << ' ' << j << ' ' << dp[i-1][j] <<endl;                 
      if(dp[i-1][j] > 0) {
	if(j+items[i] >= 0 && j+items[i] <= 20)
          dp[i][j+items[i]] += dp[i-1][j]; //たす                            
        if(j-items[i] >= 0 && j-items[i] <= 20)
          dp[i][j-items[i]] += dp[i-1][j]; //ひく                            
      }
    }
  }

  cout << dp[n-2][items[n-1]] << endl;

  return 0;
}



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

int n, m, temp;

int main() {
  cin >> n >> m;
  rep (i, m) {
    cin >> temp;
    n -= temp;
  }
  if (n < 0) n = -1;
  cout << n << endl;
  return 0;
}


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

int n;
int a[200000];

signed main() {
  cin >> n;
  rep(i,n) cin >> a[i];
  sort(a, a+n, greater<int>());
  
  priority_queue<pair<int,int>> q;
  ll ans = 0;
  q.emplace(a[0],a[0]);

  for(int i=1; i<n; i++) {
    auto p = q.top(); q.pop();
    //cout << "pop: " << p.first << " " << p.second << endl;
    //cout << "ans: " << ans << " + " << p.first << " = " << ans + p.first << endl;
    ans += p.first;
    //cout << "add: " << a[i] << " " << p.first << endl;
    //cout << "add: " << a[i] << " " << p.second << endl;
    q.emplace(a[i], p.first);
    q.emplace(a[i], p.second);
  }
  cout << ans << endl;
}


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

int main(){
	ll n;
	cin>>n;
	vector<ll>v;
	for(int k=1;k<=n+1;k++)v.push_back((k*(k-1)/2));
	ll i;
	bool f=0;
	for(int j=0;j<v.size();j++){
		if(v[j]==n){
			i=j+1;
			f=1;
			break;
		}
	}
	if(f){
		cout<<"Yes\n"<<i<<endl;
		cout<<i-1<<' ';
		for(int k=1;k<=i-1;k++)cout<<v[k]<<' ';
		cout<<endl;
		ll now=1,add=1,x=i-1;
		while(x--){
			cout<<i-1<<' ';
			for(int k=0;k<add;k++)cout<<k+now<<' ';
			ll cnt=add,num=add*(add+1)/2;
			for(int k=0;k<i-1-add;k++){
				num+=cnt;
				cout<<num<<' ';
				cnt++;
			}
			cout<<endl;
			now+=add;
			add++;
		}
	}else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 4248
#include<bits/stdc++.h>
#include<math.h>
//#include<vector>
//#include <iostream>
//#include <algorithm>
#include <limits>
using namespace std;
#define nMAX numeric_limits<int>::max()
int main(void){
	int N;
	int i,j,k;
	cin >> N;
	int h[N+1];
	for(i=0;i<N;i++){
		cin >> h[i+1];
	}
	int dp[N+1];
	for(i=0;i<N+1;i++){
		dp[i] = nMAX;
	}
	//cout << "aa";
	dp[1]=0;
	for(i=1;i<N;i++){
		for(j=i;j<=i+2&&j<N;j++){
				//cout << i << " " << j << endl;
				dp[j+1]=min(dp[j]+(int)abs(h[j+1]-h[j]),dp[j+1]);
				//cout << dp[i+1][j+1] << endl;
			if(j+2>N){
				//cout << "q" << endl;
				break;
			}else{
				dp[j+2]=min(dp[j]+(int)abs(h[j+2]-h[j]),dp[j+2]);
				//cout << dp[i+1][j+2]<<endl;
				
			}
			/*for(k=1;k<=N;k++){
				cout << dp[k] << " ";
			}
			cout << endl;*/
		}
		
		/*for(long long i1=1;i1<=N;i1++){
			for(long long j1=1;j1<=N;j1++){
				cout << dp[i1][j1] << " ";
			}
			cout << endl;
		}*/
	}
	/*for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	//cout << endl;
	/*long long summin=MAX;
	for(i=1;i<=N;i++){
		summin=min(summin,dp[i][N]);
	}*/
	cout << dp[N] <<endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a * 500 + b * 100 + c * 50 == X:
                ans += 1

print(ans)


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D) {
		cout << "Left" << endl;
	}
     if (A+B==C+D) {
		cout << "Balanced" << endl;
	}
	 if (A + B < C + D) {
		 cout << "Right" << endl;
	}
     return 0;
}


Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())

que = list()

for i in range(n):
    query = sys.stdin.readline().split()
    if query[0] == '0': # push
        que.append(query[1])
    elif query[0] == '1':
        print(que[int(query[1])])
    elif query[0] == '2':
        que.pop()


Measured memory_bytes: 19820
#include <stdio.h>
int main()
{
    int i,x,y,j,a[100];
    scanf("%d%d",&x,&y);


        for(i=x,j=0;i<=y;i++)
        {
           a[0] = i/10000;
           a[1] = i/1000%10;
           a[2] = i/100%10;
           a[3] = i/10%10;
           a[4] = i%10;

           if(a[0] == a[4]&&a[1] == a[3])
           {
              j++;
           }
        }
          printf("%d\n",j);

     return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
if(n%2==0) {
  cout << n << endl;
} else {
  cout << 2*n << endl;
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mod=1000000007;
int main()
{
    int n,k;
    cin>>n;
    cin>>k;
    int dp[100005]={0};
    dp[0]=1;
    int counterr=0;
  //  dp[1]=-1;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        int add[100005]={0};
        for(int j=k;j>=0;j--)
        {
            add[j+1]=add[j+1]+dp[j];
            add[j+1]%=mod;
           /* if(add[j+1]<0)
            add[j+1]+=mod;
            else
            add[j+1]=add[j+1]%mod;*/
            if(j+a+1<=k)
            {
            add[j+a+1]-=dp[j];
            add[j+a+1]=add[j+a+1]%mod;
            }
         /*   if(j+a+1<=k)
            {
            add[j+a+1]-=dp[j];
            if(add[j+a+1]<0)
            add[j+a+1]+=mod;
            else
            add[j+a+1]=add[j+a+1]%mod;
            }*/
        }
        for(int g=1;g<=k;g++)
        {
            if(add[g]<0)
            add[g]+=mod;
            
            add[g]+=add[g-1];
            add[g]=add[g]%mod;
            if(add[g]<0)
            counterr++;
            /*if(add[g]<0)
            add[g]+=mod;
            else
            add[g]=add[g]%mod;*/
        }
        for(int g=1;g<=k;g++)
        {
        dp[g]+=add[g];
        dp[g]=dp[g]%mod;
        }
        /*for(int i=1;i<=k;i++)
    {
        dp[i]+=dp[i-1];
    }*/
      //  cout<<"counterr is "<<counterr<<endl;
counterr=0;
    }
 /*   for(int i=1;i<=k;i++)
    {                          
        dp[i]+=dp[i-1];
    }*/
    cout<<dp[k];
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 2e4+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int c[N],a[400][N],n,ans,t,day[N];
signed main()
{
	Very_fast;
	cin>>n;
	for(int i=0;i<26;i++)cin>>c[i];
	rep(i,n)
	rep(j,26)cin>>a[i][j];
	rep(i,n)cout<<i%26+1<<" ";
	return 0;
}

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

using namespace std;

char s[101];

int main(){

  int n;
  scanf("%d", &n);

  scanf("%s", s );

  string ans = string( s );

  int del = 0;
  for( int i = 0; i < n; i++ ){
    if( s[i] == '(' ) del ++;
    else del--;

    if( del < 0 ) ans = '(' + ans, del++;
  }
  while( del-- ) ans += ')';
  printf("%s\n", ans.c_str());
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#include <tuple>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

typedef tuple<int, int, int> tupiii;

class D {
	int rows, cols;
	vector<string> field;
	vector<vector<int>> dist;
	int black{ 0 };
public:
	D()
	{
		cin >> rows >> cols;
		field.resize(rows);
		dist.resize(rows, vector<int>(cols, INTMAX));
		REP(y, rows)
		{
			cin >> field[y];
			REP(x, cols)
				if (field[y][x] == '#')
					++black;
		}
	}

	int bfs()
	{
		deque<tupiii> q{ make_tuple(0, 0, 1) };

		int x, y, d;
		while (!q.empty())
		{
			y = get<0>(q.front());
			x = get<1>(q.front());
			d = get<2>(q.front());
			q.pop_front();

			if (y == rows - 1 && x == cols - 1)
				return d;

			REP(i, 4)
			{
				if (0 <= x + dx[i] && x + dx[i] < cols && 0 <= y + dy[i] && y + dy[i] < rows)
					if (field[y + dy[i]][x + dx[i]] == '.' && dist[y + dy[i]][x + dx[i]] == INTMAX)
					{
						q.emplace_back(make_tuple(y + dy[i], x + dx[i], d + 1));
						dist[y + dy[i]][x + dx[i]] = d + 1;
					}
			}

		}

		return -1;

	}

	void solve()
	{
		int d{ bfs() };

		if (d == -1)
		{
			cout << -1 << endl;
			return;
		}

		else
			cout << (rows * cols - black - d) << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define yes(b) std::cout<< (b ? "Yes" : "No")
#define YES(b) std::cout<< (b ? "YES" : "NO")
const ll INF = 1LL << 50;
using namespace std;
/*int ketawa(ll num) {
int dig, sum = 0;
while (num) {
dig = num % 10;
sum = sum + dig;
num = num / 10;
}
return sum;
}

bool keta(ll num, vector<int> v) {
int dig;
while (num) {
dig = num % 10;
for (auto& i : v) {
if (dig == i) {
return false;
}
}
num = num / 10;
}
return true;
}

ll func(ll a, ll b, ll c, ll d, int n) {
return ((c / (d - b) + n)*(d - b)) + (a % (d - b));
}
*/
int main(void) {
	int n = 50;
	ll k, a[50], m;
	cin >> k;
	m = k / n;
	rep(i, n) {
		a[i] = i + m;
	}
	k %= n;
	rep(i, k) {
		rep(j, n) {
			if (j != i) {
				a[j]--;
			}
		}
		a[i] += n;
	}
	cout << n << endl;
	rep(i, n) {
		cout << a[i];
		if (i < n - 1) {
			cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => number[0]);

		if (t[0] < t[1]) {
			Console.WriteLine("<");
		} else if (t[0] > t[1]) {
			Console.WriteLine(">");
		} else {
			Console.WriteLine("=");
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 11092
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

D = i()
c = l()
s = [l() for _ in range(D)]
last = [0]*26
score = 0
for i in range(D):
    pl = last
    ps = [0]*26
    for j in range(26):
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[k] -= c[k]*(i+1-pl[k])
    indx = ps.index(max(ps))
    score += max(ps)
    last[indx] = i+1
    print(indx+1)

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

typedef VVI Graph;

void visit(const Graph &g, int v, vector< vector<int> >& scc,
		   stack<int> &S, vector<bool> &inS,
		   vector<int> &low, vector<int> &num, int& time){
  low[v] = num[v] = ++time;
  S.push(v); inS[v] = true;
  for(int w: g[v]) {
    if (num[w] == 0) {
      visit(g, w, scc, S, inS, low, num, time);
      low[v] = min(low[v], low[w]);
    } else if (inS[w])
      low[v] = min(low[v], num[w]);
  }
  if (low[v] == num[v]) {
    scc.push_back(vector<int>());
    while (1) {
      int w = S.top(); S.pop(); inS[w] = false;
      scc.back().push_back(w);
      if (v == w) break;
    }
  }
}
void SCC(const Graph& g,
		 vector< vector<int> >& scc) {
  const int n = g.size();
  vector<int> num(n), low(n);
  stack<int> S;
  vector<bool> inS(n);
  int time = 0;
  REP(u, n) if (num[u] == 0)
    visit(g, u, scc, S, inS, low, num, time);
}

LL dp[2][1010];
LL dfs(int i, const VVI& G){
  if(dp[1][i] >= 0) return (dp[0][i] + dp[1][i])%MOD;
  dp[0][i] = dp[1][i] = 1;
  for(int from: G[i]){
	dp[1][i] *= dfs(from, G);
	dp[1][i] %= MOD;
	dp[0][i] *= dp[0][from];
	dp[0][i] %= MOD;
  }
  return (dp[0][i] + dp[1][i]) % MOD;
}

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

  int N, M;
  cin >> N >> M;
  Graph G(N);
  REP(i,M){
	int s, d; cin >> s >> d;
	--s, --d;
	G[s].PB(d);
  }

  VVI scc;
  SCC(G, scc);

  VI tab(N);
  REP(i,SZ(scc))
	for(int x: scc[i])
	  tab[x] = i;

  vector<set<int>> mem(SZ(scc));
  REP(i,N)
	for(int x: G[i])
	  mem[tab[i]].insert(tab[x]);

  N = SZ(scc);
  VVI G_(N);
  REP(i,N){
	for(int x: mem[i])
	  if(x != i)
		G_[i].PB(x);
  }

  VVI in(N);
  REP(i,N){
	for(int to: G_[i]){
	  in[to].PB(i);
	}
  }
  
  fill((LL*)dp, (LL*)dp+2*1010, -1);
  LL ans = 1;
  REP(i,N)
	if(G_[i].empty()){
	  ans *= dfs(i, in);
	  ans %= MOD;
	}

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1540
#include<cstdio>
#include<set>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
using namespace std;
typedef long long LL;
multiset <int> S;
multiset <int> :: iterator it;
int n,m,a[300010];
LL sum,ans,s1[300010],s2[300010];
int main(){
	scanf("%d",&m),n=m*3;
	rep(i,1,n) scanf("%d",a+i);
	rep(i,1,n){
		if (i<=m){
			S.insert(a[i]);
			sum+=a[i];
			s1[i]=sum;
			continue;
		}
		sum+=a[i];
		S.insert(a[i]);
		sum-=*S.begin();
		S.erase(S.begin());
		s1[i]=sum;
	}
	sum=0,S.clear();
	per(i,n,1){
		if (n-i<m){
			S.insert(a[i]);
			sum+=a[i];
			s2[i]=sum;
			continue;
		}
		sum+=a[i];
		S.insert(a[i]);
		it=S.end(),--it;
		sum-=*it;
		S.erase(it);
		s2[i]=sum;
	}
	ans=-1e18;
	rep(i,m,m*2) ans=max(ans,s1[i]-s2[i+1]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10880
N,M=gets.split.map(&:to_i)
result=Array.new(N,nil)
collect=0
total_penalty=0
tmp_penalty=Array.new(N,0)

M.times{
    prob,judge=gets.chomp.split.map(&:to_s)
    prob=prob.to_i
    if judge=="AC"
        if result[prob-1]!="AC"
            result[prob-1]="AC"
            collect+=1
            total_penalty+=tmp_penalty[prob-1]
        end
    else
        if result[prob-1]!="AC"
            tmp_penalty[prob-1]+=1
        end
    end
}

puts "#{collect} #{total_penalty}"

Measured memory_bytes: 10364
#include<bits/stdc++.h>
#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 each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

inline vi inverse(const vi& perm) {
  vi inv(perm.size());
  rep(i, perm.size()) {
    inv[perm[i]] = i;
  }
  return inv;
}

vi multiply(const vi& a, const vi& b) {
  vi ans(a.size());
  rep(i, a.size()){
    ans[i] = b[a[i]];
  }
  return ans;
}

vi pow(const vi& a, ll k) {
  if (k == 0) {
    vi ans(a.size());
    rep(i, a.size()) ans[i] = i;
    return ans;
  }

  vi ans = pow(a, k / 2);
  ans = multiply(ans, ans);
  if (k & 1LL) {
    ans = multiply(ans, a);
  }
  return ans;
}

int main(){
  ll n, k;
  cin >> n >> k;
  vi p(n), q(n);
  rep(i,n) {
    cin >> p[i]; p[i]--;
  }
  rep(i,n) {
    cin >> q[i]; q[i]--;
  }

  vi ans(n);
  if (k == 1) {
    ans = p;
  } else if (k == 2) {
    ans = q;
  } else if (k < 30) {
    vi a1 = p, a2 = q;
    for(int i = 3; i <= k; ++i) {
      vi a3 = multiply(inverse(a1), a2);
      swap(a1, a2);
      swap(a2, a3);
    }
    ans = a2;
  } else {
    vi prefix_base = multiply(inverse(q), multiply(p, multiply(q, inverse(p))));
    vi prefix = pow(prefix_base, (k-2) / 6);
    vi suffix_base = multiply(inverse(p), multiply(q, multiply(p, inverse(q))));
    vi suffix = pow(suffix_base, (k-2) / 6);
    vi very_suffix = multiply(inverse(p), q);

    vi core = multiply(inverse(q), multiply(p, multiply(q, multiply(p, inverse(q)))));
    if (k % 6 == 2LL) {
      core = p;
    } else if (k % 6 == 3LL) {
      core.resize(n);
      rep(i, n) core[i] = i;
    } else if (k % 6 == 4LL) {
      core = inverse(q);
    } else if (k % 6 == 5LL) {
      core = multiply(inverse(q), multiply(p, inverse(q)));
    } else if (k % 6 == 0LL) {
      core = multiply(inverse(q), multiply(p, multiply(p, inverse(q))));
    }

    ans = multiply(prefix, multiply(core, multiply(suffix, very_suffix)));
  }

  rep(i, n) {
    cout << ans[i] + 1 << " \n"[i == n-1];
  }
}


Measured memory_bytes: 5728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
    { for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
    { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
    { cerr << " " << H; debug_out(T...); }
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

vector<pii> G[101010];
vector<int> edge(101010);

void dfs(int v, int p = -1, int pre = -1) {
    int color = 0;
    for (auto &u : G[v]) {
        if (u.fi == p) continue;
        color++;
        if (color == pre) color++;
        dfs(u.fi, v, color);
        edge[u.se] = color;
    }
}

void solve() {
    int n;
    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back({b, i});
        G[b].push_back({a, i});
    }
    int maxdeg = 0;
    rep(i, n) {
        chmax(maxdeg, (int)G[i].size());
    }
    dfs(1);
    cout << maxdeg << endl;
    rep(i, n - 1) {
        cout << edge[i] << endl;
    }
}

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


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

int main() {
    int n,m,c,t;
    cin>>n>>m>>c;
    vector<int> B(m);
    for(int i=0;i<m;i++)
    cin>>B[i];
    
    int count=0,sum;
    for(int i=0;i<n;i++)
    {
        sum=0;
        for(int j=0;j<m;j++)
        {
            cin>>t;
            sum+=B[j]*t;
        }
        if((sum+c)>0)
        count++;
    }
    cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int go = 0, back = 0;
    imfor(i, m) {
        int a;
        cin >> a;
        if (x < a) {
            go++;
        }
        else {
            back++;
        }
    }
    cout << min(go, back) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());

            var ls = new List<int>();
            var sorted = new List<int>();
            for (int i = 0; i < N; i++)
            {
                int tmp = int.Parse(ReadLine());
                ls.Add(tmp);
                sorted.Add(tmp);
            }
            sorted.Sort();
            sorted.Reverse();
            for (int i = 0; i < N; i++)
            {
                if (ls[i] == sorted[0])
                {
                    WriteLine(sorted[1]);
                }
                else
                {
                    WriteLine(sorted[0]);
                }
            }
        }
    }
}


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


int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=min(a,b)+min(c,d);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
n = int(input())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
if n == 0:
    print(1)
    sys.exit()
elif n == 1:
    print(1)
    sys.exit()

for i in range(2, n+1):
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n])


Measured memory_bytes: 5604
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
long long dp[1<<13][1005];
vector < vector < int > >vec;
int  c[1005];
int  n,m;
bool ones(int mask){
    if(mask+1==1<<(n))return true;
    return false;
}
int updatemask(int mask , int a){
    int p=mask;
  for(int i=0;i<vec[a].size();i++){
    mask=mask|(1<<(vec[a][i]-1));
  }
  if(mask==p)return -1;
  return mask;
}
long long solve(int a , int mask){
   if(a==m){
    if(ones(mask))return 0;
    return 10000000000;
   }
   if(dp[mask][a]!=0)return dp[mask][a];
   long long x=solve(a+1,mask);
   int maskupdate=updatemask(mask,a);
   if(maskupdate==-1)return x;
   return dp[mask][a]=min( c[a]+solve(a+1,maskupdate), x);

}
int main()
{
   // cin>>n>>m;
           int k;
           int o;
   scanf("%d %d",&n,&m);
    vec.resize(m);
    for(int i=0;i<m;i++){
        //cin>>c[i];
        scanf("%d",&c[i]);
        //cin>>k;
        scanf("%d",&k);
        for(int j=0;j<k;j++){
           // cin>>o;
           scanf("%d",&o);
            vec[i].push_back(o);
        }
    }
    long long ans=solve(0,0);
    if(ans>=10000000000)cout<<-1;
    else cout<<ans;
    return 0;
}


Measured memory_bytes: 33024
from math import sqrt
from itertools import combinations

N, D = map(int,input().split())
cnt = 0
listX = []
for j in range(N):
    listX.append(list(map(int,input().split())))

comb = list(combinations(listX, 2))

for i in comb:
    goukei = 0
    for m, n in zip(i[0], i[1]):
        goukei += (m - n) ** 2
    if sqrt(goukei) == int(sqrt(goukei)):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
int n,v[55];
double h;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	sort(v+1,v+n+1,cmp);
	ll c=1;
	for(int i=1;i<n;i++)
	{
		c*=2;
		h+=v[i]*1.0/c;
	}
	h+=1.0*v[n]/c;
	printf("%f",h);
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
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); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
bool echeck(ll a) { return a % 2 == 0 ? 1 : 0; }
ll comb(ll n, ll m){
  ll tmp = 1;
  for(int i = n; i >= n - m + 1; i--){
    tmp *= i;
  }
  ll temp = 1;
  for(int i = 1; i <= m; i++){
    temp *= i;
  }
  return tmp / temp;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n,q;
  cin >> n >> q;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  sort(v.begin(),v.end());
  int l,r;
  rep(i,q){
    cin >> l >> r;
    int L = lower_bound(all(v),l) - v.begin();
    int R = upper_bound(all(v),r) - v.begin();
    cout << R - L << endl;
  }
  return 0;
} 


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n;
  cin>>n;

  cout<<n*(n-1)/2<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);
// like n-partite graph, no-intra-connection
// even f(6): (1, 6) (2, 5) (3, 4)
// odd: f(7): (1, 6) (2, 5), (3, 4), (7)
int main() {
    int n;
    cin >> n;
    set<pair<int, int>> cand;
    for(int i = 1; i <= n; i++) {
        for(int j = i+1; j <= n; j++)
            cand.insert({i, j});
    }
    // disconnect intra-link
    int upper = (n%2 == 0) ? n : n-1;
    int lower = 1;
    while (lower < upper) {
        cand.erase({lower++, upper--});
    }
    cout << cand.size() << endl;
    for(auto p: cand)
        cout << p.first << " " << p.second << endl;
    return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
string s,a[105];
int n,v[10005],ans,fl;
int main(){
	scanf("%d",&n);
	For(i,1,n) cin>>a[i]>>v[i];
	cin>>s;
	For(i,1,n) if (a[i]==s) fl=1;
	else if (fl) ans+=v[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int b[200001]={};
  int w[200001]={};
  for(int i=0;i<n;i++){
    if(s[i]=='#') b[i+1]++;
    else w[i+1]++;
    b[i+1]+=b[i];
    w[i+1]+=w[i];
  }
  int ans=1e9;
  for(int i=0;i<n;i++){
      ans=min(ans,b[i]-b[0]+w[n]-w[i+1]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2180
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){

	int n;
	cin >> n;
	for(int j = 0; j < n; j++){
        char a[1000] = {0};
        char b[1000] = {0};
        scanf("%s%s",a,b);
        int len_a = 0,len_b = 0;
        //長さを測る
        for(int i = 0; a[i] != 0; i++) len_a++;
        for(int i = 0; b[i] != 0; i++) len_b++;
        //もし80桁を超えてたらoverflowと出力
        if(len_a > 80 || len_b > 80){
            printf("overflow\n");
        }
        //80桁を超えてなかったら
        else{
            char ans[1000] = {0};
            //aを逆向きに入れ替える
            for(int i = 0; i < len_a/2; i++){
                swap(a[i],a[len_a-i-1]);
            }
            //bを逆向きに入れ替ええる
            for(int i = 0; i < len_b/2; i++){
                swap(b[i],b[len_b-i-1]);
            }
            //aとbで長い方の長さをとる
            int len = max(len_a,len_b);
            //ここで足し算をする
            for(int i = 0; i < len; i++){
                if(ans[i] != 0){
                    if(a[i] == 0 || b[i] == 0)
                        ans[i] += a[i] + b[i] - '0';
                    else ans[i] += a[i] + b[i] - '0' - '0';

                }
                else if(a[i] == 0 || b[i] == 0) ans[i] += a[i] + b[i];
                else ans[i] += a[i] + b[i] - '0';
                if(ans[i] >= 58){
                    ans[i+1]+='1';
                    ans[i] -= 10;
                }
            }
            //このままではansが逆向きなので入れ替える
            for(int i = 0; i < strlen(ans)/2; i++){
                swap(ans[i],ans[strlen(ans)-i-1]);
            }

            int len_ans = 0;
            //ansの長さを測る
            for(int i = 0; ans[i] != 0; i++) len_ans++;
            //もし80桁を超えていたらoverflowと出力する
            if(len_ans > 80) printf("overflow");
            //それ以外なら一文字ずつ出力
            else for(int i = 0; ans[i] != 0; i++) printf("%c",ans[i]);
            printf("\n");
        }
	}

	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long n = nk[0];
			long k = nk[1];
			long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			Array.Sort(a);

			long ok = (long)(-1e18) - 1;
			long ng = (long)(1e18) + 1;
			while (ng - ok > 1) {
				long mid = (ng + ok) / 2;
				long cnt = 0;
				for (int i = 0; i < a.Length; i++) {
					if (a[i] < 0) {
						int ng2 = i;
						int ok2 = a.Length;
						while (ok2 - ng2 > 1) {
							int mid2 = (ok2 + ng2) / 2;
							if (a[i] * a[mid2] < mid) {
								ok2 = mid2;
							} else {
								ng2 = mid2;
							}
						}

						cnt += a.Length - ok2;
					} else {
						int ok2 = i;
						int ng2 = a.Length;
						while (ng2 - ok2 > 1) {
							int mid2 = (ok2 + ng2) / 2;
							if (a[i] * a[mid2] < mid) {
								ok2 = mid2;
							} else {
								ng2 = mid2;
							}
						}

						cnt += ok2 - i;
					}
				}

				if (cnt < k) {
					ok = mid;
				} else {
					ng = mid;
				}
			}

			Console.WriteLine(ok);
		}
	}
}

Measured memory_bytes: 40124
#include <iostream>
#include <stdlib.h>
using namespace std;
int X;
int ans;
int main() {
  cin >> X;
  ans += div(X, 500).quot;
  X -= ans * 500;
  ans *= 1000;
  ans += div(X, 5).quot * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var N int; fmt.Scan(&N);
	var V []int;
	for i:=0; i<N; i++ {
		var v int;
		fmt.Scan(&v)
		V = append (V, v);
	}
	var C []int;
	for i:=0; i<N; i++ {
		var c int;
		fmt.Scan(&c);
		C = append (C, c);
	}
	var ans int = 0;
	for i:=0; i<N; i++{
		if V[i] - C[i] >= 0{
			ans += V[i]-C[i]
		}
	}
	fmt.Println(ans);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll N;
vector<vector<ll>> edge;
vector<ll> sum;
vector<ll> ans;

void dfs(ll u,ll p,ll w){
  sum[u]+=w;
  ans[u]=sum[u];
  for(auto &v:edge[u]){
    if(v==p){continue;}
    dfs(v,u,sum[u]);
  }
}

int main(){
  cin>>N;
  edge.resize(N);
  sum.resize(N,0);
  ans.resize(N,0);
  ll Q;
  cin>>Q;
  for(int i=1;i<N;i++){
    ll u,v;
    cin>>u>>v;
    u--; v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  for(int i=0;i<Q;i++){
    ll p,x;
    cin>>p>>x;
    p--;
    sum[p]+=x;
  }
  dfs(0,-1,0);
  cout<<ans<<endl;
  
  return 0;
}


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

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

	int res = 0;
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
	}
	cout << res << endl;
	
	return 0;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int A, B;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> A >> B;
    FOR(i, 1, 4) {
        if (A != i && B != i) cout << i;
    }
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256