akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<algorithm>
//#define DEBUG
using namespace std;

typedef vector< pair<int, int> > vecs;
vector<vecs> table;
vector<vecs> rev_table;
int N, M;

vecs mov(vecs x){
	int tmp;
	#ifdef DEBUG_mov
	for(vecs::iterator p = x.begin(); p != x.end(); p++){
		cout<<"before: "<< p->first <<", "<< p->second << endl;
	}
	#endif
	for(vecs::iterator p = x.begin(); p != x.end(); p++){
		tmp = p->first;
		p->first = -(p->second);
		p->second = tmp;
	}
	#ifdef DEBUG_mov
	for(vecs::iterator p = x.begin(); p != x.end(); p++){
		cout<<"after: "<< p->first <<", "<< p->second << endl;
	}
	#endif
	return x;
}
bool veq(vecs a, vecs b){
	//90ツ度ツづ慊づュツつキ
	vecs tmp = a;
	for(int i = 0; i < 4; i++){
		#ifdef DEBUG
		for(vecs::iterator p = tmp.begin(); p != tmp.end(); p++){
			cout<<"tmp: "<< p->first <<", "<< p->second << endl;
		}
		for(vecs::iterator p = b.begin(); p != b.end(); p++){
			cout<<"b: "<< p->first <<", "<< p->second << endl;
		}
		#endif
		if(tmp == b)return true;
		tmp = mov(tmp);
	}
	return false;
}

int main(){
	while(cin>>N, N){
		int i, j;
		table.clear(); rev_table.clear();
		for(int i = 0; i <= N; i++){
			cin>>M;
			int x, y; int x0, y0;
			cin>>x0>>y0;
			vecs tmpv;
			for(int j = 0; j < M-1; j++){
				cin>>x>>y;
				tmpv.push_back(make_pair(x-x0, y-y0));
				x0 = x; y0 =  y;
			}
			table.push_back(tmpv);
			reverse(tmpv.begin(), tmpv.end());
			rev_table.push_back(tmpv);
		}
		#ifdef DEBUG_in
		for(vector<vecs>::iterator p = table.begin(); p != table.end(); p++){
			for(vecs::iterator q = p->begin(); q != p->end(); q++){
				cout<< q->first <<", "<< q->second <<endl;
			}
			cout<<endl;
		}
		#endif
		for(i = 1; i <= N; i++){
			if(veq(table[i], table[0]) || veq(table[i], rev_table[0])){
				cout<<i<<endl;
			}
		}
		cout<<"+++++"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
c = [list(map(int, input().split())) for _ in range(3)]
b = [i - c[0][0] for i in c[0]]
a = [i[0] - c[0][0] for i in c]
if all(c[i][j]-a[i]-b[j] == c[0][0] 
        for i in range(3) for j in range(3)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
#define MAXN 100010

priority_queue<pi,vpi,greater<pi>> pq;
vi V[MAXN];
ll N,M;
ll W,ans;
ll A[MAXN];
ll save;

int main(){
	cin>>N>>M;
	for (ll i=1;i<=N;++i){
		cin>>A[i];
	}
	for (ll i=1;i<N;++i){
		ll w = (A[i+1]+M-A[i])%M;
		W += w;
		if (A[i+1] < A[i]){
			save += (M-A[i]);
			pq.push(mp(A[i+1], A[i]));
			// cout<<"Push "<<A[i]<<' '<<A[i+1]<<'\n';
		}
		V[A[i]].pb(A[i+1]);
	}
	ll sv = 0;
	// cout<<"Save 1 "<<W-save<<'\n';
	sv = max(sv,save);
	for (ll i=2;i<=M;++i){
		// cout<<pq.top().f<<'\n';
		while(SZ(pq) && pq.top().f == i-1){
			pi p = pq.top();pq.pop();
			// cout<<"Remove "<<p.s<<' '<<p.f<<'\n';
			save -= (p.f+M-p.s)%M; 
			++save;
		}
		save += SZ(pq);
		for (auto x:V[i-1]){
			if(i-1>x)pq.push(mp(x+M,i-1));
			else pq.push(mp(x,i-1));
			// cout<<i-1<<' '<<x<<'\n';
		}
		// cout<<"Save "<<i<<' '<<W-save<<'\n';
		sv = max(sv,save);
	}
	cout<<W-sv<<'\n';
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> sum(N+1);
  sum.at(0)=0;
  int s;
  int ma;
  for(int i=1;i<=N;i++){
    sum.at(i)=sum.at(i-1)+i;
    if(N-sum.at(i)<i+1){
      int diff=N-sum.at(i);
      s=i-diff+1;
      ma=i+1;
      break;
    }
  }
  for(int i=1;i<=ma;i++){
    if(i==s){
      continue;
    }
    cout << i << endl;
  }
  return 0;
}


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

int main() {
  bool b = 1;
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  rep(i, n){
    if(v[i] % 2 == 0 && v[i] % 3 != 0 && v[i] % 5 != 0){
      b = 0;
      break;
    }
  }
  if(b) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}

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

int main(void) {
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < O.size() - 1; i++) {
		printf("%c%c", O[i], E[i]);
	}
	if (E.size() == O.size()) printf("%c%c\n", O[O.size() - 1], E[E.size() - 1]);
	else printf("%c\n", O[O.size() - 1]);

	return 0;
}


Measured memory_bytes: 3664
n=int(input())
z=[]
for i in range(n):
    x,y=map(int,input().split())
    z.append([x,y])
z.sort(reverse=True)
dif=[]
for i in range(n):
    for j in range(n):
        if i<j:
            x=z[j][0]-z[i][0]
            y=z[j][1]-z[i][1]
            dif.append([x,y])
dif.sort(reverse=True)
count=-1
buf=0
comp=[0,0]
ans=[0,0]
l=len(dif)
for i in range(l):
    if comp==dif[i]:
        buf+=1
    else:
        if count<buf:
            count=buf
            ans=comp
        buf=1
        comp=dif[i]
if count<buf:
    count=buf
    ans=comp
print(n-count)

Measured memory_bytes: 3188
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll cur = 1000;
  rep(i, n - 1){
    if(a[i] < a[i + 1]){
      ll num = cur / a[i];
      cur -= num * a[i];
      cur += a[i + 1] * num;
    }
  }
  cout << cur << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int total = 0;
	int[] T = new int[N];
	for (int i = 0; i < N; i++) {
	    int tmp = Integer.parseInt(scan.next());
	    total += tmp;
	    T[i] = tmp;
	}
	int M = Integer.parseInt(scan.next());
	int[] P = new int[M];
	int[] X = new int[M];
	for (int i = 0; i < M; i++) {
	    P[i] = Integer.parseInt(scan.next()) - 1;
	    X[i] = Integer.parseInt(scan.next());
	}

	for (int i = 0; i < M; i++) {
	    System.out.println(total - (T[P[i]] - X[i]));
	}
	scan.close();
    }
}


