akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,m;
int c[20],a[20][20],sum[20];
bool f[20];
int x;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>x;
	rep(i,n){
		cin>>c[i];
		rep(j,m)
		cin>>a[i][j];
	}
	int ans=-1;
	rep(i,(1<<n)){
		rep(j,n)
		f[j]=(i&(1<<j));
		rep(j,m)
		sum[j]=0;
		int cost=0;
		rep(j,n){
			if(f[j]){
				cost+=c[j];
				rep(k,m)
				sum[k]+=a[j][k];
			}
		}
		bool ok=true;
		rep(j,m){
			if(sum[j]<x)
			ok=false;
		}
		if(ok){
			if(ans==-1)
			ans=cost;
			ans=min(ans,cost);
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3656
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int DAY = 365;
const int CONT = 26;

struct Solver {
    int D, C[CONT], S[DAY][CONT], ans[DAY];
    void read_input() {
        scanf("%d", &D);
        for(int i=0; i<CONT; i++) {
            scanf("%d", &C[i]);
        }
        for(int i=0; i<D; i++) {
            for(int j=0; j<CONT; j++) {
                scanf("%d", &S[i][j]);
            }
        }
    }

    ll calc_score() {
        ll res = 0;
        int last[CONT] = {};
        for(int i=0; i<D; i++) {
            res += S[i][ ans[i] ];
            last[ ans[i] ] = i+1;
            for(int j=0; j<CONT; j++) {
                res -= C[j] * (i+1 - last[j]);
            }
            printf("%lld\n", res);
        }
        res += 1000000;
        return max(0LL, res);
    }

    ll update(int day, int contest) {
        return 0;
    }
};

int main() {
    Solver solver;
    solver.read_input();
    for(int i=0; i<solver.D; i++) {
        int t; scanf("%d", &t);
        solver.ans[i] = --t;
    }
    solver.calc_score();
    return 0;
}


Measured memory_bytes: 3800
#include<iostream>
using namespace std;
int main(){
    long long int a,b,c,d,x,p;
    cin>>a>>b>>c;
    /*if(a==0 && b==0){
        cout<<"0"<<endl;
        return 0;
    }*/
    d=b/c;
    x=a/c;
    x=d-x;
    if(a%c==0){
        x++;
    }
    cout<<x<<endl;



}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        int n = Read.Int();
        int[] a = new int[n]
            ;
        int[] b = new int[n];
        bool All_0 = true;
        for(int i = 0; i < a.Length; i++)
        {
            a[i] = Read.Int();
            b[i] = a[i] % 10;
            if (a[i] % 10 != 0)
            {
                All_0 = false;
            }
        }
        Array.Sort(a);
        if (All_0) { Console.WriteLine(0);return; }
        int dsum = a.Sum();
        int sum = dsum;
        for (int i = 0; ; i++)
        {
            if (sum % 10 != 0) { Console.WriteLine(sum); return; }
            if (dsum % 10 != 0) { Console.WriteLine(dsum); return; }
            dsum -= a[i];
            sum = a.Sum() - a[i];
        }
    }
   
    public static int gcd(int a, int b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static int lcm(int a, int b)
    {
        return a * b / gcd(a, b);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (int i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] Ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

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


int main(){
	int n,m,ans=0,tmp=0;
	string s[100],t[100];

	cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	cin>>m;
	for(int i=0;i<m;i++)cin>>t[i];

	sort(s,s+n);
	for(int i=0;i<n;i++){
		tmp=0;
		for(int j=i;j<n;j++)
			if(s[i]==s[j])tmp++;
		for(int j=0;j<m;j++)
			if(s[i]==t[j])tmp--;
		ans=max(ans,tmp);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200010
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


signed main()
{
    
    speed
    int x;cin>>x;
    int k=x/500;
    x-=k*500;
    int ans=k*1000;
    ans+=(x/5)*5;
    cout<<ans<<endl;




    
    


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vector<int> par;

void Initpar(int n){
  par = vector<int>(n); 
  for(int i=0; i<n; i++) par.at(i) = i;
}

int root(int x){
  if(x == par.at(x)) return x;
  else par.at(x) = root(par.at(x));
}

int rootpar(int x, vi &pa){
  if(x == pa.at(x)) return x;
  else pa.at(x) = rootpar(pa.at(x), pa);
}

void unite(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx == ry) return;
  if(rx < ry) par.at(ry) = rx;
  else par.at(rx) = ry;
}

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

int main(){
  long n,k,l;
  cin >> n >> k >> l;
  vi par1,par2;
  Initpar(n);
  rep(i,k){
    int p,q;
    cin >> p >> q;
    p--;q--;
    unite(p,q);
  }
  par1 = par;
  Initpar(n);
  rep(i,l){
    int r,s;
    cin >> r >> s;
    r--;s--;
    unite(r,s);
  }
  par2 = par;
  rep(i,n){
    rootpar(i,par1);
    rootpar(i,par2);
  }
  map<pii,int> mp;
  rep(i,n){
    pii P = {par1.at(i), par2.at(i)};
    if(mp.count(P)) mp.at(P)++;
    else mp[P] = 1;
  }
  rep(i,n){
    pii P = {par1.at(i), par2.at(i)};
    cout << mp.at(P) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 14352
S2 = input()
T = input()
for i in reversed(range(0, len(S2)-len(T)+1)):
  s = S2[i:i+len(T)]
  #print(s)
  ok = True
  for j in range(len(T)):
    if not(s[j] == "?" or s[j] == T[j]):
      ok = False
  if ok:
    S = S2[:i] + T + S2[i+len(T):]
    S = S.replace("?", "a")
    print(S)
    exit()
print("UNRESTORABLE")


Measured memory_bytes: 3064
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

int main() {
    string S;cin >> S;
    cout << S.at(0) << S.at(1) << S.at(2) << endl;
}


Measured memory_bytes: 3596
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
mod = 10**9+7
x = 10**10
count = 0
c=[]
for i in range(n):
    if a[i]!=x:
        if i != 0:
            c.append([x,count])
        x=a[i]
        count = 1
    else:
        count += 1
    
    if i==n-1:
        c.append([x,count])

fact = [1]*(n+1)
inv_fact = [1]*(n+1)
for i in range(n):
    fact[i+1] = fact[i]*(i+1)
    fact[i+1] %= mod
for i in range(n,0,-1):
    if i == n:
        inv_fact[i] = pow(fact[i],mod-2,mod)
    else:
        inv_fact[i] = inv_fact[i+1]*(i+1)
        inv_fact[i] %= mod
        
sum_min = 0
sum_max = 0
b = 0
for i,j in c:
    if n-b < k:
        break
    b += j
    for l in range(max(1,k-n+b),min(k,j)+1):
        sum_min += i*fact[j]*inv_fact[j-l]*inv_fact[l]*fact[n-b]*inv_fact[n-b-k+l]*inv_fact[k-l]
        sum_min %= mod
b = 0
for i,j in c[::-1]:
    if n-b < k:
        break
    b += j
    for l in range(max(1,k-n+b),min(k,j)+1):
        sum_max += i*fact[j]*inv_fact[j-l]*inv_fact[l]*fact[n-b]*inv_fact[n-b-k+l]*inv_fact[k-l]
        sum_max %= mod
        
print((sum_max-sum_min)%mod)

Measured memory_bytes: 24980
<?php

# B - Algae

fscanf(STDIN, "%d %d %d", $r, $D, $x2000);

$next = $r * $x2000 - $D;
for ( $i = 0; $i < 10; $i++ ) {
    echo $next . PHP_EOL; 
    $next = $r * $next - $D;
}



Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define N 101

int main(){
 
  int n, i, j; 
  int a, b, c;
  int A[N][N];
 
  scanf("%d",&n);
   
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      A[i][j] = 0;
    }
  }


  for(i=1;i<=n;i++){
 
    scanf("%d",&a);
    scanf("%d",&b);
 
    for(j=1;j<=b;j++){
      scanf("%d",&c);
      A[a][c]=1;
    
    }
  }
 
  for(i=1;i<=n;i++){
 
    printf("%d",A[i][1]);
 
    for(j=2;j<=n;j++){
 
      printf(" %d",A[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
# Problem D -Banned K

# input
n = int(input())
a_list = list(map(int, input().split()))

# initialization
cur_dic = {}
cur_sum = 0
for a in a_list:
    if a in cur_dic:
        cur_dic[a] += 1
    else:
        cur_dic[a] = 1

for c in cur_dic:
    num = cur_dic[c]
    cur_sum += num * (num-1) / 2

for i in range(len(a_list)):
    a = a_list[i]
    d = cur_dic[a]
    # 減らす
    if d > 1:
        cur_sum -= d * (d-1) / 2
    cur_dic[a] -= 1

    # output
    tmp = cur_sum
    if cur_dic[a] > 1:
        tmp = cur_sum + cur_dic[a] * (cur_dic[a] - 1) / 2 # update
    print("%d"%(tmp))

    # 増やす
    if d > 1:
        cur_sum += d * (d-1) / 2
    cur_dic[a] += 1


Measured memory_bytes: 26140
#include<stdio.h>

int main(){
	int A,B,C;
	while(scanf("%d %d",&A,&B)!=EOF){
		A+=B;
		C=0;
		while(A>=1){
			C++;
			A/=10;
		}
		printf("%d\n",C);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
ll mul(ll a,ll b){
    ll t=(a*b);
    if(t>=p)t%=p;
    return t;
}
ll power(ll a,ll x){
    ll r=1;
    while(x!=0){
        if(x%2==1){
            r=r*a;r%=p;
        }
        a=a*a;a%=p;
        x=x/2;
    }
    return r;
}
ll divide(ll a, ll b){
    return mul(a,power(b,p-2));
}
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0); 
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll n;cin>>n;
        ll ans=0;
        ll a[n];
        rep(i,n)cin>>a[i];
        ll lcm=1;
        map<ll,ll> m;
        rep(i,n){
            ll x=a[i];
            ll cnt=0;
            while(x%2==0){
                x=x/2;
                cnt++;
            }
            if(m.find(2)!=m.end()){
                m[2]=max(m[2],cnt);
            }
            else
            m[2]=cnt;
            for(ll j=3;j<=sqrt(x);j=j+2){
                cnt=0;
                while(x%j==0){
                    x=x/j;cnt++;
                }
                if(m.find(j)!=m.end()){
                        m[j]=max(m[j],cnt);
                }
                else
                m[j]=cnt;
            }
            if(m.find(x)!=m.end()){
                m[x]=max(m[x],(ll)1);
            }
            else
            m[x]=1;
        }
        for(auto j: m){
            // cout<<j.fst<<" "<<j.snd<<endl;
            lcm=mul(lcm,power(j.fst,j.snd));
        }
        // cout<<lcm<<endl;
        rep(i,n){
            ans=ans+divide(lcm,a[i]);
            ans%=p;
        }
        cout<<ans;
    }
    return 0;   
}

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

int power(int m, int n);

int main(void)
{
    int n,a[15],x[15][14],y[15][14],i,j,k,ans=0,which[15],honests,success;

    scanf("%d",&n);
    for ( i = 0; i < n; i++)
    {
        scanf("%d",a+i);
        for ( j = 0; j < a[i]; j++)
        {
            scanf("%d %d",x[i]+j,y[i]+j);
            x[i][j]--;
        }
    }

    for ( k = 0; k < power(2,n); k++)
    {
        honests=0;
        for ( i = 0; i < n; i++)
        {
            which[i]=(k>>i)&1;;
            honests+=which[i];
        }
        success=1;
        for ( i = 0; i < n; i++)
        {
            if (which[i]==1)
            {
                for ( j = 0; j < a[i]; j++)
                {
                    if(which[x[i][j]]!=y[i][j]) success=0;
                }
            }
        }
        if(success==1&&ans<honests) ans=honests;
    }

    printf("%d",ans);

    return 0;
}

int power(int m, int n)
{
    int p=1;
    for (int i = 0; i < n; i++) p*=m;
    return p;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int h,w,d,n;
  cin>>h>>w>>d>>n;
  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];
  int r[d];
  for(int i=0;i<d;i++) cin>>r[i];
  //for(int i=0;i<d;i++) cout<<r[i]<<" ";cout<<endl;
  bool ok[h][w];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      ok[i][j]=1;
  for(int k=0;k<n;k++){
    int x,y,t;
    cin>>x>>y>>t;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	//ok[i][j]=1;
	int di=max(abs(y-i),abs(x-j));
	//cout<<k<<" "<<di<<":"<<i<<" "<<j<<" "<<y-i<<" "<<x-j<<endl;
	if(t==0){
	  if(di<=r[0]) continue;
	  ok[i][j]=0;
	}else if(t==d){
	  if(r[d-1]<di) continue;
	  ok[i][j]=0;
	}else{
	  if(r[t-1]<di&&di<=r[t]) continue;
	  ok[i][j]=0;
	}
      }
    }
    /*
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout<<ok[i][j];
      }
      cout<<endl;
    }
    cout<<endl;
    */
  }
  int cnt=0,cnt2=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(ok[i][j]&&s[i][j]!='#') cnt++;

  if(cnt==0){
    cout<<"Broken"<<endl;
    return 0;
  }

  int sy,sx;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]=='D') sy=i,sx=j;

  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
  
  typedef pair<int,int> P;
  queue<P> q;
  int dp[h][w];
  memset(dp,-1,sizeof(dp));
  dp[sy][sx]=0;
  q.push(P(sy,sx));
  while(!q.empty()){
    P p=q.front();q.pop();
    int y=p.first,x=p.second;
    //cout<<y<<" "<<x<<endl;
    if(ok[y][x]) cnt2++;
    for(int k=0;k<4;k++){
      int ny=y+ay[k],nx=x+ax[k];
      if(ny<0||h<=ny||nx<0||w<=nx) continue;
      if(s[ny][nx]=='#') continue;
      //cout<<ny<<"n"<<nx<<endl;
      if(dp[ny][nx]<0){
	dp[ny][nx]=dp[y][x]+1;
	q.push(P(ny,nx));
      }
    }
  }
  //cout<<cnt<<" "<<cnt2<<endl;
  if(cnt==cnt2){
    cout<<"Yes"<<endl;
  }else if(cnt2==0){
    cout<<"No"<<endl;
  }else{
    cout<<"Unknown"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3216
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline
    #define re register
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 5005
#define base 233
#define ull unsigned long long
int n;
char s[N];
ull power[N],h[N];
ull cal(int l,int r){
	ull x=h[r]-h[l-1]*power[r-l+1];
	return x;
}
int main(){
	read(n);
	scanf("%s",s+1);
	power[0]=1;
	for(re int i=1;i<=n;i++) power[i]=power[i-1]*base;
	for(re int i=1;i<=n;i++) h[i]=h[i-1]*base+s[i];
	int len=1;
	bool flag=0;
	for(re int i=1;i+len-1<=n;i++){
		for(re int j=i+len;j+len-1<=n;j++){
			while(i+len-1<=n&&j>i+len-1&&j+len-1<=n&&cal(i,i+len-1)==cal(j,j+len-1)) flag=1,len++;
		}
	}
	if(!flag) printf("0");
	else printf("%d",len-1);
	return 0;
}

Measured memory_bytes: 256
function Main(input){
    input = input.split(" ");

    var a = Math.abs(input[0] - input[1]);
    var b = Math.abs(input[0] - input[2]);

    if(a > b){
        console.log("B");
    }else{
        console.log("A");
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#https://atcoder.jp/contests/abc142/tasks/abc142_c

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

b = []
for i in range(n):
    b.append([a[i],i])

b.sort()

c = []

for i in range(n):
    print(b[i][1]+1,end=' ')
print('')

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

int H,W;
vector<vector<int>> field;

void dfs(int h, int w){
    field[h][w] = 0;

    for (int dh = -1; dh <= 1; ++dh) {
        for (int dw = -1; dw <= 1; ++dw) {
            int nh = h + dh, nw = w + dw;

            if(nh < 0 || nh  >= H || nw < 0 || nw >= W) continue;
            if(field[nh][nw] == 0) continue;

            dfs(nh, nw);
        }
    }
}

int main() {
    while (cin >> W >> H){
        if(H == 0 and W == 0) break;

        field.assign(H,vector<int>(W, 0));
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                cin >> field[h][w];
            }
        }

        int count = 0;
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                if(field[h][w] == 0) continue;
                dfs(h, w);
                count++;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int n, ans = 1;
int UP, down;
int a[100010];
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int pre = a[1];
	for (int i = 1; i <= n; i++) {
		if (a[i] > pre) UP = 1;
		else if (a[i] < pre) down = 1;
		if (UP && down) {
			UP = 0;
			down = 0;
			ans++;
		}
		pre = a[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
void judge(int x, int y, int z){
	int f=0;
	if( x * x == y * y + z * z )f=1;
	else if( y * y == z * z + x * x )f=1;
	else if( z * z == x * x + y * y )f=1;
	printf( (f==1) ? ("YES\n") : ("NO\n") );
	return;
}
int main(void){
	int n,a,b,c;
	
	scanf("%d", &n);
	while(n--){
		scanf("%d%d%d", &a, &b, &c);
		judge(a,b,c);
	}
	return 0;
}

Measured memory_bytes: 580
input_data = gets.chomp.split(" ")
n = input_data[0].to_i
m = input_data[1].to_i
pp = input_data[2].to_f

while n != 0 do
    g = 0
    winner = []
    n.times do |i|
        f = gets.chomp.to_f
        g += f
        winner.push(f)
    end
    
    if winner[m-1] == 0
        p 0
    else
        gg = g * (100 - pp) / winner[m-1]
        p gg.floor
    end

    input_data = gets.chomp.split(" ")
    n = input_data[0].to_i
    m = input_data[1].to_i
    pp = input_data[2].to_f
end


Measured memory_bytes: 6884
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		Integer n = sc.nextInt();

		Integer[] array = new Integer[n];

		for (Integer i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}

		for (Integer j = n; j > 0; j--) {
			if (j - 1 == 0) {
				System.out.println(array[j - 1]);
				return;
			}
			System.out.print(array[j - 1]);
			System.out.print(" ");
		}

	}

}



Measured memory_bytes: 26216
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define N 50
long long int K;
long long int a[N];
int main(){
  cin >> K;
  for(int i=0;i<N;i++)a[i]=N-1;
  long long int x,y;
  x=K/N;y=K%N;
  for(int i=0;i<N;i++)a[i]+=x;
  for(int i=0;i<y;i++){
    for(int j=0;j<N;j++){
      if(i==j)a[j]+=N;
      else a[j]--;
    }
   
  }
  cout << N << endl;
  for(int i=0;i<N;i++)cout << a[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


A,B,C,D = map(int,input().split())

c_cnt = B//C - (A-1)//C


d_cnt = B//D - (A-1)//D

cd_lcm = lcm(C,D)

cd_cnt = B//cd_lcm - (A-1)//cd_lcm


print((B-A+1) - c_cnt - d_cnt + cd_cnt)

Measured memory_bytes: 64084
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    string S;
    while(N != 0 && N != 1){
        ll n = N;
        if(N < 0) --N;
        N /= -2;
        S += to_string(n - N * (-2));
    }
    S += to_string(N);
    reverse(all(S));
    cout << S;
    cout << endl;
    return 0;
}



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

int main() {
  int h, n, a;
  cin >> h >> n;
  bool flag = false;
  for(int i=0; i<n; i++) {
    cin >> a;
    h -= a;
    if(h <= 0) {
      flag = true;
      break;
    }
  }
  
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, a) for(int i = 1; i < a; i++)//iは1//////////////////
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
//#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main(){
    int n;
    cin >>n;
    VE vec(10000,0);
    rep(i,100){
        rep(j,100){
            rep(k,100){
                int v=i*i+j*j+k*k+i*j+j*k+k*i;
                if(v<10001) vec[v]++;
            }
        }
    }
    rep(i,n+1){
         cout << vec[i] <<endl;
    }
 }

Measured memory_bytes: 3524
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main(){
	int n,i,p[100],t,j,a;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			t = 0;
			for(j=0;j<5;j++){
				cin >> a;
				t += a;
			}
			p[i] = t;
		}
		sort(p,p+n,greater<int>());
		cout << p[0] << " " << p[n-1] << endl;
		for(i=0;i<100;i++){
			p[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import math
import itertools
N,M = input().split()
N1=int(N)
M1=int(M)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if N1>=2:
    n=combinations_count(N1,2)
else:
    n=0
if M1>=2:
    m=combinations_count(M1,2)
else:
    m=0
print(n+m)


Measured memory_bytes: 3060
N, M = map(int, input().split())
to = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    to[a].append(b)
    to[b].append(a)


def dfs(v, seen):
    if seen == [1] * N:
        return 1
    
    res = 0
    for nv in to[v]:
        if not seen[nv]:
            seen[nv] = 1
            res += dfs(nv, seen)
            seen[nv] = 0
    return res


def main():
    seen = [0] * N
    seen[0] = 1
    print(dfs(0, seen))    


if __name__ == "__main__":
    main()


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

const ll MAX = 1000000000000001;

vector<ll> p;

void print(int len, ll x)
{
    if(len == 0) return;

    for(int ch = 0; ch < 26; ch++){
        if(p[len-1] >= x){
            cout << (char)('a'+ch);
            print(len-1, x);
            return;
        }
        x -= p[len-1];
    }
}

int32_t main()
{
    FASTIO;

    p.PB(1);
    while(p.back() <= MAX)
        p.PB(p.back()*26LL);

    ll n;
    cin >> n;
    int len = 0;
    for(int i = 1; i < p.size(); i++){
        if(p[i] >= n){
            len = i;
            break;
        }
        n -= p[i];
    }
    // DEBUG(len);
    // DEBUG(n);
    print(len, n);

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>

#define PI 3.141592653589

using namespace std;

int main() {
	int a, b, r;
	char op;

	while (1) {
		cin >> a >> op >> b;

		if (op == '?') {
			break;
		}

		switch (op) {
		case '+':
			r = a + b;
			break;
		case '-':
			r = a - b;
			break;
		case '*':
			r = a * b;
			break;
		case '/':
			if (b == 0) {
				break;
			}
			r = a / b;
			break;
		default:
			break;
		}

		cout << r << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

uint32_t gcd(uint32_t a, uint32_t b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int main(int argc, char *argv[])
{
  uint32_t N, K, A, MAXA;
  uint32_t total_gcd;

  cin >> N >> K >> A;

  total_gcd = MAXA = A;
  FOR(i, N-1) {
    cin >> A;
    if (A > MAXA)
      MAXA = A;
    total_gcd = gcd(total_gcd, A);
  }

  if (K <= MAXA && K % total_gcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d=0,e,g=0,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> n >> k; //k--;
    vector<ll> V(n+1),C(n+1),A;
    for(i=1;i<=n;i++)cin >> V[i];
    i = 1;
    while(C[i]==0)
    {
        A.pb(i); C[i] = 1;
        i = V[i];
    }
    m = A.size();
    for(j=0;j<m;j++)
    {
        if(A[j]==i) break;
    }
    if(k<=j) {cout << A[k]; return 0;}

    k -= j;
    m -= j;
    k %= m;
    cout << A[j+k];

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


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

#define NUM 32000

int main(){
	int table[NUM],limit;

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

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n,count = 0;

	scanf("%d",&n);

	printf("%d:",n);
	for(int i=2; i< NUM && n != 1; i++){
		while(table[i] == 1 && n%i == 0 && n != 1){
			printf(" %d",i);
			n /= i;
			count++;
		}
	}
	if(count == 0)printf(" %d",n);
	printf("\n");

	return 0;
}

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

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////



int main(){fastio
    
    ll n;cin>>n;
    vector<ll> v[n];
    rep(i,1,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll c[n];rep(i,0,n-1)cin>>c[i];
    sort(c,c+n);
    ll pos=n-1;
    queue<ll>q;
    ll ans[n];memset(ans,-1,sizeof(ans));
    ans[0]=c[pos];
    pos--;
    q.push(0);
    while(!q.empty()){
        ll t=q.front();q.pop();
        for(auto x:v[t]){
            if(ans[x]!=-1)continue;
            ans[x]=c[pos];
            pos--;
            q.push(x);
        }
    }
    ll sum=0;rep(i,0,n-2)sum+=c[i];
    cout<<sum<<endl;
    rep(i,0,n-1){
        cout<<ans[i]<<" ";
    }
    
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int two[61];


signed main(){
	int A, B, t;
	cin >> A >> B;
	vector<P> V;
	if (A == B) {
		cout << 1 << endl;
		return 0;
	}
	two[0] = 1;
	for (int i = 1; i <= 60; i++)  two[i] = 2 * two[i - 1];
	for (int i = 60; i >= 0; i--) {
		if ((A & (1LL << i)) != (B & (1LL << i))) {
			t = i;
			break;
		} else if (A & (1LL << i)) A -= two[i], B -= two[i];
	}
	//cout << A << ' ' << B << endl;
	int bit = -1;
	for (int i = t - 1; i >= 0; i--) {
		if (B & (1LL << i)) {
			bit = i;
			break;
		}
	}
	int l1 = A;
	int l2 = two[t] + A;
	int r1 = two[t] + two[bit + 1] - 1;
	int r2 = two[t + 1] - 1;
	int ans;
	if (l2 <= r1) ans = r2 - l1 + 1;
	else ans = r1 - l1 + 1 + r2 - l2 + 1;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
using namespace std;
long long n,m,h=0;
int main()
{
    scanf("%lld%lld",&n,&m);
    printf("%lld",mn(n,m/2)+mx(m-n*2,0ll)/4);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int q, typ[maxn];
vector<pii>v;
map<pii, int>mp;
ll f[2][maxn];
void upd(int t, int i, ll val)
{
    for(; i < maxn; i += i & -i)
        f[t][i] += val;
}
ll get(int t, int i)
{
    ll ret = 0;
    for(; i > 0; i -= i & -i)
        ret += f[t][i];
    return ret;
}
ll get(int t, int l, int r)
{
    return get(t, r) - get(t, l - 1);
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> q;
    vector<pii>sorted;
    v.resize(q);
    for(int i = 0; i < q; i++)
    {
        cin >> typ[i];
        if(typ[i] == 1)
        {
            cin >> v[i].x >> v[i].y;
            sorted.pb({v[i].x, i});
        }
    }
    sort(all(sorted));
    for(int i = 0; i < sz(sorted); i++)
        mp[sorted[i]] = i + 1;
    ll bsum = 0, cnt = 0;
    for(int i = 0; i < q; i++)
    {
        if(typ[i] == 1)
        {
            ll a, b;
            tie(a, b) = v[i];
            bsum += b;
            upd(0, mp[pii(a, i)], 1);
            upd(1, mp[pii(a, i)], a);
            ++cnt;
        }
        else
        {
            int pos = (cnt + 1) / 2;
            int l = 1, r = maxn - 1;
            while(l < r)
            {
                int mid = (l + r) / 2;
                if(get(0, mid) >= pos)
                    r = mid;
                else
                    l = mid + 1;
            }
            ll val = get(1, l, l);
            ll ans = val * pos - get(1, l);
            ans += get(1, l + 1, maxn - 1) - val * (cnt - pos);
            cout << val << " " << ans + bsum << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 20336
array = []

for i in range(2):
    val = input()
    array.append(val.split())

summar_days = int(array[0][0])
amount_homework = int(array[0][1])

if amount_homework != len(array[1]):
    print("Error: M is different than length of A")
    exit()

for need_days in array[1]:
    summar_days = summar_days - int(need_days)
    if summar_days < 0:
        summar_days = -1
        break

print(summar_days)


Measured memory_bytes: 9444
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, m, r;
        n = sc.nextInt();
        m = sc.nextInt();
        r = sc.nextInt();
        if (r - n * m < 0) {
            System.out.println("0");
            return;
        }
        BigInteger ZERO = BigInteger.ZERO;
        BigInteger ONE = BigInteger.ONE;
        BigInteger b = ONE, k;
        BigInteger lb = new BigInteger(Integer.toString(r - n * m));
        k = new BigInteger(Integer.toString(r - n * m + n - 1));
        while (k.compareTo(lb) > 0) {
            b = b.multiply(k);
            k = k.subtract(ONE);
        }
        k = new BigInteger(Integer.toString(n - 1));
        while (k.compareTo(ZERO) > 0) {
            b = b.divide(k);
            k = k.subtract(ONE);
        }
        System.out.println(b);
    }
}

Measured memory_bytes: 103292
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        
        if (b+1 >= c) {
            System.out.println(n+1);
            return;
        }
        
        
        n = n - b + 1;
        
        // System.out.println(n);
        
        long tmp = b;
        if (n % 2 == 0) {
            tmp += (c - b) * (n / 2);
        } else {
            tmp += (c - b) * (n / 2);
            tmp++;
        }
        System.out.println(tmp);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1000000007LL;
int main() {
	string X;
	cin >> X;
	int S = 0;
	int T = 0;
	int cnt = 0;
	for (int i = 0; i < X.size(); i++) {
		if (X[i] == 'S') {
			if (T == 0) {
				S++;
			}
			else {
				int m = min(S, T);
				cnt += min(S, T) * 2;
				S -= m;
				S++;
				T = 0;
			}
		}
		else {
			if (S > 0) T++;
		}
	}
	cnt += min(S, T) * 2;
	cout << X.size() - cnt << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
/*int main()
{int n,x,t;
cin>>n>>x>>t;
int ans=0;
int y=x;
for(int i=t;;i+=t){
if(n<=y){ans=i;break;}
y+=x;
}
cout<<ans<<endl;
return 0;
}*/

/*int main(){
string s;
cin>>s;
int sum=0;
for(int i=0;i<s.length();i++){
    sum+=(s[i]-'0');
    sum%=9;
}
if(sum==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}*/
int main(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
ll sum=0;
for(int i=1;i<n;i++){
if(a[i-1]<=a[i])continue;
else{
    sum+=(1ll)*abs(a[i-1]-a[i]);
    a[i]=a[i-1];
}
}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 4400
#include<iostream>
#include<cstdio>
#include<cstring>
#define _A_ true
using namespace std;
  
int main(){
  int n,AC=0,strA,strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];
  
  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;
strA = strlen(A);
strB = strlen(B);
 
    for(int i=0;i<strA;i++){
      for(int j=0;j<strB;j++){
    if(A[i] == B[j]){
      dp[i+1][j+1]=dp[i][j]+1;
    }
    else{
      if(dp[i+1][j] > dp[i][j+1]){
        dp[i+1][j+1]=dp[i+1][j];
      }
      else {
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
      }
    }
    printf("%d\n",dp[strA][strB]);
    AC++;
  }
  delete [] A;
  delete [] B;
  
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		
		BufferedReader vd = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(vd.readLine());
		System.out.println(x/3);

	}

}


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

int main(void) {
  int ans,i,m;
  ans=0;
  char a;
  scanf("%c",&a);
  if(a=='A'||a=='B'||a=='C'||a=='D'||a=='F'||a=='E'||a=='F'||a=='G'||a=='H'||a=='I'||a=='J'||a=='K'||a=='L'||a=='M'||a=='S'||a=='O'||a=='P'||a=='Q'||a=='R'||a=='S'||a=='T'||a=='U'||a=='V'||a=='W'||a=='X'||a=='Y'||a=='Z')
  {
    printf("A");
  }
  else
  {
    printf("a");
  }
  return 0;
}

Measured memory_bytes: 1584
def selection_sort(A, N):
  sw = 0
  for i in range(0,N-1):
    minj = i
    for j in range(i,N):
      if A[j] < A[minj]:
        minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
      sw += 1
  print(*A)
  print(sw)

N = int(input())
A = list(map(int, input().split()))
selection_sort(A, N)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define _ ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

typedef long long ll;

const int MAX = 1e3+2;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int seg[3*MAX];
int n;

void build(){
	for(int i = 1000 - 1; i; i--)
		seg[i] = seg[i*2] + seg[i*2+1];
}
void update(int a, int x){
	seg[a += 1000] += x;
	while(a /= 2) seg[a] = seg[a*2]+seg[a*2+1];
}
ll query(int a, int b){
	ll ret = 0;
	for(a += 1000, b += 1000; a <= b; a /= 2, b /= 2){
		if(a%2)
			ret += seg[a++];
		if(b%2 == 0)
			ret += seg[b--];
	}
	return ret;
}

int main(){_
	memset(seg,0,sizeof(seg));
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		seg[v[i]+1000]++;
	}
	build();
	ll ans = 0;
	for(int i = 0; i < n; i++){
		update(v[i], -1);
		for(int j = i+1; j < n; j++){
			update(v[j], -1);
			int mx = min(v[i]+v[j]-1, 1000);
			int mn = max(v[j]-v[i], v[i] - v[j]) + 1;
			if(mn > mx) continue;
			ans += query(mn, mx);
		}
		for(int j = i+1; j < n; j++)
			update(v[j], 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

        if(a[0]!=0){
            cout << -1 << endl;
            return 0;
        }

    int now=0;
    ll ans=0;
    rep(i,n-1){
        if(a[i+1]-a[i]>1){
            cout << -1 << endl;
            return 0;
        }
        else if(a[i+1]-a[i]==1){
            ans++;
        }
        else ans+=a[i+1];
    }

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

Measured memory_bytes: 4036
def kuksan(array):
    for i in range(0, n):
        if array[i] > 0:
            left = i
            for j in range(left,n + 1):
                if array[j] <= 0:
                    right = j - 1
                    return left, right, True
    return 0,0,0

n = int(input())
h_list = list(map(int, input().split()))
cnt = 0
while True:
    h_list.append(0)
    kukan = kuksan(h_list)
    if kukan[2]:
        for i in range(kukan[0], kukan[1] + 1):
            h_list[i] -= 1
        cnt += 1
    else:
        break

print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  int m,f,r;
  while(scanf("%d %d %d",&m,&f,&r),m+f+r!=-3){
    if(m==-1||f==-1)
      printf("F\n");
    else if(m+f>=80)
      printf("A\n");
    else if(m+f>=65)
      printf("B\n");
    else if(m+f>=50)
      printf("C\n");
    else if(m+f>=30){
      if(r>=50)
	printf("C\n");
      else
	printf("D\n");
    }
    else
      printf("F\n");
  }
  return 0;
}

Measured memory_bytes: 584
program kadai
   implicit none
    integer(8)  ::  n,k
    integer,allocatable  ::  a(:)
    integer(8)  ::  i,j
    integer(8)  ::  big
    integer(8)  ::  num1,num2,num
    integer(8)  ::  small
    integer(8)  ::  kari

    read(*,*) n,k
    allocate(a(n))
    read(*,*) a

    num=0
    big=0
    small=0
    kari=0

    do i=1,n-1
        do j=i+1,n
            if (a(i)>a(j)) then
                big=big+1
            end if
            if (a(i)<a(j)) then
                small=small+1
            end if
        end do
    end do


    !big=mod(big,10**9+7)
    !small=mod(small,10**9+7)

    !kari=dble(k-1)*dble(k)/2
    !kari=mod(kari,10**9+7)
    !write(*,*) kari
    small=mod((mod(k*(k-1)/2,10**9+7))*small,10**9+7)
    big=mod((mod(k*(k+1)/2,10**9+7))*big,10**9+7)
    !num1=dble(kari)*dble(small)
    !num1=mod(num1,10**9+7)
    !kari=mod(kari+k,10**9+7)
    !num2=dble(kari)*dble(big)
   ! write(*,*) num1,num2
    !num2=mod(num2,10**9+7)
   ! write(*,*) num2
    !num=mod(num1+num2,10**9+7)

    write(*,*) mod(big+small,10**9+7)

stop
contains

end program kadai

Measured memory_bytes: 256