akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int inf = 1e7;

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
struct Node
{
	int w, v;
}a[1010];
int n, W;
int cnt[5];
int b[5][110];

bool cmp(Node a, Node b)
{
	if(a.w == b.w) return a.v > b.v;
	return a.w < b.w;
}

int main()
{
	n = read();
	W = read();
	for(int i = 1; i <= n; i ++)
		a[i].w = read(), a[i].v = read();

	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i ++)
	{
		if(a[i].w - a[1].w == 0) b[1][++ cnt[1]] = a[i].v;
		if(a[i].w - a[1].w == 1) b[2][++ cnt[2]] = a[i].v;
		if(a[i].w - a[1].w == 2) b[3][++ cnt[3]] = a[i].v;
		if(a[i].w - a[1].w == 3) b[4][++ cnt[4]] = a[i].v;
	}

	int ans = 0;
	for(int i1 = 0; i1 <= cnt[1]; i1 ++)
		for(int i2 = 0; i2 <= cnt[2]; i2 ++)
			for(int i3 = 0; i3 <= cnt[3]; i3 ++)
				for(int i4 = 0; i4 <= cnt[4]; i4 ++)
				{
					ll cost = 1ll * i1 * a[1].w + 1ll * i2 * (a[1].w + 1) + 1ll * i3 * (a[1].w + 2) + 1ll * i4 * (a[1].w + 3);
					if(cost > W) break;
					int now = 0;
					for(int i = 1; i <= i1; i ++) now += b[1][i];
					for(int i = 1; i <= i2; i ++) now += b[2][i];
					for(int i = 1; i <= i3; i ++) now += b[3][i];
					for(int i = 1; i <= i4; i ++) now += b[4][i];
					ans = max(ans, now);
				}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    vector<ll> H(N);
    for (int i=0;i<N;i++) cin >> H[i];
    string ans = "Yes";
    for (int i=N-1;i>=1;i--){
        if (H[i-1]-H[i]>=2) ans = "No";
        if (H[i-1]-H[i]==1) H[i-1]--;
    }    
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

struct edge { int to, cost; };
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int MAX_N=200000;
VECINT par1(MAX_N);
VECINT ranc1(MAX_N);
VECINT par2(MAX_N);
VECINT ranc2(MAX_N);

void init() {
  REP(i,MAX_N) {
    par1[i]=i;
    par2[i]=i;
    ranc1[i]=0;
    ranc2[i]=0;
  }
}

int root1(int s) {
  if (par1[s]==s) return s;
  else return root1(par1[s]);
}
int root2(int s) {
  if (par2[s]==s) return s;
  else return root2(par2[s]);
}

bool same1(int x,int y) {
  return root1(x)==root1(y);
}
bool same2(int x,int y) {
  return root2(x)==root2(y);
}

void unite1(int x,int y) {
  x = root1(x);
  y = root1(y);
  if (x==y) return;
  if (ranc1[x]>ranc1[y]) {
    par1[y] = x;
  } else {
    par1[x] = y;
    if (ranc1[x]==ranc1[y]) ranc1[y]++;
  }
}
void unite2(int x,int y) {
  x = root2(x);
  y = root2(y);
  if (x==y) return;
  if (ranc2[x]>ranc2[y]) {
    par2[y] = x;
  } else {
    par2[x] = y;
    if (ranc2[x]==ranc2[y]) ranc2[y]++;
  }
}