Measured memory_bytes: 20052
#include <iostream>

using namespace std;

int main() {
  int r, g, b;
  int num;
  cin >> r >> g >> b;
  num = 100 * r + 10 * g + b;
  if (num % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static int h, w;
    public static bool[,] map;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '.') map[i, j] = true;
        }
        goDp();
    }
    static void goDp()
    {
        var dp = new int[h, w];
        for (int i = 1; i < w; i++)
            if (map[0, i - 1] && !map[0, i]) dp[0, i] = dp[0, i - 1] + 1;
            else dp[0, i] = dp[0, i - 1];
        for (int i = 1; i < h; i++)
            if (map[i - 1, 0] && !map[i, 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++)
            {
                var c1 = map[i - 1, j] && !map[i, j] ? dp[i - 1, j] + 1 : dp[i - 1, j];
                var c2 = map[i, j - 1] && !map[i, j] ? dp[i, j - 1] + 1 : dp[i, j - 1];
                dp[i, j] = Min(c1, c2);
            }
        var dphw = dp[h - 1, w - 1];
        Console.WriteLine(!map[0, 0] ? dphw + 1 : dphw);
    }
}


Measured memory_bytes: 13396
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] kadomatsu = new int[n];
        for(int i = 0; i < n; i++) {
            kadomatsu[i] = sc.nextInt();
        }
        System.out.println(dfs(kadomatsu, n, 0, a, 0, b, 0, c, 0));
    }
    private static int dfs(int[] kadomatsu, int n, int currentN, int a, int currentA, int b, int currentB, int c, int currentC) {
        if(currentN == n) {
           if(currentA != 0 && currentB != 0 && currentC != 0) {
               return  Math.abs(a - currentA) + Math.abs(b - currentB) + Math.abs(c - currentC) - 30;
           }
           return 10000;
        }
        int candidate1 = dfs(kadomatsu, n, currentN + 1, a, currentA, b, currentB, c, currentC);
        int candidate2 = dfs(kadomatsu, n, currentN + 1, a, currentA + kadomatsu[currentN], b, currentB, c, currentC) + 10;
        int candidate3 = dfs(kadomatsu, n, currentN + 1, a, currentA, b, currentB + kadomatsu[currentN], c, currentC) + 10;
        int candidate4 = dfs(kadomatsu, n, currentN + 1, a, currentA, b, currentB, c, currentC + kadomatsu[currentN]) + 10;

        return Math.min(candidate1, Math.min(candidate2, Math.min(candidate3, candidate4)));
    }
}


