akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int nlimit=10;
int n, m;
bool graph[nlimit][nlimit];
bool visited[nlimit];

int dfs(int, int);
int main(){
  cin >> n >> m;
  int a, b;
  for(int i=0; i<m; i++){
    cin >> a >> b;
    graph[a][b] = true;
    graph[b][a] = true;
  }

  int ans = dfs(1, 0);

  cout << ans << endl;

  return 0;
}

int dfs(int start, int path){
  if(visited[start]) return 0;
  if(path==n-1){
    for(int i=1; i<=n; i++){
      if(!visited[i] && i!=start) return 0;
    }
    return 1;
  }

  visited[start] = true;

  int cnt=0;
  for(int i=1; i<=n; i++){
    if(graph[start][i]) cnt += dfs(i, path+1);
  }

  visited[start] = false;

  return cnt;
}


Measured memory_bytes: 256
from collections import defaultdict

n =int(input())
a = list(map(int, input().split()))

b = []
c = defaultdict(int)
for i in range(n):
    b.append(i+a[i])
    c[i-a[i]] += 1

ans = 0

for i in range(n):
    ans += c[b[i]]

print(ans)


Measured memory_bytes: 133532
#include<iostream>

using namespace std;

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

	for (i = 0; i < 1000; i++) {
		d = a * i;
		e = d % b;
		if (c == e) {
			cout << "YES" << endl;
			return 0;
		}
	}  cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		ArrayList<Integer>[] adj=new ArrayList[100001];
		for(int i=0;i<=100000;i++)
		{
			adj[i]=new ArrayList<Integer>();
		}
		for(int i=0;i<n;i++)
		{
			int u=scan.nextInt();
			int v=scan.nextInt();
			adj[u].add(v);
		}
		long tot=0;
		PriorityQueue<Integer> que=new PriorityQueue<Integer>(Collections.reverseOrder());
		for(int i=1;i<=m;i++)
		{
			for(int x:adj[i])
			{
				que.add(x);
			}
			if(!que.isEmpty())
			{
				int q=que.poll();
//				System.out.println(q);
				tot+=q;
			}
		}
		System.out.println(tot);
	}
}

Measured memory_bytes: 98800
#include <bits/stdc++.h>
#pragma optimize("O2")
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
using namespace std;

int A[100002];
vector<int> t(400000);
map<int, vector<int>> M;

int f(int a, int b){
	int res = a;
	for(int i = 0; i < b - 1; i++){
		res = res * 10 + a;
	}
	return res;
}
int main(){
	IOS;
	int a, b;
	cin >> a >> b;
	if(a > b){
		swap(a, b);
	}
	cout << f(a, b);
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

cnt = r_cnt * g_cnt * b_cnt

for i in range(n):
	for d in range(n):
		j = i + d
		k = j + d
		if k >= n:
			break
		if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
			cnt -= 1


print(cnt)

Measured memory_bytes: 73544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0), list(20, 0);
    rep1(i, n) cin >> a[i];
    ll sum = a[0];
    rep2(i, (ll)1, n){
        sum = sum ^ a[i];
    }
    ll ans = 0;
    rep1(i,n){
        ans = sum ^ a[i];
        if (i == 0) cout << ans;
        else cout << " " << ans;
    }
}

