akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node {
  int key;
  struct node *right, *left, *p;
 }node;
typedef struct node* Node;
Node root,NIL;

void insert(int);
void inorder(Node);
void preorder(Node);
int main(){
  int m, i, k;
  char string[8];
  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%s",string);
    if(strcmp(string,"insert") == 0){
      scanf("%d",&k);
      insert(k);
    }
    else if(strcmp(string,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node )malloc(sizeof(node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node r){
  if(r == NIL) return;
  inorder(r->left);
  printf(" %d",r->key);
  inorder(r->right);
}

void preorder(Node r){
  if(r == NIL) return;
  printf(" %d",r->key);
  preorder(r->left);
  preorder(r->right);
}



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

void Main()
{
    long n;
    cin >> n;
    if ( n % 2 == 1) {
        cout << 0 << endl;
        return;
    }

    long d = 10;
    long ans = 0;
    while (d <= n) {
        ans += n / d;
        d *= 5;
    }
    cout << ans << endl;

    // (2*5の倍数)*1 + (2*5^2の倍数)*1 + (2*5^3の倍数)*1 ...
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int n, x;
int a[105];

signed main(){
  scanf("%ld %ld", &n, &x);
  for(int i = 0; i < n; i++){
    scanf("%ld", &a[i]);
  }
  std::sort(a, a+n);
  for(int i = 0; i < n; i++){
	if(a[i] == x){
      printf("%ld\n", i+1);
      return 0;
    }else if(a[i] > x){
      printf("%ld\n", i);
      return 0;
    }else{
      x -= a[i];
    }
  }
  printf("%ld\n", n-1);
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int rocks[100003];
int dp[100003];

int main()
{
    int n, in;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d", &in);
        rocks[i] = in;
    }
    for(int i=0; i<=n; i++)
        dp[i] = 1000000000;
    dp[1]=0;
    for(int i=1; i<n; i++)
    {
        dp[i+1]=min(dp[i+1], abs(rocks[i+1]-rocks[i])+dp[i]);
        dp[i+2]=min(dp[i+2], abs(rocks[i+2]-rocks[i])+dp[i]);
    }
    printf("%d", dp[n]);
}


Measured memory_bytes: 896
def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1] - A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    
    if K-se > mx:
        mx = K - se
    print(K - mx)
main()

Measured memory_bytes: 25840
//
// Created by 末永健悟 on 2019-05-19.
//

#include <iostream>
#include <string>

using namespace std;

int main() {
    int S;
    string result;

    cin >> S;

    int right = S % 100;
    int left = S / 100;

    bool right_m = false;
    if (right <= 12 && right >= 1) right_m = true;

    bool left_m = false;
    if (left <= 12 && left >= 1) left_m = true;

    if (!right_m && !left_m) {
        cout << "NA" << endl;
        return 0;
    }

    if (!right_m && left_m) {
        cout << "MMYY" << endl;
        return 0;
    }

    if (right_m && !left_m) {
        cout << "YYMM" << endl;
        return 0;
    }

    if (right_m && left_m) {
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val ints = List.fill(n)(sc.nextInt())
    val count = solve(ints, 0)
    println(count)
  }

  @tailrec
  def solve(ints: List[Int], actionCount: Int): Int = {
    if (ints.exists(_ % 2 != 0)){
      return actionCount
    }
    val division = ints.map(_ / 2)
    solve(division, actionCount + 1)
  }
}

Measured memory_bytes: 27204
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;

typedef long long ll;



int main(){

  int H,W,K;
  
  cin>>H>>W>>K;
  vector<int> C(H,0);
  
  string s[H];

  for(int i=0;i<H;++i){
    cin>>s[i];
  }
  //rep(i,H)cout<<s[i]<<endl;

  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      if(s[i][j]=='#'){
        C[i]|=(1<<j);
        //cout<<C[i]<<endl;
      }
    }
  }

//  rep(i,H) cout<<C[i]<<" ";
//  cout<<endl;

int ans=0;

  for(int bit=0;bit<(1<<H);++bit){
    vector<int> vec;
    for(int i=0;i<H;++i){
      if(bit&(1<<i)){
        vec.push_back(C[i]);
      }
    }


    for(int bt=0;bt<(1<<W);++bt){
      int count=0;
      for(int j=0;j<vec.size();++j){
        count+=__builtin_popcount(vec[j]&bt);
      }
      if(count==K){
        ++ans;
      }
     
    }

  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if (S == "SAT") cout << 1;
  if (S == "FRI") cout << 2;
  if (S == "THU") cout << 3;
  if (S == "WED") cout << 4;
  if (S == "TUE") cout << 5;
  if (S == "MON") cout << 6;
  if (S == "SUN") cout << 7;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define END system("PAUSE");return 0
string s;
int x, y;
signed main() {
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == '0')x++;
		else y++;
	}
	cout << min(x, y) * 2 << endl;
	END;
}


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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll A,B,K;
int main(){
  cin >> K >> A >> B;
  if(B-A<=2||K<=A-1) cout << K+1;
  else if((K-A+1)%2==1) cout << (K-A+1)/2*(B-A)+A+1;
  else cout << (K-A+1)/2*(B-A)+A;
  return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int f(int n)
{
	if (n == 2)
	{
		return 2;
	}
	else if (n == 4 || n == 6 || n == 9 || n == 11)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int x, y;
	cin >> x >> y;
	if (f(x) == f(y))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    long double pi = acos(-1);
    long double hangle = (2*pi/720)*(h*60 + m);
    long double mangle = (2*pi/60)*m;
    long double dif = abs(hangle - mangle);
    if (dif == pi) {
        cout << a + b;
        return 0;
    }
    if (dif > pi) {
        dif = 2*pi - dif;
    }
    long double c = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(dif));
    cout << setprecision(40) << c;
}


Measured memory_bytes: 4092
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
stc=[A.pop()]
now=0
ans=0
while len(A)>0:
    new=A.pop()
    stc.append(new)
    stc.append(new)
    ans+=stc[now]
    now+=1

print(ans)
    


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DBG(fmt, ...)
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;

    cin >> N;
    vector<ll> array(N, 0);

    std::unordered_map<string,int> table;
    REP(i, N){
        string c;
        cin >> c;
        table[c]++;
    }

    const char* title[]={"AC","WA","TLE","RE"};

    for(int i = 0 ; i < 4; i++ ){
        printf("%s x %d\n", title[i], table[title[i]]);
    }

    return 0;
}