Measured memory_bytes: 25684
#include<bits/stdc++.h>
using namespace std;
int N;
int A[100005];
int B[100005];
int main()
{
    scanf("%d", &N);
    int len = 0;
    for(int i=0;i<N;i++)
    {
         scanf("%d", &A[i]);
         B[A[i]]++;
         len = max(len, A[i]);
    }
    int flag = 0;
    int ans = 0;
    for(int i=1;i<=len;i++)
    {
         while(B[i]>2) B[i]-=2;
         if(B[i]==2) flag^=1;
         if(B[i]>0) ans++;
    }
    printf("%d\n", ans-flag);
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int a[3][3];
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int k=0;k<n;k++)
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                if(a[i][j]==b[k])
                    a[i][j]=0;
    int ans=0;
    for(int i=0;i<3;i++)
        if(a[i][0]+a[i][1]+a[i][2]==0)
            ans=1;
    for(int i=0;i<3;i++)
        if(a[0][i]+a[1][i]+a[2][i]==0)
            ans=1;
    if(a[0][0]+a[1][1]+a[2][2]==0)
        ans=1;
    if(a[0][2]+a[1][1]+a[2][0]==0)
        ans=1;
    if(ans==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,st[22],top,x;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>=st[top])
		 st[++top]=x;
	}
	cout<<top<<endl;
	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char s[353];
int k;

int dp[2][353][353];  // dp[k][l][r] := s[l,r) k modified max pal subseq

int main(){
  scanf("%s%d",s,&k);
  int n = strlen(s);
  REP(i,k+1){
    REP(j,353)REP(k,353)dp[1][j][k] = 0;
    REP(l,n+1){
      REP(lef,n-l+1){
        int rig = lef+l;
        if(l<=1){
          dp[1][lef][rig] = l;
        }else{
          CHMAX(dp[1][lef][rig], dp[1][lef+1][rig-1] + (s[lef]==s[rig-1]?2:0));
          CHMAX(dp[1][lef][rig], dp[1][lef+1][rig]);
          CHMAX(dp[1][lef][rig], dp[1][lef][rig-1]);
          if(i>0)CHMAX(dp[1][lef][rig], dp[0][lef+1][rig-1] + 2);
        }
      }
    }
    // REP(i,n)REP(j,n+1)printf("%d%c",dp[1][i][j],j==n?'\n':' ');puts("");
    REP(j,353)REP(k,353)dp[0][j][k] = dp[1][j][k];
  }
  printf("%d\n",dp[0][0][n]);
  return 0;
}


Measured memory_bytes: 1280
using System;

class Program {
  static void Main(string[] args) {
    int len = 0, ic;
    int N = 100000;
    int[] last = new int[26];
    int[,] count = new int[26, N];

    for(int i = 0; i < 26; ++i) {
      last[i] = -1;
      for(int j = 0; j < N; ++j) {
        count[i, j] = 0;
      }
    }

    while((ic = Console.Read()) >= 'a' && ic <= 'z') {
      ic -= 'a';
      for(int i = (0 > last[ic] - 3 ? 0 : last[ic] - 3); i < last[ic]; ++i) {
        if(count[ic, i] > 0) {
          // Console.WriteLine("l = {0}, freq[{1}, {2}] = {3}", len + 1, ic, i, ++count[ic, i] / (len - i + 1.0));
          if((++count[ic, i] / (len - i + 1.0)) > 0.5) {
            Console.WriteLine("{0} {1}", i + 1, len + 1);
            return;
          }
        }
      }
      count[ic, len] = 1;
      last[ic] = ++len;

    }

    Console.WriteLine("-1 -1");
  }
}


Measured memory_bytes: 21088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

class unionfind{
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    std::vector<int> UF,rank;
    public:
    
    void init(int N){
        UF.clear();
        rank.clear();
        for(int i=0;i<N;i++){
            UF.push_back(i);
            rank.push_back(0);
        }
    }
    
    int root(int k){
        if(UF[k]==k){
            return k;
        }else{
            UF[k]=root(UF[k]);
            return UF[k];
        }
    }
    
    bool same(int p,int q){
        return root(p)==root(q);
    }
    
    void unite(int P,int Q){
        int p=root(P);
        int q=root(Q);
        if(p==q)return;
        if(rank[p]<rank[q])std::swap(p,q);
        UF[q]=p;
        if(rank[p]==rank[q])rank[p]++;
    }
    
};


int main(void){
    ll N,M,a,b;
    vector<pair<ll,ll>> AB;
    
    cin >> N >> M;
    REP(i,M){
        cin >> a >> b;
        a--;b--;
        AB.push_back({a,b});
    }
    
    unionfind UF;
    UF.init(N);
    
    REP(i,M){
        UF.unite(AB[i].first,AB[i].second);
    }
    
    ll num=0;
    REP(i,N){
        if(UF.root(i)==i){
            num++;
        }
    }
    
    cout << num-1 << endl;
    
    return 0;
}



Measured memory_bytes: 6144
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int a, b, ans;
	cin >> a >> b;
	ans = a - 1;
	if ( a <= b ) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, M;