Measured memory_bytes: 4732
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#define inf 99999999
using namespace std;
const int MAX=100000+10;
int main(){
    #ifdef SIYU
    //freopen("in.txt","r",stdin);
    #endif // SIYU
    long long n,m;
    scanf("%lld%lld",&n,&m);
    if(n*2>m){
        printf("%lld\n",m/2);
    }
    else{
        printf("%lld\n",n+(m-n*2)/4);
    }
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int main()
{
	char T[100 + 1];
	char H[100 + 1];
	int n,tc,hc,i,j;

	scanf("%d",&n);

	tc = hc = 0;

	for (i = 0; i < n; i++)
	{
		scanf("%100s",T);
		scanf("%100s",H);

		j = 0;

		while (T[j] != '\0' && H[j] != '\0' && T[j] == H[j]) j++;

		if (T[j] == '\0' && H[j] == '\0')
		{
			tc++; hc++;
		}
		else
		{
			if ((T[j] - H[j]) > 0) tc += 3;
			else hc += 3;
		}
	}

	printf("%d %d\n",tc,hc);

	return 0;
}

Measured memory_bytes: 1780
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;
int main(void) {
    int A, B;
    cin >> A >> B;

    if (A != 2 && B != 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int x[14][14], n; string S[14];
string dp[14][16384];
bool erased[14]; vector<int>vec;
int SSS(string S, string T) {
	for (int i = min(S.size(), T.size()); i >= 0; i--) {
		if (S.substr(S.size() - i, i) == T.substr(0, i))return i;
	}
}
int main() {
	while (true) {
		cin >> n; vec.clear(); if (n == 0)break; for (int i = 0; i < n; i++)cin >> S[i];
		for (int i = 0; i < 14; i++) {
			erased[i] = false;
			for (int j = 0; j < 16384; j++) { dp[i][j] = "$"; }
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (S[i].size() > S[j].size()) {
					for (int k = 0; k <= S[i].size() - S[j].size(); k++) {
						if (S[i].substr(k, S[j].size()) == S[j])erased[j] = true;
					}
				}
			}
		}
		for (int i = 0; i < n; i++) { if (erased[i] == false)vec.push_back(i); }
		n = vec.size(); for (int i = 0; i < n; i++)S[i] = S[vec[i]];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j)x[i][j] = SSS(S[i], S[j]);
			}
		}
		for (int i = 0; i < n; i++) { dp[i][(1 << i)] = S[i]; }
		for (int j = 0; j < (1 << n); j++) {
			for (int i = 0; i < n; i++) {
				if (dp[i][j] == "$")continue;
				int bit[14]; for (int k = 0; k < n; k++)bit[k] = (j / (1 << k)) % 2;
				for (int k = 0; k < n; k++) {
					if (bit[k] == 1)continue;
					string W1 = dp[i][j] + S[k].substr(x[i][k], S[k].size() - x[i][k]);
					if (dp[k][j + (1 << k)] == "$") { dp[k][j + (1 << k)] = W1; }
					if (dp[k][j + (1 << k)].size() > W1.size()) { dp[k][j + (1 << k)] = W1; }
					if (dp[k][j + (1 << k)].size() == W1.size() && dp[k][j + (1 << k)] > W1) { dp[k][j + (1 << k)] = W1; }
				}
			}
		}
		string minx = dp[0][(1 << n) - 1];
		for (int i = 0; i < n; i++) {
			if (minx.size() > dp[i][(1 << n) - 1].size()) { minx = dp[i][(1 << n) - 1]; }
			if (minx.size() == dp[i][(1 << n) - 1].size() && minx > dp[i][(1 << n) - 1]) { minx = dp[i][(1 << n) - 1]; }
		}
		cout << minx.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 39652
from itertools import product

R, G, B, N = map(int, input().split())
R_max = N // R
G_max = N // G
ans = 0
for r, g in product(range(R_max+1), range(G_max+1)):
    if N >= r*R + g*G and (N - (r*R + g*G)) % B == 0: ans += 1
print(ans)

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

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

typedef unsigned long long ull;

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    ull x;
    cin >> x;
    int ans = 0;
    
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if ((500*i) + (100*j) + (50*k) == x) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string.h>
using namespace std;
int main(){
	long n,q; cin >> n >> q;
	int MAX_N=0; long MAX_POW=1;
	while(q>MAX_POW) MAX_N++,MAX_POW*=2;
	long a[300000]={0}; long num[300000];
	memset(num,-1,sizeof(num));
	map<long,long> f;
	long MAX_POW_tmp=MAX_POW; long curr=0;
	for(long i=0;i<q;i++){
		long tmp,TMP; cin >> tmp >> TMP;
		tmp--; //tmpはinputでは1base、処理は0base
		if(f.find(tmp)==f.end()) f[tmp]=curr++, num[f[tmp]]=tmp;
		a[f[tmp]]+=TMP; long acc=0; MAX_POW=MAX_POW_tmp;
		long next_N=f[tmp]/2;
		//以下seg tree
		for(int j=1;j<=MAX_N;j++){
			long prev_N=next_N*2;
			if(a[acc+prev_N]>a[acc+prev_N+1] || (a[acc+prev_N]==a[acc+prev_N+1] && num[acc+prev_N]<num[acc+prev_N+1]) )
				a[acc+next_N+MAX_POW]=a[acc+prev_N], num[acc+next_N+MAX_POW]=num[acc+prev_N];
			else a[acc+next_N+MAX_POW]=a[acc+prev_N+1],num[acc+next_N+MAX_POW]=num[acc+prev_N+1];
			acc+=MAX_POW; MAX_POW/=2; next_N/=2;
		}
		//以上seg tree
		cout << num[acc]+1 << ' ' << a[acc] << '\n';
	}
}

Measured memory_bytes: 11832
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-7
long long mod = 1e9 +7;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
int n , m , ans[1005][1005];
char arr[1005][1005];
bool InRange(int i , int j)
{
    if(i < n && i >= 0 && j < m && j >= 0)
        return true;
    return false;
}
ll solve(int i , int j)
{
    if(i == n - 1 && j == m - 1)
        return 1;
    if(ans[i][j] != -1)
        return ans[i][j];
    ll anss = 0;
    if(arr[i][j + 1] == '.' && InRange(i , j + 1))
        anss += solve(i , j + 1);
    if(arr[i + 1][j] == '.' && InRange(i + 1 , j))
        anss += solve(i + 1 , j);
    ans[i][j] = anss % mod;
    return anss % mod;


}

int main()
{
    em3
    cin >> n >> m;
    memset(ans , -1 , sizeof ans);
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            cin >> arr[i][j];

    cout << solve(0 , 0) % mod << endl;

    return 0;
}



Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
vector<int>G;
long long cnt;
int a[1000005];

void InsertionSort(int a[],int n,int g){
	for(int i=g;i<n;i++){
		int v=a[i];
	   int j=i-g;
	   while(j>=0&&a[j]>v){
	   	    a[j+g]=a[j];
	   	    j=j-g;
	   	    cnt++;
	   }
	   a[j+g]=v;
	}
}

void ShellSort(int a[],int n){
	int cnt=0;
	int m=2;
	for(int h=1;;){
		if(h>n)break;
		G.push_back(h);
		h=3*h+1;
	}
	for(int i=G.size()-1;i>=0;i--){
		InsertionSort(a,n,G[i]);
	}
}





int main(){
	int n;
	cin>>n;
	cnt=0;
	for(int i=0;i<n;i++)cin>>a[i];
	ShellSort(a,n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--){
		cout<<G[i];
		if(i)cout<<" ";
	}
	cout<<endl;
	cout<<cnt<<endl;
	for(int i=0;i<n;i++){
		cout<<a[i]<<endl; 
	}
} 


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

long int Lucas(int x);

long int memo[100];

int main() {
  int n;
  cin >> n;
  cout << Lucas(n);
}

long int Lucas(int n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n] != 0) return memo[n];
  else return memo[n] = (Lucas(n-1) + Lucas(n-2));
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
void f(int n){
    // Your code here!
    ll s[n];
    ll tot=0;
    for(int i=0;i<n;i++){
        cin>>s[i];
        tot+=s[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        if(tot/n>=s[i])ans++;
    }
    cout<<ans<<endl;
}
int main(void){
    while(true){
        int N;
        cin>>N;
        if(N==0)break;
        f(N);
    }
    return 0;
}



Measured memory_bytes: 3156
#include<stdio.h>
    int main(void)
    {
      int A,B,C;
      scanf("%d %d",&A,&B);
      C=A+B;
      if(A%3 == 0 || B%3 == 0 || C%3 == 0){
        printf("Possible\n");
      } else {
        printf("Impossible\n");
      }
      return 0;
    }

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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define eb emplace_back
#define pb push_back
#define lli long long int
#define PI 3.14159265358979
#define modn 1000000007
#define NL '\n'

using namespace std;

typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< bool > vb;
typedef vector< string > vs;
typedef vector< lli > vli;
typedef vector< vector< char > > vvc;
typedef vector< vector< int > > vvi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef pair< lli, int> pli;
typedef pair< lli, lli> pll;
typedef set< int > si;
typedef set< ii > sii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	#ifdef LOCAL_TEST
		clock_t z = clock();
    	ifstream h("in");
	    ofstream g("out");
	#else
	    #define h cin
	    #define g cout
	#endif // LOCAL_TEST
	
	int n;
	h >> n;
	vi v(n);
	f(i, 0, n, 1)
		h >> v[i];
	f(i, 0, n, 1){
		if (v[i] % 2 == 0 && v[i] % 3 != 0 && v[i] % 5 != 0){
			g << "DENIED";
			return 0;
		}
	}
	g << "APPROVED";
	
	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif // LOCAL_TEST
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    long long V[N];

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

    long long a=0;
    long long t=0;
    for(int i=0;i<N;i++){
        if(a<=V[i])
            a=V[i];
        else{
            a=a-V[i];
            t=t+a;
            V[i]=V[i]+a;
            a=V[i];
        }
    }
    cout<<t<<endl;
}


Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a); i < (b); ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1); i >= (b); --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) RP(__i,n)
template<class T,class U>
bool cmax(T & a, const U & b) {return a < b ? a = b, 1 : 0;}
template<class T,class U>
bool cmin(T & a, const U & b) {return b < a ? a = b, 1 : 0;}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define CLR(a) (a).clear()
#define BK(a) ((a).back())
#define FT(a) ((a).front())
#define DB(a) (a).pop_back()
#define DF(a) (a).pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {cerr<<s<<endl;};
template<class T, class ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		for (char x : "([{") c += *s == x;
		for (char x : ")]}") c -= *s == x;
	}
	cerr<<" = "<<a;
	if (sizeof...(b)) {
		cerr<<", ";
        ++s;
    }
    _BG(s,b...);
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD() {return 1;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<class T, class ... TT>
bool RD(T & a, TT & ... b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define DR(T,...) T __VA_ARGS__; RD(__VA_ARGS__)
#define RI(...) DR(int,__VA_ARGS__)

/* For it's time for you to fulfill your output. */
void PT(const char & a) {putchar(a);}
void PT(char const * const & a) {fputs(a, stdout);}
void PT(const double & a) {printf("%.16f", a);}
void PT(const int & a) {printf("%d", a);}
void PT(const ll & a) {printf("%lld", a);}

/* The line will last forever! */
template<char s = ' ', char e = '\n'>
void PL() {if (e) PT(e);}
template<char s = ' ', char e = '\n', class T, class ... TT>
void PL(const T & a, const TT & ... b)
{PT(a); if (sizeof...(b) && s) PT(s); PL<s,e>(b...);}

/* Good Luck && Have Fun ! */
const int C = 4e6 + 87;
bitset<C> dp;
int main()
{
    dp[0] = 1;
    RI(n);
    int s = 0;
    while (n--) {
        RI(a);
        dp |= dp << a;
        s += a;
    }
    REP(x,(s+1)/2,C)
        if (dp[x]) {
            PL(x);
            return 0;
        }
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int a[3][3],vis[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
			vis[i][j]=0;
		}
	}
	int n,t;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(a[j][k]==t)
					vis[j][k]=1;
			}
		}
	}
	/*for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cout<<vis[i][j]<<" ";
		}
		cout<<endl;
	}*/
	for(int i=0;i<3;i++){
		int flag=0;
		for(int j=0;j<3;j++){
			if(vis[i][j]==0) flag=1;
		}
		if(flag==0){
			cout<<"Yes\n"; return 0;
		}
	}
	for(int i=0;i<3;i++){
		int flag=0;
		for(int j=0;j<3;j++){
			if(vis[j][i]==0) flag=1;
		}
		if(flag==0){
			cout<<"Yes\n"; return 0;
		}
	}
	int flag=0;
	for(int i=0;i<3;i++){
		if(vis[i][i]==0)
			flag=1;
	}
	if(flag==0){
		cout<<"Yes\n";
		return 0;
	}
	flag=0;
	for(int i=0;i<3;i++){
		if(vis[i][3-i-1]==0){
			flag=1;
		}
	}
	if(flag==0){
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
q, h, s, d = map(int, input().split())
n = int(input())

if n%2 == 0:
    print(min(n*4*q, n*2*h, n*s, n//2*d))
else:
    print(min((n-1)*4*q, (n-1)*2*h, (n-1)*s, (n-1)//2*d) + min(4*q, 2*h, s))

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

using namespace std;
int main(){
  vector<int> a;
  int x;
  cin >> x;
  int i=1;
  while(x!=0){
  	cout << "Case " << i << ": "<<x<<endl;
  	i++;
  	cin>>x;
  }
  return 0;
}


Measured memory_bytes: 2980
#include <iostream>

using namespace std;

int main()
{
	int H, N;
	cin >> H >> N;
	
	long long s = 0;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		s += A;
	}
	if (s >= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#import<cstdio>
int main(){for(int n,a,b,c,x,i,t,y[101];scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n;printf("%d\n",t>10000?-1:t)){for(i=0;i<n;)scanf("%d",y+i++);for(t=i=0;t<10001&i<n;x=(a*x+b)%c,t++)if(y[i]==x&&++i==n)break;}}

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


int main() {
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n) cin >> h[i];

    sort(h.begin(), h.end());
    int ans = h[n-1] - h[0];
    for(int i = 0; i+k-1 < n; i++){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //初期化
  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) sizes.push_back(1);
    return;
  }

  //頂点nの根
  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size(ll n) {
    return sizes[root(n)];
  }

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    sizes[root(a)] += size(b);
    parent[root(b)] = root(a);
    return;
  }
};

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

  union_find uf;
  uf.init(n);

  vll a(m), b(m), c(k), d(k);
  vector<vll> nx(n);
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    uf.unite(a[i] - 1, b[i] - 1);
    nx[a[i] - 1].push_back(b[i] - 1);
    nx[b[i] - 1].push_back(a[i] - 1);
  }
  vll cnt(n, 0);
  for (ll i = 0; i < k; i++) {
    cin >> c[i] >> d[i];
    if (uf.is_united(c[i] - 1, d[i] - 1)) {
      cnt[c[i] - 1]++;
      cnt[d[i] - 1]++;
    }
  }

  for (ll i = 0; i < n - 1; i++) {
    cout << uf.size(i) - 1 - nx[i].size() - cnt[i] << " ";
  }
  cout << uf.size(n - 1) - 1 - nx[n - 1].size() - cnt[n - 1] << endl;
}

Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string S;
  ll K;
  cin >> S >> K;
  ll same = 0, tmp = 0;  //連続部分
  int k = 0;
  bool t = false, start = false;
  unordered_map<char, int> onaji{};
  onaji[S[0]]++;
  REP(i, S.size() - 1) {
    onaji[S[i]]++, onaji[S[i + 1]]++;
    if (S[i] == S[i + 1] && !t) {
      start = true;
      t = true;
      k = i;
    } else if (S[i] != S[i + 1] && start && t) {
      same += (i - k + 1);
      tmp += (i - k + 1) / 2;
      k = -1;
      t = false;
    }
  }
  if (t) {
    same += (S.size() - k);
    tmp += (S.size() - k) / 2;
  }
  string s = S;
  s.erase(unique(s.begin(), s.end()), s.end());
  if ( s.size() == 1) {
    cout << S.size() * K / 2 << endl;
    return 0;
  }
  if (S[0] != S[S.size() - 1]) {
    cout << tmp * K << endl;
    return 0;
  }
  ll a = 0, b = 0;
  char c = S[0];
  REP(i, S.size()) {
    if (S[i] == c) {
      a++;
    } else {
      break;
    }
  }
  c = S[S.size() - 1];
  REP(i, S.size()) {
    if (S[S.size() - 1 - i] == c) {
      b++;
    } else {
      break;
    }
  }
  cout << tmp * K - (K - 1) * (a / 2 + b / 2 - (a + b) / 2) << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  vector<int> a(5);
  rep(i, 5) { cin >> a[i]; }
  rep(i, 5) {
    if (a[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(6);
    int N, K, T, U, V, L;
    cin >> N >> K >> T >> U >> V >> L;
    vector<int> D(N);
    for(int i = 0; i < N; i++) cin >> D[i];
    double ans = 0;
    double ut = 1.0 / U, vt = 1.0 / V;
    int carrot = 0, pos = 0, dist;
    bool accel = false;
    for(int now = 0; now < L; now++)
    {
        if(pos < N && now == D[pos])
        {
            carrot++; 
            pos++;
        }
        if(carrot > K)
        {
            accel = true;
            carrot--;
            dist = V * T;
        }
        else if(not accel && carrot > 0)
        {
            accel = true;
            carrot--;
            dist = V * T;
        }
        if(accel)
        {
            ans += vt;
            dist--;
            if(dist == 0) accel = false;
        }
        else ans += ut;
    }
    cout << ans << endl;
    return 0;
}




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

string columns = "zabcdefghijklmnopqrstuvwxy";

int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    ifstream in("in.txt");
    cin.rdbuf(in.rdbuf());
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long N;
    cin >> N;
    
    string name;
    string id;
    while (N > 0) {
        long long mod = N % 26;
        id.insert(id.begin(), columns[N % 26]);
        if (mod == 0) {
            N -= 26;
        }
        N /= 26;
    }
    
    //reverse(name.begin(), name.end());
    
    cout << id << endl;
    
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin>>S;
    long long  sum=0;
    if(S.size()==1){
        cout <<S.at(0)<<endl;
        return 0;
    }
    bool AAA=true;
    for(int i=1;i<S.size();i++){
        if(S.at(i)!='9'){
            AAA=false;
        }
    }
    if(AAA){
    sum = S.at(0)-'0'+9*(S.size()-1);
    cout<< sum<<endl;
    }
    else{
     sum = S.at(0)-'0'-1+9*(S.size()-1);
    cout<< sum<<endl;       
    }
}

Measured memory_bytes: 3612
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 998244353;

long double PI = 4*atan(1);
long double eps = 1e-12;



int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    ll n,m; cin >> n >> m;
    ll a[20000] = {};
    ll sum = 0;
    FOR(i,0,m) {
        cin >> a[i];
        sum += a[i];
    }
    
    cout << ((n - sum >= 0) ? n - sum : -1) << endl;
    
    
    
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


Measured memory_bytes: 3804
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B,C=get_i
if A==B and B==C
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>c) swap(a,c);
	if((c-a+c-b)&1)
	{
		printf("%d\n",(c-a+c-b+3)/2);
		return 0;
	}
	else 
	{
		printf("%d\n",(c-a+c-b)/2);
		return 0;
	}
	return 0;
}

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

