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

bool cmp(const string& lhs,const string& rhs)
{
	int lsize=lhs.size();
	int rsize=rhs.size();
	if(lsize!=rsize)
		return lsize<rsize;
	
	for(int i=0;i<lsize;i++)
		if(lhs[i]!=rhs[i])
			return lhs[i]-'0'<rhs[i]-'0';
	return false;
}

int main()
{
	const int cost[]={0,2,5,5,4,5,6,3,7,6};
	const string num[]={"0","1","2","3","4","5","6","7","8","9"};

	int N,M;
	int A[10]={};

	cin >> N >> M;
	for(int i=1;i<=M;i++)
		cin >> A[i];
	
	sort(A+1,A+M+1,greater<int>());

	string dp[10010]={};
	for(int i=0;i<=N;i++)
		dp[i]="";
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=M;j++)
		{
			if(i-cost[A[j]]<0)
				continue;
			if(dp[i-cost[A[j]]]=="" && i-cost[A[j]]!=0)
				continue;
			string nxt1=dp[i-cost[A[j]]]+num[A[j]];
			string nxt2=num[A[j]]+dp[i-cost[A[j]]];
			if(cmp(dp[i],nxt1))
				dp[i]=nxt1;
			//if(cmp(dp[i],nxt2))
				//dp[i]=nxt2;
		}
	}
	
	cout << dp[N] << endl;
	return 0;
}



Measured memory_bytes: 45568
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long long n,a[1000],s,m,p,q;
	while(cin>>n)
	{
		s=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			s+=a[i];
		}
		cin>>m;
		for(int i=0;i<m;i++)
		{
			cin>>p>>q;
			cout<<s-a[p]+q<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
S = []
for i in range(N):
    s = input()
    S.append(s)

cnt = [0]*5
M = 'MARCH'
for s in S:
    for i in range(5):
        if s[0] == M[i]:
            cnt[i] += 1

ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += cnt[i]*cnt[j]*cnt[k]

print(ans)

Measured memory_bytes: 18992
#include<stdio.h>
int main(void)
{
    int a,b,i,x = 0,y = 1;
    scanf("%d %d",&a,&b);
    if(a > b)
    {
        i = a;
        a = b;
        b = i;
    }
    for(i = 0 ; i < b ; i++)
    {
        x += a*y;
        y = y*10;
    }
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n;
int a[100010];
int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  int cnt1=0,cnt2=0,cnt4=0;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%4==0){
	cnt4++;
      }
      else{
	cnt2++;
      }
    }
    else{
      cnt1++;
    }
  }
  if(cnt4>=cnt1){
    prin("Yes");
  }
  else if(cnt1-1==cnt4&&cnt2==0){
    prin("Yes");
  }
  else{
    prin("No");
  }
  
  
  

  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
LR = [tuple(map(int,input().split())) for i in range(K)]
MOD = 998244353

dp = [1]
cumdp = [0,1]
for i in range(1,N):
    tmp = 0
    for l,r in LR:
        if i-l+1 <= 0: continue
        tmp += cumdp[i-l+1] - cumdp[max(0,i-r)]
    tmp %= MOD
    dp.append(tmp)
    cumdp.append((cumdp[-1] + tmp) % MOD)
print(dp[-1])

Measured memory_bytes: 24980
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    c = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())
    csum = sum((sum(ci) for ci in c))
    trace = sum((cij for i, ci in enumerate(c) for j, cij in enumerate(ci) if i == j))
    if csum == 3 * trace:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""
input:
3 8