int main(){
cin >> N >> M;

cout << (1900 * M + 100 * (N - M)) * ll(pow(2, M)) << endl;


  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];
    int ans = INT_MAX;

    int mi = *min_element(x.begin(), x.end());
    int ma = *max_element(x.begin(), x.end());
    for (int p = mi; p <= ma; ++p) {
        int total = 0;
        for (auto xi : x) {
            total += (xi - p) * (xi - p);
        }
        if (ans > total) ans = total;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
lst_1 = sorted([(a - 1) % 10, (b - 1) % 10, (c - 1) % 10, (d - 1) % 10, (e - 1) % 10])
print(((a+9)//10)*10 + ((b+9)//10)*10 + ((c+9)//10)*10 + ((d+9)//10)*10 + ((e+9)//10)*10 - (10 - (lst_1[0] + 1) if lst_1[0] != 9 else 0))

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

#define MAX 200000

int main() {
	int n;
	vector<string> S(MAX);
	cin >> n;
	map<string, int> s;
	for (int i = 0; i < n; i++) {
		cin >> S[i];
		s[S[i]]++;
	}
	map<string, int>::iterator it1;
	int value = 0;
	for (it1 = s.begin(); it1 != s.end(); it1++) {
		   value = max((*it1).second, value);
	}
	map<string, int>::iterator it2;
	for (it2 = s.begin(); it2 != s.end(); it2++) {
		if ((*it2).second == value) 
			cout << (*it2).first << endl;
	}
	return 0;		
}

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

namespace AOJ.Problem0034
{
  class RailwayLines
  {
    static void Main()
    {
      // after t[h],
      // train1 runs t * v1 [km],
      // train2 runs t * v2 [km].
      // position of trains are
      // * train1: t * v1
      // * train2: l - (t * v2)
      // t * v1 = l - (t * v2)
      // t * v1 + t * v2 = l
      // t (v1 + v2) = l
      // t = l / (v1 + v2)
      foreach (var input in ReadNumbers())
      {
        var section = input[0];
        var velocity = input[1];
        var t = (double)section.Sum() / velocity.Sum();
        var x = t * velocity[0];
        var sec = 1;
        while (section.Take(sec).Sum() < x)
          ++sec;
        Console.WriteLine(sec);
      }
    }

    static IEnumerable<int[][]> ReadNumbers()
    {
      string line;
      while (!string.IsNullOrEmpty(line = Console.ReadLine()))
      {
        var t = line.Split(',').Select(s => int.Parse(s));
        yield return new[] { t.Take(10).ToArray(), t.Skip(10).ToArray() };
      }
    }
  }
}

Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N,M,r,q;
	while(cin>>N>>M,N){
		int t[1001],n[1001],m[1001],s[1001];
		int ts,te,mq;
		cin>>r;
		REP(i,0,r){
			cin>>t[i]>>n[i]>>m[i]>>s[i];
		}
		cin>>q;
		REP(i,0,q){
			cin>>ts>>te>>mq;
			int ans=0,cnt=0,k=0;
			REP(j,ts,te){
				for(;k<r&&t[k]<=j;k++){
					if(m[k]==mq){
						if(s[k]==0)cnt--;
						else cnt++;
					}
				}
				if(cnt) ans++;
			}
			p(ans);
		}
	}
	return 0;
}

Measured memory_bytes: 3048
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()

	var sum int
	nn := make([]int, 0, n)
	for i := 0; i < n; i++ {
		nn = append(nn, nextInt())
		sum += nn[i]
	}

	var e int
	for index := 1; index < n; index++ {
		e += Min(nn[index-1], nn[index])
	}

	fmt.Printf("%#v\n", sum-e)
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("function min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2],fa[maxn],d[maxn],a[maxn];
int i,j,k,l,t,n,m,tot,root;
bool czy;
void add(int x,int y){
    d[y]++;
    go[++tot]=y;
    nxt[tot]=h[x];
    h[x]=tot;
}
void dfs(int x,int y){
    if (d[x]==1){
        fa[x]=a[x];
        return;
    }
    int t=h[x];
    fa[x]=2*a[x];
    while (t){
        if (go[t]!=y){
            dfs(go[t],x);
            fa[x]-=fa[go[t]];
        }
        t=nxt[t];
    }
}
void dg(int x,int y){
    if (d[x]==1) return;
    int t,l=0;
    if (fa[x]>a[x]) czy=0;
    else{
        t=h[x];
        while (t){
            if (go[t]!=y){
                if (fa[go[t]]>a[x]-fa[x]) l+=(fa[go[t]]+fa[x]-a[x]);
            }
            t=nxt[t];
        }
        if (l>fa[x]) czy=0;
    }
    t=h[x];
    while (t){
        if (go[t]!=y) dg(go[t],x);
        t=nxt[t];
    }
}
int main(){
    scanf("%d",&n);
    fo(i,1,n) scanf("%d",&a[i]);
    fo(i,1,n-1){
        scanf("%d%d",&j,&k);
        add(j,k);add(k,j);
    }
    if (n==2){
        if (a[1]==a[2]) printf("YES\n");else printf("NO\n");
        return 0;
    }
    fo(i,1,n)
        if (d[i]>1) break;
    root=i;
    dfs(root,0);
    if (fa[root]){
        printf("NO\n");
        return 0;
    }
    czy=1;
    dg(root,0);
    if (czy) printf("YES\n");else printf("NO\n");
}

Measured memory_bytes: 7296
#include<stdio.h>

int main(){
  int x, y, height[10];
    for(x = 0; x < 10; x++){
      scanf("%d", &height[x]);
    }
    int temp;
    for(x = 0; x < 10; x++){
      for(y = 0; y < 9; y++){
	if(height[y] < height[y+1]){
	  temp = height[y];
	  height[y] = height[y+1];
	  height[y+1] = temp;
	}
      }
    }
  for(y = 0; y < 3; y++){
    printf("%d\n", height[y]);
  }
  return 0;
}

Measured memory_bytes: 600
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;

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

    int x[n];

    REP(i, n) {
        scanf("%d", &x[i]);
    }

    int minv = INT_MAX;
    for (int i = 0; i + k - 1 < n; ++i) {
        minv = min(abs(x[i]) + abs(x[i + k - 1] - x[i]), min(abs(x[i + k - 1]) + abs(x[i] - x[i + k - 1]), minv));
    }

    OUT(minv);

    return 0;
}



Measured memory_bytes: 640
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iomanip>

using namespace std;
#define INF 1e9
#define MAX 100005
#define MOD 1000000007
#define Q queue
#define PQ priority_queue
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; i++ )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; i-- )
#define wa cout<<"Wa"<<endl
#define READ(filename)  freopen(filename, "r", stdin);
#define WRITE(filename)  freopen(filename, "w", stdout);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<int , vector<int> > mvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