int main() {
  init();
  int N,K,L;cin>>N>>K>>L;
  REP(i,K) {
    int p,q;cin>>p>>q;
    p--;
    q--;
    unite1(p,q);
  }
  REP(i,L) {
    int r,s;cin>>r>>s;
    r--;
    s--;
    unite2(r,s);
  }
  map<P,int> res;
  REP(i,N) {
    res[{root1(i),root2(i)}]++;
  }
  REP(i,N) {
    cout << res[{root1(i),root2(i)}] << ' ';
  }

  return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <complex>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define REPS(i, n) for(int i=1;i<=(int)n;i++)
#define RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int T, n, m, a, b, c;

vector<vi> mul(const vector<vi> &a, const vector<vi> &b){
	vector<vi> res(n, vi(n));
	REP(i, a.size())REP(j, b.size())REP(k, b.size())
		res[i][j] |= a[i][k] & b[k][j];
	return res;
}

vector<vi> pow(const vector<vi> &g, int b){
	if(b == 0){
		vector<vi> gg(n, vi(n));
		REP(i, n) gg[i][i] = 1;
		return gg;
	}
	auto res = pow(mul(g, g), b/2);
	if(b&1) res = mul(res, g);
	return res;
}	
int main(){
	cin >> n >> m >> a >> b >> c;
	vector<vi> gg(n, vi(n));
	REP(i, m){
		int u, v;
		cin >> u >> v; u--; v--;
		gg[u][v] = 1;
	}
	vector<vector<vi>> g({pow(gg, a), pow(gg, b), pow(gg, c)});
	vi dp(n, 1<<29);
	dp[n-1] = 0;
	REP(_, n)REP(u, n){
		vi c(3, 1<<29);
		REP(i, 3)REP(v, n)if(g[i][u][v]){
			c[i] = min(c[i], dp[v] + 1);
		}
		dp[u] = min(dp[u], *max_element(ALL(c)));
	}
	if(dp[0] == (1<<29)) cout << "IMPOSSIBLE" << endl;
	else cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 3264
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void solve(ll N) { cout << "ABC" << N << endl; }

int main() {
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,k,i,j,srx[200001],sry,t,p;
int main()
{
   scanf("%d%d",&n,&k);
   for(i=1;i<=n;++i)
   {scanf("%d",&t);
   srx[t]++;}//统计每个数字的出现次数
   sort(srx+1,srx+n+1);//因为这题保障srx[i]严格小于n，所以直接sort到n就可以了~
   for(i=n;i>n-k;--i)//i>n-k,一开始错在这了...
   sry+=srx[i];//最多数的个数
   printf("%d",n-sry);//这里要拿总数-多数的个数
   return 0;
}

Measured memory_bytes: 896
#include <float.h>
#include <math.h>
#include <stdio.h>

int rel_l_l( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y ) {
	double a, b, c, d;
	int rel;

	if ( x0 != x1 ) {
		a = ( y0 - y1 ) / ( x0 - x1 );
		b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
	}
	if ( x2 != x3 ) {
		c = ( y2 - y3 ) / ( x2 - x3 );
		d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
	}

	rel = 0;
	if ( x0 == x1 ) {
		*x = x0;
		if ( x2 == x3 )
			if ( x0 == x2 )
				rel = 2;
			else
				rel = 1;
		else {
			*y = c * *x + d;
			if ( y2 == y3 )
				rel = 3;
		}
	} else {
		if ( x2 == x3 ) {
			*x = x2;
			if ( y0 == y1 )
				rel = 3;
		} else
			if ( a == c )
				if ( b == d )
					rel = 2;
				else
					rel = 1;
			else {
				*x = ( -b + d ) / ( a - c );
				if ( fabs( a * c + 1.0 ) < 1e-12 )
					rel = 3;
			}
		*y = a * *x + b;
	}

	return rel;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		int rel;
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel = rel_l_l( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );

		printf( "%d\n", rel == 0 ? 0 : rel == 1 || rel == 2 ? 2 : 1 );
	}

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	int* a = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j =N-1; j>0; j--) {
			if (a[j] > a[j - 1]) {
				int tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
	}
	int point = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0)point += a[i];
		else if (i % 2 == 1)point -= a[i];
	}
	cout << point;
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    int[][] edges;
    int[][] adjs;
    for (int i = 0; i <= n; i++) adjs ~= [[]];
    for (int i = 0; i < n-1; i++) {
        auto edge = readints;
        edges ~= edge;
        adjs[edge[0]] ~= edge[1];
        adjs[edge[1]] ~= edge[0];
    }
    int[] cs = readints;
    cs.sort();

    auto refs = new int[n + 1];
    foreach (e; edges) {
        refs[e[0]]++;
        refs[e[1]]++;
    }

    auto used = new int[n + 1];
    auto q = DList!int();
    for (int i = 1; i <= n; i++) {
        if (refs[i] == 1) {
            q.insertBack(i);
        }
    }

    int cp = 0;
    auto nodes = new int[n + 1]; // node score
    while (!q.empty) {
        int node = q.front;
        q.removeFront();
        if (used[node]++) continue;

        nodes[node] = cs[cp++];
        refs[node] = 0;
        foreach (a; adjs[node]) {
            if (used[a]) continue;

            refs[a]--;
            if (refs[a] == 1) {
                q.insertBack(a);
            }
        }
    }

    int score = 0;
    foreach (e; edges) {
        score += min(nodes[e[0]], nodes[e[1]]);
    }
    writeln(score);
    writeln(nodes.drop(1).map!(text).join(" "));




}



Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int *a = new int[100010];
int find(int x){return x == a[x]?x:a[x] = find(a[x]);}

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

    for(int i  = 0; i <= n; i++)a[i] = i;
    int x, y, z;
    int ans = 0;
    while(line--)
    {
        scanf("%d%d%d", &x, &y, &z);
        x = find(x);
        y = find(y);
        if(x != y)
        {
            ans++;
            a[x] = y;
        }
    }

    cout << n - ans << endl;


    //system("pause");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    int N;
    cin >> N;
    int a[3];
    REP(i,N){
        cin >> a[0] >> a[1] >> a[2];
        sort(a,a+3);
        if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])
            cout << "YES" << '\n';
        else
            cout << "NO" << '\n';
    }
        

}

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