int main(){
    int A = 0, B = 0;
    for(long i = 0; i < 1000000000000000; i++)
      if(1 < 2) A++;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>

int main() {
  int num;
  std::cin >> num;

  std::string color_count = "Three";
  for (int i = 0; i < num; i++) {
    std::string color;
    std::cin >> color;
    if (color == "Y") {
      color_count = "Four";
      break;
    }
  }
  std::cout << color_count << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>

#define rep(i,m,n) for(unsigned long long int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	rep(i, a, b + 1) {
		if (i%k == 0) {
			cout << "OK" << '\n';
			return 0;
		}
	}
	cout << "NG" << '\n';

	return 0;
}

Measured memory_bytes: 3624
from collections import Counter
n = int(input())

l =  [int(i) for i in input().split()]

c = Counter(l)

m = int(input())

ans = sum(l)
for i in range(m):
    x,y = [int(i) for i in input().split()]
    
    ans += (y-x) * c[x]
    print(ans)
    
    c[y] += c[x]
    c[x] = 0



Measured memory_bytes: 24188
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x = na()

minc = 99999999999999999
for u in range(1, 101):
    cost = 0
    for v in x:
        cost += (v-u)*(v-u)
    minc = min(cost, minc)
print(minc)


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

vector<int> v(5, 0);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i = 0; i < 5; ++i){
        cin >> v[i];
    }
    for(int i = 0; i < 5; ++i){
        if(!v[i]){
            cout << i + 1;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long lli;
const int NMAX = 10000006;

lli fact[NMAX];
lli inv_fact[NMAX];
lli inv[NMAX];
bool sieve[NMAX];

lli c(lli a, lli b){
	return (fact[a] * ((inv_fact[b] * inv_fact[a-b]) % MOD)) % MOD;
}

signed main(){
	for(int i=2; i<NMAX; i++){
		if(!sieve[i])
			for(int j=i*2; j<NMAX; j+=i)
				sieve[j] = 1;
	}
	
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < NMAX; ++i)
    	inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
    
    for(int i=2; i<NMAX; i++){
    	fact[i] = (i * fact[i-1]) % MOD;
    	inv_fact[i] = (inv[i] * inv_fact[i-1]) % MOD;
	}
	
	lli n, m;
	cin >> n >> m;
	map <lli, lli> pri_fac;
	while(m > 1){
		for(int i=2; i<=m; i++){
			if(!sieve[i] and m % i == 0){
				m /= i;
				pri_fac[i]++;
				break;
			}
		}
	}
	
	lli ans = 1;
	for(map<lli, lli>::iterator it=pri_fac.begin(); it!=pri_fac.end(); it++){
		lli loc = c(n + it->second - 1, n - 1);
		ans = (ans * loc) % MOD;
	}
	
	cout << (ans) % MOD << endl;
	return 0;
}

Measured memory_bytes: 244352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int total = A + B;
		if(total >= 10) {
			System.out.println("error");
		}else {
			System.out.println(total);
		}
	}

}


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