void base(){
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
}


int main(){
	base();
	int x,a,b;
	cin>>x>>a>>b;
	if (b-a<=0){
		cout<<"delicious"<<endl;
		return 0;
	}
	
	if (b-a <= x){
		cout<<"safe"<<endl;
		return 0;
	}else cout<<"dangerous"<<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	double a,b,c,degree,S;
	scanf("%lf %lf %lf",&a,&b,&degree);
	S = (0.5)*a*b*sin(M_PI*degree/180);
	c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
	printf("%.8lf\n",S);
	printf("%.8lf\n",a+b+c);
	printf("%.8lf\n",2*S/a);
}



Measured memory_bytes: 3096
def main():
    N = int(input())
    A = list(map(int,input().split()))
    a = [i for i in A if i%2==0]
    for j in a:
        if j%3!=0 and j%5!=0:
            print("DENIED")
            return
    print("APPROVED")


if __name__=='__main__':
    main()


Measured memory_bytes: 2940
// Problem : A - Nickname
// Contest : AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest 2020
// URL : https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

void solve(){
    string s;
    cin>>s;
    cout<<s.substr(0,3);
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int k,a,b;
	cin>>k>>a>>b;
	if(b/k==(a-1)/k)cout<<"NG"<<endl;
	else cout<<"OK"<<endl;
}


Measured memory_bytes: 3652
int main(f){
  double w;
  char *p[11]={"light fly","fly","bantam","feather","light","light welter",
	       "welter","light middle","middle","light heavy","heavy"};
  
  while(scanf("%lf",&w)!=-1){
    f=w>48?w>51?w>54?w>57?w>60?w>64?w>69?w>75?w>81?w>91?10:9:8:7:6:5:4:3:2:1:0;
    puts(p[f]);
  }
  return 0;
}