Measured memory_bytes: 3968
n, m = map(int, input().split())
 
h_list = list(map(int,input().split()))
 
way_list = []
for i in range(m):
    org = list(map(int, input().split()))
    org.sort()
    way_list.append(org)
 
bad = []
 
for j in range(m):
    way = way_list[j]
    if h_list[way[0]-1] > h_list[way[1]-1]:
        bad.append(way[1])
    elif h_list[way[0]-1] < h_list[way[1]-1]:
        bad.append(way[0])
    else:
        bad.append(way[0])
        bad.append(way[1])
 
bad = list(set(bad))
print(n - len(bad))

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

#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl;

const int P=1e9+7;
const int N=1e6+5;
const double eps=1e-9;
const int INF=1e18;

int X,Y;
int fac[N],I[N],inv[N];

void Init()
{
    fac[0]=I[0]=inv[0]=1,fac[1]=I[1]=inv[1]=1;
    for(int i=2;i<=1000000;i++){
        fac[i]=fac[i-1]*i%P;
        I[i]=(P-P/i)*I[P%i]%P;
        inv[i]=inv[i-1]*I[i]%P;
    }
}

int C(int n,int m)
{
    if(n<m) return 0;
    if(n<P&&m<P) return fac[n]*inv[m]%P*inv[n-m]%P;
    return C(n/P,m/P)*C(n%P,m%P)%P;
}

signed main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    cin>>X>>Y;//X++;Y++;
    if((X+Y)%3){
    	puts("0");
    	return 0;
	}
	int tmp=(X+Y)/3;
	X-=tmp,Y-=tmp;
    int ans=0;
    Init();
    if(X<0||Y<0){
    	puts("0");
    	return 0;
	}
    ans=C(X+Y,Y);
    cout<<ans<<endl;
    return 0;
}

//Created Time  :2019/11/16 20:18:34

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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//begineer contest 139
//a

int main()
{
	string s,t;
	cin>>s;
	cin>>t;

	int ans =0;

	for (int i = 0; i < 3; ++i)
	{
		if(s[i]==t[i])
			ans++;
	}
	cout<<ans<<endl;
}

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

