akhauriyash/Code-Regression huggingface dataset:
#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>;

bool check(vector<P> s) {
    int h = 0;
    for (P p : s) {
        int b = h + p.first;      //断片の最後の点の高さを出す
        h += p.second;            //増減は加算していくだけ
        if (b < 0) return false;  //最下点が0を下回ったらfalse
    }
    return true;
}

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<P> ls, rs;  //増減+はls、増減-はrsに入れる
    int total = 0;  //和が0にならないとダメなので、その確認用
    rep(i, n) {
        //入力
        string s;
        cin >> s;
        //最下点と増減を計算
        int h = 0, b = 0;
        for (char c : s) {
            if (c == '(')
                ++h;
            else
                --h;
            b = min(b, h);
        }
        //増減の正負で分類
        if (h > 0)
            ls.emplace_back(b, h);
        else
            rs.emplace_back(b - h, -h);
        total += h;
    }
    // sort
    sort(ls.rbegin(), ls.rend());
    sort(rs.rbegin(), rs.rend());
    // checkする
    if (check(ls) && check(rs) && total == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 18924
#include <iostream>

using namespace std;

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

    string S;
    cin >> S;

    int rankAll=0;
    int rankB=0;
    for (int i=0; i<N; i++){
        if (S.at(i)=='a') {
            if(rankAll < (A+B)) {
                rankAll++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if (S.at(i)=='b') {
            if(rankAll < (A+B) && rankB < B){
                rankAll++;
                rankB++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

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

int main(){
	string s;
	cin >> s;
	int a=0;
	int b=0;
	int c=0;
	for(int i=0; i<3; i++){
		if(s[i]=='a') a++;
		else if(s[i]=='b') b++;
		else c++;
	}
	if(a == 1 && b == 1 && c == 1) cout << "Yes";
	else cout << "No";
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//printf("%d", n);
//printf("%d", sum);
//scanf("%d", &n);
//scanf("%c", &c);
//scanf("%lf", &d);

#define NUM (10000)

int main(int argc, char** argv){
    int H, N;
    vector<int> A;
    scanf("%d", &H);
    scanf("%d", &N);
    rep(i, N){
        int t;
        scanf("%d", &t);
        A.push_back(t);
    }
    sort(A.begin(), A.end());

    rep(i, N){
        H -= A[i];
        if(H <= 0){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");

    return 0;
}




Measured memory_bytes: 892
// Aizu Vol-1 0121: Seven Puzzle 
// 2017.8.4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	while (isspace(*p)) p++;
	return *p++ - '0';
}

#define MAGIC 37

typedef struct { char x; int a; } T;
T s[50]; int top;

#define HASHSIZ 39989		// 20160
typedef struct { int s; char v; } NODE;
NODE nd[HASHSIZ + 2], *hashend;

int lookup(int s)
{
	NODE *np = nd + s%HASHSIZ;
	while (1) {
		if (np->s == s) return np->v;
		if (np->s == 0) break;
		if (++np == hashend) np = nd;
	}
	return 0;
}

void insert(int s, char v)
{
	NODE *np = nd + s%HASHSIZ;
	for (;;) {
		if (np->s == 0) { np->s = s, np->v = v; break; }
		if (np->s == s) { np->v = v; break; }
		if (++np == hashend) np = nd;
	}
}

char to[8][4] = {
	{ 1, 4, 10 }, { 0, 2, 5, 10 }, { 1, 3, 6, 10 }, { 2, 7, 10 },
	{ 0, 5, 10 }, { 1, 4, 6, 10 }, { 2, 5, 7, 10 }, { 3, 6, 10 } };

int swap(int a, int x, int y)
{
	int i, aa[10];

	for (i = 7; i >= 0; i--) aa[i] = a % 10, a /= 10;
	a = aa[x], aa[x] = aa[y], aa[y] = a;
	for (a = 0, i = 0; i < 8; i++) a = 10 * a + aa[i];
	return a;
}

int main()
{
	int x, a, i, j, n;

	hashend = nd + HASHSIZ;
	s[0].a = 1234567, s[0].x = 0, top = 1;
	insert(1234567, 1);
	while (top > 0) {
		x = s[--top].x, a = s[top].a, n = lookup(a) + 1;
		if (n > MAGIC) continue;
		for (i = 0; (j = to[x][i]) < 10; i++) {
			int k = swap(a, x, j);
			int m = lookup(k);
			if (!m || m > n) {
				s[top].a = k, s[top++].x = j, insert(k, n);
			}
		}
	}

	while (gets(p = buf) != NULL) {
		for (i = 0, a = 0; i < 8; i++) a = a * 10 + getInt();
		printf("%d\n", lookup(a) - 1);
	}
	return 0;
}

Measured memory_bytes: 828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstInp.Sort();                                                  // 昇順
            int iOut = lstInp[0] + lstInp[1];

            //出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int N;cin >> N;
    cout << N / 3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int dfs(string s){
  if(stoll(s)>N){return 0;}
  int ret=0,c3=0,c5=0,c7=0;
  for(int i=0;i<s.size();i++){ 
    if(s.at(i)=='3'){c3++;}
    if(s.at(i)=='5'){c5++;}
    if(s.at(i)=='7'){c7++;}
  }
  if(c3>0&&c5>0&&c7>0){ret++;}
  ret+=dfs(s+"3");
  ret+=dfs(s+"5");
  ret+=dfs(s+"7");
  return ret;
}

int main() {
  cin>>N;
  cout<<dfs("0")<<endl;
}

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

int main() {
    int n,i,k;
     double  t,p,min,y;
    cin>>n>>t>>p;
    double a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    min=100000000.987;
    for(i=0;i<n;i++)
    {
        y=t-a[i]*.006;
        y=abs(p-y);
        if(min>y)
        {
            k=i;
            min=y;
        }
    }
    cout<<k+1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    //printf("%d %d %d\n",a,b,c);
    int m = a * c;
    if(m <= b){
        printf("%d\n",c);
    }else{
        printf("%d\n",b/a);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> d = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			d.add(sc.nextInt());
		}
		Collections.sort(d);
		if(d.get(N/2 -1) == d.get(N/2)) {
			System.out.println(0);
		} else {
			System.out.println(d.get(N/2) - d.get(N/2 -1));
		}
	}
}

Measured memory_bytes: 61900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N;
  cin>>N;
  ll man[N];
  rep(i,N){
    cin>>man[i];
  }
  ll ans=0;
  rep(i,N-1){
    ll a=0;
    ans+=max(man[i]-man[i+1],a);
    man[i+1]=max(man[i],man[i+1]);
   // cout<<man[i+1];
  }
  cout<<ans;
  
}


Measured memory_bytes: 5188
def Recursion(S):
    list = []
    list.append(S)
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = left
        for y in Recursion(right):
            list.append(x+"+"+y)
            list.append(x+"-"+y)
    return list

S = input()
for y in Recursion(S):
    if len(y) == len(S)+len(S)-1:
        cand = 0
        for i, x in enumerate(list(y)):
            if i == 0:
                cand += int(x)
            elif x == "+":
                flag = 1
            elif x == "-":
                flag = 0
            elif i % 2 == 0:
                if flag == 0:
                    cand -= int(x)
                else:
                    cand += int(x)
        if cand == 7:
            print(y+"=7")
            break


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

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int ans_sugar = 0, ans_sugar_water = 0;
    double conc = 0.0;
    for (int i = 0; i <= 30; i++) {
        for (int j = 0; j <= 30; j++) {
            int water = 100 * a * i + 100 * b * j;
            if (water > f) continue;
            for (int k = 0; k <= 100; k++) {
                for (int l = 0; l <= 100; l++) {
                    int sugar = c * k + d * l;
                    if (water + sugar <= f && ((water / 100) * e >= sugar)) {
                        if (conc <= (100.0 * sugar / (water + sugar))) {
                            conc = 100.0 * sugar / (water + sugar);
                            ans_sugar_water = water + sugar;
                            ans_sugar = sugar;
                        }
                    }
                }
            }
        }
    }

    cout << ans_sugar_water << " " << ans_sugar << endl;
    return 0;
}

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

int main() {
  int X, N;
  cin >> X >> N;
  if(N == 0) {
    cout << X << endl;
  } else {
    vector<int> pi;
    for(int i = 0; i < N; i++) {
      int temp;
      cin >> temp;
      pi.push_back(temp);
    }
    sort(pi.begin(), pi.end());
    int maxi = 0;
    for(int i = 1; i < N; i++) {
      int temp = abs(pi[i] - X);
      if((abs(pi[maxi] - X)) > temp) {
        maxi = i;
      }
    }
    if(pi[maxi] != X) {
      cout << X << endl;
    } else {
      int dec = 1;
      int inc = 1;
      int p = maxi - 1;
      while(((X - dec) > 0) && (p >= 0)) {
        if(pi[p] != (X - dec)) {
          break;
        } else {
          p--;
        }
        dec++;
      }
      p = maxi + 1;
      while(p < N) {
        if(pi[p] != (X + inc)) {
          break;
        } else {
          p++;
        }
        inc++;
      }
      if(inc >= dec) {
        cout << (X - dec) << endl;
      } else {
        if(inc == 0) {
          cout << (X + 1) << endl;
        } else {
          cout << (X + inc) << endl;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vecll = vector<long long>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(n) (n).begin(), (n).end()

int main()
{
    ll n, k, mask=0, b;
    cin >> n >> k;
    rep(i, k)
    {
        cin >> b;
        mask |= (1LL << b);
    }

    for (ll bit=0; bit < (1LL<<n); bit++)
    {
        vector<ll> S;
        if ((bit&mask)==bit)
        {
            for (ll i=0; i < n; i++)
            {
                if (bit & (1LL << i))
                {
                    S.push_back(i);
                }
            }

            cout << bit << ":";
            for (ll i=0;i<(ll)(S.size());i++)
            {
                cout << " " << S[i];
            }
            cout << endl;
        }
    }

}


Measured memory_bytes: 3156
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; 
char c[3];
bool flag1=0,flag2=0,flag3=0;
int main(){
	for(int i=0;i<3;i++){
		cin>>c[i];
	}
	for(int i=0;i<3;i++){
		if(c[i]=='a') flag1=1;
		if(c[i]=='b') flag2=1;
		if(c[i]=='c') flag3=1;
	}
	if(flag1==1&&flag2==1&&flag3==1){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
long long a, b, c, flag;
int main()
{
	scanf("%lld%lld%lld",&a, &b, &c);
	if(b>=a){printf("1\n");return 0;}
	else if(c >= b) {printf("-1\n");return 0;}
	if((a-b)%(b-c) >= 1) flag = 1;
	printf("%lld\n",((a-b)/(b-c)+flag)*2+1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,a,b;
  cin >> n >> a >> b;
  vector<int> h(n);
  REP(i,n) cin >> h[i];

  sort(ALL(h));

  ll ng = 0, ok = h[n-1]/b+1;
  while(abs(ok-ng) > 1) {
    ll mid = (ok+ng)/2;
    ll key = mid * b;
    auto it = upper_bound(ALL(h), key);
    ll sum = mid;

    for (ll j = it-h.begin(); j < n; j++) {
      ll nh = h[j]-key;
      sum -= nh/(a-b) + (nh%(a-b) > 0);
    }

    if (0 <= sum) ok = mid;
    else ng = mid;
  }

  COUT(ok);
  return 0;
}

Measured memory_bytes: 3732
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  char c;
  cin >> c;
  cout << (c >= 'a' && c <= 'z' ? 'a' : 'A') << endl;  

  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
const int MAX_N = 100;
typedef long long lint;

int main() {
	int r,c;
	int a[MAX_N+1][MAX_N+1]={0};
	int sum=0;
	//in
	cin>>r>>c;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
		}
	}
	//summer
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			a[i][c]+=a[i][j];
			a[r][j]+=a[i][j];
			sum+=a[i][j];
		}
	}
	a[r][c]=sum;
	//out
	for(int i=0;i<r+1;i++){
		for(int j=0;j<c+1;j++){
			if((j==c)){
				cout<<a[i][j];
			}else{cout<<a[i][j]<<" ";}
		}
		cout<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1208
#include"stdio.h"
int main(){int N;scanf("%d",&N);int po[N];for(int i=0;i<N;i++){scanf("%d",&po[i]);}int M;scanf("%d",&M);for(int i=0;i<M;i++){int a,b;scanf("%d %d",&a,&b);int ans=0;for(int j=0;j<N;j++){if(a-1==j)ans+=b;else ans+=po[j];}printf("%d\n",ans);}return 0;}



Measured memory_bytes: 128
from operator import mul
from functools import reduce

def comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
  

S = int(input())

count = 1
nums = 2

while S - nums * 3 >= 0:
  #print(S-nums*3, comb(S - nums*3 + nums - 1, nums - 1))
  count += comb(S - nums*3 + nums - 1, nums - 1)
  nums += 1
  
if S < 3:
  print(0)
else:
  print(count % (10**9 + 7))

Measured memory_bytes: 9612
#include <iostream>
#include <algorithm>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n,count_max,count_min,temp;
	long long sum = 0;
	cin >> n;

	rep(i,n)
	{
		cin >> temp;
		if(i == 0)
		{
			count_max = count_min = temp;
		}
		else
		{
			count_max = max(count_max,temp);
			count_min = min(count_min,temp);
		}
		sum += temp;
	}

	cout << count_min << " " << count_max << " " << sum << endl;

	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;
int n,m;
vector<vector<int>>edge(10);


bool connect(int now,int next){

    for(auto ne:edge[now]){
        if(next==ne)return true;
    }
    return false;


}


bool check(vector<int>v){
    bool ok=true;
    rep(i,n-2){
        ok&=connect(v[i],v[i+1]);
    }

    return ok;
}




int main(){

    
    cin>>n>>m;

    

    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        edge[a].emplace_back(b);
        edge[b].emplace_back(a);
    }
    bool start[n]={};
    rep(i,edge[0].size()){
        start[edge[0][i]]=true;
    }
    vector<int>v(n-1);
    rep(i,n-1)v[i]=i+1;

    long long ans=0;
    do{
        if(!start[v[0]])continue;

        if(check(v))ans++;

    }while(next_permutation(v.begin(),v.end()));
    
    cout<<ans<<endl;


    return 0;

}
/*


*/


Measured memory_bytes: 256
num = gets.split.map!{|item| item.to_i}

if (num[2] - num[4]) >= 0	 && (num[2] + num[4]) <= num[0] && (num[3] - num[4]) >= 0 && (num[3] + num[4]) <= num[1]	then
		print "Yes\n"

else
	print "No\n"
end

Measured memory_bytes: 6100
#include <iostream>

const int INF = 100000000;
const int MAX_AB = 20;
const int MAX_N = 50;
int N, A, B;
int memo[MAX_AB][MAX_AB];
bool obstacle[MAX_AB][MAX_AB] = {false};

long dfs(long x, long y);

int main(){
    while(true){
        std::cin >> A >> B;
        if(A == 0 && B == 0)
            break;
        std::cin >> N;
        
        for(int i = 0; i < MAX_AB; ++i){
            for(int j = 0; j < MAX_AB; ++j){
                obstacle[i][j] = false;
                memo[i][j] = INF;
            }
        }

        for(int i = 0; i < N; ++i){
            int x, y;
            std::cin >> x >> y;
            --x, --y;
            obstacle[x][y] = true;
        }

        std::cout << dfs(A - 1, B - 1) << std::endl;
    }
    return 0;
}

long dfs(long x, long y){
    if(memo[x][y] != INF)
        return memo[x][y];
    else if(obstacle[x][y])
        return memo[x][y] = 0;
    else if(x == 0 && y == 0)
        return memo[x][y] = 1;
    else
        return memo[x][y] = (x - 1 >= 0 ? dfs(x - 1, y) : 0) + (y - 1 >= 0 ? dfs(x, y - 1) : 0);
}

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


vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
            }
    }
    sort(begin(ret), end(ret), greater<ll>());
    return (ret);
}


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> vec = divisor(m);
    rep(i, vec.size()){
        if (vec[i] * n <= m){
            cout << vec[i] << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

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

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

    vector <int> cost(n + 1);
    cost[2] = abs(a[2] - a[1]);
    for(int i = 2; i <= n; i++)
    {
    	cost[i]=INT_MAX;
    	for(int j = i-1;j>=max(i - k,1);j--){
			cost[i] = min(cost[i], cost[j] + abs(a[i] - a[j]) );
    	}
    }

    cout << cost[n];
    return 0;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
#define maxn 110
#define ll long long
using namespace std;
int x[maxn], y[maxn], res;
set<pair<ll, ll> > S;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> x[i] >> y[i];
		S.insert(make_pair(x[i], y[i]));
	}
	int ans = n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			int p = x[i] - x[j], q = y[i] - y[j], res = 0;
			if (p == 0 && q == 0) continue;
			for (int c = 1; c <= n; c++)
				if (S.find(make_pair((ll)x[c] - p, (ll)y[c] - q)) == S.end()) res++;
			ans = min(ans, res);
		}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

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

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

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

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uni = UnionFind(n)
for i in range(m):
    a, b = ab[i]
    uni.union(a - 1, b - 1)
print(uni.group_count() - 1)


Measured memory_bytes: 90568
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    // 初期化
    int i;
    double n;
    cin>>n;
    double x[1001]={};
    double y[1001]={};
    
    for(i=0; i<n; i++){
        cin>>x[i];
    }
    for(i=0; i<n; i++){
        cin>>y[i];
    }
    
    
    //マンハッタン
    double sum1=0.0;
    for(i=0; i<n; i++){
        sum1 += abs(x[i]-y[i]);
    }
    printf("%.8f\n",sum1);
    
    //ユークリッド
    double sum2=0.0;
    for(i=0; i<n; i++){
        sum2 += pow(abs(x[i]-y[i]),2);
    }
    printf("%.8f\n",sqrt(sum2));
    
    //p=3
    double sum3=0.0;
    for(i=0; i<n; i++){
        sum3 += pow(abs(x[i]-y[i]),3);
    }
    printf("%.8f\n",pow(sum3,1.0/3.0));
    
    //チェビシェフ距離
    double sum4=-1.0;
    for(i=0; i<n; i++){
        sum4 = max(sum4, abs(x[i]-y[i]));
    }
    printf("%.8f\n",sum4);
    
        
    return 0;
}


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

int middle(int p1,int p2,int p3){
    if(p1 < p2){
        swap(p1,p2);
    }
    if(p1 < p3){
        swap(p1,p3);
    }
    if(p2 < p3){
        swap(p2,p3);
    }

    return p2;
}

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

    vector<int> v(n);

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

    sort(v.begin(),v.end());

    cout << v[n/2] - v[n/2 - 1] << endl; 
}

Measured memory_bytes: 640
class in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const my_iterator& begin(){return i;}const my_iterator& end(){return n;}};

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

const int MOD = 1e5;
int dp[101][101][4]; // 0:=nn 1:=ee 2:=en 3:= ne
int dfs(int x, int y, int k) {
    if(x == 0) return k == 0 ? 1 : 0;
    if(y == 0) return k == 1 ? 1 : 0;
    int& res = dp[y][x][k];
    if(res != -1) return res;
    res = 0;
    if(k == 0) {
        (res += dfs(x, y - 1, 0)) %= MOD;
        (res += (dfs(x, y - 1, 2))) %= MOD;
    }
    else if(k == 1) {
        (res += dfs(x - 1, y, 1)) %= MOD;
        (res += (dfs(x - 1, y, 3))) %= MOD;
    }
    else if(k == 2)
      (res += (dfs(x, y - 1, 1))) %= MOD;
    else
      (res += (dfs(x - 1, y, 0))) %= MOD;
    return res;
}


int main() {
    int w, h;
    while(~scanf("%d%d", &w, &h) && w) {
        memset(dp, -1, sizeof(dp));
        int ans = 0;
        for(int i : in(4))
          (ans += (dfs(w - 1, h - 1, i))) %= MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3312
ref = "SCHD"
first = 0
while 1:
	try:
		n = input()
		if first: print
		first = 1
	except:
		break
	P = [map(int,raw_input().split()) for i in range(4)]
	H = map(int,raw_input().split())
	for _ in range(n):
		hand = raw_input().replace("A","1").replace("T","10").replace("J","11").replace("Q","12").replace("K","13").split()
		num  = [int(i[:-1]) for i in hand]
		suit = [ref.index(i[-1]) for i in hand]
		ans  = sum(P[suit[i]][num[i]-1] for i in range(5))
		snum = sorted([i - min(num) for i in num])
		same = max(num.count(i) for i in set(num))
		if len(set(suit)) == 1:
			if snum == [0,9,10,11,12]:
				ans *= H[8]
			elif snum == [0,1,2,3,4]:
				ans *= H[7]
			else:
				ans *= H[4]
		elif snum == [0,1,2,3,4] or snum == [0,9,10,11,12]:
			ans *= H[3]
		elif same == 4:
			ans *= H[6]
		elif same == 3:
			if len(set(num)) == 2:
				ans *= H[5]
			else:
				ans *= H[2]
		elif same == 2:
			if len(set(num)) == 3:
				ans *= H[1]
			else:
				ans *= H[0]
		else:
			ans = 0
		print ans

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



int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    
    int q;
    cin >> q;
    vector<int> b(q), c(q);
    rep(i,q) {
        cin >> b[i];
        cin >> c[i];
    }
    
    vector<int> all(100005);
    long int sum = 0;
    rep(i,n) {
        all[a[i]]++;
        sum += a[i];
    }
    
    //cout << sum << endl;
    rep(i,q) {
        sum += (c[i] - b[i]) * all[b[i]];
        all[c[i]] += all[b[i]];
        all[b[i]] = 0;
        
        cout << sum << endl;
    }
    
    return 0;
}




Measured memory_bytes: 4840
#include <iostream>
#include <iomanip>
#include <chrono>
using namespace std;

void Main() {
    // input
    int64_t N, K;
    cin >> N >> K;
    int64_t P[N+1], C[N+1], D[N+1], L[N+1];

    P[0] = 0;
    C[0] = 0;
    D[0] = 0;
    L[0] = 0;
    for (int64_t i = 1; i <= N; i++) {
        cin >> P[i];
    }
    for (int64_t i = 1; i <= N; i++) {
        cin >> C[i];

    }



    // process
    for (int64_t startPos = 1; startPos <= N; startPos++) {
        int64_t pos = startPos;
        int64_t now = 0;
        int64_t length = 0;

        pos = P[pos];
        now += C[pos];
        length++;
        while (pos != startPos) {
            pos = P[pos];
            now += C[pos];
            length++;
        }
        D[startPos] = now;
        L[startPos] = length;
        // cout << startPos << ":" << now << ":" << length << endl;
    }

    int64_t ans = INT64_MIN;
    for (int64_t startPos = 1; startPos <= N; startPos++) {
        int64_t now = 0;
        int64_t pos = startPos;
        for (int64_t count = 1; count <= K && count <= N; count++) {
            pos = P[pos];
            now += C[pos];
            if (D[pos] > 0) {
                ans = max(ans, now + D[pos] * ((K - count) / L[pos]));
            }
            else {
                ans = max(ans, now);
            }
            // cout << startPos << ":" << ans << endl;
        }
    }


    // output
    cout << ans << endl;

}

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


Measured memory_bytes: 3780
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int A, P;
	std::cin >> A >> P;
	std::cout << (3 * A + P) / 2 << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"
#include "sstream"
#include <numeric>

int main() {
    // get values from input
    int n;
    std::vector<int> l;

    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        int l_i;
        std::cin >> l_i;
        l.push_back(l_i);
    }
    // main procedure
    std::sort(l.begin(), l.end());

    // output
    if (std::accumulate(l.begin(), l.end() - 1, 0) > l.back()) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	string s;
	cin >> s;
	string t = "keyence";

	int n = s.size();
	if (s == t) {
		cout << "YES" << endl;
		return 0;
	}

	rep(i, n) {
		for (int j = i; j < n; j++) {
			string x = "";
			if (i) x += s.substr(0, i);
			if (j + 1 < n) x += s.substr(j + 1);
			if (x == t) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
class BITree {//1-index
	int N;
	vector<LL> bit;
public:
	BITree();
	BITree(int n) {
		N = n;
		bit = vector<LL>(N + 1, 0);//1-index
	}
	void init(int n) {
		N = n;
		bit = vector<LL>(N + 1, 0);//1-index
	}
	void add(int a, LL w) {//aにwを足す
		if (a <= 0 || N < a) return;//a:[1,N]
		for (int i = a; i <= N; i += i & -i) {
			bit[i] += w;
		}
	}
	LL sum(int a) {//[1,a]の和,a:[1,N]
		/*
		1番目からa番目までの和、1-index
		*/
		LL ret = 0;
		if (a > N) a = N;
		for (int i = a; i > 0; i -= i & -i) {
			ret += bit[i];
		}
		return ret;
	}
};

void solve() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	
	/////
	int Q;
	cin >> Q;
	vector<int> Qt(Q);
	vector<int> ans(Q, -1);
	vector<int> L(Q), R(Q);
	vector<int> pos(Q);
	vector<int> ch(Q);
	
	for (int i = 0; i < Q; ++i) {
		cin >> Qt[i];
		if (Qt[i] == 1) {
			char temp;
			cin >> pos[i] >> temp;
			pos[i]--;
			ch[i] = temp - 'a';
		}
		else {
			cin >> L[i] >> R[i];
		}
	}

	for (int z = 0; z < 26; ++z) {
		vector<int> A(N,-1);
		BITree bit(N + 1);

		for (int i = 0; i < N; ++i) {
			int ter = S[i] - 'a';
			if (ter == z) {
				A[i] = z;
				bit.add(i+1,1);
			}
		}
		
		for (int i = 0; i < Q; ++i) {
			if (Qt[i] == 1) {
				if (ch[i] == z) {
					if (A[pos[i]] != z) {
						A[pos[i]] = z;
						bit.add(pos[i] + 1, 1);
					}
					else {//もともとz
					}
				}
				else {
					if (A[pos[i]] == z) {
						A[pos[i]] = -1;
						bit.add(pos[i] + 1, -1);
					}
				}
			}
			else {//Qt[i]==2
				if (ans[i] == -1) {
					ans[i] = 0; 
				}
				int Rres = bit.sum(R[i]);
				int Lres = bit.sum(L[i] - 1);
				int res =  Rres-Lres;
				if (res) {
					ans[i] += 1;
				}
			}
		}
	}
	for (int i = 0; i < Q; ++i) {
		if (ans[i] == -1)continue;
		cout << ans[i] << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 7220
#include<stdio.h>
int main(){
  int a[4][4];
  int i,j,k,check=0;
  for(i=0;i<3;i++)
    for(j=0;j<3;j++)
      scanf("%d",&a[i][j]);
  int n;
  scanf("%d",&n);
  int b[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
    for(j=0;j<3;j++)
      for(k=0;k<3;k++)
        if(b[i]==a[j][k])
          a[j][k]=0;
  }
  for(i=0;i<3;i++)
    if(((a[i][0]==a[i][1])&&(a[i][1]==a[i][2]))||((a[0][i]==a[1][i])&&(a[1][i]==a[2][i])))
      check=1;
  if(a[0][0]==a[1][1] && a[1][1]==a[2][2])
    check=1;
  if(a[0][2]==a[1][1] && a[1][1]==a[2][0])
    check=1;
  if(check==1)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,i;
		cin>>n;
		ll arr[n+1],ans[n+1];
			memset(ans,0,sizeof(ans));
		for(i=0;i<n-1;i++)	{cin>>arr[i];ans[arr[i]]++;}

		for(i=1;i<=n;i++)	cout<<ans[i]<<endl;
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 6920
#include <iostream>
using namespace std;
int main(void){
    int N,X,T;
    cin>>N>>X>>T;
    if(N%X==0){
        cout<<(N/X)*T<<endl;
    }
    else{
        cout<<(N/X+1)*T<<endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main() {
  int N, k;
  long long h[110000];
  long long dp[110000];
  cin >> N >> k;
  for(int i=0;i<N;++i) {
    cin >> h[i];
  }
  
  for(int i=1;i<N;++i) {
    dp[i]=INF;
  }
  dp[0]=0;
  for(int i=0;i<N;++i) {
    for(int j=1;j<=k;++j) {
    chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
  }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;
typedef long long ll;


int main() {
	int N,count=0,min=1000000000;
	cin >> N;
	vector<int>X(N, 0);
	FOR(N)cin >> X[i];
	sort(X.begin(), X.end());
	for (int i = 1; i <= 100; i++) {
		FOR2(N) {
			count += (i - X[j]) * (i - X[j]);
		}
		if (min > count)
			min = count;
		count = 0;
	}
	cout << min<< endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll W, H, x, y;
    cin >> W >> H >> x >> y;

    int a2 = (H == 2 * y && W == 2 * x) ? 1 : 0;
    cout << W * H / (long double) (2) << " " << a2 << endl;


}


Measured memory_bytes: 3796
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static int maxn = 200005;


    static void solve() {
      int x=ni();
      int a=ni();
      if(x<a)
          out.println(0);
      else
          out.println(10);
    }
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<vector <int> > numN(10);
  for(int i = 0; i < N; i++){
    char tmp = S[i];
    if(tmp == '0') numN[0].push_back(i);
    if(tmp == '1') numN[1].push_back(i);
    if(tmp == '2') numN[2].push_back(i);
    if(tmp == '3') numN[3].push_back(i);
    if(tmp == '4') numN[4].push_back(i);
    if(tmp == '5') numN[5].push_back(i);
    if(tmp == '6') numN[6].push_back(i);
    if(tmp == '7') numN[7].push_back(i);
    if(tmp == '8') numN[8].push_back(i);
    if(tmp == '9') numN[9].push_back(i);
  }
  int count = 0;
  for(int i = 0; i < 10; i++){
    if(numN[i].size() == 0) continue;
    int iP = numN[i][0];
    for(int j = 0; j < 10; j++){
      bool jOK = false;
      int jP = -1;
      for(int j2 = 0; j2 < numN[j].size(); j2++){
        if(numN[j][j2] > iP){
          jP = numN[j][j2];
          jOK = true;
          break;
        }
      }
      if(!jOK) continue;
      for(int k = 0; k < 10; k++){
        // cout << i << " " << j << " " << k << endl;
        for(int k2 = 0; k2 < numN[k].size(); k2++){
          if(numN[k][k2] > jP){
            // cout << i << j << k << endl;
            count++;
            break;
          }
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

int main(void){
    string str;
    cin >> str;
    int ans=1;
    int size=str.length();
    int wherc=str.find("C");
    if(wherc>=2 && wherc<=size-2)ans=1;
    else ans=0;
    for(int i=1; i<size; i++){
        if(i==wherc)continue;
        for(char j='A'; j<='Z'; j++){
            string temp{j};
            if(str.substr(i,1)==temp)ans=0;
        }
    }
    if(str.substr(0,1)!="A")ans=0;
    if(ans)printf("AC\n");
    else printf("WA\n");
    return 0;
}

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

int main(){
	string S;
	cin >> S;
	int N = S.length();
	bool ispld = true;
	for(int i = 0; i < N/2; i++){
		if(S[i] != S[N-i-1]){
			ispld = false;
			break;
		}
	}

	for(int i = 0; i < N/4; i++){
		if(S[i] != S[N/2-1-i] || S[i+(N+1)/2] != S[N-i-1]){
			ispld = false;
			break;
		}
	}

	cout << (ispld?"Yes":"No") << endl;

	return 0;	
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    """
    nをmax(A)にしていい理由が腑に落ちなかったので厳密証明。
    とはいえ証明は簡単で、M=max(A), m=(AのM以外の元), R=(M/2に一番近いAの元), r=(m/2に一番近いAの元)
    とすると
        comb(M, R) >= comb(M, r) >= comb(m, r)
    てだけでした。。。
    """
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx > 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 85036
#include<algorithm>//atcoder67
#include<iostream>
using namespace std;
int main(void)
{
	int n,k,l[1001],i,j,all=0;
	cin>>n>>k;
	for(i=0;i<n;i++) cin>>l[i];
	sort(l,l+n,greater<int>());
	for(i=0;i<k;i++) all=all+l[i];
	cout<<all<<endl;
	return 0;
}

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

int main(void){
  int A,B;
  string S,T,U;
  cin >> S >> T >> A >> B >> U;
  if(S == U)
    cout << A-1 << " " << B << endl;
  else
    cout << A << " " << B-1 <<endl;
    
  
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt(); // 全て小文字へ
			int t = 0,  h = 0;
			for(int i = 0; i < n; i++) {
				String taro = sc.next();
				String hanako = sc.next();
			
				// 文字列の大小比較は compareTo
				if(taro.equals(hanako)) {
					t += 1;
					h += 1;
				}
				else if(taro.compareTo(hanako) > 0) {
					t += 3;
				}
				else {
					h +=3;
				}
			}
			System.out.println(t + " " + h);
		}
	}
}


Measured memory_bytes: 29344
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n-1];
  for(int i=1;i<n;i++){
	scanf("%d",&a[i]);
  }
  int b[n];
  for(int i=0;i<n;i++){
    	b[i]=0;
  }

  for(int i=1;i<n;i++){
	b[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
	printf("%d\n",b[i]);
  }
  return 0;
}

Measured memory_bytes: 3292
from collections import deque

s = list(input())
q = int(input())

qs = [list(input()) for _ in range(q)]

d = deque([])

for c in s:
    d.append(c)

flag_r = False

for qq in qs:
    if qq[0] == '1':
        flag_r = not flag_r
    else:
        if flag_r:
            if qq[2] == '1':
                d.append(qq[4])
            else:
                d.appendleft(qq[4])
        else:
            if qq[2] == '1':
                d.appendleft(qq[4])
            else:
                d.append(qq[4])

if flag_r:
    d.reverse()

print(''.join(d))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0)
	cout<<"1"<<endl;
	if(b==0)
	cout<<"2"<<endl;
	if(c==0)
	cout<<"3"<<endl;
	if(d==0)
	cout<<"4"<<endl;
	if(e==0)
	cout<<"5"<<endl;
	return 0;
}



Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll a, b, c;
    ll l;

    cin >> a >> b >> c;

    l = c - a - b;

    if(l>0 && 4 * a * b < l*l) {
        cout << "Yes";
    } else {
        cout << "No";
    }

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int ls = S.length();
        int lt = T.length();
        for(int i = ls-lt;i >= 0;i--){
            for(int j = 0;j < lt;j++){
                char s = S.charAt(i+j);
                char t = T.charAt(j);
                if(s != '?' && s != t)  break;
                if(j == lt-1){
                    S = S.replace('?', 'a');
                    System.out.println(S.substring(0, i)+T+S.substring(i+lt, S.length()));
                    return;
                }
            }
        }
        System.out.println("UNRESTORABLE");
    }
}

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

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

    string s;
    cin >> s;
    int n = s.size();

    ll sm = 0;
    rep(i, n){
        sm += s[i] - '0';
    }

    if(sm%9 == 0) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3740
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3108