Measured memory_bytes: 0
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	
	writeln(A <= 9 && B <= 9 ? A*B : -1);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    r = sum(x // 2 for x in a) * k
    if s[0] == s[-1] and a[0] & a[-1] & 1:
        r += k - 1
    print(r)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pll pair <long long,long long>
#define f first
#define s second
#define ll long long
using namespace std;
ll d[101][100001];
int main () {
	ios;
	ll n,m;
	cin>>n>>m;
	pll a[n+1];
	for (ll k=1;k<=n;k++) cin>>a[k].f>>a[k].s;
	for (int k=a[1].f;k<=m;k++) d[1][k]=a[1].s;
	for (int k=2;k<=n;k++) {
		for (int j=1;j<=m;j++) {
			d[k][j]=d[k-1][j];
			if (j-a[k].f>=0) d[k][j]=max(d[k][j],d[k-1][j-a[k].f]+a[k].s);
		}
	}
	ll mx=0;
	for (ll k=1;k<=m;k++) mx=max(mx,d[n][k]);
	cout<<mx;
	return 0;
}


Measured memory_bytes: 78336
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


n, m = map(int, input().split())
s = input()
t = input()

l = lcm(n, m)
g = gcd(n, m)

ng = n // g
mg = m // g
k = 0
flg = True
while True:
    if k * ng >= n or k * mg >= m:
        break
    if s[k * ng] != t[k * mg]:
        flg = False
        break
    k += 1

if flg:
    print(l)
else:
    print(-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k; cin >> n >> k;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int pi; cin >> pi;
    p.push_back(pi);
  }
  sort(begin(p), end(p));
  int t = 0;
  for (int i = 0; i < k; i++) {
    t += p[i];
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,M;
  cin>>N>>M;
 vector<pair<ll,ll>> vec(N);
  for(ll i=0;i<N;i++) {
ll A,B;
    cin>>A>>B;
    vec[i]=make_pair(B,A);
  }
  
  sort(all(vec));
  reverse(all(vec));
  
  vector<vector<ll>> note(M,vector<ll>(0));
  for(ll i=0;i<N;i++) {
if(vec[i].second>M) {
continue;
}
    note[vec[i].second-1].push_back(vec[i].first);
  }
  
 
  ll ans=0;
  priority_queue<tuple<ll,ll,ll>> S;
  for(ll i=1;i<=M;i++) {
if(note[i-1].size()>0) {
S.push(make_tuple(note[i-1][0],i-1,0));
}
    if(S.empty()) {
continue;
    }
    ll A,B,C;
  tie(A,B,C)=S.top();
    S.pop();
    ans+=A;
    if(note[B].size()>C+1) {
S.push(make_tuple(note[B][C+1],B,C+1));
    }
  }
  
  
  cout<<ans<<endl;
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

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

int main() {

	int n; cin >> n;

	vector<int> v(n), c(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	for (int i = 0; i < n; i++) cin >> c[i];

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (0 < v[i] - c[i]) {
			ans += v[i] - c[i];
		}
	}

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

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    string str;
    cin >> str;

    string enki[4] = {"A", "C", "G", "T"};

    if(str == "A"){
        cout << enki[3] << endl;
    } else if(str == "C"){
        cout << enki[2] << endl; 
    } else if(str == "G"){
        cout << enki[1] << endl;
    } else {
        cout << enki[0] << endl;
    }
    return 0;
}

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

int main(){
    string n;
    cin >> n;
    int count = 0;
    for(int i = 0;i < n.size();i++){
        if(n.at(i)=='7'){
            cout << "Yes" << endl;
            break;
        }else{
            count += 1;
        }
    }
    if(count == n.size()){
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
using namespace std; 
int main()
{
	int a,b,k;
	cin>>k;
	cin>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			flag=1;
			break;
		}
	}
	if(flag) cout<<"OK\n";
	else cout<<"NG\n";
	return 0;
}

Measured memory_bytes: 3624
class UnionFind3
  def initialize(size)
    @table = [-1]*size
  end

  def find(x)
    if @table[x] < 0
      return x
    else
      return @table[x] = find(@table[x])
    end
  end

  def union(x, y)
    s1 = find(x)
    s2 = find(y)
    if s1 != s2
      if @table[s1] <= @table[s2]
        @table[s1] += @table[s2]
        @table[s2] = s1
      else
        @table[s2] += @table[s1]
        @table[s1] = s2
      end
      return true
    end
    return false
  end
end

#UF=Hash.new{-1}
#def u a,b;UF[f a]=f b;end
#def f c;0>UF[c]?c:UF[c]=f(UF[c])end

cities=(1..n=gets.to_i).map{|i|gets.split.map(&:to_i)+[i]}

road = cities.sort_by{|x,y,i|x}.each_cons(2).map{|(x1,y1,i),(x2,y2,j)|[x2-x1,i,j]}+
       cities.sort_by{|x,y,i|y}.each_cons(2).map{|(x1,y1,i),(x2,y2,j)|[y2-y1,i,j]}

uf=UnionFind3.new(100001)
p road.sort.inject(0){|s,(cost,i,j)|
  if uf.find(i)!=uf.find(j)
    uf.union(i,j)
    s+cost
  else
    s
  end
}


Measured memory_bytes: 27028
all = []

for i in range(4):
    for j in range(13):
        if i == 0:
            num = j + 1
            all.append("S " + str(num))
        elif i == 1:
            num = j + 1
            all.append("H " + str(num))
        elif i == 2:
            num = j + 1
            all.append("C " + str(num))
        else:
            num = j + 1
            all.append("D " + str(num))

n = int(input())

for i in range(n):
    card = input()
    all.remove(card)


for i in range(len(all)):
    print(all[i])


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;


int main() {
    int x,y,z;
    cin >> x >> y >> z;
    cout << z <<' '<< x<<' '<< y;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// A := strings.Split(nextLine(), " ")

	X := strings.Split(nextLine(), " ")

	// Z := strings.Split(nextLine(), " ")
	// n, _ := strconv.Atoi(input[0])

	N, _ := strconv.Atoi(X[0])
	// W, _ := strconv.Atoi(X[1])
	// K, _ := strconv.Atoi(X[2]) //strconv.ParseInt(X[2], 10, 64)

	// Y := strings.Split(nextLine(), " ")

	// arr := make([]otosidama, N)
	var ans float64
	for i := 0; i < N; i++ {
		Y := strings.Split(nextLine(), " ")

		x, _ := strconv.ParseFloat(Y[0], 64)
		v := Y[1]

		if v == "BTC" {
			ans += exchange(x)
		} else {
			ans += x
		}

	}

	/*文字列連結高速化
	初期化:buf := make([]byte, 0,N+1)
	連結:buf=append(buf,str)
	出力:string(buf)
	*/
	// sort.Sort(sort.Reverse(dp[M][N]))

	fmt.Fprintln(wtr, ans)

	_ = wtr.Flush()
}

type otosidama struct {
	x float64
	v string
}

func exchange(x float64) float64 {
	return x * 380000.0
}

func culc(a, b, c, d int64) (ret int64) {
	ret = abs(a-c) + abs(b-d)
	return
}

func chmax(a *string, b string) {
	if len(*a) < len(b) {
		*a = b
	} else if len(*a) == len(b) && *a < b {
		*a = b
	}
}

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

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return 0 //abs(a - b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}
func sum(a []int) (sum int) {
	for _, num := range a {
		sum += num
	}
	return
}

type item struct {
	x int
	// y     int
	// point int
}

type que []item

func (p que) Len() int {
	return len(p)
}

func (p que) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p que) Less(i, j int) bool {

	// return p[i].point > p[j].point //p[i].x+p[i].y > p[j].x+p[j].y
	return p[i].x < p[j].x
}

func (p que) Push(in int) {
	p = append(p, item{x: in})
	sort.Sort(p)
}

func (p que) Pop() int {
	res := p[0].x
	p = p[1:]
	return res
}

func (p que) Peek() int {
	return p[0].x
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int zero[100100] = { 0 };
int main(){
	int n, k1;
	int ans, max = 0;
	string s;
	cin >> n >> k1 >> s;
	int co = 1, co1 = 1, co2;
	for (int i = 0; i < n; i++) {
		if (s[i] != s[i + 1] || n == n - 1) {
			zero[co1] = co;
			co1++;
			co = 1;
			continue;
		}
		else {
			co++;
		}
	}
	for (int j = 0; j <= co1; j++) {
		zero[j] += zero[j - 1];
	}
	if (s[0] == '0') {
		co2 = k1 * 2;
	}
	else {
		co2 = k1 * 2 + 1;
	}
	if (co2 > co1) {
		cout << n << endl;
		return 0;
	}
	for (int k = co2; k <= co1; k+=2) {
		ans = zero[k] - zero[k - k1 * 2 - 1];
		if (ans > max) {
			max = ans;
		}
	}
	cout << max << endl;
    return 0;
}

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



struct UnionFind{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int size) : par(size), sizes(size,1){
        for(int i=0;i<size;i++) par[i] = i;
    }

    bool unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x == y) return false;
        if(sizes[x] < sizes[y]) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return true;
    }

    int find(int x){
        if(par[x] == x) return x; 
        return par[x] = find(par[x]);
    }

    bool isSame(int x,int y){
        return find(x) == find(y);
    }

    int getSize(int x){
        return sizes[find(x)];
    }
};
#define int long long 
signed main(){
    int N,M;
    cin >> N >> M;
    UnionFind forest(N);

    vector<int> A(M),B(M);
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    vector<int> ans(M);
    ans[M-1] = N*(N-1)/2;

    for(int i=M-1;i>0;i--){
        int sizeA = forest.getSize(A[i]);
        int sizeB = forest.getSize(B[i]);
        ans[i-1] = ans[i];
        if(forest.unite(A[i],B[i])) ans[i-1] -= (sizeA*sizeB);
    }

    for(int i=0;i<M;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
	vi b(n);
	rep(i,n)cin>>b[i];
	vi ans(n);
	int able = -1;
	rep(i,n){
		able =-1;
		rep(j,b.size()){
			if(b[j]==j+1){
				able=j;
			}
		}
		if(able==-1){
			cout<<-1<<endl;
			return 0;
		}
		else{
			ans[i]=able+1;
			b.erase(b.begin()+able);
		}
	}
	reverse(been(ans));
	rep(i,n){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 256
import           Control.Monad
import           Data.Array.IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main = do
  n <- getInt
  as <- getIntVec n

  cs <- VM.new 61
  VM.set cs (0::Int)

  forM_ [0..n-1] $ \i -> do
    let a = as V.! i
    forM_ [0..60] $ \j ->
      when (testBit a j) $ do
        c <- VM.read cs j
        VM.write cs j (c+1)

  cs' <- V.freeze cs
  let ans = V.ifoldr calc 0 cs' `mod` 1000000007
      calc i c a = let c1 = fromIntegral c :: Integer
                       c2 = fromIntegral (n-c) :: Integer
                   in
                     c1 * c2 * bit i + a

  print ans

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

int main(){
  string s;
  cin >>s;
  int ans = 0;
  rep(i,s.size()){
    if(s[i] == '+') ans++;
    if(s[i] == '-') ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N,num=0,mini=0;
		N=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		for(int i=0;i<N-1;i++){
			mini=i;
			for(int j=i+1;j<N;j++){
				if(A[j]<A[mini]){
					mini=j;
				}
			}
			if(mini!=i){
				int tmp=A[i];
				A[i]=A[mini];
				A[mini]=tmp;
				num++;
			}
		}
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}
			else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(num);
	}
}


Measured memory_bytes: 26204
#include <iostream>
#include <string>

using namespace std;
int main(){//D問題
    string s;
    cin >> s;
    char a = '0';
    char b = '1';
    bool notExist=true;
    for(int i=0;i<s.size();++i){
        if(a==s[i] || b==s[i]){
            notExist=false;
            if(i==1)
                cout << "1 2";
            else
                cout << i-1 << " " << i+1;
            break;
        }
        a = b;
        b = s[i];
    }
    if(notExist){
        cout << "-1 -1";
    }
    return 0;
}

Measured memory_bytes: 512
from itertools import chain, product, zip_longest
 
s = input()
assert all(c in '123456789' for c in s)

betweens = product(('', '+'), repeat=len(s)-1)
def make_string(between):
  return ''.join(chain.from_iterable(zip_longest(s, between, fillvalue='')))
strings = (make_string(between) for between in betweens)
print(sum(map(eval, strings)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

void solve() {
  int n; cin >> n;
  vector<ll> K(n), L(n), R(n);
  priority_queue<ll, vector<ll>, greater<ll>> q;
  map<int, vector<int>> mpp, mpm;
  ll ans = 0;
  int np = 0, nm = 0;
  rep(i, n) {
    cin >> K[i] >> L[i] >> R[i];
    K[i]--;
    if(L[i]-R[i]>=0) {
      mpp[K[i]].push_back(i);
      np++;
    } else {
      mpm[n-K[i]-2].push_back(i);
      nm++;
    }
    ans += min(L[i], R[i]);
  }
  rep(i, n) {
    for(int j: mpp[i]) q.push(L[j]-R[j]);
    while((int)q.size() > min(i+1, np)) q.pop();
  }
  while(!q.empty()) {
    ans += q.top(); q.pop();
  }
  rep(i, n) {
    for(int j: mpm[i]) q.push(R[j]-L[j]);
    while((int)q.size() > min(i+1, nm)) q.pop();
  }
  while(!q.empty()) {
    ans += q.top(); q.pop();
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t; cin >> t;
  rep(_, t) solve();
  return 0;
}


Measured memory_bytes: 44648
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    int  w,y,i,j;

    char a[55][55],sum='0';
    while(cin>>w>>y)
    {
        for(i=0;i<w;i++)
        {
            for(j=0;j<y;j++)
            {
                cin>>a[i][j];
            }
        }
         for(i=0;i<w;i++)

            for(j=0;j<y;j++)
            {
                sum ='0';
                if(a[i][j]=='.')
            {
                    if(a[i-1][j-1] == '#')
                    sum++;
                if(a[i-1][j]=='#')
                      sum++;
            if(a[i-1][j+1] =='#')
                        sum++;
        if(a[i][j-1]=='#')
                sum++;
            if(a[i][j+1] =='#')
                       sum++;
            if(a[i+1][j-1]=='#')
                        sum++;
            if(a[i+1][j] =='#')
                    sum++;
        if(a[i+1][j+1]=='#')
                sum++;
                    a[i][j]=sum;
                }
                else a[i][j]='#';

            }

        for(i=0;i<w;i++)
        {
            for(j=0;j<y;j++)
            {
                cout<<a[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
using namespace std;
// 0オリジンなことに注意！！！！

#define MAX 100
#define INF 101 // 距離の最大値+2

int n, M[MAX][MAX];
int d[MAX]; // distance from 1

void bfs(int start){
    int i, j, u;
    queue<int> q;
    
    for (i = 0; i < n; i++) {
        d[i] = INF;
    }
    
    q.push(start);
    d[start] = 0;
    while( !q.empty() ) {
        u = q.front();
        q.pop();
        for (j = 0; j < n; j++) { // 取り出した頂点から繋がっている頂点のうち未探索なものをqueueに入れる
            if(M[u][j] == 1 && d[j] == INF){
                d[j] = d[u] + 1;
                q.push(j);
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        printf("%d %d\n", i+1, d[i] == INF ? -1 : d[i]);
    }
}


int main(){
    int i, j, m, a;
    
    scanf("%d", &n);
    // init
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    // read
    for(i = 0; i < n; i++){
        scanf("%d %d", &m, &m); // First m is dammy
        for(j = 0; j < m; j++){
            scanf("%d", &a);
            M[i][a-1] = 1;
        }
    }
#ifdef D
    // どういう風にグラフが格納されてるか見る
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            printf("%d ", M[i][j]);
        }
        printf("\n");
    }
#endif
    
    bfs(0);
    
    return 0;
}



Measured memory_bytes: 3224