#define REP(i,N) for(int i=0;i<(N);++i) 

int main(){
  string S;
  cin >> S;
  int len = S.size();
  if(len < 26){
    int used[26] = {};
    REP(i, len) {
      used[S[i] - 'a'] = 1;
    }
    char ap;
    REP(i, 26) {
      if(!used[i]) {
        ap = 'a' + i;
        break;
      }
    }
    cout << S << ap << endl;
  } else {
    int change = 24;
    while(change >= 0){
      if(S[change] < S[change+1])
        break;
      --change;
    }
    if(change >= 0){
      char min = 'z';
      for(int i = change+1; i < 26; ++i) {
        if(S[i] > S[change] && S[i] < min)
          min = S[i];
      }
      REP(i, change) {
        cout << S[i];
      }
      cout << min << endl;
    } else {
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int n,x;
    cin >> n >> x;
    vi v(n);
    int ans = n;
    rep(i, n)
    {
        cin >> v[i];
        x -= v[i];
    }
    sort(v.begin(), v.end());
    ans += x / v[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0

for i in range(10):
  x = s.find(str(i))
  if x != -1:
    for j in range(10):
      y = s.find(str(j), x + 1, n)
      if y != -1:
        for k in range(10):
          z = s.find(str(k), y + 1, n)
          if z != -1:
            ans += 1
print(ans)


Measured memory_bytes: 3060
al = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
C=input()

for i in range(len(al)):
    if al[i] == C:
        print(al[i+1])
        exit()

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

using namespace std;

int main()
{
    string s;
    int i,j,k;

    cin>>s;
    int len=s.length();

    vector<char>mystk;
    for(i=0;i<len;i++){
        if(s[i]=='B'){
            if(!mystk.empty()){
                mystk.pop_back();
            }
        }
        else mystk.push_back(s[i]);
    }
    k=mystk.size();
    for(i=0;i<k;i++){
        cout<<mystk[i];
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

A=list(map(int,input().split()))
A.sort()
A=A[::-1]
#print(A)

Al=sum(A)
for i in range(M):
    if A[i]<Al/(4*M):
        print("No")
        exit()

print("Yes")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define vll vector<ll>
#define pll vector<pair<ll,ll>>

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
    //cin>>t;
    t=1;
	start:
	while(t--){

            string s;
    cin>>s;
    if(s[s.size()-1]=='s'){
        cout<<s+"es"<<endl;
    }
    else cout<<s+"s"<<endl;


      }
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  li n,k;
  cin>>n>>k;

  vli v(n);
  rep(i,0,n)
  cin>>v[i];

  li j=0;
  rep(i,k,n)
  {
    if(v[j]<v[i])
    {
      cout<<"Yes\n";
    }
    else
      cout<<"No\n";
    j++;
  }

}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    solve();
    return 0;
}

Measured memory_bytes: 4776
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int n,k,table[100001],tmp,max = -1,pre,current,tmp_max;
	bool zeroFLG;

	while(true){
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0)break;

		for(int i=0; i <= n; i++)table[i] = 0;

		for(int i= 0; i < k; i++){
			scanf("%d",&tmp);
			table[tmp] = 1;
		}

		if(table[0] == 1){ //????´????????????´???
			pre = 0;
			current = 0;
			zeroFLG = false;	//pre??¨current?????£???????????????true

			for(int i=1; i <= n; i++){
				if(table[i] == 1){
					current++;
					if(i == n){
						if(zeroFLG){
							max = (max >= (pre+current+1))?max:(pre+current+1);
							zeroFLG = false;
						}else{
							max = (max >= current+1)?max:current+1; //????´????????????\??????1???n?????????????°?????????¨???1?????????????????¨??????
						}
					}
				}
				else{ //table[i] == 0
					if(i >1 && table[i-1] == 1){ //1????????????0?????????????????£????????§??????????????£?¶???°??¨?????§????????????
						if(zeroFLG){
							max = (max >= (pre+current+1))?max:(pre+current+1);
							zeroFLG = false;
						}else{
							max = (max >= current+1)?max:current+1;
						}

						pre = current;
						current = 0;

						if(i < n && table[i+1] == 1){	//0??§??????zeroFLG????????????????????´???
							zeroFLG = true;
						}
					}
				}
			}

			printf("%d\n",max);

		}else{
			tmp_max = 0;
			for(int i=1; i <= n; i++){
				if(table[i] == 1){
					tmp_max++;
					if(i == n){
						max = (max >= tmp_max)?max:tmp_max;
					}
				}
				else{
					max = (max >= tmp_max)?max:tmp_max;
					tmp_max = 0;
				}
			}

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

	}

    return 0;
}

Measured memory_bytes: 2992
import math


def prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    else:
        return True


while 1:
    n = int(input())
    if n == 0:
        break

    if n % 2 == 0:
        n -= 1

    for i in range(n, 3, -2):
        if prime(i) and prime(i-2):
            print(i-2, i)
            break



Measured memory_bytes: 5672
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {

    int N, K, X, A, B, D, tmp1, tmp2, i = 0, ans = 0, cst = 1;

    unsigned long long L, R;
    std::cin >> L >> R;

    ans = 2019;

    if((R-L)>=2019){
        ans = 0;
    }else if(L+1 == R){
        ans = (L*R)%2019;
    }else {
        for(unsigned long long i=L;i<=R;i++){
            for(unsigned long long j=i+1;j<=R;j++){
                unsigned long long tmp = (i*j)%2019;
                if(ans > tmp)ans = tmp;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
A,B,C,K = map(int,input().split())
s1 = 0
s2 = 0
for i in range(2):
    a = A + 2 * B
    b = B + 2 * A
    A = a
    B = b
    if i == 0:
        s1 = A - B
    else:
        s2 = A - B
if K % 2 == 1:
    if s1 < 10 ** 18:
        print(s1)
    else:
        print("Unfair")
else:
    if s2 < 10 ** 18:
        print(s2)
    else:
        print("Unfair")



Measured memory_bytes: 9128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=INF;
  string s="",t="";
  //

  // ここから
  IN2(n,s);
  Vi left;
  Vi right;
  if(s[0]=='W') left.pb(1);
  else left.pb(0);
  if(s[n-1]=='E') right.pb(1);
  else right.pb(0);
  FOR(i,1,n){
    if(s[i]=='W') left.pb(left[i-1]+1);
    else left.pb(left[i-1]);
    if(s[n-i-1]=='E') right.pb(right[i-1]+1);
    else right.pb(right[i-1]);
  }
  REV(right);
  REP(i,n){
    z = min(z, left[i]+right[i]-1);
  }
  OUT(z);
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    #endif // LOCAL_EXEC
    long long int n,i,j;
    cin>>n;
    long long int A[n][3],result[n][3];
    for(i=0;i<n;i++){
        cin>>A[i][0]>>A[i][1]>>A[i][2];
    }
    result[0][0]=A[0][0];
    result[0][1]=A[0][1];
    result[0][2]=A[0][2];
    for(i=1;i<n;i++){
        result[i][0]=A[i][0]+max(result[i-1][1],result[i-1][2]);
        result[i][1]=A[i][1]+max(result[i-1][0],result[i-1][2]);
        result[i][2]=A[i][2]+max(result[i-1][0],result[i-1][1]);
    }
    cout<<max(result[n-1][0],max(result[n-1][1],result[n-1][2]));
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n, m, Q;
  cin >> n >> m >> Q;
  vector<vector<ll>> t(n, vector<ll>(n, 0)), sum(n + 1, vector<ll>(n + 1, 0));
  vector<P> q;
  REP(i, m) {
    ll l, r;
    cin >> l >> r;
    --l, --r;
    t[l][r]++;
  }

  REP(i, Q) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    q.push_back(P(a, b));
  }

  REP(i, n) {
    sum[i][0] = 0;
    REP(j, n) { sum[i][j + 1] = sum[i][j] + t[i][j]; }
  }

  REP(i, Q) {
    ll a, b;
    a = q[i].first, b = q[i].second;
    ll ans = 0;
    FOR(j, a, b + 1) { ans += sum[j][b + 1] - sum[j][a]; }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 6512
from operator import itemgetter


n = int(input())
info = [list(map(int, input().split())) for i in range(n)]

info = sorted(info, key = itemgetter(1))
sum1 = 0
for i in range(n):
    sum1 += info[i][0]
    if sum1 > info[i][1]:
        print("No")
        exit()
print("Yes")

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


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

  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int data[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k; cin >> k;
	cout << data[k - 1] << endl;

	return 0;
}

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

#define N 10

int main(void){
    int n, i;
    int a[N];
    int cnt[N];
    int sum=1, odd=1;

    scanf("%d", &n);
    for(i=0; i<n; i++)
        scanf("%d", &a[i]);

    for(i=0; i<n; i++){
        if(a[i]&0x01) odd *= 1;
        else odd *= 2;
        sum *= 3;
    }

    printf("%d\n", sum-odd);
    

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//素数かどうかを判定する関数.
int isprime(long long int n){
	if (n == 1) return 0;
    for (long long int i=2;i*i <= n;i++){
        if (n % i == 0) return 0;
    }
    return 1;
}
 
//nの約数を返す関数.sortされてない.
vector<long long int> divisors(long long int n){
	vector<long long int> res;
	for (long long int i = 1; i * i <= n;i++){
		if (n % i == 0){
			res.push_back(i);
			if(i * i != n){
				res.push_back(n / i);
			}
		}
	}
	return res;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}
//aとbの公約数を列挙する.divisors,gcdが必要.sortされていない.
vector<long long int> common_divisors(long long int a, long long int b){
	long long int g = gcd(a, b);
	return divisors(g);
}
 
int main() {
	ll a, b;
	cin >> a >> b;
	vector<ll> cd = common_divisors(a, b);
	int ans = 0;
	rep(i, cd.size()){
		if(isprime(cd[i]))
			ans++;
	}
	cout << ans + 1 << endl;
 
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

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


    }


Measured memory_bytes: 256
// Created by bisuk on 2014/09/18.
//
public class Main
{
	public static void main(String[] args)
	{
		for(int j=1;j<10;j++){
			for(int i=1;i<10;i++){
				//System.out.println("%dx%d=%d",i,j,i*j);
				System.out.println(j+"x"+i+"="+(i*j));
			}
		}
	}
}

/*
	> javac xxx.java
	> java xxx
*/

Measured memory_bytes: 16996
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
// #define fill(x, v) memset(x, v, sizeof(x))
#define FER(i,a,b) for(int i=int(a); i< int(b); ++i)
#define IFR(i,a,b) for(int i=int(a); i>=int(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
// #define N 21000000
// #define M 19
// #define mod 
#define mod  998244353
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 3000000000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef int ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<vi> vv;
typedef vector<ii> vii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}
 
inline ll add(ll a, ll b, ll m) { return a+b < m? a+b : a+b-m;}
inline ll rem(ll a, ll b, ll m) { return a >= b? a - b: a- b + m;}
inline ll mul(ll a, ll b, ll m) { return (long long) a*b%m;}
inline void Mul(ll &a, ll b, ll m) { a = (long long) a*b%m;}
inline ll bp(ll a, ll p, ll m){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, m)) (p & 1) && (Mul(ret, a, m), 1);
	return ret;
}
 
static inline void read(ll &x) { cin>>x;}

long double dp[1<<19];
inline long double Que(ll l, ll r){
	if(l) return dp[r-1] - dp[l-1];
	return dp[r-1];
}
int main(){
	fastio;
	ll n, k; read(n), read(k);
	long double ans = 0;
	FER(i, 0, n){
		ll x; read(x);
		ans += log2(x);
		dp[i] = ans;
	}
	FER(i, 0, n-k){
		long double a, b;
		a = Que(i, i+k);
		b = Que(i+1, i+1+k);
		if(a + 1e-10 < b){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 6868
N = int(input())
abc = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
result = []
while N>0:
    result += [abc[((N-1) % 26)]]
    N = (N-1) // 26
print("".join(result[::-1]))

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
		ll n;
		cin>>n;

		ll arr[n];
		ll sum[n+1]={0};

		for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			sum[i+1]=sum[i]+arr[i];
		}

		ll dp[n+1][n+1];

		for(ll gap=0;gap<n;gap++)
		{
			for(ll i=0,j=gap;j<n;i++,j++)
			{
				if(gap==0)
				{
					dp[i][j]=0;
				}
				else
				{
					dp[i][j]=1e18;
					for(ll k=i;k<j;k++)
					{
						ll val=sum[j+1]-sum[i];
						dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+val);
					}
				}
			}
		}

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

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int mp[1001][1001],dp[1001][1001];
int h,w,n;

void saiki(int x,int y){
  int dx[]={0,1},dy[]={1,0};
  if(y==h||x==w)cout << y+1<<" "<<x+1<<endl;
  else  saiki(x+dx[mp[y][x]],y+dy[mp[y][x]]);
}

int main(){
  while(1){
    cin>>h>>w>>n;
    if(!h&&!w&&!n)break;

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>mp[i][j];
    memset(dp,0,sizeof(dp));
    dp[0][0]=n-1;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	dp[i][j+1]+=dp[i][j]/2+mp[i][j]*dp[i][j]%2;
	dp[i+1][j]+=dp[i][j]/2+!mp[i][j]*dp[i][j]%2;
	if(dp[i][j]%2)mp[i][j]=!mp[i][j];
      }

    saiki(0,0);
  }


  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int data[n], ans;
  vector<int> up(n/2), dn(n/2);
  for(int i = 0; i < n; i++){
    cin >> data[i];
    if (i%2==0) { up[i/2] = data[i]; }
    else  { dn[(i-1)/2] = data[i]; }
  }

  int up_tmpcnt = 1, upcount = 1, upsemicnt = 1;
  int dn_tmpcnt = 1, dncount = 1, dnsemicnt = 1;
  sort(up.begin(), up.end() );
  sort(dn.begin(), dn.end() );

  int upnum = up[0], dnnum = dn[0];
  int upmode = upnum, dnmode = dnnum;
  int upsemi = 0, dnsemi = 0;
  for(int i = 1; i < n/2; i++){
    if ( up[i] == upnum )
      up_tmpcnt++;
    if ( up[i] != upnum || i == n/2-1){
      if ( up_tmpcnt > upcount ){
        upsemicnt = upcount;
        upcount = up_tmpcnt;
        upsemi = upmode;
        upmode = upnum;
      }
      else if ( up_tmpcnt > upsemicnt ){
      	upsemicnt = up_tmpcnt;
      	upsemi = upmode;
      }
      up_tmpcnt = 1;
      upnum = up[i];
    }
    if ( dn[i] == dnnum )
      dn_tmpcnt++;
    if ( dn[i] != dnnum || i == n/2-1 ){
      if ( dn_tmpcnt > dncount ){
        dnsemicnt = dncount;
        dncount = dn_tmpcnt;
        dnsemi = dnmode;
        dnmode = dnnum;
      }
      else if ( dn_tmpcnt > dnsemicnt ){
      	dnsemicnt = dn_tmpcnt;
      	dnsemi = dnnum;
      }
      dn_tmpcnt = 1;
      dnnum = dn[i];
    }
  }
  if( upmode != dnmode ) {
    ans = n - upcount - dncount;
  }else{
    if ( upcount > dncount ){
      ans = n - upcount - dnsemicnt;
    }else if( upcount < dncount ){
      ans = n - upsemicnt - dncount;
    }else{  // upcount == dncount
      if( upsemicnt > dnsemicnt ){
        ans = n - upsemicnt - dncount;
      }else {
        ans = n - upcount - dnsemicnt;
      }
    }

    if( upcount == n/2 && dncount == n/2 ){
      ans = n/2;
    }
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
using namespace std;

typedef pair<bool,int>P;//flag,cost


int main(){
	
	
	int ans=9;
	int n;
	string s="",g,t;
	cin>>n;
	for(int i=0,j;i<n;i++){
		cin>>j;
		s+=('a'+j-1);
	}
	g=s;
	for(int i=0;i<=g.size();i++)for(int j=0;j<g.size()-1;j++)if(g[j]>g[j+1])swap(g[j],g[j+1]);
	
	queue<string>Q;
	map<string,bool>Flag;
	map<string,int>Cost;
	Q.push(s);
	Flag[ s ]=1;
	Cost[s]=0;
	
	for(int cost;!Q.empty();Q.pop()){
		s=Q.front();
		cost=Cost[s];
		
		if(cost<4){
			for(int i=0;i<g.size()-1;i++){
				for(int j=i+2;j<=g.size();j++){
					t=s;
					reverse(t.begin()+i,t.begin()+j);
					if(Flag[t]==0){
						Q.push(t);
						Flag[t]=1;
						Cost[t]=cost+1;
					}
				}
			}
		}
	}
	
	map<string,bool>Elag;
	map<string,int>Eost;
	Q.push(g);
	Elag[g]=1;
	Eost[g]=0;
	
	for(int cost;!Q.empty();Q.pop()){
		s=Q.front();
		cost=Eost[s];
		if(cost<4){
			for(int i=0;i<g.size()-1;i++){
				for(int j=i+2;j<=g.size();j++){
					t=s;
					reverse(t.begin()+i,t.begin()+j);
					if(Elag[t]==0){
						Q.push(t);
						Elag[t]=1;
						Eost[t]=cost+1;
					}
				}
			}
		}
		if(Flag[s]){
			ans=min(ans,cost+Cost[s]);
		}
	}
	
	cout<<ans<<endl;
	
	/*
	string str="abcde",r;
	for(int i=0;i<str.size()-1;i++){
		for(int j=i+2;j<=str.size();j++){
			r=str;
			reverse(r.begin()+i,r.begin()+j);
			cout<<i<<" "<<j<<" "<<r<<endl;
		}
	}
	*/
	return 0;
}


Measured memory_bytes: 140396
import java.io.*;
public class Main {

	public static void main(String[] args)throws IOException {
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String[] num=str.split(" ");
		int m=Integer.parseInt(num[0]);
		int r=Integer.parseInt(num[1]);
		int f=Integer.parseInt(num[2]);
		while (m!=-1 || r!=-1 || f!=-1){
			
			if (m==-1 || r==-1){
				System.out.println("F");
			}else if(m+r>=80){
				System.out.println("A");
			}else if(m+r>=65){
				System.out.println("B");
			}else if(m+r>=50 || f>=50){
				System.out.println("C");
			}else if(m+r>=30){
				System.out.println("D");
			}else {
				System.out.println("F");
			}
			str=br.readLine();
			num=str.split(" ");
			m=Integer.parseInt(num[0]);
			r=Integer.parseInt(num[1]);
			f=Integer.parseInt(num[2]);
		}
	}
}

Measured memory_bytes: 16936
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RS(a) string  a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
const int maxn=2e3+1;
int f[maxn];
int nCr(int n,int r)
{
    int ans=f[n];
    ans=(ans*modInverse(f[r],mod))%mod;
    ans=(ans*modInverse(f[n-r],mod))%mod;
    return ans;
}
signed main()
{
    fastio;
    f[0]=1;
    fr(i,1,maxn)
    {
        f[i]=(f[i-1]*i)%mod;
    }
    int ans=0;
    R(s);
    fr(i,1,2001)
    {
        int x=s-i*3;
        if(x<0)break;
        ans=(ans+nCr(x+i-1,i-1))%mod;


    }
    cout<<ans<<endl;


}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
 int n; cin>>n; 
 string s; cin>>s;
 int kosuu[n]; kosuu[0]=0;
  
 FOR(i,1,n){
  kosuu[i]=0;
  string t1=s.substr(0,i);
   string t2=s.substr(i,n-i);
  //cout<<t1<<" "<<t2<<endl;
  sort(ALL(t1));
  sort(ALL(t2));
   
  REP(j,t1.size()){
      if(j>0&&t1[j]==t1[j-1])continue;
      REP(k,t2.size()){
      //cout<<"今切れ目は"<<i<<"番目：t１の"<<j<<"番目：t２の"<<k<<"番目"<<endl;
            if(t2[k]==t1[j]){
                kosuu[i]++;
                break;
      }
    }
  }
  //cout<<"共通のものの種類"<<kosuu[i]<<endl;
 }
 int res=0;
 REP(i,n)if(res<kosuu[i])res=kosuu[i];
cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using i64 = long long;

i64 f(const i64 n, const i64 m, i64 a, i64 b) {
    i64 ret = a / m * n * (n - 1) / 2 + b / m * n;
    a %= m;
    b %= m;

    const i64 p = (a * n + b) / m, q = p * m - b;
    if (p > 0) {
        ret += (n - (q + a - 1) / a) * p + f(p, a, m, (a - q % a) % a);
    }
    return ret;
}

int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int n, m, a, b;
        std::cin >> n >> m >> a >> b;
        std::cout << f(n, m, a, b) << '\n';
    }

    return 0;
}


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

int a;
string s;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> a >> s;
    if (a < 3200) cout << "red\n";
    else cout << s << '\n';
}

Measured memory_bytes: 256
import math
from itertools import combinations

eps = 10 ** -7

def midpoint(a, b):
    return (a[0] + b[0]) / 2, (a[1] + b[1]) / 2

def distance(a, b):
    return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5

def within(c, r, a):
    return (a[0] - c[0]) ** 2 + (a[1] - c[1]) ** 2 <= r ** 2 + eps

def tcircle(t1, t2, t3):
    x1, y1 = t1
    x2, y2 = t2
    x3, y3 = t3
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d == 0:
        return (0.0, 0.0), -1.0
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r

def main():
    N = int(input())
    L = [tuple(map(int, input().split())) for _ in range(N)]
    br = float('inf')
    for p, q in combinations(L, 2):
        c, r = midpoint(p, q), distance(p, q) / 2
        if all(within(c, r, i) for i in L):
            return r
        ac, ar = (0.0, 0.0), 0.0
        for i in L:
            if within(c, r, i):
                continue
            pc, pr = tcircle(p, q, i)
            if pr == -1:
                break
            if ar < pr:
                ac, ar = pc, pr
        else:
            if ar < br and all(within(ac, ar, i) for i in L):
                br = ar
    return br

print(main())


Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int n;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);
		a *= a;
		b *= b;
		c *= c;
		
		if (a == b + c || b == a + c || c == a + b){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
import java.io.*;
import java.util.StringTokenizer;

public class Main {

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

        int n = nextInt();
        int[] a = new int[n];
        int[][] x = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                x[i][j] = -1;
            }
        }
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            for (int j = 0; j < a[i]; j++) {
                x[i][nextInt() - 1] = nextInt();
            }
        }
        int max = 0;
        for (int option = 0; option < (1 << n); option++) {
            boolean ok = true;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                boolean isHonestI = (option & (1 << i)) == (1 << i);
                if (isHonestI) {
                    ans++;
                    for (int j = 0; j < n; j++) {
                        boolean isHonestJ = (option & (1 << j)) == (1 << j);
                        if ((x[i][j] == 1 && !isHonestJ) || (x[i][j] == 0 && isHonestJ)) {
                            ok = false;
                            break;
                        }
                    }
                }
            }
            if (ok) max = Math.max(max, ans);
        }

        System.out.println(max);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

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

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

  while (1) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    int s[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double a2 = 0;
    for (int i = 0; i < n; i++) {
      double m = double(sum) / n;
      a2 += (s[i] - m) * (s[i] - m) / n;
    }
    cout << fixed << setprecision(8) << sqrt(a2) << endl;
  }
} 