ll calc_seg(string& seg) {
  int n = seg.size();
  ll bc=0;
  ll ret=0;
  revrep(i,n) {
    if(seg[i]=='B')
      bc++;
    else
      ret+=bc;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  string s;
  int n;
  cin>>s;
  n=s.size();
  {
    stringstream ss;
    int i = 0;
    while(i<n) {
      if(s[i]=='A') {
	ss<<'A';
	i++;
	continue;
      }
      if(s[i]=='B'&&i+1<n&&s[i+1]=='C') {
	ss<<'B';
	i+=2;
	continue;
      }
      ss<<'X';
      i++;
    }
    s=ss.str();
  }
  vector<string> segs;
  {
    int m = s.size();
    stringstream ss;
    rep(i,m) {
      if(s[i]=='X') {
	if(ss.str()!="") {
	  segs.push_back(ss.str());
	  ss.str("");
	}
	continue;
      }
      ss<<s[i];
    }
    if(ss.str()!="")
      segs.push_back(ss.str());
  }
  ll ans=0;
  for(auto& seg : segs) {
    ans+=calc_seg(seg);
  }
  cout << ans << endl;
  cout<<fixed;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
set<int> E[101010][2];
set<pair<int,int>> S;

void add_edge(int a,int b) {
	if(E[a][0].count(b)) {
		E[a][0].erase(b);
		E[b][0].erase(a);
		S.insert({min(a,b),max(a,b)});
		E[a][1].insert(b);
		E[b][1].insert(a);
	}
	else {
		E[a][0].insert(b);
		E[b][0].insert(a);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	int id=-1;
	FOR(i,2*(N-1)) {
		cin>>x>>y;
		add_edge(x-1,y-1);
	}
	
	FOR(i,N-1) {
		if(S.empty()) return _P("NO\n");
		x = S.begin()->first;
		y = S.begin()->second;
		S.erase(S.begin());
		E[x][1].erase(y);
		E[y][1].erase(x);
		
		if(E[x][0].size()+E[x][1].size()<E[y][0].size()+E[y][1].size()) {
			swap(x,y);
		}
		// merge y->x
		FORR(e,E[y][0]) if(x!=e) {
			E[e][0].erase(y);
			add_edge(x,e);
		}
		E[y][0].clear();
		
		FORR(e,E[y][1]) if(x!=e) {
			E[e][1].erase(y);
			E[e][1].insert(x);
			E[x][1].insert(e);
			S.erase({min(e,y),max(e,y)});
			S.insert({min(x,e),max(x,e)});
		}
		
	}
	return _P("YES\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 28544
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,s,ans=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int m=0;m<=k;m++){
        if(s-i-m<=k&&0<=s-i-m) ans++;
      
    }
  }
  cout<<ans<<endl;
}


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

class Program
{
	static void Main(string[] args)
	{
		// 入力
		string[] input = Console.ReadLine().Split(' ');
		var n = decimal.Parse(input[0]);
        var a = decimal.Parse(input[1]);
		var b = decimal.Parse(input[2]);

		//値の判定
        decimal count = 0;
        if ((b-a)%2 == 0)
        {
            //偶数の場合
            count =(b-a)/2;
        }
        else
        {
            //奇数の場合
            if (a==1)
            {
                //Aが卓1にいる場合
                count =1+(b-a-1)/2;
            }
            else if (b == n)
            {
                //Bが卓Nにいる場合
                count = 1+(b-a-1)/2;
            }
            else if ((n-b) > a-1)
            {
                //卓1に近い場合
                count = a+(b-a-1)/2;
            }
            else
            {
                //卓Nに近い場合        
                count = (n-b)+1+(b-a-1)/2;    
            }
        }

        //出力
        Console.WriteLine(count);
	}
}

Measured memory_bytes: 11220
# coding: utf-8
# Your code here!

import math

N = int(input())
X = [N] + [int(input()) for _ in range(5)]

count = 0
for i in range(1, 6):
    if min(X[:i]) > X[i]:
        count += math.ceil((N - (count - i + 1) * X[i]) / X[i])
    else:
        count += 1
        
print(count)
    

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using lint = long long;

lint n, x, m, w, cnt1, cnt2, sum1, res;
vector<lint>vec;
bool used[100010];
int main() {
	cin >> n >> x >> m;

	lint a1 = x;
	while (true) {
		used[a1] = true;
		vec.push_back(a1);
		a1 = a1 * a1 % m;
		if (used[a1]) {
			w = a1;
			break;
		}
	}

	cnt1 = find_if(vec.begin(), vec.end(), [=](lint x) { return w == x; }) - vec.begin();
	cnt2 = vec.size() - cnt1;

	if (n < cnt1) {
		cout << accumulate(vec.begin(), vec.begin() + n, 0LL) << endl;
	}
	else {
		res = accumulate(vec.begin(), vec.begin() + cnt1, 0LL);

		n -= cnt1;
		sum1 = accumulate(vec.begin() + cnt1, vec.end(), 0LL);
		res += n / cnt2 * sum1;

		n %= cnt2;
		res += accumulate(vec.begin() + cnt1, vec.begin() + cnt1 + n, 0LL);
		cout << res << endl;
	}
}

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

int main(){

    int N;
    cin >> N;

  vector<int> X(N);
    int64_t ans, ans_min=100000000;

//    cin >> N;
    for (int i=0; i<N; i++){
        cin >> X.at(i);
    }

    for (int i=1; i<=100; i++){
        ans = 0;
        for (int j=0; j<N; j++){
            ans += (X.at(j) - i)*(X.at(j) - i);
        }
        if (ans < ans_min){
            ans_min = ans;
        }
    }

    cout << ans_min << endl;
    return 0;
}

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

int main()
{
    int n,i,j,k;cin>>n;
    int p[n],q[n];
    for(i=0;i<n;i++) cin>>p[i];
    for(i=0;i<n;i++) cin>>q[i];
    int arr[n]; for(i=0;i<n;i++) arr[i]=i+1;
    k=1;int a,b;
    do
    {
        int f=1;
        for(i=0;i<n;i++)
        {
            if(arr[i]!=p[i])
            {
                f=0;break;
            }
        }
        if(f==1) a=k;

        f=1;
        for(i=0;i<n;i++)
        {
            if(arr[i]!=q[i])
               {
                   f=0;break;
               }
        }
        if(f==1) b=k;
        k++;
    }while(next_permutation(arr,arr+n));

    cout<<abs(a-b);




    return 0;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,m:usize,
        lr:[(Usize1,Usize1);m],
    }
    let mut lmax = 0;
    let mut rmax = n;
    for &(l, r) in lr.iter() {
        lmax = max(lmax, l);
        rmax = min(rmax, r + 1);
    }
    println!("{}", rmax.saturating_sub(lmax));
}


Measured memory_bytes: 4676
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
void sw(int *f){
	int ff=f[3];
	f[3]=f[2];
	f[2]=f[1];
	f[1]=f[0];
	f[0]=ff;
}
int n,m,i,j,k,a[305][305],book[305],sum[305],max1,max2,ans;
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();m=read();
   	for(i=1;i<=n;i++)
   		for(j=1;j<=m;j++)
    		a[i][j]=read();
    ans=1000000;
    for(i=1;i<=m;i++){
		for(j=1;j<=n;j++)
			for(k=1;k<=m;k++)
				if(book[a[j][k]]==0){
					sum[a[j][k]]++;
					break;
				}
		max1=0;
		for(j=1;j<=m;j++)
			if(sum[j]>max1){
				max1=sum[j];
				max2=j;
			}
		book[max2]=1;
		ans=min(ans,max1);
		for(j=1;j<=m;j++)
			sum[j]=0;
	}
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int a[4] = {0};
    rep(i,0,3)
    {
        int x, y;
        cin >> x >> y;
        --x; --y;
        a[x]++;
        a[y]++;
    }
    int one = 0, two = 0;
    rep(i,0,4)
    {
        one += a[i] == 1;
        two += a[i] == 2;
    }
    if (one == 2 && two == 2)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

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

using namespace std;

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


Measured memory_bytes: 256
#include <stdio.h> 

int main(void)
{
	int a, b, c;

	scanf("%d %d %d",&a, &b, &c);

	if(a < b && b < c)
	{
		printf("Yes\n");
	}
	
	else
	{
		printf("No\n");
	}
	
	return 0;
}

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

class Procon
{
  public Procon() {}
  static void Main(string[] agrs)
  {
    new Procon().Do();
  }

  Scanner cin;

  public void Do()
  {
    cin = new Scanner();
    int s = cin.nextInt();
    
    int n = s;
    List<int> prevn = new List<int>();
    for (int i=1; ;i++) {
      prevn.Add(n);
      n = fn(n);
      for (int j=0; j<i; j++) {
        if (prevn[j] == n) {
          Console.WriteLine(i+1);
          return;
        }
      }
    }
  }

  public static int fn(int n) {
    if (n%2 == 0) {
      return n/2;
    } else {
      return 3 * n+1;
    }
  }
}


class Scanner
{
  string[] s;
  int i;
  int max_i;

  public Scanner()
  {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString()
  {
    if (i >= s.Length) 
    {
      s = Console.ReadLine().Split(' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) 
      {
        return "";
      }
      return s[i++];
    } else 
    {
      return s[i++];
    }
  }

  public int nextInt()
  {
    return int.Parse(nextString());
  }


  public long nextLong()
  {
    return long.Parse(nextString());
  }

  public double nextDouble()
  {
    return double.Parse(nextString());
  }

  public string[] arrayString()
  {
    return Console.ReadLine().Split(' ');
  }

  public int[] arrayInt()
  {
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = int.Parse(str[i]);
    }
    return array;
  }

  public long[] arrayLong()
  {
    string[] str = Console.ReadLine().Split(' ');
    long[] array = new long[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = long.Parse(str[i]);
    }
    return array;
  }

  public double[] arrayDouble()
  {
    string[] str = Console.ReadLine().Split(' ');
    double[] array = new double[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = double.Parse(str[i]);
    }
    return array;
  }
}


Measured memory_bytes: 11220
def main():
    while True:
        n = int(input())
        if n == 0: break

        teams = []
        for i in range(n):
            teams.append(list(map(int, input().split())))
       
        def same_len(l):
            return len(list(filter(lambda x: x[1] == e[1], ans))) 

        ans = []
        rank = sorted(sorted(sorted(teams, key=lambda x: x[0]), key=lambda x: x[3]), key=lambda x: x[2], reverse=True) 
        for e in rank:
            if len(ans) < 10 and same_len(ans) < 3:
                ans.append(e)
            elif len(ans) < 20 and same_len(ans) < 2:
                ans.append(e)
            elif len(ans) < 26 and same_len(ans) == 0:
                ans.append(e)

        for a in ans:
            print(a[0])


if __name__ == "__main__":
    main()




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

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    int ans = m;
    rep(i, m){
        UnionFind uf(n);
        rep(j, m) {
            if (i==j) continue;
            uf.unite(a[j], b[j]);
        }
        if (uf.same(a[i], b[i])) ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int64_t N;
  cin >> N;
  int64_t A, B, C, D;
  A = B = C = 1;
  D = 1000000007;
  rep(i, N) {
    A *= 10;
    if(A >= D) {
      A = A % D;
    }
  }
  rep(i, N) {
    B *= 9;
    if(B >= D) {
      B = B % D;
    }
  }
  rep(i, N) {
    C *= 8;
    if(C >= D) {
      C = C % D;
    }
  }
  int64_t X = A - B * 2 + C;
  while(X < 0) {
    X += D;
  }
  cout << X % D << endl;
}

Measured memory_bytes: 3632
N=int(input())
l=0
r=0
for i in range(1,N+1):
  s=i*(i+1)//2
  if s>=N:
    l=i
    r=s-N
    break
ans=list(range(1,l+1))
if r!=0:
  ans.remove(r)
print(*ans,sep='\n')

Measured memory_bytes: 9384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    string s;
    cin >> s;

    string t = "ATCG";
    int ans = 0;
    
    rep(i, s.size()) {
        int now = 0; //ATCGを含む位置を0と1で管理する。開始位置を0にする。
        for(int j = i; j < s.size(); j++) { //iから開始することで、連続をカウントできる
            bool ok = false;
            rep(k, t.size()) {
                if(s[j] == t[k]) ok = true;
            }
            if(ok) {
                now++; //ATCGがあった位置は1としてそれらを加算してく
                ans = max(now, ans);
            }
            else break;
        }
    }
    cout << ans << endl;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using pii = pair<int, int>;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

signed main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i+=2) {
        ++ans;
    }
    cout << (ans >= k ? "YES" : "NO") << nl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N, M;
        cin >> N >> M;
        map<int, int> mp;

        for (int i = 0; i < N; i++)
        {
                int K;
                cin >> K;
                for (int i = 0; i < K; i++)
                {
                        int a;
                        cin >> a;
                        mp[a]++;
                }
        }
        int ans = 0;
        for (auto itr : mp)
        {
                if (itr.second == N)
                {
                        ans++;
                }
        }
        cout << ans << endl;

        return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    for(int i = 0; i < 30; i++){
        for(int j = 0; j < 15; j++){
            if(N == 4*i + 7*j){
                cout << YES << endl;
                exit(0);
            }
        }
    }
    cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

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

  int n, q;
  long long m;
  cin >> n >> m >> q;

  vector<int> ds(n);
  for (int i = 0; i < n; i++)
    ds[i] = i;

  function<int(int)> get = [&](int x)
  {
    return x == ds[x] ? x : ds[x] = get(ds[x]);
  };

  vector<pair<int, int>> queries;
  int dsCnt = n;
  while (q--)
  {
    int x, y, c;
    cin >> x >> y >> c;
    if (c) queries.push_back({x, y});
    else
    {
      int dx = get(x), dy = get(y);
      if (dx != dy)
      {
        ds[dx] = dy;
        dsCnt--;
      }
    }
  }

  if (m == n - 1) cout << (queries.empty() ? "Yes\n" : "No\n");
  else
  {
    for (auto u : queries)
      if (get(u.first) == get(u.second))
      {
        cout << "No\n";
        return 0;
      }

    long long maxM = (n - dsCnt) + (dsCnt - 1LL) * dsCnt / 2;
    cout << (m <= maxM ? "Yes\n" : "No\n");
  }
}


Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, t;
    cin >> n >> t;

    int nowtime, nexttime, result = 0;

    cin >> nowtime;
    FOR(i,1,n){
        cin >> nexttime;
        result += min(t, nexttime - nowtime);
        nowtime = nexttime;
    }
    result += t;
    cout << result << endl;

    return 0;
}


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