output:
3 -1
"""

import sys


def ext_euclid(a, b):
    if b == 0:
        return 1, 0
    else:
        x, y = ext_euclid(b, a % b)
        x, y = y, (x - (a // b) * y)
        return x, y


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1, n2 = map(int, _input[0].split())
    print(*ext_euclid(n1, n2))

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


int main()
{
    int n,sum = 0,res = 1000;
    std::cin>>n;
    for(int i = 0;i<n;i++){
        int a;
        std::cin>>a;
        sum += a;
        if(a%10!=0){
            res = std::min(res,a);
        }
    }
    if(sum%10!=0){
        std::cout<<sum<<std::endl;
    }else{
        if(res%10!=0){
            std::cout<<sum-res<<std::endl;
        }else{
            std::cout<<0<<std::endl;
        }
    }
}

Measured memory_bytes: 256
n=int(input())
a1=[int(i) for i in input().split()]
a2=[int(i) for i in input().split()]
count=[0]*n
count[0]=sum(a1)+a2[n-1]
for i in range(n-1):
    count[i+1]=count[i]+a2[n-i-2]-a1[n-i-1]
print(max(count))

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

using ll = long long;

int main() {
    const ll MOD = 1e9 + 7;

    int n, m;
    cin >> n >> m;

    const int MAXN = 200000;
    const int MAXM = 200000;
    static ll x[MAXN], y[MAXM];
    static ll cumx[MAXN], cumy[MAXM];

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

        cumx[i] = x[i];
        if (i > 0) cumx[i] += cumx[i - 1];

        cumx[i] = (cumx[i] + MOD * MOD) % MOD;
    }

    for (int i = 0; i < m; i++) {
        cin >> y[i];

        cumy[i] = y[i];
        if (i > 0) cumy[i] += cumy[i - 1];

        cumy[i] = (cumy[i] + MOD * MOD) % MOD;
    }

    ll xterm = 0,
       yterm = 0;
    for (int i = 0; i < n; i++) {
        xterm += ((i + 1) * x[i] - cumx[i] + MOD * MOD) % MOD;
        xterm %= MOD;
    }
    for (int i = 0; i < m; i++) {
        yterm += ((i + 1) * y[i] - cumy[i] + MOD * MOD) % MOD;
        yterm %= MOD;
    }

    cout << (xterm * yterm) % MOD << endl;

    return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};int dy[4] = {0,-1,0,1};

int main() {
    int n,m;cin >> n >> m;
    vector<int> v(m);
    for(int i=0;i<m;i++){
	cin >>v[i];
    }
    int dp[m+1][n+1];
    rep(i,m+1)rep(j,n+1)dp[i][j] = 1000000;
    dp[0][0] = 0;
    for(int i=1;i<=m;i++){
	for(int j=0;j<=n;j++){
	    chmin(dp[i][j],dp[i-1][j]);
	    if(j>=v[i-1]) dp[i][j] = min(dp[i][j],min(dp[i-1][j-v[i-1]]+1,dp[i][j-v[i-1]]+1));
	}
    }
    cout << dp[m][n] << endl;
    return 0;
}




Measured memory_bytes: 7204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double  
#define mp make_pair
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    string s,t;
    cin >> s;
    t = s;
    int ans = 0;
    for (int i = 1; i < s.length(); ++i)
    {
        if (s[i] == s[i - 1])
        {
            if (s[i] == '0')
                s[i] = '1';
            else
                s[i] = '0';
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<char,char> pcc;
const ll mod=998244353;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
char s[10004];
int main()
{
	int n;
	cin>>n;
	cin>>s;
	ll ans=0;
	int r[10004],g[10004],b[10004];
	int ri=0,gi=0,bi=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='G')
		g[gi++]=i;
		else if(s[i]=='B')
		b[bi++]=i;
		else 
		r[ri++]=i;
	}
	for(int i=0;i<n;i++)
	{
		char x1=s[i];
		char x2,x3;
		for(int j=i+1;j<n;j++)
		{
			if(s[j]!=x1)
			{
				x2=s[j];
				if(x1!='G'&&x2!='G')
				{
					int y1=upper_bound(g,g+gi,j+j-i)-g;
					ans+=(ll)(gi-y1);
				}
				else if(x1!='R'&&x2!='R')
				{
					int y2=upper_bound(r,r+ri,j+j-i)-r;
					ans+=(ll)(ri-y2);
				}
				else if(x1!='B'&&x2!='B')
				{
					int y3=upper_bound(b,b+bi,j+j-i)-b;
					ans+=(ll)(bi-y3);
				}
			}
		}
	}
	char ss[10004];
	for(int i=0;i<n;i++)
	ss[i]=s[n-i-1];
	ri=0,gi=0,bi=0;
	for(int i=0;i<n;i++)
	{
		if(ss[i]=='G')
		g[gi++]=i;
		else if(ss[i]=='B')
		b[bi++]=i;
		else 
		r[ri++]=i;
	}
	for(int i=0;i<n;i++)
	{
		char x1=ss[i];
		char x2,x3;
		for(int j=i+1;j<n;j++)
		{
			if(ss[j]!=x1)
			{
				x2=ss[j];
				if(x1!='G'&&x2!='G')
				{
					int y1=upper_bound(g,g+gi,j+j-i)-g;
					ans+=(ll)(gi-y1);
				}
				else if(x1!='R'&&x2!='R')
				{
					int y2=upper_bound(r,r+ri,j+j-i)-r;
					ans+=(ll)(ri-y2);
				}
				else if(x1!='B'&&x2!='B')
				{
					int y3=upper_bound(b,b+bi,j+j-i)-b;
					ans+=(ll)(bi-y3);
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3668
fun main(args: Array<String>) = println(run {
    val s = readLine()!!
    val x = s.take(2)
    val y = s.takeLast(2)
    when {
        x !in "01".."12" && y in "01".."12" -> "YYMM"
        x in "01".."12" && y !in "01".."12" -> "MMYY"
        x in "01".."12" && y in "01".."12" -> "AMBIGUOUS"
        else -> "NA"
    }

})



Measured memory_bytes: 33384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> H >> W >> K;
    char cake[300][300];
    int map[300][300] = {0};
    int row[300] = {0};
    rep(i, H){
        rep(j, W){
            cin >> cake[i][j];
            if(cake[i][j] == '#') row[i]++;
        }
    }
    int cakenum = 1;
    bool uppest = true;
    rep(i, H){
        int nowrow = cakenum;
        if(row[i] == 0 && uppest) continue;
        uppest = false;
        if(row[i] == 0){
            rep(j, W) map[i][j] = map[i-1][j];
        }else{
            bool flag = false;
            rep(j, W){
                flag = false;
                map[i][j] = cakenum;
                if(cake[i][j] == '#' && row[i] != cakenum-nowrow+1){
                    cakenum++;
                    flag = true;
                }
            }
            if(!flag) cakenum++;
        }
    }
    rep(i, H){
        bool flag = true;
        rep(j, W){
            if(map[H-i-1][j] != 0) flag = false;
        }
        if(!flag) continue;
        rep(j, W){
            map[H-i-1][j] = map[H-i][j];
        }
    }

    rep(i, H){
        rep(j, W){
            cout << map[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1152
N = int(input())

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

flag = 1
for A_i in A:
    if A_i % 2 == 0:
        if A_i % 3 == 0 or A_i % 5 == 0:
            pass
        else:
            flag = 0
    if flag == 0:
        break

if flag == 1:
    print("APPROVED")
else:
    print("DENIED")

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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define chmin(a,b) if ((a)>(b)) { a=(b); }
#define chmax(a,b) if ((a)<(b)) { a=(b); }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);
#else
#define debug(...) 
#endif

ll f[10000000];

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

    rep0(i,n+1) f[i] = 0;
    rep1(i,n) {
        int k=0;
        while(k<=n) {
            f[k]++;
            k += i;
        }
    }

    ll ans = 0;
    rep1(i,n) {
        debug(i, f[i]);
        ans += f[i] * (ll)i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 81756
#include<stdio.h>
signed main(){
    int k,a,b;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    int sum=(b/k)*k;
    if(a<=sum){
        printf("OK\n");
    }else{
        printf("NG\n");
    }
    return(0);
    }

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    
    int s[100], sum = 0;
    rep(i, n){
        cin >> s[i];
        sum += s[i];
    }

    if(sum % 10 != 0){
        cout << sum;
        return 0;
    }
    else{
        sort(s, s+n);
        rep(i, n){
            for(int j = i; j < n; j++){
                if((sum - s[j]) % 10 != 0){
                    cout << sum - s[j];
                    return 0;
                }
            }
            sum -= s[i];
        }        
    }
    cout << 0;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) push_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = INF;
class mint {
public:
	ll x;
	mint(ll x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { 
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}
	friend ostream& operator<<(ostream& os, const mint& m){
		os << m.x;
		return os;
	}
};

ll modpow(ll x, ll n, ll p = INF) {
	if (n == 0) return 1 % p;
	if (n % 2 == 0) return modpow(x * x % p, n / 2, p);
	else return x * modpow(x, n - 1, p) % p;
}

void Main(){

	ll N;
	cin >> N;
	vl T(N), A(N);
	rep(i, N) cin >> T[i] >> A[i];
	
	ll t = T[0];
	ll a = A[0];
	
	rep2(i, 1, N){
		
		ll c1, c2;
		
		if(T[i] < t) c1 = (t + T[i] - 1) / T[i];
		else c1 = 1;
		if(A[i] < a) c2 = (a + A[i] - 1) / A[i];
		else c2 = 1;
		
		ll tmp_t = c1 * T[i];
		ll tmp_a = c1 * A[i];
		
		if(tmp_t >= t && tmp_a >= a){
			t = tmp_t;
			a = tmp_a;
			continue;
		}
		
		tmp_t = c2 * T[i];
		tmp_a = c2 * A[i];
		
		if(tmp_t >= t && tmp_a >= a){
			t = tmp_t;
			a = tmp_a;
			continue;
		}		
		
	}

	ll ans = t + a;
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}





Measured memory_bytes: 3608
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void){
int n,i,j,a[5001],b[5001],c[5001],d[5001],p=0,team1[5001],result[5001],cnt=0,z=0;

cin>>n;

for(i=0;i<5001;i++){
	a[i]=0;
	b[i]=0;
	c[i]=0;
	d[i]=0;
	team1[i]=0;
	result[i]=1;
}

p=n*(n-1)/2;

for(i=1;i<=p;i++){
	cin>>a[i]>>b[i]>>c[i]>>d[i];

	if(c[i]>d[i]){
	team1[a[i]]=team1[a[i]]+3;
	}

	else if(c[i]<d[i]){
	team1[b[i]]=team1[b[i]]+3;
	}

	else{
	team1[a[i]]=team1[a[i]]+1;
	team1[b[i]]=team1[b[i]]+1;
	}
}

for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
        if(team1[i]<team1[j]){
            result[i]=result[i]+1;
        }
    }
}
for(i=1;i<=n;i++){
    printf("%d\n",result[i]);
}

return 0;
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    rrep (i, 1, 9) {
        rrep (j, 1, 9) {
            if (i*j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
const int N = 1e5 + 5;
ll a[N];
const unsigned int M = 1000000007;
 
int main()
{
  int x,n;
  cin>>x>>n;
  int p[n];
  bool hash[200]={ 0 };
  for(int i=1;i<=n;i++)
  {
    cin>>p[i];
    hash[p[i]]=1;
  }
  for(int i=x,j=x;i>=0;i--,j++)
  {
    if(!hash[i])
    {
      cout<<i;
      break;
    }
    else if(!hash[j])
    {
      cout<<j;
      break;
    }
  }
return 0;
}



Measured memory_bytes: 3620
#include <stdio.h>

int main() {
  int number = 0, i;
  char str[5];
  scanf("%s", str);
  for(i = 0; i < 4; i++) {
    if(str[i] == '+') {
      number++;
    } else {
      number--;
    }
  }
  printf("%d\n", number);
  return 0;
}


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

int main()
{
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  int num = 0;
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> h.at(i);
  }
  vector<double> tmp(n);
  double tmin = 1000.0;
  for(i = 0; i < n; i++)
  {
    tmp.at(i) = abs(t - 0.006 * h.at(i) - a);
    if(tmp.at(i) < tmin)
    {
      tmin = tmp.at(i);
      num = i+1;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n;
int main(void) {
    cin >> n;
    ll h[n];
    rep(i,n){
        cin >> h[i];
    }
    bool flg=true;
    ll length[n]={};
    ll res=0;
    bool first;
    while(flg){
        flg=false;
        first=true;
        rep(i,n){
            if(length[i]==h[i]){
                first=true;
            }else{
                if(first){
                    first=false;
                    flg=true;
                    res++;
                }
                length[i]++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  bool ok = false;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(n==i*j) ok = true;
    }
  }
  if(ok) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define MOD 998244353
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){

    ll n;
    cin >> n;
    ll dp[3000]; dp[0] = 1;
	rep(i, n) rep2(j, 3, n + 1){
		if(i + j < n + 5){
			dp[i + j] += dp[i];
			dp[i + j] %= INF;
		}
	}
	ll ans = dp[n];
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 3556
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
 
        Scanner sc = new Scanner(System.in);
        
        int gameNum = sc.nextInt();//GAMEする回数

//        System.out.println(gameNum);

        int pointTaro = 0;
        int pointHanako = 0;
    
//    while(sc.hasNextLine()){    
        for(int i = 0; i < gameNum; i++){
 
            String cardTaro = sc.next();
            String cardHanako = sc.next();
              //     System.out.println(cardTaro + " T" + cardHanako);
              //     System.out.println(pointTaro + " H" + pointHanako); 

            if(cardTaro.compareTo(cardHanako) > 0){
                pointTaro += 3;
            }
            if(cardTaro.compareTo(cardHanako) < 0){
                pointHanako += 3;
            }
            if(cardTaro.compareTo(cardHanako) == 0){
                pointTaro += 1;
                pointHanako += 1;
            }
//            System.out.println(cardTaro + " @" + cardHanako);
//            System.out.println(pointTaro + " #" + pointHanako);
        }
        System.out.println(pointTaro + " " + pointHanako);
    }
}




Measured memory_bytes: 30604
#include<stdio.h>

int main()
{
	int a, b;
	int sumw = 0, sumb = 0, n = 0;
	while( scanf("%d,%d", &a, &b) != -1 ){
		sumw += a * b;
		sumb += b;
		n++;
	}
	
	int aveb = (double)sumb / n + 0.5;
	printf("%d\n%d\n", sumw, aveb);
	return 0;
}

Measured memory_bytes: 1020
def main():
    S = input()
    T = input()
    
    if S == T:
        print("Yes")
    else:
        same = False
        for i in range(len(S)):
            S = S[-1] + S[:len(S)-1]
            if S == T:
                print("Yes")
                same = True
                break
        if same == False:
            print("No")
main()

Measured memory_bytes: 2940
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;
    
    auto ans = new int[] (n);
    
    int totxr = 0;
    foreach (e; arr) { totxr ^= e; }
    
    foreach (i; 0 .. n) { ans[i] = arr[i] ^ totxr; }
    
    ans.map!(to!string).join(" ").writeln;
}

Measured memory_bytes: 16340
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 50;

string s[N];
int d[N][N];
int h,w;
int _di[4]={1,-1,0,0}, _dj[4]={0,0,1,-1};

void bfs(pii p){
	queue<pii> Q;
	Q.push(p);
	while(!Q.empty()){
		pii p1=Q.front();Q.pop();
		int i=p1.first,j=p1.second;
		rep(k,4) {
			int di=_di[k],dj=_dj[k];
			if(i+di<0||i+di>h-1||j+dj<0||j+dj>w-1) continue;
			if(s[i+di][j+dj]=='#') continue;
			if(d[i+di][j+dj]>d[i][j]+1){
				d[i+di][j+dj]=d[i][j]+1;
				Q.push(pii(i+di,j+dj));
			}
		}
	}
}

int main() {
	cin>>h>>w;
	rep(i,h) cin>>s[i];
	rep(i,h) rep(j,w) d[i][j]=INF;
	d[0][0]=1;
	bfs(pii(0,0));
	int c=0;
	rep(i,h) rep(j,w) if(s[i][j]=='.') c++;
	if(d[h-1][w-1]==INF) cout<<-1<<endl;
	else cout<<c-d[h-1][w-1]<<endl;
}


Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (int i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl;}
void outl(ll x) { cout << x << endl;}
void outs(string x) { cout << x << endl;}
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}

Measured memory_bytes: 3624
// Aliceを先行として2人とも残ったカードの中で数が最大のカードから取っていく.
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  int a[105];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  
  int Alice=0,Bob=0;
  for(int i=0;i<n;i++){
    if(i%2==0) Alice += a[n-1-i];
    else Bob += a[n-1-i];
  }
  cout << Alice - Bob << endl;
  return 0;
}

Measured memory_bytes: 256
a=gets.split(' ').map(&:to_s)
b=Array.new
a.each{|v|
   case v
   when '+' then
        v1=b.pop.to_i
        v2=b.pop.to_i
        b.push(v2+v1)
   when '-'
        v1=b.pop.to_i
        v2=b.pop.to_i
        b.push(v2-v1)
   when '*'
        v1=b.pop.to_i
        v2=b.pop.to_i
        b.push(v2*v1)
   else
        b.push(v)
   end
}
p b.pop

Measured memory_bytes: 8624
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
long long A[310][310];
int main(){
long long h,w,d;
cin>>h>>w>>d;
long long x[90010]={};
long long y[90010]={};
rep(i,h){
    rep(k,w){
        long long a;
        cin>>a;
        x[a]=k;
        y[a]=i;
    }
}

long long dist[90010];
for(int i=1;i<=d;i++)dist[i]=0;
for(int i=1;i<=d;i++){
    for(int k=i+d;k<=h*w;k+=d){
        dist[k]=dist[k-d]+abs(x[k]-x[k-d])+abs(y[k]-y[k-d]);
    }   
}
int q;
cin>>q;

rep(i,q){
long long l,r;
cin>>l>>r;
long long ans=0;
    ans=dist[r]-dist[l];
    printf("%d\n",ans);
}
 return 0;
}
/*
3 3 2
1 4 3
2 5 7
8 9 6
1
4 8

5

4 2 3
3 7
1 4
5 2
6 8
2
2 2
2 2

0
0

5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13

0
5
0
*/


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

using namespace std;

void solve()
{
    int x;
    cin >> x;
    string str;
    cin >> str;
    stack<char> s;
    for (int i = 0; i < x; i++)
    {
        if (s.empty())
            s.push(str[i]);
        else if (s.top() == '(' && str[i] == ')')
            s.pop();
        else
            s.push(str[i]);
    }
    // while (!s.empty()){
    //     cout<<s.top()<<" ";
    //     s.pop();
    // }
    while (!s.empty())
    {

        if (s.top() == ')')
        {
            s.pop();
            str = "(" + str;
        }
        else
        {
            s.pop();
            str = str + ")";
        }
    }
    cout << str;
}
int main()
{
    //freopen("in.txt","r",stdin);

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
int main()
{
	char s[25];
	for (int i = 1 ; i <=19 ; i++)
	 scanf ("%c",&s[i]);
	
    for (int i = 1 ; i <= 19 ;i++)
	 {
	 	if (i == 6 || i ==14)
	 	 s[i] = ' ';
	 } 
	 for (int i = 1 ; i <=19 ; i++)
	 printf ("%c",s[i]);
return 0;
}

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

int main() {
  int n,m,ans;
  ans = 0;
  cin >>n>>m;
  vector<long long> height(n);
  vector<int> num(n);
  vector<int> a(m);
  vector<int> b(m);
  for(int i = 0; i < n; i++){
    cin >> height.at(i);
  }
  for(int i = 0; i < m; i++){
    cin >> a.at(i);
    cin >> b.at(i);
    if(height.at(a.at(i) - 1) > height.at(b.at(i) - 1)){
      num.at(b.at(i) - 1) = 1;
    }
    else if(height.at(a.at(i) - 1)==height.at(b.at(i) - 1)){
      num.at(a.at(i) - 1) = 1;
      num.at(b.at(i) - 1) = 1;
    }
    else{
      num.at(a.at(i) - 1) = 1;
    }
  }
  for(int i = 0 ;i < n;i++){
    if(num.at(i) == 0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5040
# coding: utf-8
N, M = map(int, input().split())
AC, WA = [], []
AC = [False for _ in range(10**5)]
WA = [0 for _ in range(10**5)]
ac, wa = 0, 0
for i in range(M):
    tmp = input().split()
    p = int(tmp[0]) - 1
    s = tmp[1]
    if AC[p]:
        continue
    else:
        if s == "AC":
            AC[p] = True
        else:
            WA[p] += 1
for i in range(N):
    if AC[i]:
        ac += 1
        wa += WA[i]
print(ac, wa)

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

int main() {
	
	int n, a[100];

	cin >> n;

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

	for (int i = n - 1; i >= 0; i--) {
		cout << a[i];
		if (i)cout << " ";
	}

	cout << "\n";

	return 0;

}

Measured memory_bytes: 1164
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt

  val shops = (0 until n).map { _ =>
    StdIn.readLine().split(' ').map(_.toInt)
  }.toArray

  val p = (0 until n).map { _ =>
    StdIn.readLine().split(' ').map(_.toInt)
  }.toArray

  var res = Int.MinValue
  for (b <- 1 until (1 << 10)) {
    //println(b.toBinaryString)
    var cc = 0
    (0 until n).foreach { i =>
      var c = 0
      (0 until 10).foreach { k =>
        //println("::" + ((b >> k) & 1).toBinaryString)
        c += (if (((b >> k) & 1) == 1 && shops(i)(k) == 1) 1 else 0)
      }
      cc += p(i)(c)
    }
    res = if (res < cc) cc else res
  }

  println(res)
}

Measured memory_bytes: 34660
import sys

def gcd(x, y):
  if y == 1:
    return 1
  elif y == 0:
    return x
  else:
    return gcd(y, x % y)

line = sys.stdin.readline()
(a, b) = line.split()
a = int(a)
b = int(b)
if a > b:
  b, a = a, b

print gcd(a, b)

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  
  for (int i = 0; i < n-1; i++) {
	for(int j = i+1; j < n; j++) {
    	if(vec[i] < vec[j]){
        	int tmp = vec[i];
          	vec[i] = vec[j];
          	vec[j] = tmp;
        }
    }
  }
    
  int ans = 1;
  for(int i = 0; i < n-1; i++){
    if(vec[i] > vec[i+1]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
typedef long long ll;
typedef long double ld;
 
 
 
ll MOD=1e9 + 7;
ll OO=1e9 + 1;
const int N=1e6 + 10,M=20;
int fr[N];


int n,m,k,T;
int a,b,c;
int l,r,mid;
string str;

vector<pair<int,int>> vec;
set<pair<int,int>> st;
map<int,vector<int>> mp;


int main(){
	IO
	//freopen("in.txt","r",stdin);
	cin>>n>>m>>k;
	for(int i=0;i<k;++i){
		cin>>a>>b;
		vec.push_back({a,b});
		if(!fr[b])
			st.insert({0,b});
		st.erase({fr[b],b});
		fr[b]++;
		st.insert({fr[b],b});
	}
	
	
	for(auto &it:vec)
		mp[it.first].push_back(it.second);
	
	int ans = 0;
	for(auto &it:mp){
		for(int &i:it.second){
			st.erase({fr[i],i});
			--fr[i];
			st.insert({fr[i],i});
		}
		
		ans = max(ans,SZ(it.second) + (*st.rbegin()).first);
		
		for(int &i:it.second){
			st.erase({fr[i],i});
			++fr[i];
			st.insert({fr[i],i});
		}
	}
	
	cout<<ans<<endl;

}

 

Measured memory_bytes: 53664
import sys

N, K = map(int, sys.stdin.readline().split())

comb = (N-1) * (N-2) // 2

if K > comb:
    print(-1)
else:
    # print("comb", comb, "K", K)
    res = comb - K
    print(N-1 + res)
    for i in range(2, N+1):
        print(1, i)
    for i in range(2, N):
        for j in range(i, N):
            if res == 0:
                sys.exit()
            print(i, j+1)
            res -= 1

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

int main(){
    string s;
    cin >> s;
    string abc={"abcdefghijklmnopqrstuvwxyz"};
    sort(s.begin(),s.end());
    for(int i=0;i<26;i++){
        if(binary_search(s.begin(),s.end(),abc[i])==1){
            continue;
        }else{
            cout << abc[i];
            return 0;
        }
    }
    cout << "None";
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int       i = 0;
	int buf[10] = { 0 };
	int top3[3] = { 0 };
	while(i < 10) {
		scanf("%d",&buf[i]);
		if(10000 < buf[i] ||
		   0     > buf[i]) {
			continue;
		}
		i++;
	}
	
	for(i = 0; i < 10; i++) {
		if(buf[i] > top3[2]) {
			if(buf[i] > top3[1]){
				if(buf[i] > top3[0]){
						top3[2] = top3[1];
						top3[1] = top3[0];
						top3[0] = buf[i];
				}
				else{
					top3[2] = top3[1];
					top3[1] = buf[i];
				}
			}
			else {
				top3[2] = buf[i];
			}
		}
	}
	printf("%d\n%d\n%d\n", top3[0],top3[1],top3[2]);
	return 0;
}

Measured memory_bytes: 2752
def main():
    n = int(input())

    l = []
    for i in range(1, n + 1):
        k = i
        c = 0
        while k % 2 == 0:
            c += 1
            k = k // 2
        l.append(c)
    print(l.index(max(l)) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

bool compair(pair<long long, long long> a, pair<long long, long long> b){
    if(a.first != b.first){
        return a.first > b.first;
    }
    else{
        return a.second > b.second;
    }
}

int main(){
    long long n, m;
    cin >> n >> m;

    vector<vector<long long> > mem(m+1);

    for(long long i = 0; i < n; i++){
        long long a, b;
        cin >> a >> b;
        if(a > m) continue;
        mem[a].push_back(b);
    }

    priority_queue<long long> que;

    long long ans = 0;

    for(long long d = m-1; d >= 0; d--){
        for(long long j = 0; j < mem[m-d].size(); j++) que.push(mem[m-d][j]);

        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8320
import bisect
N,Q=[int(x) for x in input().split()]
S=input()

L=[]
c=0
while True:
    try:
        if S[c]=="A" and S[c+1]=="C":
            L.append(c+1)
        c+=1
    except:
        break

for i in range(Q):
    l,r=[int(x) for x in input().split()]
    first=bisect.bisect_left(L,l)
    last=bisect.bisect_left(L,r-1)
    L.append(10**5+1)
    if L[last]==r-1:
        print(last-first+1)
    else:
        print(last-first)


Measured memory_bytes: 6492
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def floor(a, b): return -(-a // b)


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


MOD = 10**9 + 7
N = z()
if (N >= 2):

    # 0使わないのは
    zero_nasi = pow(9, N, MOD)
    # 1を使わないのは
    one_nasi = pow(9, N, MOD)
    # 0も1も使わないのは
    zero_one_nasi = pow(8, N, MOD)
    # 全部は
    all_ = pow(10, N, MOD)

    ans = (all_ - zero_nasi - one_nasi + zero_one_nasi) % MOD

else:
    ans = 0


print(ans)


Measured memory_bytes: 9624
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
template <typename T>
void ivec(vector<T> &v, ll N){
    REP(i,0,N){ T x; cin >> x; v.push_back(x); }
}

int main(){
    vector<vector<ll>> C(3, vector<ll>(3,1));
    map<ll, pii> A;
    REP(i,0,3){
        REP(j,0,3){
            ll a;
            cin >> a;
            A[a] = make_pair(i,j);
        }
    }

    ll N;
    cin >> N;

    REP(i, 0, N){
        ll b;
        cin >> b;
        if(A.count(b) != 0){
            C[A[b].first][A[b].second] = 0;
        }
    }

    REP(i,0,3){
        if(C[i][0]+C[i][1]+C[i][2]==0 
         || C[0][i]+C[1][i] + C[2][i]==0){
             cout << "Yes" << endl;
             return 0;
         }
    }
    if(C[0][0]+C[1][1]+C[2][2]==0 
        || C[0][2]+C[1][1] + C[2][0]==0){
            cout << "Yes" << endl;
            return 0;
    }
 

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
char a[1000][1001],a2[1000][1001];
int main(void)
{
	int h,w,n,i,j,k,cnt,sum,sx,sy,x2,y2,x,y,nnn;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<h;i++)	scanf("%s",a[i]);
	sum=0;
	for(i=0;i<h;i++)	{
		for(j=0;j<w;j++)	{
			if(a[i][j]=='S')	{
				sx=j;	sy=i;
			}
		}
	}
	for(i=1;i<=n;i++)	{
		queue<int> xx,yy,nn;
		for(j=0;j<h;j++)	strcpy(a2[j],a[j]);
		xx.push(sx);	yy.push(sy);	nn.push(0);
		while(!xx.empty() )	{
//			printf("size=%d\n",xx.size());
			x=xx.front();	y=yy.front();	nnn=nn.front();
			xx.pop();	yy.pop();	nn.pop();
			if(a2[y][x]-'0'==i)	{
				sum+=nnn;
				sx=x;	sy=y;
				break;
			}
			else {
				if(a2[y][x]!='X')	{
					a2[y][x]='X';
					for(k=0;k<4;k++)	{
						x2=x+dx[k];	y2=y+dy[k];
						if(x2>=0 && x2<w && y2>=0 && y2<h && a2[y2][x2]!='X')	{
							xx.push(x2);	yy.push(y2);	nn.push(nnn+1);
						}
					}
				}
			}
		}
//		while(xx.size()!=0)	{
//			xx.pop();	yy.pop();	nn.pop();
//		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 4676
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j,k,m,n,H,W,A[81][81],B[81][81];

int memo[80][80][13000];

int dp(int s,int t,int u)
{
  if(memo[s][t][u]!=-1)
  {
    return memo[s][t][u];
  }
  
  int temp;
  temp=0;
  if(s>0 && abs(u-A[s][t]+B[s][t])<80*(s+t+1)) temp=max(temp,dp(s-1,t,abs(u-A[s][t]+B[s][t])));
  if(s>0 && abs(u+A[s][t]-B[s][t])<80*(s+t+1)) temp=max(temp,dp(s-1,t,abs(u+A[s][t]-B[s][t])));
  if(t>0 && abs(u-A[s][t]+B[s][t])<80*(s+t+1)) temp=max(temp,dp(s,t-1,abs(u-A[s][t]+B[s][t])));
  if(t>0 && abs(u+A[s][t]-B[s][t])<80*(s+t+1)) temp=max(temp,dp(s,t-1,abs(u+A[s][t]-B[s][t])));
  
  memo[s][t][u]=temp;
  return temp;           
      
           
}


int main()
{
  cin >>H>>W;
  for(i=0;i<H;i++)
  {
    for(j=0;j<W;j++)
    {
      cin>>A[i][j];
    }
  }
  for(i=0;i<H;i++)
  {
    for(j=0;j<W;j++)
    {
      cin>>B[i][j];
    }
  }
  
    for(i=0;i<H;i++)
  {
    for(j=0;j<W;j++)
    {
      for(k=0;k<(H+W)*80;k++)
      {
         memo[i][j][k]=-1; 
      }
    }
  }
    
  for(i=0;i<(H+W)*80;i++)
  {
    memo[0][0][i]=0;
  }
  m=abs(A[0][0]-B[0][0]);
  memo[0][0][m]=1;
  
  for(i=0;i<(H+W)*80;i++)
  {
    if(dp(H-1,W-1,i)==1)
    {
      cout << i;
      break;
    }
  }

  
  
}

Measured memory_bytes: 325248
from collections import Counter
n = int(input())
#li = ['apple', 'orange', 'apple', 'banana', 'grape','orange']
li = []
for i in range(n):
    li.append(input())

#print(li)
#出現回数がもっとも多いタプルを返す（でもこれだと同一の場合１つしか出てこない...）
dic = Counter(li)
#print(dic.most_common())
#print(max(dic.values()))
max = max(dic.values())

list=[]

for k,v in dic.items():
    if(v == max):    
        list.append(k)


list = sorted(list)

#print(list)

for i in range(len(list)):
    print(list[i])



Measured memory_bytes: 35572
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



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

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

    int N;
    int count = 0;

    cin >> N;

    vector<int> V(N);

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

    cout << count;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    //ool ans =
    string s;
    cin>>s;
    if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)!=s.at(2))cout<<"Yes"<<endl;
    else if(s.at(0)==s.at(2)&&s.at(1)==s.at(3)&&s.at(0)!=s.at(1))cout<<"Yes"<<endl;
    else if(s.at(0)==s.at(3)&&s.at(2)==s.at(1)&&s.at(0)!=s.at(2))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
   



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;
vector<int>a;
int f = 0;int n, m, nn;
void go(int ff)
{
    if(ff){
        FF(i, 0, m-2) printf("%d ", a[i]);
        PR(a[m-1]);
    }
    else{
        RR(i, m-1, 1) printf("%d ", a[i]);
        PR(a[0]);
    }
    f ^= 1;
}
int main()
{
#ifndef ONLINE_JUDGE

#endif


    SCCC(n, m, nn);

    FF(i, 1, nn)
    {
        int x; SC(x);
        FF(j, 1, x)
        {
            a.PB(i);
            if(a.size() % m == 0){
                go(f);
                a.clear();
            }
        }
    }
    return 0;
}


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

int main() {
  long long x;
  cin >> x;
  long long yokin = 100;
  int count = 0;
  long long w;
  while(yokin < x){
    w = yokin/100;
    yokin += w;
    count++;
  }  
  cout << count << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//const int maxn=1e9+7;

int main()
{
    ll n,x,ans=0,p;
    int a,b;
    //ios::sync_with_stdio(false);
    cin>>n>>x;
    scanf("%d",&a);
    for(int i=1;i<n;i++){
        scanf("%d",&b);
        p=a+b;
        if(p>x){
           if(b<p-x){
            ans+=(p-x);
            a=0;
           }
           else{
            ans+=p-x;
            b-=(p-x);
            a=b;
           }
        }
        else a=b;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define pi acos(-1)
#define p 1000000007
using namespace std;
int N,c[201010];
long long f2[303030],ans,F[201010];
int n,m;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&c[i]);
	sort(c+1,c+n+1);
	
	f2[0]=1;
	for(int i=1;i<=n;i++)
	f2[i]=f2[i-1]*2LL%p;
	
	F[0]=1;
	for(int i=1;i<=n;i++) F[i]=(2LL*F[i-1]%p+f2[i-1])%p;
	for(int i=1;i<=n;i++)
		(ans+=1LL*c[i]*f2[i-1]%p*F[n-i]%p)%=p;	
	printf("%lld\n",1LL*ans*f2[n]%p);
	return  0;
}
		

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	cout << a << " " << b << " " << c << endl;
	return  0;
}

Measured memory_bytes: 3088
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#ABC145 E
n,t = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()

a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
    
dp = [[0 for j in range(t)] for _ in range(n+1)]
# i番目より前まで注文してT分以内(max T-1)で完食する
    
for i in range(n):
    for j in range(t): 
        if j+ a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]

#一番遅いものをラスト(T-1分)に注文
#i番目をラストに注文 = dp[i][t-1] + b[i]
ans = 0
for i in range(n):
    ans = max(ans,dp[i][t-1]+b[i])
    
print(ans)


Measured memory_bytes: 124376
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
void f(ll n)
{
   if(n==0)return;
   n--;
   f(n/26);
   putchar('a'+(n%26));
}
int main()
{
    ll n;
    cin>>n;
    f(n);
}


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int n, k;
int a[100010];
ll b[100010];

ll f(int mask) {
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if ((a[i]|mask) == mask) ans += b[i];
  }
  return ans;
}

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

  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

  int mask = 0;
  ll ans = 0;
  for (int i = 30; i >= 0; i--) {
    if (k & (1<<i)) {
      mask += (1<<i);
      ans = max(ans, f(mask-1));
    }
  }
  cout << max(ans, f(k)) << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  double den =0;
  for(int i=0;i<n;++i)
  {
    	cin>>v[i];
  		den+=(double)1/v[i];
  }
  double ans=(double)1/den;
  cout<<setprecision(8)<<ans;
  return 0;
}


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

int main(){
    map<string, int> weekday;
    weekday["SUN"] = 0;
    weekday["MON"] = 1;
    weekday["TUE"] = 2;
    weekday["WED"] = 3;
    weekday["THU"] = 4;
    weekday["FRI"] = 5;
    weekday["SAT"] = 6;

    string day;
    std::cin >> day;

    std::cout << 7 - weekday[day];

}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int a = Integer.parseInt(br.readLine());
			String s = br.readLine();

			System.out.println(a>=3200?s:"red");
		}
	}
}

Measured memory_bytes: 25280