Measured memory_bytes: 3276
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::string T;
  std::cin >> T;

  uint32_t prev_quest = 0;
  for (uint32_t i = 0; i < T.size(); i++) {
    if (T[i] == '?') {
      prev_quest++;
      T[i] = 'D';
    } else if (prev_quest) {
      if (prev_quest != 1) {
        T[i - 1] = (T[i] == 'D') ? 'P' : 'D';
      }
      prev_quest = 0;
    }
  }
  if (prev_quest) T.back() = 'D';

  std::cout << T << std::endl;

  return 0;
}

Measured memory_bytes: 3752
S = input()

A = int(S[:2])
B = int(S[2:])

if A > 0 and 12 >= A:
    if B > 0 and 12 >=B:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif B > 0 and 12 >=B:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main (){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int e = a + b;
  int f = c + d;
  if (e > f){
    cout << "Left" <<endl;
  }
  else if (e == f){
    cout << "Balanced" <<endl;
  }
  else{
    cout << "Right" <<endl;
  }
  
  
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a, b, c, x, r, ans;
int main() {
	cin>>a>>b>>c>>x;
	int i, j;
	for(i=0; i<=a; i++) for(j=0; j<=b; j++) {
		r = x - 500*i - 100*j;
		if(r>=0) r/=50, ans += r<=c;
	}
	cout<<ans;
	return 0;
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int count=0;
    int koko=0;
    for(int k=1;k<=n;k++){
        for(int i=koko;i<n;i++){
            koko=i+1;
            if(a[i]==k){
                break;
            }
            if(a[i]!=k){
                count++;
            } 
            if(count == (n-1) && k==1){
                cout <<"-1";
                return 0;
            }
        }
    }
    cout << count;

}

Measured memory_bytes: 1024