int main() {
    int n, ans=0;
    cin >> n;
    rep(i,n) ans+=i+1;

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


Measured memory_bytes: 256
def main():
	s = str(input())
	
	s = list(s)

	for i in range(len(s)-1):
		if s[i] == "P" and s[i+1] == "?":
			s[i+1] = "D"
		elif s[i] == "?" and s[i+1] == "D":
			s[i] = "P"
		elif s[i] == "?":
			s[i] = "D"

	if s[-1] == "?":
		s[-1] = "D"

	print(''.join(map(str, s)))


if __name__ == '__main__':
	main()

Measured memory_bytes: 96108
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        getAns(a, b);
    }
    static void getAns(long a, long b)
    {
        long ans;
        if (a % 2 == 0 && b % 2 == 1)
        {
            var c0 = (b - 1 - a) / 2 + 1;
            if (c0 % 2 == 0) ans = 0;
            else ans = 1;
        }
        else if (a % 2 == 0 && b % 2 == 0)
        {
            var c0 = (b - 2 - a) / 2 + 1;
            if (c0 % 2 == 0) ans = b;
            else ans = b ^ 1L;
        }
        else if (a % 2 == 1 && b % 2 == 1)
        {
            var c0 = (b - a - 2) / 2 + 1;
            if (c0 % 2 == 0) ans = a;
            else ans = a ^  1L;
        }
        else
        {
            var c0 = (b - 3 - a) / 2 + 1;
            if (c0 % 2 == 0) ans = a ^ b;
            else ans = a ^ b ^ 1L;
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 13140
#include<stdio.h>

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

    for(i=0;i<9;i++)
    {
        for(j=i+1;j<10;j++)
        {
            if(n[j]>n[i])
            {
                t = n[j];
                n[j] = n[i];
                n[i] = t;
            }
        }
    }

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

return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>

int main() {
	int a, b, m; std::cin >> a >> b >> m;
	std::vector<int> reizouko(a), renji(b);
	for (auto& r : reizouko) std::cin >> r;
	for (auto& r : renji) std::cin >> r;
	int min_price = *std::min_element(reizouko.begin(), reizouko.end()) + *std::min_element(renji.begin(), renji.end());
	for (auto i = 0; i < m; ++i) {
		int x, y, c; std::cin >> x >> y >> c; --x, --y;
		min_price = std::min(min_price, reizouko[x] + renji[y] - c);
	}
	std::cout << min_price << std::endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int X;
	int A;
	int B;
	int i;
	scanf("%d", &X);
	scanf("%d", &A);
	scanf("%d", &B);
	X = X - A;
	i = X / B;
	printf("%d\n", X - i*B);
}

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

int main(){
  char S[101];
  scanf("%s",S);
  int l=strlen(S);
  int c=0;
  for(int i=0;i<l;i++){
    if(c==0 && S[i]=='C') c=1;
    else if(c==1 && S[i]=='F') c=2;
  }
  if(c==2) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1656
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	if a == b {
		fmt.Println(a * 2)
	} else {
		fmt.Println(larger(a, b)*2 - 1)
	}
}


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

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=1e5+5;

int data[maxn];

int main() {
    int a, b;
    while(cin>>a>>b){
        for(int i=0;i<a;i++)cin>>data[i];
        sort(data, data+a);
        int ans=0;
        for(int i=a-b;i<a;i++){
            ans+=data[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
enum COLOR {
	BLACK,
	UNKNOWN,
	WHITE,
	BOTH,
};

int w, h;
char field[52][52];

COLOR color;
int count;

void dfs(int x, int y) {
	field[y][x] = '#';
	count++;
	for (int i = 0; i < 4; i++) {
		int nextX = x + dx[i];
		int nextY = y + dy[i];
		if (0 <= nextX && nextX < w && 0 <= nextY && nextY < h && field[nextY][nextX] != '#') {
			switch (field[nextY][nextX]) {
			case '.':
				dfs(nextX, nextY);
				break;
			case 'W':
				if (color == BLACK) color = BOTH;
				else if (color == UNKNOWN) color = WHITE;
				break;
			case 'B':
				if (color == WHITE) color = BOTH;
				else if (color == UNKNOWN) color = BLACK;
				break;
			}
		}
	}
}

void printfield() {
	for (int i = 0; i < h; i++) {
		cout << field[i] << endl;
	}
}

int main () {
	while (cin >> w >> h, w || h) {
		for (int i = 0; i < h; i++) {
			cin >> field[i];
		}
		int black = 0, white = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] == '.') {
					count = 0;
					color = UNKNOWN;
					dfs(j, i);
					if (color == BLACK) black += count;
					if (color == WHITE) white += count;
//					if (color == UNKNOWN) cout << "unknown: " << count << endl;
//					if (color == BOTH) cout << "both: " << count << endl;
//					printfield();
				}
			}
		}
		cout << black << ' ' << white << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   string S,T;
   cin >> S >> T;
   cout << T << S << endl;
   return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
x = sum(a)//N
x1 = x + 1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += (a[i]-x)**2
    ans2 += (a[i]-x1)**2
print(min(ans1,ans2))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

int Hash[1000000007];
char s[20];

int getchar(char ch){
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

//?????????????????°?????????????????????key???????????????
int getkey(){
	int sum = 0, p = 1;
	rep(i, strlen(s)){
		sum += p * (getchar(s[i]));
		p *= 5;
	}
	return sum;
}

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

	rep(i, n){
		char meirei[10];
		scanf("%s %s", meirei, s);

		if (meirei[0] == 'i'){
			//???????????????????????´???
			//???????????\??¢??°????????¨?????????????????\???????¨????????????????????????\???????????????????????°?????£??\??????
			Hash[getkey()] = true;
		}else{
			//????´¢????????´???
			if (Hash[getkey()])//?????§?????????????????????????????´???
				printf("yes\n");
			else
				printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 20096
H,N=map(int,input().split())
M=[tuple(map(int,input().split())) for i in range(N)]

D=[1<<31]*(H+10**4)
D[0]=0

for hp in range(H):
    for a,b in M:
        D[hp+a]=min(D[hp+a],D[hp]+b)
print(min(D[H:]))


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

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

    int p[n],d[n];
    int i,j;
    int minv = 2000000000;
    for(i=0;i<n;i++){
        cin >> p[i];
        d[i] = abs(p[i] - x);
        minv = min(minv,d[i]);
    }

    int ans = minv;
    int flag = 1;
    while(flag){
        for(j=0;j<n;j++){
            if((d[j]%ans)!=0)break;
            if(j==n-1)flag=0;
        }

        if(flag == 1) ans = ans-1;
        if(ans == 1) flag = 0;
    }
    cout << ans << endl;
}

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

#define DEBUG if(0)
#define lli long long int
const int maxN = 2e5 + 1, mod = 2019;
int acc[maxN], cnt[mod];
char s[maxN];

int main()
{
  scanf("%s", s);
  int n = strlen(s), ans = 0;
  acc[n] = 0;
  for (int i = n - 1, p = 1; i >= 0; i--, p = (p * 10) % mod)
    acc[i] = (acc[i + 1] + (s[i] - '0') * p) % mod;
  DEBUG
    for (int i = 0; i < n; i++)
      printf("%d\n", acc[i]);
  cnt[0] = 1;
  for (int i = 0; i < n; i++)
    cnt[acc[i]]++;
  for (int i = 0; i < mod; i++)
    ans += cnt[i] * (cnt[i] - 1) / 2;
  printf("%d\n", ans);
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	string ans="~"s,base;
	for(auto&&i:s){
		if(i=='?')base+='a';
		else base+=i;
	}
	for(int i=0;i<s.size();++i){
		if((s.at(i)=='?'||s.at(i)==t.at(0))&&t.size()+i<=s.size()){
			string tans=base.substr(0,i);
			bool yes=true;
			for(int j=i;j<t.size()+i;++j){
				if(s.at(j)=='?'||s.at(j)==t.at(j-i)){
					tans+=t.at(j-i);
				}
				else{
					yes=false;
					break;
				}
			}
			if(yes){
				tans+=base.substr(tans.size());
				ans=min(ans,tans);
			}
		}
	}
	cout<<(ans=="~"s?"UNRESTORABLE"s:ans)<<"\n"s;
}


Measured memory_bytes: 3628
N = int(input())
 
#from collections import deque
 
#Q = deque()
 
S = "a"
 
def printer(S,max_s):
    if len(S)==N:
        print(S)
    else:
        max_s = max(ord(S[-1])-ord('a'),max_s)
        for i in range(ord('a'),ord('a')+max_s+2):        
            printer(S + chr(i),max_s)
        
printer(S,0)

Measured memory_bytes: 58456
// ※※※ 解答不能 ※※※
// scott_wu氏
// https://atcoder.jp/contests/agc040/submissions/8274233
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int N;
pair<int, int> loc[MAXN];

int main(){
    int ans = 0;
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%d %d", &loc[i].first, &loc[i].second);
        loc[i].second++;
        ans = max(ans, loc[i].second - loc[i].first);
    }
    sort(loc, loc + N);
    reverse(loc, loc + N);
    
    int nfar = -1e9;
    for(int i = 0; i < N; i++) nfar = max(nfar, loc[i].second);
    
    int nbest = -1e9;
    for(int i = 0; i < N; i++){
        int cv = loc[i].second;
        nbest = max(nbest, max(nfar, cv) - loc[i].first);
        nfar = min(nfar, cv);
    }
    
    int lh = -1e9, rl = 1.1e9;
    for(int i = 0; i < N; i++){
        lh = max(lh, loc[i].first);
        rl = min(rl, loc[i].second);
    }
    ans = max(ans, nbest + rl - lh);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const LL maxn = 1e6+10;

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



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int K, S;
	cin >> K >> S;

	int ans = 0;
	int temp;
	for (int X = 0; X <= K; X++)
	{
		for (int Y = 0; Y <= K; Y++)
		{
			temp = S - X - Y;
			if (temp >= 0 && temp <= K) ans++;
		}
	}

	cout << ans;

	return 0;
}


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

using namespace std;

void Main() {
    string s;
    cin >> s;

    string top = s.substr(0, 1);
    string last = s.substr(s.size() - 1, 1);
    cout << top << (s.size() - 2) << last << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;



int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */

    int n, m; scanf("%d %d", &n, &m);
    vector<pair<int, int>> vp(m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &vp[i].first, &vp[i].second);
        vp[i].second--;
    }
    sort(vp.begin(), vp.end());
    vector<int> l(n), r(n); for (int i = 0; i < n; i++) l[i] = i, r[i] = i;
    for (int i = 0; i < m; i++) {
        r[vp[i].second] = r[vp[i].second + 1];
        l[vp[i].second + 1] = l[vp[i].second];
    }
    for (int i = 0; i < n; i++) printf("%d%c", r[i] - l[i] + 1, " \n"[i + 1 == n]);
    return 0;
}


Measured memory_bytes: 5120