int main() {
  int A, B;
  scanf("%d%d", &A, &B);

  if (A >= 13) {
    printf("%d", B);
  } else if (6 <= A && A <= 12) {
    printf("%d", B / 2);
  } else if (A <= 5) {
    printf("%d", 0);
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    vector<char> v(1000000);
    ll f, r, i;
    f = r = 300000;
    for(i = 0; i < s.length(); i++) {
    	v[r++] = s[i];
    }
    f--;
    ll q;
    cin>>q;
    while(q--) {
    	ll t, f1;
    	char c;
    	cin>>t;
    	if(t == 1) {
    		swap(f, r);
    	} else {
    		cin>>f1>>c;
    		if(f1 == 1) {
    			if(f <= r) {
    				v[f--] = c;
    			} else {
    				v[f++] = c;
    			}
    		} else {	
    			if(r >= f) {
    				v[r++] = c;
    			} else {
    				v[r--] = c;
    			}
    		}
    	}
    }
    if(f <= r) {
    	for(i = f + 1; i < r; i++) {
    		cout<<v[i];
    	}cout<<"\n";
    } else {
    	for(i = f - 1; i > r; i--) {
    		cout<<v[i];
    	}cout<<"\n";
    }
}

Measured memory_bytes: 1744
#include <stdio.h>
#include<math.h>
using namespace std;

int main(){
	int N;
	double x_a,y_a,r_a,x_b,y_b,r_b,dist;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&x_a,&y_a,&r_a,&x_b,&y_b,&r_b);

		if(r_a > r_b){
			dist = sqrt((x_a -x_b)*(x_a-x_b)+(y_a-y_b)*(y_a-y_b));
			if(dist < (r_a-r_b))printf("2\n");
			else if(dist >= (r_a-r_b) && dist <= (r_a+r_b))printf("1\n");
			else{
				printf("0\n");
			}
		}else{	//r_a < r_b
			dist = sqrt((x_b -x_a)*(x_b-x_a)+(y_b-y_a)*(y_b-y_a));
			if(dist < (r_b-r_a))printf("-2\n");
			else if(dist >= (r_b-r_a) && dist <= (r_b+r_a))printf("1\n");
			else{
				printf("0\n");
			}
		}
	}

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

