akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var se = new int[N][];
            for (var i = 0; i < N; i++) {
               var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
               se[i] = new int[2];
               se[i][0] = t[0] - t[1];
               se[i][1] = t[0] + t[1];
            }
            
            Array.Sort(se, (a,b)=>a[0]-b[0]);
            
            var s = se[0][0];
            var e = se[0][1];
            var dust = 0;
            for (var i = 1; i < N; i++) {
                if (e <= se[i][0]) {
                    s = se[i][0];
                    e = se[i][1];
                } else if (e < se[i][1]) {
                   dust++; 
                } else if (se[i][1] <= e) {
                   dust++;
                   s = se[i][0];
                   e = se[i][1];
                }
            }
            
            Console.WriteLine(N-dust);
        }
    }
}


Measured memory_bytes: 23864
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int main() {

	int A, B;

	cin >> A >> B;

	cout << (A + B) % 24 << endl;

	return 0;
}

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

int main() {
  int N, i, c = 0;
  cin >> N;
  int H[N];
  for (i = 0; i < N; i++)
    cin >> H[i];
  
  for (i = 1; i <= N; i++) {
    int max = 0;
    for (int j = 1; j <= i; j++) {
      if (max < H[j - 1])
        max = H[j - 1];
    }
    if (max == H[i - 1])
      c++;
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

x,n=map(int,input().split())
a=[]*n
a=list(map(int,input().split()))
answer=0
b=[i for i in range(n+x+10)]
c=list(set(b)-set(a))
d=[x for i in range(len(c))]
e=[abs(x-y) for (x,y) in zip(c,d)]
f=np.argmin(e)
print(c[f])

Measured memory_bytes: 27184
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <algorithm>

#define rep(i, n) for(int i=0;i<n;i++)
#define IOS() ios_base::sync_with_stdio(false)

using namespace std;

char ch[13];

void input() {

    cin >> ch;
}

void process() {

    int n = strlen(ch);
    int maxi = 0;


    for(int i=0;i<n;i++) {

        int co = 0;

        if(ch[i] == 'A' || ch[i] == 'C' || ch[i] == 'G' || ch[i] == 'T') {
            for(int j=i;j<n;j++) {
                if(ch[j] == 'A' || ch[j] == 'C' || ch[j] == 'G' || ch[j] == 'T') {
                   co++;
                }
                else {
                    i = j-1;
                    break;
                }
            }
            if(co > maxi) {
                maxi = co;
            }

        }
    }

    cout << maxi;


}

int main() {

    IOS();

    input();
    process();


    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(c,b/a) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

// https://atcoder.jp/contests/abc179/submissions/16889528
void solve() {
    int n, q;
    cin >> n >> q;
    
    ll ans = 1LL * (n - 2) * (n - 2);
    set<pii> s[2];
    rep(i, 2) s[i].emplace(n, n);
    while (q--) {
        int k, x;
        cin >> k >> x;
        --k;
        auto it = s[k].lower_bound(pii(x, -1)); // 自分より手前
        if (it == s[k].begin()) { // 自分より手前が存在しない
            it = s[k ^ 1].begin();
            ans -= (*it).F - 2;
            s[k].emplace(x, (*s[k ^ 1].begin()).F);
        } else { // 自分より手前で一番近いのと同じのに堰き止められる
            --it;
            ans -= (*it).S - 2;
            s[k].emplace(x, (*it).S); // debuged
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 12952
#include <stdio.h>
int main(void) {
    int mo,af,i,max,shop;
    while (scanf("%d %d",&mo,&af)!=EOF&&(mo!=0||af!=0)) {
        shop=0,max=mo+af;
        for (i=0; i<4; i++) {
            scanf("%d %d",&mo,&af);
            if (mo+af>max) {
                max=mo+af;
                shop=i+1;
            }
        }
        printf("%c %d\n",shop+'A',max);
    }
    return 0;
}

Measured memory_bytes: 600
x,y,a,b,c = map(int,input().split())
P = map(int,input().split())
Q = map(int,input().split())
R = map(int,input().split())

e = sorted(P)[-x:]
e += sorted(Q)[-y:]
e += R
print(sum(sorted(e,reverse=True)[:x+y]))


Measured memory_bytes: 28992
use std::io::*;
use std::str::FromStr;
 
fn main(){
    let (x,a,b) = (read::<i32>(), read::<i32>(), read::<i32>());
    println!("{}", (x-a)%b )    
}
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
n,q=gets.chomp.split.map(&:to_i)
s=gets.chomp.gsub(/AC/, "Ac")
que,r=[],[0]
q.times{que<< gets.chomp.split.map(&:to_i)}
s.size.times{|i|
  s[i]=="c"?r<< r[i-1]+1:r<< r[i-1]
  r.shift if i==0
}
q.times{|a|p (r[que[a][1]-1]-r[que[a][0]-1])}

Measured memory_bytes: 17404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

vector<int> Zalgorithm(const string &s) {
	vector<int> prefix(s.size());
	for (int i = 1, j = 0; i < s.size(); i++) {
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
		else {
			int k = max(0, j + prefix[j] - i);
			while (i + k < s.size() && s[k] == s[i + k]) ++k;
			prefix[i] = k;
			j = i;
		}
	}
	prefix[0] = (int)s.size();
	return prefix;
}

//139 League
struct LLPair {
	int a = 0;
	int b = 0;
	LLPair() {}
	LLPair(int a, int b) {
		this->a = a;
		this->b = b;
	}
};

int main() {
	int N;
	scanf("%d", &N);
	vector<vector<int>> A(N, vector<int>(N - 1, 0));
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N - 1; i++) {
			scanf("%d", &A[j][i]);
			A[j][i]--;
		}
	}

	vector<vector<vector<LLPair>>> graph(N, vector<vector<LLPair>>(N, vector<LLPair>(0)));
	vector<vector<vector<LLPair>>> graphR(N, vector<vector<LLPair>>(N, vector<LLPair>(0)));
	vector<vector<int>> inEdge(N, vector<int>(N, 0));
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N - 2; i++) {
			int a = j;
			int b = A[j][i];
			if (a > b) {
				swap(a, b);
			}

			int c = j;
			int d = A[j][i + 1];
			if (c > d) {
				swap(c, d);
			}

			graph[a][b].push_back(LLPair(c, d)); //a vs b �̌�� c vs d ���s��			
			graphR[c][d].push_back(LLPair(a, b)); //c vs d ���s���O�� a vs b
			inEdge[c][d]++; //c vs d �ւ̗����G�b�W��
		}
	}

	//���[�v�̌��o���g�|���W�J���\�[�g�Ŏ��{

	queue<LLPair> S; //���������N����0�ł���m�[�h�̃Z�b�g
	vector<LLPair> L; //�g�|���W�J���\�[�g�̌���
	
	for (int j = 0; j < N; j++) {
		for (int i = j + 1; i < N; i++) {
			if (graphR[j][i].size() == 0) {
				S.push(LLPair(j, i));
			}
		}
	}

	while (S.empty() == false) {
		LLPair node = S.front();
		S.pop();
		L.push_back(node);

		for (auto next : graph[node.a][node.b]) {
			inEdge[next.a][next.b]--;
			if (inEdge[next.a][next.b] == 0) {
				S.push(LLPair(next.a, next.b));
			}
		}
	}

	//���[�v�����݂���ꍇ�͉��Ȃ�
	if ((int)L.size() < N * (N - 1) / 2) {
		printf("-1\n");
		return 0;
	}

	int result = 0;
	stack<LLPair> st;
	vector<vector<int>> dist(N, vector<int>(N, 1));

	int maxDist = 0;

	for (auto node : L) {
		int d = dist[node.a][node.b];

		for (auto next : graph[node.a][node.b]) {
			if (d + 1 > dist[next.a][next.b]) {
				dist[next.a][next.b] = d + 1;
				maxDist = max(maxDist, d + 1);
			}
		}
	}

	result = maxDist;

	printf("%d\n", result);
}


Measured memory_bytes: 94188
#include <stdio.h>
int main(void){
int X,Y,Z;
int temp;
int no;

scanf("%d",&X);
scanf("%d",&Y);
scanf("%d",&Z);

    temp=X;
    X=Y;
    Y=temp;
    
    no=X;
    X=Z;
    Z=no;
   
printf("%d %d %d",X,Y,Z);

return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n;string s;cin>>n>>s;
  int b=0;
  int r=0;
  REP(i,n){
    if(s[i]=='B')b++;
    else r++;
  }
  if(r>b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
//B - Coins: 30Min
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, c, x, aux, ans = 0;
    cin >> a >> b >> c >> x;
    loop(i, 0, a+1) {
        loop(j, 0, b+1) {
            loop(k, 0, c+1) {
                aux = i*500 + j*100 + k*50;
                if(aux == x) ans++;
            }
        }
    }
    cout << ans << "\n";
}

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

int main() {
  vector<char> t1(3), t2(3);
  
  for (int i = 0; i < 3; i++) {
    cin >> t1[i];
  }
  for (int i = 0; i < 3; i++) {
    cin >> t2[i];
  }
  
  if (t1[0] == t2[2] && t1[1] == t2[1] && t1[2] == t2[0]) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int h, w,key,black=0,cnt=0,tmp=0;
    string s;
    vector<string>grid;
    cin >> h >> w >> key;
    vector<int>bh(w, 0);
    vector<int>bw(h, 0);
    vector<int>hmemo,wmemo;
    vector<vector<int>>diffh(w,vector<int>(h,0));
    rep(i, h) {
        cin >> s;
        grid.push_back(s);
        for (auto c : s) {
            if (c == '#')black++;
            if (c == '#')bw[i]++;
        }
    }
    rep(i, w) {
        rep(j, h) {
            if (grid[j][i] == '#') {
                bh[i]++;
                diffh[i][j]++;
            }

        }
    }

    /*for (int i = -1; i < h; i++) {
        for (int j = -1; j < w; j++) {
            tmp = black;
            if (j != -1)tmp -= bh[j];
            if (i != -1)tmp -= bw[i];

            if (tmp == k)cnt++;
        }
    }*/

    for (int i = 0; i < (1 << w); i++) {
        for (int k = 0; k < (1 << h); k++) {
            tmp = black;
            hmemo.clear();
            wmemo.clear();
            rep(j, w) {
                if (i & (1 << j)) {
                    tmp -= bh[j];
                    hmemo.push_back(j);
                }
            }
            rep(l, h) {
                if (k & (1 << l)) {
                    tmp -= bw[l];
                    wmemo.push_back(l);
                }
            }
            for (auto s : hmemo) {
                for (auto g : wmemo)tmp += diffh[s][g];
            }
            if (tmp == key)cnt++;
        }
    }
    cout << cnt << endl;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> hoge(n);
	map<int,int> mp;

	for(int i=0;i<n;i++){
		int a;
		cin>>a;

		if(mp.count(a)) mp.at(a)++;
		else mp[a]=1;

		hoge.at(i)=a;
	}

	long long ans=0;

	for(auto a:hoge){
		int b=mp.at(a);

		if(b>=a) ans+=b-a;
		else ans+=b;

		mp.at(a)=a;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int nMin = scanner.nextInt();
        int nMax = scanner.nextInt();
        while (m != 0 && nMin != 0 && nMax != 0) {
            int score[] = new int[m];
            int maxGap = 0;
            int bestN = 0;
            
            for (int i = 0; i < m; ++i) {
                score[i] = scanner.nextInt();
            }

            for (int n = nMin; n <= nMax; n++) {
                int gap = score[n - 1] - score[n];
                if (maxGap <= gap) {
                    maxGap = gap;
                    bestN = n;
                }
            }

            System.out.println(bestN);

            m = scanner.nextInt();
            nMin = scanner.nextInt();
            nMax = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 56136
#include <stdio.h>
#include <ctype.h>

int buffer[5];
int buffernum;

const int table[32][9]={
	{3,1,0,1},
	{6,0,0,0,0,0,0},
	{6,0,0,0,0,1,1},
	{8,1,0,0,1,0,0,0,1},
	{6,0,1,0,0,0,1},
	{6,0,0,0,0,0,1},
	{6,1,0,0,1,0,1},
	{8,1,0,0,1,1,0,1,0},

	{4,0,1,0,1},
	{4,0,0,0,1},
	{3,1,1,0},
	{5,0,1,0,0,1},
	{8,1,0,0,1,1,0,1,1},
	{6,0,1,0,0,0,0},
	{4,0,1,1,1},
	{8,1,0,0,1,1,0,0,0},

	{4,0,1,1,0},
	{5,0,0,1,0,0},
	{8,1,0,0,1,1,0,0,1},
	{8,1,0,0,1,1,1,1,0},
	{5,0,0,1,0,1},
	{3,1,1,1},
	{8,1,0,0,1,1,1,1,1},
	{4,1,0,0,0},

	{5,0,0,1,1,0},
	{5,0,0,1,1,1},
	{8,1,0,0,1,1,1,0,0},
	{8,1,0,0,1,1,1,0,1},
	{6,0,0,0,0,1,0},
	{8,1,0,0,1,0,0,1,0},
	{8,1,0,0,1,0,0,1,1},
	{8,1,0,0,1,0,0,0,0}
};

void output(void) {
	int toout;
	toout=(buffer[0]<<4)+
	      (buffer[1]<<3)+
	      (buffer[2]<<2)+
	      (buffer[3]<<1)+
	      buffer[4];
	if(toout<=25)putchar(toout+'A');
	else if(toout==26)putchar(' ');
	else if(toout==27)putchar('.');
	else if(toout==28)putchar(',');
	else if(toout==29)putchar('-');
	else if(toout==30)putchar('\'');
	else if(toout==31)putchar('?');
	buffernum=0;
}

void addone(int toadd) {
	int i;
	for(i=1;i<=table[toadd][0];i++) {
		buffer[buffernum]=table[toadd][i];
		buffernum++;
		if(buffernum>=5)output();
	}
}

void add(int code) {
	if(code==' ')addone(0);
	else if(code=='\'')addone(1);
	else if(code==',')addone(2);
	else if(code=='-')addone(3);
	else if(code=='.')addone(4);
	else if(code=='?')addone(5);
	else if(isupper(code))addone(code-'A'+6);
}

int main(void) {
	int input;
	while((input=getchar())!=EOF) {
		if(input=='\n') {
			if(buffernum!=0) {
				for(;buffernum<5;buffernum++)buffer[buffernum]=0;
				output();
			}
			putchar('\n');
		} else {
			add(input);
		}
	}
	if(buffernum!=0) {
		for(;buffernum<5;buffernum++)buffer[buffernum]=0;
		output();
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
long long Ceil(long long a, long long b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool isPowerOfTwo (long long x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        string s,t;cin>>s>>t;
        int n1 = s.size(), n2 = t.size();
        int ans = n2;
        for(int i = 0 ; i < n1 ; i++){
            if(i+n2-1 > n1-1)
                break;
            int cnt = 0;
            for(int j = 0 ; j < n2 ; j++){
                if(s[i+j] != t[j])
                    cnt++;
            }
            ans = min(cnt, ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>

int main(void)
{
long long int a,b,k;

scanf("%ld",&a);
scanf("%ld",&b);

k = (a*a-b*b)/(2*a-2*b);
if((a*a-b*b)%(2*a-2*b)!=0)
        printf("IMPOSSIBLE\n");
else    printf("%ld\n",k);
return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second
using namespace std;
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;
const int MM = 305;
double dp[MM][MM][MM];
int main() {fio;
	int n;
	cin >> n;
	int c1 = 0, c2 = 0, c3 = 0;
	for(int i = 0; i < n; i++) {
		int u;
		cin >> u;
		c1 += u == 1;
		c2 += u == 2;
		c3 += u == 3;
	}
	for(int i3 = 0; i3 <= n + 1; i3++) {
		for(int i2 = 0; i2 <= n + 1; i2++) {
			for(int i1 = 0; i1 <= n + 1; i1++) {
				double &cur = dp[i1][i2][i3];
				if(i1 + i2 + i3 == 0) {
					cur = 0;
					continue;
				}
				cur = 1;
				if(i1) {
					cur += (double)i1 / n * (dp[i1 - 1][i2][i3]);
				}
				if(i2) {
					cur += (double)i2 / n * (dp[i1 + 1][i2 - 1][i3]);
				}
				if(i3) {
					cur += (double)i3 / n * (dp[i1][i2 + 1][i3 - 1]);
				}
				cur *= (double)n / (i1 + i2 + i3);
			}	
		}	
	}
	cout << fixed << setprecision(10) << dp[c1][c2][c3];
    return 0;
}

Measured memory_bytes: 221440
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, weight, s = 0, m = 0;
    cin >> n >> weight;
    long long w[n + 1], v[n + 1];
    for (long long i = 1; i <= n; i++) 
    {
        cin >> w[i] >> v[i];
        s += v[i];
    }
    long long dp[n + 1][s + 1];
//calculate min weight from choosing first i-th items satisfying that min total value is v;
    dp[0][0] = 0;
    for (long long i = 1; i <= s; i++) dp[0][i] = 1e18;
    for (long long i = 1; i <= n; i++)
    {
    	for (long long j = 0; j <= s; j++)
    	{
    		if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
    		else dp[i][j] = dp[i - 1][j];
    		if (dp[i][j] <= weight) m = max(m, j);
    	}
    }
    cout << m;
}

Measured memory_bytes: 82480
#include <fstream>
//#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unordered_map>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int SIZE = 1 << 17;

char buffer[SIZE];
int pointer = SIZE;

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 100;

int weight[1 + MAXN], value[1 + MAXN], delta[1 + MAXN];
int dp[1 + MAXN][1 + MAXN][1 + 3 * MAXN];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n, limit, answer = 0;
    scanf("%d%d", &n, &limit);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &weight[i], &value[i]);
        delta[i] = weight[i] - weight[1];
    }
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i <= n; i++)
        dp[i][0][0] = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 3 * n; k >= 0; k--) {
                dp[i][j][k] = dp[i - 1][j][k];
                if (k >= delta[i] && dp[i - 1][j - 1][k - delta[i]] != -1)
                    dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - delta[i]] + value[i]);
            }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 0; k <= 3 * n; k++)
                if (1LL * j * weight[1] + k <= limit)
                    answer = max(answer, dp[i][j][k]);
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 12160
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


n,q=map(int,input().split())
UnionFind=UnionFind(n)
for _ in range(q):
    com,x,y=map(int,input().split())
    if com:print(1 if UnionFind.isSameGroup(x,y) else 0)
    else:UnionFind.Unite(x,y)


Measured memory_bytes: 5832
#A
D = int(input())
c = [0] + list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0] * 27
manzoku = [0] * 27
for i in range(1, D+1):
    for j in range(1, 27):
        if last[j] != 0:
            manzoku[j] -= c[j] * (i - last[j])
    manzoku[s[i-1].index(max(s[i-1]))] += max(s[i-1])
    last[s[i-1].index(max(s[i-1]))] = i
    result = s[i-1].index(max(s[i-1])) + 1
    print(result)





Measured memory_bytes: 9400
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<lu> vu;
typedef vector<v> vv;
typedef vector<vu> vvu;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
typedef pair<lu, lu> puu;
typedef vector<puu> vpuu;
const ll MOD = 1000000007;
const ld PI = 2 * acos(0.0);
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }

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

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll n;
    cin >> n;
    v a = ga(n);

    vector<vector<vld>> dp(n + 1, vector<vld>(n + 1, vld(n + 1, 0)));
    vld harmonics(n + 1, 0);
    for (ll i = 1; i <= n; i++) {
        harmonics[i] += harmonics[i - 1] + (ld)1 / i;
    }

    for (ll a3 = 0; a3 <= n; a3++) {
        for (ll a2 = 0; a2 <= n; a2++) {
            for (ll a1 = 0; a1 <= n; a1++) {
                ll a0 = n - a3 - a2 - a1;
                if (a0 < 0) {
                    break;
                }

                if (a0 == n) {
                    // dp[a1][a2][a3] = n * (harmonics[a1]);
                    continue;
                }

                ld x = (a2 > 0) ? (dp[a1 + 1][a2 - 1][a3] * (ld)a2 / n) : 0;
                ld y = (a1 > 0) ? (dp[a1 - 1][a2][a3] * (ld)a1 / n) : 0;
                ld z = (a3 > 0) ? (dp[a1][a2 + 1][a3 - 1] * (ld)a3 / n) : 0;

                dp[a1][a2][a3] = (1 + x + y + z) / (1 - (ld)a0 / n);
            }
        }
    }

    v x(3, 0);
    for (auto y : a)
        x[y - 1]++;
    cout << fixed << setprecision(15) << dp[x[0]][x[1]][x[2]];
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    int ans = 0;
    REP(i, S.length()) {
        if(S[i] == '+') { ans++; }
        else { ans--; }
    }
    printf("%lld\n", ans);
    return 0;
}


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


int main() {


    string s;

    cin >> s;

    int ans = 0;
    char s1 = s[0];

    if(s1 == s[1] && s1 ==s[2]){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans, mi1,mi2,sum;
string s;
int main() {
	cin >> N;
	vector<LL> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	ans = 0;
	for (int i = 0; i <N; i++) {
		if (ans - 1 > H[i]) {
			cout << "No" << endl;
			return 0;
		}
		ans = max(ans, H[i]);
	}
	cout <<"Yes"<< endl;
	return 0;
}



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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   std::vector<std::pair<long, long>> graph[112345];
   void solve() {
      long n; scan(n);
      for(long i = 0; i < n - 1; ++i) {
         long a, b, c; scan(a, b, c);
         graph[a].push_back(std::make_pair(b, c));
         graph[b].push_back(std::make_pair(a, c));
      }
      long q, k; scan(q, k);
      LI dist(n+1, (1LL << 53));
      dist[k] = 0;
      std::priority_queue<std::pair<long, long>> pq;
      pq.push(std::make_pair(0, k));
      while( not pq.empty() ) {
         long d, a;
         std::tie(d, a) = pq.top(); pq.pop();
         for(auto bc : graph[a]) {
            long b, c; std::tie(b, c) = bc;
            long nd = -d + c;
            if( nd < dist[b] ) {
               dist[b] = nd;
               pq.push(std::make_pair(-nd, b));
            }
         }
      }
      for(long i = 0; i < q; ++i) {
         long x, y; scan(x, y);
         printf("%ld\n", dist[x] + dist[y]);
      }
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 11376
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int dist[3001];
bool visit[3001];
pair<P, int> edge[100001];

vector<P> G[3001];

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	rep(i, m){
		int a, b, l;
		cin >> a >> b >> l;
		a--, b--;
		G[a].push_back(MP(l, b));
		G[b].push_back(MP(l, a));
		edge[i] = MP(MP(a, b), l);
	}

	priority_queue<P, vector<P>, greater<P> > q;

	rep(i, k){
		int s;
		cin >> s;
		q.push(MP(0, s-1));
	}

	while(!q.empty()){
		int pos = q.top().Y;
		int d = q.top().X;
		q.pop();

		if(visit[pos])continue;
		visit[pos] = true;

		dist[pos] = d;

		rep(i, G[pos].size()){
			q.push(MP(d+G[pos][i].first, G[pos][i].second));
		}
	}

	double ans = 0;
	rep(i, m){
		double l, s, d;
		l = dist[edge[i].first.first];
		s = dist[edge[i].first.second];
		d = edge[i].second;
		if(l < s) swap(l, s);
		if(l > s+d){
			ans = max(ans, l);
		}else{
			ans = max(ans, (s+l+d)/2);
		}
	}

	cout << (int)(ans+0.5) << endl;


    return 0;
}

Measured memory_bytes: 7164
#include <stdio.h>
#include <vector>

using namespace std;

struct Node{
	Node(){
		parent = -1;
		depth = num_of_children = 0;
	}
	int parent;
	int depth;
	vector<int> children;
	int num_of_children;
};

void calcDepth(Node nodes[],int root_id){
	for(int i = 0;i < nodes[root_id].num_of_children;i++){
		nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
		calcDepth(nodes,nodes[root_id].children[i]);
	}
}

int main(){
	int n,id,k,child_id,root_id;
	scanf("%d",&n);
	Node nodes[n];

	for(int i = 0; i < n; i++){
		scanf("%d %d",&id,&k);
		for(int j = 0; j < k; j++){
			scanf("%d",&child_id);
			nodes[id].children.push_back(child_id);
			nodes[id].num_of_children++;
			nodes[child_id].parent = id;
		}
	}

	for(root_id = 0; root_id < n; root_id++){
		if(nodes[root_id].parent == -1) break;
	}

	calcDepth(nodes,root_id);

	for(int i = 0; i < n; i++){
		if(nodes[i].parent == -1){
			printf("node %d: parent = -1, depth = 0, root, ",i);
		}else if(nodes[i].num_of_children == 0){
			printf("node %d: parent = %d, depth = %d, leaf, ",i,nodes[i].parent,nodes[i].depth);
		}else{
			printf("node %d: parent = %d, depth = %d, internal node, ",i,nodes[i].parent,nodes[i].depth);
		}
		printf("[");
		for(int j = 0; j < nodes[i].num_of_children-1; j++){
			printf("%d, ",nodes[i].children[j]);
		}
		if(nodes[i].num_of_children > 0){
			printf("%d",nodes[i].children[nodes[i].num_of_children-1]);
		}
		printf("]\n");
	}
}


Measured memory_bytes: 7288
N, T = map(int, input().split())
c = []
t = []
count = 1001
for i in range(N):
    ci,ti=[int(i) for i in input().split()]
    c.append(ci)
    t.append(ti)

for i in range(0, N):
    if t[i] <= T:
        if c[i] < count:
            count = c[i]

if count == 1001:
    print("TLE")
else:
    print(count)

Measured memory_bytes: 3064
import Data.Function (on)
import Data.List (group, sort, sortBy)

main :: IO ()
main = do
    (_:k:as) <- getParams
    print $ solve k as

getParams :: IO [Int]
getParams = map read . words <$> getContents

solve :: Int -> [Int] -> Int
solve k = length . rewrites k

rewrites :: Int -> [Int] -> [Int]
rewrites k = concat . drop k . sortBy lenDesc . group . sort
  where
    lenDesc = flip compare `on` length


Measured memory_bytes: 43516
def main():
    N = int(input())
    S = input()
    
    ans = S.count('R') * S.count('G') * S.count('B')

    for i in range(N-2):
        for j in range(i+1, i+1+(N-1-i)//2):
            k = j + (j - i)
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
            
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9232
#include "bits/stdc++.h"

using namespace std;

int main(){
    int N, ans;
    cin >> N;
    ans = 0;
    int V[30];
    int C[30];

    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }
    for(int i = 0; i < N; i++){

        if(C[i] < V[i]){
            ans += V[i] - C[i];
        }
    }

    cout << ans << endl;

}

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

using namespace std;


int main()
{
    int A, B, sum;
    cin >> A >> B;

    if (A==B) {
        sum = A*2;
    } else if (A > B) {
        sum = A + (A-1);
    } else {
        sum = B + (B-1);
    }

    cout << sum << endl;
   
    return 0;   
}

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

int main(){
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    int x[N];
    int y[M];
    for(int i=0;i<N;i++) cin >> x[i];
    for(int i=0;i<M;i++) cin >> y[i];
    sort(x,x+N);
    sort(y,y+M);
    if(x[N-1]<y[0] && y[0]>X && x[N-1]<Y) cout << "No War" << endl;
    else cout << "War" << endl;
}






Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    long long n,m,i,j,k,s;
    scanf("%lld%lld",&n,&m);
    if(m==0)
    {
        printf("%lld\n",n*n);
        return 0;
    }
    s=0;
    for(i=m+1;i<=n;i++)
    {
        j=n/i;
        s=s+j*(i-m);
        k=n%i;
        s=s+max((long long)0,k-m+1);
    }
    printf("%lld\n",s);
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s && s!= "0"){
    set<string> st;
    queue<string> q;
    q.push(s);
    int num = 0;
    int flag = 0;
    while(1){
      auto n = q.size();
      rep(i,n){
        auto el = q.front();q.pop();
//         debug(el);
        if(st.insert(el).se){
          auto el2 = el;
          bool f = true;
          rep(j,el.size()){
            if(el[0] != el[j]){
              f = false;
              break;
            }
          }
          if(f){
            flag = 2;
            break;
          }
          rep(j,el.size()-1){
            el = el2;
            if(el[j] != el[j+1]){
              if(el[j] != 'g' && el[j+1] != 'g'){
                el[j] = 'g';
                el[j+1] = 'g';
              }
              else if(el[j] != 'r' && el[j+1] != 'r'){
                el[j] = 'r';
                el[j+1] = 'r';
              }
              else{
                el[j] = 'b';
                el[j+1] = 'b';
              }
              q.push(el);
            }
          }
        }
      }
      if(!q.size() && flag != 2){
        cout << "NA" <<endl;
        break;
      }
      else if(flag == 2){
        cout << num <<endl;
        break;
      }
      ++num;
    }
  }
  return 0;
}

Measured memory_bytes: 4968
package main

import (
  "fmt"
)

func main() {
  var n, k int
  set := make(map[int]struct{})
  fmt.Scanf("%d %d", &n, &k)

  for i := 0; i < k; i++ {
    var d, v int
    fmt.Scanf("%d", &d)

    for j := 0; j < d; j++ {
      fmt.Scanf("%d", &v)
      set[v] = struct{}{}
    }
  }

  ans := n - len(set)
  fmt.Println(ans)

}


Measured memory_bytes: 2372
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 998244353;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ld a, b;
	cin >> a >> b;
	cout << (ll)(a * b);
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const int INF=1000000009;
const double PI=3.141592653589;


int main(){
  int a,b,c; cin>>a>>b>>c;
  if(a+b+c>=22)
  cout<<"bust"<<endl;
  else
  cout<<"win"<<endl;


  return 0;
}


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

int main(void){
    int n, w;
    cin >> n >> w;
    int value[110], weight[110];

    for(int i = 0 ; i < n; i++){
        cin >> value[i] >> weight[i];
    }
    
    int dp[110][10010];
    
    //?????????
    for(int i = 0; i < n; i++){
        dp[i][0] = 0;
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= w; j++){
            if(i == 0){
                if(j - weight[i] >= 0){
                    dp[i][j] = dp[i][j-weight[i]] + value[i];
                }else{
                    dp[i][j] = 0;
                }
            }else{
                if(j - weight[i] >= 0){
                    dp[i][j] = max(dp[i-1][j], dp[i][j-weight[i]] + value[i]);
                }
                else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
    }

   cout << dp[n-1][w] << endl;
    
    return 0;

}

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

int main() {
    int N, M;
    cin >> N >> M;
    pair<int, int> s[N], c[M];
    for (int i = 0; i < N;i ++) {
        cin >> s[i].first >> s[i].second;
    }
    for (int i = 0; i < M; i++) {
        cin >> c[i].first >> c[i].second;
    }
    for (int si = 0; si < N; si ++) {
        int min = 1e9;
        int min_ci = 0;
        for (int ci = 0; ci < M; ci ++) {
            int tmp = abs(s[si].first - c[ci].first) + abs(s[si].second - c[ci].second);
            if (tmp < min) {
                min = tmp;
                min_ci = ci;
            }
        }
        cout << min_ci + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[100010][4];
const int e=110000;
int a[e][4];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i][1]>>a[i][2]>>a[i][3];
	}
	f[1][1]=a[1][1];
	f[1][2]=a[1][2];
	f[1][3]=a[1][3];
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
		{
			int t1,t2;
			if(j==1){t1=2;t2=3;}
			else if(j==2){t1=1;t2=3;}
			else{t1=1;t2=2;}
			f[i][j]=max(f[i-1][t1],f[i-1][t2])+a[i][j];
		}
	}
	int ans=-1;
	for(int i=1;i<=3;i++)
		ans=max(ans,f[n][i]);
	cout<<ans;
	return 0;
}




Measured memory_bytes: 3328
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int dp[110][10010]={}; //[v][w]

int main() {
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int num, i, ans = 0;
	cin >> num;
	vector<int> d(num + 1);
	for (i = 1; i <= num; i++)
		scanf("%d", &d[i]);
	for (i = 1; i <= num; i++) {
		if (d[d[i]] == i)
			ans++;
	}
	ans >>= 1;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#define ll long long

int main() {
    ll x, rez = 0;
    scanf("%lld", &x);
    ll d = x / 11;
    d = d * 2;
    ll rest = x % 11;
    if (rest == 0)
        rez = 0;
    else if (rest <= 6)
        rez = 1;
    else
        rez = 2;
    rez += d;
    printf("%lld", rez);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[101][10001];
int main(void){
	int n;
	int box[100];
	int i,j;
	int MAX,sum;
	scanf("%d",&n);
	sum=0;
	for(i=0;i<n;i++){
		scanf("%d",&box[i]);
		sum+=box[i];
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=10000;j++){
			dp[i][j]=0;
		}
	}
	dp[0][0]=1;
	for(i=0;i<n;i++){
		for(j=0;j<=sum;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(dp[i][j]==1){
				if(j+box[i]<=sum){
					dp[i+1][j+box[i]]=1;
				}
			}
		}
	}
	// for(i=0;i<=n;i++){
		// for(j=0;j<=sum;j++){
			// printf("%d ",dp[i][j]);
		// }
		// printf("\n");
	// }
	MAX=0;
	for(i=0;i<=sum;i++){
		if(dp[n][i]==1){
			if(i%10!=0){
				MAX=max(MAX,i);
			}
		}
	}
	printf("%d\n",MAX);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int X, Y;
	cin >> X >> Y;

	cout << X + Y / 2 << endl;
}

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


int main() {
  vector<int> vec;
  vec={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int a; cin >> a;

    cout << vec.at(a-1) << endl;
}


Measured memory_bytes: 256