long int W = 1e+9+7;
int main(void){
    int n;
    cin >> n;
    vector<long int> h(n),dp(n,1000000000+5);
    rep(i,n){
        cin >> h[i];
    }
    dp[0]=0;
    rep(i,n-1){
        if(i+1<n && dp[i+1] > dp[i]+abs(h[i]-h[i+1])){
            dp[i+1] = dp[i]+abs(h[i]-h[i+1]);
        }
        if(i+2<n && dp[i+2] > dp[i]+abs(h[i]-h[i+2])){
            dp[i+2] = dp[i]+abs(h[i]-h[i+2]);
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<int> a(N - 1), b(N - 1);
    Graph G(N);
    for(int i = 0; i < N - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    int M = 0, root = -1;
    for(int i = 0; i < N; i++) {
        if(M < G[i].size()) {
            M = G[i].size();
            root = i;
        }
    }
    queue<int> q;
    q.push(root);
    vector<int> visit(N);
    visit[root] = 1;
    map<pair<int, int>, int> edge;
    vector<set<int>> color(N);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        int c = 1;
        for(auto v: G[u]) {
            if(visit[v] != 0) continue;
            visit[v] = 1;
            pair<int, int> w(u, v), x(v, u);
            while(color[u].count(c) || color[v].count(c)) c++;
            edge[w] = c; edge[x] = c;
            color[u].insert(c); color[v].insert(c); 
            q.push(v);
            c++;
        }
    }
    cout << M << endl;
    for(int i = 0; i < N - 1; i++) {
        pair<int, int> p(a[i], b[i]);
        cout << edge[p] << endl;
    }
    return 0;
}

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

main(){
    int N;
    int x[110000];
    int y[110000];
    int t[110000];

    cin >> N;
    x[0] = 0;
    y[0] = 0;
    t[0] = 0;

    for (int i = 1; i <= N;i++) cin >> t[i] >> x[i] >> y[i];
    bool arrive = true;
    int dist = 0;
    int dt = 0;

    for (int j = 1; j <= N; j++){
        dt = t[j] - t[j-1];
        dist = abs(x[j] - x[j-1]) + abs(y[j] - y[j-1]);
        if (dist > dt) {
            arrive = false;
            break;
        }
        if (dist % 2 != dt % 2) {
            arrive = false;
            break;
        }
    }

    if (arrive) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
} 

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

int main() {
  char S[100];
  int N;
  cin >> S;
  N = strlen(S);
  int TF = 1;
  for (int i=0; i <= (N-2)/2 - i; i++) {
    if (S[i] != S[(N-2)/2 - i]) TF = 0;
  }
  for (int i=0; i < (N-1)/2; i++) {
    if (S[i] != S[(N+2)/2 + i]) TF = 0;
  }
  if (TF) cout << "Yes\n";
  else cout << "No\n";   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;
#define INF INT_MAX

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int ans = INF;
  for(int i=0;i<n-2;i++){
    int num = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';
    ans = min(ans,abs(num-753));
  }
  cout << ans << endl;
}

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

int main(){
  char b;
  map<char,char> m;
  m['A'] = 'T';
  m['T'] = 'A';
  m['G'] = 'C';
  m['C'] = 'G';
  cin >> b;
  cout << m[b] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		while(sc.hasNext()) {
			int[] cards = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			int ans = 0;
			for(int i = 0; i < 10; i++) {
				if(cards[i] == a || cards[i] == b || cards[i] == c) {
					continue;
				}
				if(20 - (a + b + cards[i]) >= 0) ans++;
			}
			System.out.println((ans / 7.0 >= 0.5) ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 12000
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

vector<bool> isNotPrime(1100000);
int solve(long long N) {
    long long current = 2;
    int ans = 0;
    while (current * current <= N) {
        int count = 0;
        while (N % current == 0) {
            N /= current;
            count++;
        }
        int c = 1;
        while (c <= count) {
            ans++;
            count -= c;
            c++;
        }
        while(true) {
            current++;
            if (!isNotPrime[current]) {
                break;
            }
        }
    }
    
    if (current <= N) {
        ans += 1;
    }
    return ans;
}

int main(){
//    cout << fixed << setprecision(10);
    
    for (int i = 2; i < 1100000; i++) {
        if (isNotPrime[i] == false) {
            for (int j = i + i; j < 1100000; j+=i) {
                isNotPrime[j] = true;
            }
        }
    }
    
    long long N;
    cin >> N;

    cout << solve(N);

    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        int x = 0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'I') {
                x++;
                if (x > max) {
                    max = x;
                }
            } else {
                x--;
            }
        }
        System.out.println(max > 0 ? max : "0");
        bw.flush();
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

typedef pair <string, int> P;

#define mp(a, b) make_pair(a, b)

char diff(char a, char b)
{
	if (a != 'r' && b != 'r') return 'r';
	if (a != 'g' && b != 'g') return 'g';
	if (a != 'b' && b != 'b') return 'b';
	return 'a';
}

bool check(string str)
{
	char c = str[0];
	for (int i = 0; i < str.length(); i++){
		if (c != str[i]) return false;
	}

	return true;
}

int main(void)
{
	string str;

	while (cin >> str){
		if (str == "0") return 0;

		int ret = -1, a;
		queue < P > q;
		map <string, bool> memo;
		q.push(mp(str, 0));
		while (!q.empty()){
			P now = q.front();
			q.pop();
			if (memo[now.first]){
				continue;
			}
			memo[now.first] = true;
			if (check(now.first)){
				ret = now.second;
				break;
			}
			for (int i = 0; i < now.first.length()-1; i++){
				if (now.first[i] != now.first[i + 1]){
					string tmp = now.first;
					tmp[i] = diff(now.first[i], now.first[i + 1]);
					tmp[i + 1] = diff(now.first[i], now.first[i + 1]);
					q.push(mp(tmp, now.second + 1));
				}
			}
		}

		if (ret >= 0) cout << ret << endl;
		else cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 3196
from decimal import *
#getcontext().prec = 20      # デフォルト28桁のところを20桁にする

a,b,c = map(int,input().split())
a = Decimal(a).sqrt()
b = Decimal(b).sqrt()
c = Decimal(c).sqrt()

if a+b >= c:
  print("No")
else:
  print("Yes")

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define go(i,s) for(int i = head[s]; i; i = e[i].next)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>

const int maxn = 100050;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

int n, a[maxn];

bool judge(int x)
{
	bool vis = false; //meet itself
	int g = x;
	ll w = x;
	fo(i,1,n)
	{
		if(g == a[i] && !vis)
		{
			vis = true;
			continue;
		}
		if(w*2ll < a[i]) return false;
		w += a[i];
	}
	return true;
}

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int l, r, mid, x, ans = 0;
	l = 1; r = n;
	while(l <= r)
	{
		mid = l + r >> 1;
		if(judge(a[mid])) x = mid, r = mid - 1;
		else l = mid + 1;
	}
	fo(i,1,n) if(a[i] >= a[x]) ++ ans;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 640
import numpy as np

if __name__ == "__main__":
    n,x = map(int, input().split())
    l = list(map(int, input().split()))
    d = []
    for i in range(n + 1):
        if i == 0:
            d.append(0)
        else:
            d.append(d[i-1] + l[i-1])

    answer_array = np.array(d) <= x
    print(sum(answer_array))


Measured memory_bytes: 12420
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main(void)
{
  long long int n,n3,n5,n15,sum,sum3,sum5,sum15;

  scanf("%lld",&n);

  sum=(n*(n+1))/2;
  n3=n/3;
  n5=n/5;
  n15=n/15;
  sum3=((3+3+3*(n3-1))*n3)/2;
  sum5=((5+5+5*(n5-1))*n5)/2;
  sum15=((15+15+15*(n15-1))*n15)/2;

  sum=sum-sum3-sum5+sum15;
  printf("%lld",sum);

	return 0;
}


Measured memory_bytes: 1732
#include <stdio.h>
int n,q,i,j,cou,a,b,d,m;
bool w;
int main() {
    scanf("%d",&n);
    int s[n];
    for(j=0;j<n;j++){
        scanf("%d",&s[j]);
    }
    scanf("%d",&q);
    int t[q];
    for(i=0;i<q;i++){
        scanf("%d",&t[i]);
    }
    cou = 0;
    
    for(i=0;i<q;i++){
        a = n;
        b = 0;
        d = 1;
        w = true;
        while((a-b)/2>=d &&w == true){
            m = (a+b)/2;
            if(t[i]<s[m]){
                a = m;
            }else if(t[i]>s[m]){
                b = m;
            }else w = false;
        }
        if(s[m] == t[i]||s[a] == t[i]) cou = cou +1;
    }
    printf("%d\n",cou);
    return 0;
}


Measured memory_bytes: 3220
import sys
input = sys.stdin.readline

import heapq
import copy
def main(): 
    A,B = map(int,input().split())
    if A <= 5:
        print(0)
    elif A<=12:
        print(B//2)
    else:
        print(B)
            
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> b(n-1);
  for(int i=0; i<n-1; i++){
    cin >> b[i];
  }
 
  vector<int> a(n);
  a[0]=b[0];
  a[n-1]=b[n-2];
  
  for(int j=1; j<n-1; j++){
    a[j]=min(b[j-1], b[j]);
  }
  
  int64_t sum=0;
  for(int k=0; k<n; k++){
    sum += a[k];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3584
N = int(input())
SP = [list(input().split()) for _ in range(N)]

for i in range(N):
    SP[i].append(i+1)
  
ans = sorted(SP, key=lambda x:(x[0], -int(x[1])))

#for i in range(N):
#    print(ans[i][2])

for i in ans:
    print(i[2])

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main(void){
    int n,m,r,ans=1000000000;
    cin>>n>>m>>r;
    vector<int> perm(r),node(r);
    vector<vector<int>> cost(n,vector<int>(n,1000000000));

    iota(perm.begin(), perm.end(), 0);

    for(int i=0;i<r;i++){
        cin>>node[i];
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        cost[a-1][b-1]=c;
        cost[b-1][a-1]=c;
    }

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            for(int k=0;k<n;k++)
                if(cost[j][k]>cost[j][i]+cost[i][k]){
                    cost[j][k]=cost[j][i]+cost[i][k];
                    cost[k][j]=cost[j][i]+cost[i][k];
                }
    
    do {
        //vにnodeをどの順番で回るか。最悪8!=40000くらい
        int tmp=0;
        for(int i=0;i<r-1;i++){
            tmp+=cost[node[perm[i]]-1][node[perm[i+1]]-1];
        }
        ans=min(ans,tmp);
    } while( next_permutation(perm.begin(), perm.end()) );
    cout<<ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int m;
  int A;
  int year;
  int n;
  int ri,tes;
  double per;
  int ans;
  cin >> m;
  for (int H = 0; H < m; H++) {
	cin >> A;
	cin >> year;
	cin >> n;
	int tmp = A;
	ans = 0;
	for (int i = 0; i < n; i++) {
	  cin >> ri >> per >> tes;
	  int risi = 0;
	  A = tmp;
	  int B;
	  if (ri == 0) {
		for (int j = 0; j < year; j++) {
		  B = A*per;
		  risi += B;
		  A -= tes;
		}
		ans = max(ans, A + risi);
	  }
	  else if (ri == 1) {
		for (int j = 0; j < year; j++) {
		  B = A*per;
		  risi = A + B - tes;
		  A = risi;
		}
		ans = max(ans, risi);
	  }
	}
	cout << ans << endl;
  }
}

Measured memory_bytes: 3064
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: usize = read_as_vec()[0];
    let a: Vec<i64> = read_as_vec();

    let mut dp: Vec<Vec<i64>> = vec![vec![0;n];2]; //dp[2][n]

    dp[0][0] = a[0];
    dp[1][0] = -a[0];


    for i in 1..n{
        dp[0][i] = cmp::max(dp[0][i-1]+a[i], dp[1][i-1]-a[i]);
        dp[1][i] = cmp::max(dp[0][i-1]-a[i], dp[1][i-1]+a[i]);
    }

    println!("{}", dp[0][n-1]);
}


Measured memory_bytes: 8444