akhauriyash/Code-Regression huggingface dataset:
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-22 22:47:10
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int64 n; cin >> n;
  if (n & 1) {
    cout << 0 << endl;
    return 0;
  }

  n >>= 1;

  int64 ans = 0;

  while (n > 0) {
    int64 t = n / 5;
    ans += t;
    n /= 5;
  }

  cout << ans << endl;

  return 0;
}

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

#define LLINF (1LL<<60)
typedef long long ll;

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

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int H,W;
    cin >>H>>W;

    vector<string> S(H);
    rep(i,H) cin >> S[i];
    
    //-----------------------------------
    vector<vector<int>> HU(W,vector<int>(H,-1));
    vector<vector<int>> HD(W,vector<int>(H,-1));
    vector<vector<int>> HR(W,vector<int>(H,-1));
    vector<vector<int>> HL(W,vector<int>(H,-1));
    bool is=false;
    int ans=0;
    rep(j,H){
        HL[0][j] = (S[j][0]=='.') ? 0 : -1;
        repd(i,1,W){
            if(S[j][i]=='.'){
                HL[i][j]=HL[i-1][j]+1;
            }else{
                rep(k,HL[i-1][j]+1){
                    HR[i-1-k][j]=k;
                }
                HL[i][j]=-1;
            }
        }
        if(S[j][W-1]=='.'){
            rep(k,HL[W-1][j]+1){
                HR[W-1-k][j]=k;
            }
        }
    }
    rep(i,W){
        HU[i][0] = (S[0][i]=='.') ? 0 : -1;
        repd(j,1,H){
            if(S[j][i]=='.'){
                HU[i][j]=HU[i][j-1]+1;
            }else{
                rep(k,HU[i][j-1]+1){
                    HD[i][j-1-k]=k;
                }
                HU[i][j]=-1;
            }
        }
        if(S[H-1][i]=='.'){
            rep(k,HU[i][H-1]+1){
                HD[i][H-1-k]=k;
            }
        }
    }
    
    rep(i,W){
        rep(j,H){
            chmax(ans,HU[i][j]+HD[i][j]+HL[i][j]+HR[i][j]+1);
        }
    }

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

Measured memory_bytes: 67200
def main():
    A, B, K = list(map(int, input().split()))
    which = "A"
    for _ in range(K):
        if which == "A":
            A = A // 2
            B = B + A
            which = "B"
        else:
            B = B // 2
            A = A + B
            which = "A"
    print(str(A) + " " + str(B))


if __name__ == "__main__":
    main()

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

#define ll long long

ll N, M, K, cache[3000][3000][4];
map < pair < ll, ll >, ll > val;


ll dp(ll i, ll j, ll col){
	if (i >= N){
		return LLONG_MIN;
	}else if (j >= M){
		return LLONG_MIN;
	}else if (col > 3){
		return LLONG_MIN;
	}
	else if (i == N - 1 && j == M - 1){
		ll ret = 0;
		if (col < 3){
			if (val.find({i, j}) != val.end()){
				ret += val[{i, j}];
			}
		}
		return ret;
	}
	if (cache[i][j][col] != -1)
		return cache[i][j][col];
	ll result = LLONG_MIN;
	if (col >= 3){
		result = max({result, dp(i + 1, j, 0), dp(i, j + 1, col)});
	}else{
		if (val.find({i, j}) != val.end()){
			result = max({result, dp(i + 1, j, 0), dp(i, j + 1, col)});
			result = max({result, val[{i, j}] + dp(i + 1, j, 0), val[{i, j}] + dp(i, j + 1, col + 1)});
		}else{
			result = max({result, dp(i + 1, j, 0), dp(i, j + 1, col)});			
		}
	}
	return cache[i][j][col] = result;
}

int main(){
	cin >> N >> M >> K;
	memset(cache, -1, sizeof cache);
	for (ll i = 0; i < K; i ++){
		ll A, B, V; cin >> A >> B >> V;
		A --; B--;
		val[{A, B}] = V;
	}
	cout << dp(0, 0, 0) << "\n";
}


Measured memory_bytes: 298312
#include<bits/stdc++.h>
using namespace std;
int n,k,val[100005];
vector<int> g[100005];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(val,-1,sizeof(val));
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		int v,p;
		cin>>v>>p;
		val[v]=p;
		pq.push(make_pair(p,v));
	}
	while(!pq.empty())
	{
		pair<int,int> p=pq.top();
		pq.pop();
		for(int i=0;i<g[p.second].size();i++)
			if(val[g[p.second][i]]==-1)
			{
				val[g[p.second][i]]=val[p.second]+1;
				pq.push(make_pair(val[g[p.second][i]],g[p.second][i]));
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<g[i].size();j++)
			if(abs(val[i]-val[g[i][j]])!=1)
			{
				cout<<"No"<<endl;
				return 0;
			}
	cout<<"Yes"<<endl;
	for(int i=1;i<=n;i++)
		cout<<val[i]<<endl;
	return 0;
}


Measured memory_bytes: 7924
s = input()
pos = -1
ans = ""
t = 0

for i in range(len(s)):
	if s[i] == "A" or s[i]== "C" or s[i] == "G" or s[i] == "T":
		pos = i
		for j in s[pos:]:
			if j == "A" or j == "C" or j == "G" or j == "T": 
				ans +=  j
			else:
				break

	if t < len(ans):
		t = len(ans)
	ans = ""

print(t)


Measured memory_bytes: 3060
# ARC097C - K-th Substring
def substring_getter(a: str, x: int) -> set:
    length = len(a)
    ret = set()
    for i in range(length - x + 1):
        ret.add(a[i : i + x])
    return ret


def main():
    s = input()
    k = int(input())
    ans = set()
    for i in range(1, k + 1):
        ans = ans | substring_getter(s, i)
    print(sorted(ans)[k - 1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 4804
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

a1 = [0]
a2 = [0]

for i in range(N):
  if i == 0:
    a1.append(A1[i])
    a2.append(A2[i])
  else:
    a1.append(a1[-1] + A1[i])
    a2.append(a2[-1] + A2[i])
    
ans = 0

for i in range(N):
  if a1[i+1] + a2[-1] - a2[i] > ans:
    ans = a1[i+1] + a2[-1] - a2[i]
    
print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000000
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 21;
struct point {
    ll x, y, sol;
    bool operator == (point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (point b)
    {
        return !(*this == b);
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         ans = ans * ans % mod;
    }
    else ans = fast_exp(x, n - 1) * x % mod;
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x = 1, y = INF, ans = 0, k;
        cin >> x >> n;
        bool v[102] = {};
        for(int i = 0; i < n; i++)
        {
            cin >> k;
            v[k] = 1;
        }
        for(int i = 0; i < 102; i++)
        {
            if(v[i] == 0)
            {
                if(abs(x - i) < y)
                {
                    y = abs(x - i);
                    ans = i;
                }
            }
        }
        cout << ans << "\n";
     }
     return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using namespace std;
unsigned long long n,ans,bef,arr[100005],bsr[100005];
bool sabi;
int main(){
	cin>>n;
	for(int i =0;i<=n;i++){
		cin>>arr[i];
	}
	sabi=1;
	if(n==0){
		if(arr[0]==1)cout<<1<<endl;
		else cout<<-1<<endl;
		return 0;
	}
	if(arr[0]>0)sabi=0;

	for(int i =0;i<=n;i++){
		if(i==0)bsr[i]=1;
		else{
			bsr[i]=bsr[i-1]*2-arr[i];
		}
		if(bsr[i]<0)sabi=0;
	}
	for(int i =n;i>=0;i--){
		if(i==n){
			bef=arr[i];
			ans+=bef;
		}
		else{
			if((bef+1)/2>bsr[i])sabi=0;
			bef= min(bef,bsr[i])+arr[i];
			ans+=bef;
		}
	}
	if(sabi)cout<<ans<<endl;
	else cout<<-1<<endl;

}

Measured memory_bytes: 5152
#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
    int N;

    cin >> N;

    string S;

    vector<string> strings;

    for (int i = 0; i < N; i++)
    {
        cin >> S;
        sort(S.begin(), S.end());
        strings.push_back(S);
    }

    long long pairs = 0;

    long long count = 0;

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

    for (int i = 0; i < N-1; i++)
    {
        if (strings.at(i) == strings.at(i+1))
        {
            count++;
            pairs += count;
        }
        else 
        {
            count = 0;
        }
    }

    cout << pairs << endl;

    return 0;
}

Measured memory_bytes: 5748
#include<stdio.h>

int main(void){
  int number[100]={};
  int a=0;
  int check=1;
  int max=0;
  while(scanf("%d",&a)!=EOF){
    number[a-1]++;
    if(check==1){
      max=number[a-1];
      check=-1;
    }else{
      if(max<number[a-1]) max=number[a-1];
    }
  }
  for(int i=0;i<100;i++){
    if(max==number[i]){printf("%d\n",i+1);}
  }
  return 0;
}



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

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
    int N,K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        for (int j = 1;j <= K; j++) {
            if (i-j >= 0) {
                chmin(dp[i],dp[i-j] + abs(h[i] - h[i-j]));
            } else {
                break;
            }
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

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


def main():
    n, d = map(int, input().split())

    a = n // (2 * d + 1)
    if (n - a * (2 * d + 1)) != 0:
        print(a + 1)
        return

    print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#define N 10000
#define Q 500 
 
int main(){
  int n, s[N], q, t[Q], i, j, count = 0;
 
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &s[i]);
 
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    scanf("%d", &t[i]);
 
 
  for(i = 0; i < q; i++){
    s[n] = t[i]; 
    j = 0;
    while(s[j] != t[i]){
      j++;
    }
    if(j != n)
      count++;
  }
 
  printf("%d\n", count);
 
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(void)
{
	char cards[200];
	char buf[200];
	
	int i,j;
	
	int shuffle;
	int sh;
	
	int L;
	
	while(1){
		scanf("%s",&cards);
		if(cards[0] == '-')break;
		
		L = strlen(cards);
		
		scanf("%d",&shuffle);
		
		for(i = 0;i < shuffle;i++){
			scanf("%d",&sh);
			strncpy(buf,cards,sh);
			buf[sh] = '\0';
			
			for(j = 0;j < L-sh;j++){
				cards[j] = cards[sh+j];
			}
			
			cards[j] = '\0';
			
			strcat(cards,buf);
		}
		printf("%s\n",cards);
	}
	return 0;
}

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

int main(){
  vector<int> A(3);
  cin >> A.at(0) >> A.at(1) >> A.at(2);
  sort(A.begin(), A.end());
  if(A.at(0)==5 && A.at(1)==5 && A.at(2)==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <iostream>
#define MAXC 222222
#define MODD 1000000007
#define ll long long
using namespace std;

int C[222222];
ll cumul[222222];
ll dp[222222];

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        cin>>C[i];
        //C[i]=rand()%200000+2;
    }
    
    /*
    dp[N+1]=1;
    C[N+1]=-1;
    
    for(int i=N;i>=1;i--) {
        
        dp[i]=0;
        for(int j=i;j<=N;j++) {
            if (C[i]==C[j] && C[j+1]!=C[i]) {
                dp[i]+=dp[j+1];
            }
        }
    }
    cout << dp[1] << endl;
     */
    
    
    dp[N+1]=1;
    C[N+1]=-1;

    for(int i=1;i<=MAXC;i++)
        cumul[i]=0;
    
    cumul[C[N]]=1;
    
    
    for(int i=N;i>=1;i--) {
        
        dp[i]=cumul[C[i]];
        if (i == 1)
            break;
        
        if (C[i]!=C[i-1]) {
            cumul[C[i-1]]+=dp[i];
            cumul[C[i-1]]%=MODD;
        }
        
    }
    
    
    cout << dp[1]%MODD << endl;
    
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int> a(N),b(N);
    int x;
    for(int i=0;i<N;i++){
        cin>>x;
        a[i]=x;b[i]=x;
    }
    sort(ALL(b),greater<int>());
    int M1=b[0],M2=b[1];
    for(int i=0;i<N;i++){
        if(a[i]!=M1)cout<<M1<<endl;
        else cout<<M2<<endl;
    }
}

Measured memory_bytes: 3200
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    answer();
   }
   static  void  answer()
   {
     Scanner sc = new Scanner(System.in);
     
     int n[] = new int[3];
     //input
     for (int i = 0; i < n.length ;i ++)
     {
       n[i] = sc.nextInt();
     }
     
     sort(n);
     
     for (int i = 0; i < n.length ; i ++)
     {
       if(i != 0)System.out.print(" ");
       
       System.out.printf("%d",n[i]);
     }
     System.out.println("");
   }
   static int[] sort(int s[])
   {
     for(int i = 0 ;i + 1 < s.length;i ++)
     {
       for(int j = 0; j + 1 < s.length - i; j ++)
       {
           if(s[j] > s[j + 1])
           {
             int box = s[j];
             
             s[j] = s[j + 1];
             
             s[j + 1] = box;
           }
       }
     }
     return s;
   }
 }
    


Measured memory_bytes: 26500
#include <bits/stdc++.h>
using namespace std;
int arr[101];
int main() {
	int n;
	cin>>n;
	
	for(int i=0; i<n; i++) cin>>arr[i];
	
	int ans=10000000;
	for(int x=-100; x<=100; x++){
		int t=0;
		for(int i=0; i<n; i++){
			
			t += (x-arr[i])*(x-arr[i]);
		
		}
		
		ans= min(ans, t); 
	}
	
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String N = sc.next();

        if(N.substring(0,1).equals("9")){
            System.out.println("Yes");
        }
        else{
            if(N.substring(1).equals("9")){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A&lang=jp


typedef pair<int,int> P;

typedef pair<int,P> PP;

const int UNIMAX = 1000;
int uni[UNIMAX] = {}; //parent -- size of member , kid -- leader name,def -1

int uniroot(int a){ //return a's leader
	if (uni[a] < 0) return a;
	return uni[a] = uniroot(uni[a]); //uni[a] => 0 , reconnect root directly
}

bool uniconnect(int a,int b){
	a = uniroot(a);
	b = uniroot(b);
	
	if(a==b) return false;
	
	if(uni[a] > uni[b]){
		a ^= b;
		b ^= a;
		a ^= b;
	}
	
	uni[a] = uni[a] + uni[b]; // membersize++
	uni[b] = a;
	return true;
}

bool uniisConnect(int a,int b){
	return (uniroot(a) == uniroot(b));
}

int unisize (int a){
	return (-uni[uniroot(a)]);
}

int unireset() {
	REP(i,UNIMAX){
		uni[i] = -1;
	}
}


int main() {
	int n; SCD(n);
	static int d[UNIMAX][UNIMAX];
	priority_queue<PP,vector<PP>,greater<PP> > Q; //(cost ,(a,b)) a->b
	
	FORq(i,1,n){
		FORq(j,1,n){
			int x; SCD(x);
			d[i][j] = x;
			if ((x != -1) and (i>=j)) {
				Q.push(MP(x,MP(i,j)));
			}
		}
	}
	
	unireset();
	
	int connected = 1;
	int cost = 0;
	
	while((connected <= n) and (!Q.empty())){
		PP now = Q.top(); Q.pop();
		int ncost = now.first;
		int a = now.second.first;
		int b = now.second.second;
		
		if (uniisConnect(a,b) == false) {
			uniconnect(a,b);
			connected++;
			cost += ncost;
		}
		
	}
	
	PRINTD(cost);
	
}











Measured memory_bytes: 3296
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

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 int MOD = 998244353;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int A[200010], B[200010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N) {
		cin >> B[i];
	}

	bool ok = false;
	int cnt = 0;
	while (!ok) {
		ok = true;
		bool done = false;
		REP(i, N) {
			if (A[i] != B[i])ok = false;
			int l = (i + N-1) % N;
			int r = (i + 1) % N;
			int dif = B[l] + B[r];
			if (B[i] > dif) {
				int c = (B[i] - A[i]) / dif;
				//printf("c:%lld\n", c);
				cnt += c;
				B[i] -= c * dif;
				if(c>0)done = true;
			}
		}
		if (ok) {
			print(cnt);
			return 0;
		}
		if (!done) {
			print(-1); return 0;
		}
	}
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ll minn = 2, maxn = 2;
  repr(i, k - 1) {
    if (a[i] > maxn) {
      cout << -1 << endl;
      return 0;
    }
    chmax(minn, a[i]);
    if (minn % a[i] != 0) minn = (minn / a[i] + 1) * a[i];
    if (maxn % a[i] != 0) maxn = maxn / a[i] * a[i];
    if (minn > maxn) {
      cout << -1 << endl;
      return 0;
    }
    maxn += a[i] - 1;
  }
  cout << minn << ' ' << maxn << endl;



  
  return 0;
}


Measured memory_bytes: 1024
N=int(input())
dp=[list(map(int,input().split()))]
for _ in range(1,N):
    a,b,c=map(int,input().split())
    dp.append([a+max(dp[-1][1:]),b+max(dp[-1][0],dp[-1][2]),c+max(dp[-1][:2])])
print(max(dp[-1]))

Measured memory_bytes: 22796
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000001000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int id[1000100];
int s[1000100];
vector<P> vec;
int Max_s=-INF;
int maxcount=0;
set<int> S;
int N,Q,X;
bool C(int r)
{
	int cur=-1;
	int cnt=0;
	set<int>::iterator it;
	for(it=S.begin();it!=S.end();it++)
	{
		int a = max((s[*it]-r),cur+1);
		int b = s[*it];
		if(a>b)continue;
		cnt+=upper_bound(s,s+N,b)-lower_bound(s,s+N,a);
		cur=max(cur,s[*it]);
	}
	return (N-cnt)<=X;
}
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&s[i]);
		vec.pb(P(s[i],i));
		Max_s=max(Max_s,s[i]);
	}
	sort(s,s+N);
	sort(vec.begin(),vec.end());
	for(int i=0;i<N;i++)id[vec[i].sec]=i;
	string type;
	int a;
	for(int i=0;i<Q;i++)
	{
		cin >> type;
		if(type=="ADD")
		{
			scanf("%d",&a);
			a--;
			S.insert(id[a]);
			//cout << s[id[a]] << endl;
			if(s[id[a]]==Max_s)maxcount++;
		}
		else if(type=="REMOVE")
		{
			scanf("%d",&a);
			a--;
			S.erase(id[a]);
			if(s[id[a]]==Max_s)maxcount--;
		}
		else
		{
			scanf("%d",&X);
			int l=-1,r=INF;
			while(r-l>1)
			{
				int mid=(l+r)/2;
				if(C(mid))r=mid;
				else l=mid;
			}
			if(r==INF)printf("NA\n");
			else printf("%d\n",r);
		}
	}
	return 0;
}

Measured memory_bytes: 17020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string T; cin >> T;
    for(char& c : T){
        if(c == '?') c = 'D';
    }
    cout << T << endl;

}

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

long long ans;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) ans += i;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int>p(M,0);
    vector<string>s(M);
    for(int i=0;i<M;i++) cin >> p[i] >> s[i];
    vector<int>wa_count(N,0);
    vector<int>ac_count(N,0);
    for(int i=0;i<M;i++){
        if(s[i]=="WA" && ac_count[p[i]-1]==0){            
            wa_count[p[i]-1] +=1;
        }
        else if(s[i] == "AC"){
            ac_count[p[i]-1] = 1;
        }

        /*for(auto x:wa_count) cout << x << " ";
        cout << endl;
        for(auto x:ac_count) cout << x << " ";
        cout << endl;*/
    }
    for(int i=0;i<N;i++){
        if(ac_count[i]==0){wa_count[i]=0;}
    }

    int total_AC=0;
    int total_WA=0;
    for(int i=0;i<N;i++){
        total_AC += ac_count[i];
        total_WA += wa_count[i];
    }
    cout << total_AC << " " << total_WA << endl;
}

Measured memory_bytes: 6912
#include<iostream>
#include<string>
using namespace std;
const long double bt = 380000;
int main () {
  int N;
  cin >> N;
  long double ans = 0;
  for (int i = 0; i < N; i ++) {
    long double a;
    string s;
    cin >> a >> s;
    if (s == "JPY") ans += a;
    else ans += a * bt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    ll n,k; cin>>n>>k;
    ll x=0,y=0; 
    rep(i,1,n+1){
        if(i%k==0) x++;
        if(i%k==k/2) y++;
    }
    if(k%2==0){
        cout<<x*x*x+y*y*y<<endl;
    }else{
        cout<<x*x*x<<endl;
    }

}

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


using namespace std;

int main() {
	int N;
	cin >> N;
	
	if(N/100 ==7 || N/10%10 == 7 || N %10 == 7)
		cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll x(n);
  vin(x);

  ll min = mod;
  rep(i, 0, 101){
    ll cost = 0;
    vrep(j, x) cost += (j - i) * (j - i);
    if(cost < min) min = cost;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
n,l = map(int,input().split())
#味のリスト
#l,l+1,...,l+n-1
lis=[i for i in range(l,l+n)]
if lis[-1]<0: print(sum(lis[:-1]))
elif lis[0]*lis[-1]<=0: print(sum(lis))
else: print(sum(lis[1:]))

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

int main() {
  int K, A, B;
  string ans = "NG";
  cin >> K >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) ans = "OK";
  }
  cout << ans << endl;
}


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

int main(){

  int A,B,coin=0;
  
  cin >> A >> B;
  
  for(int i=0;i<2;i++){
  
    if(A>B){
      coin+=A;
        A--;
    
    }else{
    coin+=B;
      B--;
    }
  
  }
  
  cout << coin;
 
  return 0;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        String s = scan.next();
        int R = 0;
        int B = 0;
        char[] data = s.toCharArray();
        for(char c : data) {
            if (c == 'R') {
                R += 1;
                continue;
            }
            B += 1;
        }
        String answer = "No";
        if (R > B) {
            answer = "Yes";
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
	static int W, H;
	static char[][] tile;

	static int move(int x, int y) {
		int count = 1;

		if (y + 1 < H) {
			if (tile[y + 1][x] == '.') {
				tile[y + 1][x] = 'o';
				count += move(x, y + 1);
			}
		}
		if (y - 1 >= 0) {
			if (tile[y - 1][x] == '.') {
				tile[y - 1][x] = 'o';
				count += move(x, y - 1);
			}
		}
		if (x + 1 < W) {
			if (tile[y][x + 1] == '.') {
				tile[y][x + 1] = 'o';
				count += move(x + 1, y);
			}
		}
		if (x - 1 >= 0) {
			if (tile[y][x - 1] == '.') {
				tile[y][x - 1] = 'o';
				count += move(x - 1, y);
			}
		}

		return count;
	}

	public static void main(String[] args) {
		String temp;
		int atX = 0, atY = 0;
		int num;
		Scanner s = new Scanner(System.in);

		while (true) {
			W = s.nextInt();
			H = s.nextInt();
			
			if(W==0 && H==0) break;

			tile = new char[H][W];

			for (int i = 0; i < H; i++) {
				temp = s.next();
				tile[i] = temp.toCharArray();

				for (int j = 0; j < W; j++) {
					if (tile[i][j] == '@') {
						atX = j;
						atY = i;
					}
				}
			}

			num = move(atX, atY);

			System.out.println(num);
		}
		s.close();
	}

}

Measured memory_bytes: 35448
#include<bits/stdc++.h>
using namespace std;
string s;
int a,b,c,d; 
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++) 
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<s.size();j++) 
	        {
		    if(s[j]=='F')
		    {
			    cout<<"Yes";
			    return 0;
		}
	        }
		} 
	}
	cout<<"No";
	return 0;
}


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

int main() {
  int N,i,count=0;
  cin>>N;
  vector<int> num(N);
  for(i=0;i<N;i++)cin>>num[i];    
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());
  for(i=0;i<N;i++){
    if(i%2==0)count+=num[i];
    else count-=num[i];
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

enum
{
	x,
	y,
};

int main()
{
	int n;
	cin >> n;
	int d2_min = 800000001;
	int d2_min_thisloop;
	int d2;
	int min_d_index = 0;
	vector< vector<int> > a(n, vector<int>(2));
	for (int i = 0; i < n; i++)
	{
		cin >> a[i][x] >> a[i][y];
	}
	sort(a.begin(), a.end()); // xの値で昇順にソートされる
	for (int i = 0; i < n; i++)
	{
		d2_min_thisloop = 800000001;
		for (int j = i + 1; j < n; j++)
		{
			if (pow(a[j][x] - a[i][x], 2) > d2_min_thisloop) break; // j以降のaj-ai間距離は必ずd2min < d2となる
			d2 = pow(a[j][x] - a[i][x], 2) + pow(a[j][y] - a[i][y], 2);
			d2_min_thisloop = min(d2_min_thisloop, d2);
			d2_min = min(d2_min, d2);
		}
	}
	cout << d2_min << endl;
	return 0;
}


Measured memory_bytes: 30344
n,m = gets.chomp.split(" ").map(&:to_i)

max_l = 0
min_r = n
m.times do |i|
  l,r=gets.chomp.split(" ").map(&:to_i)
  max_l = l if l > max_l
  min_r = r if r < min_r
end

result = min_r - max_l + 1
if result > 0 then
  puts result
else
  puts 0
end


Measured memory_bytes: 3836
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, x) = get!(usize, usize);
    let v = get!([usize]);
    let mut ans = 1;
    let mut dist = 0;
    for i in 0..n {
        if v.len() <= i {
            break;
        }
        dist += v[i];
        if x < dist {
            break;
        }
        ans += 1;
    }
    println!("{}", ans);
}


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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 




int main(int argc, char** argv) {
    fast_io
   
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a < b && b < c ? "Yes\n" : "No\n");
	
	

    return 0;
}























Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

struct mint {
	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 { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int s;
	cin >> s;
	vector<mint> v(s+1, 0);
	for (int i = 3; i <= s; i++) {
		mint x = 1;
		map<int, int> mp;
		for (int j = 3; i - j >= 3; j++) {
			if (mp[j]) continue;
			mp[i-j]++;
			if (j == i - j) x += v[j];
			else x += v[j] + v[i - j];
		}
		v[i] = x;
	}
	cout << v[s] << endl;
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int main() {
	int n,a[200],c=0;
	cin >> n;
	REP(i, n)cin >> a[i];
	for (int j = 0;; j++) {
		REP(i, n) {
			if (i == n - 1) {
				if (a[i] % 2 == 0)c++;
			}
			if (a[i] % 2 == 0) {
				a[i] = a[i] / 2;
			}
			else {
				cout << c;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;

  bool a = true;
  int a_count = 0, b_count = 0;
  REP(i, s.length()) {
    if(s[i] - '0' == a) b_count++;
    else a_count++;

    a = !a;
  }

  cout << min(a_count, b_count) << endl;
}


Measured memory_bytes: 512
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let mut v = vec![];
    for _ in 0..5 {
        v.push(read_t_in_line::<i32>()[0]);
    }
    let k = read_t_in_line::<i32>()[0];
    let len = 5;

    for i in 0..len {
        for j in 0..len {
            let a = v[i];
            let b = v[j];
            if (a-b) > k {
                println!(":(",);
                return;
            }
        }
    }
    println!("Yay!");

    
}



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

int main(){
  int a,b,c,k; cin>>a>>b>>c>>k;
  int ans=0;
  if(a<=k){
    ans+=a;
    k-=a;
  }
  else{
    cout<<k<<endl;
    return 0;
  }
  if(b<=k)
    k-=b;
  else{
    cout<<ans<<endl;
    return 0;
  }
  if(c==k){
    ans-=c;
    cout<<ans<<endl;
  }
  else
    cout<<ans-k<<endl;
}

Measured memory_bytes: 3596
n, h = gets.split.map(&:to_i)

as = []
bs = []
n.times do
    a, b = gets.split.map(&:to_i)
    as << a
    bs << b
end

amx = as.max
bsum = 0
bcnt = 0
bs.sort!
bs.reverse!
bs.each do |bi|
    if bi > amx
        bsum += bi
        bcnt += 1
        if bsum >= h
            puts bcnt
            exit
        end
    end
end

puts (h - bsum + amx - 1)/amx + bcnt


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  vector<string> v(3);
  REP (i, 3) {
    cin >> v[i];
  }

  int ans = 0;
  REP (j, n) {
    if (v[0][j] == v[1][j] && v[1][j] == v[2][j]) {
      ans += 2;
    } else if (v[0][j] != v[1][j] && v[0][j] != v[2][j] && v[1][j] != v[2][j]) {
      continue;
    } else {
      ans+= 1;
    }
  }
  
  cout << n * 2 - ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int n, m;
    cin >> n >> m;
    vi a(n);
    ll sum = 0;
    rep(i, m){
        cin >> a[i];
        sum += a[i];
    }
    if(n-sum >= 0){
    cout << n-sum << endl;
    }
    else {
    cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 7204
def main():
    size = 45
    fib = [0]*size
    fib[0] = 1
    fib[1] = 1
    for i in range(2,size):
        fib[i] = fib[i-1]+fib[i-2]
    n = int(input())
    print (fib[n])


if __name__ == '__main__':
    main()




Measured memory_bytes: 5600
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define Kmax (int)(1e5+10)

using namespace std;

typedef long long int Int;

Int dp[Kmax]; //i番目までの子供でj配る
int N,K;

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

    dp[0] = 1;
    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;

        Int sum = 0;
        for(int j = 0;j <= a;j++) {
            sum = (sum + dp[K-j]) % MOD;
        }

        for(int j = K;j >= 0;j--) {
            sum = (sum + MOD - dp[j]) % MOD;
            dp[j] = (dp[j] + sum) % MOD;
            if(j - a - 1 >= 0)
                sum = (sum + dp[j - a - 1]) % MOD;
        }
    }

    cout<<dp[K]<<endl;

    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(void) {
    int N, ans=0;

    int A[3][3];
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++) cin >> A[i][j];
    }
    cin >> N;
    vector<int> b(N);
    for(int i=0; i<N; i++) cin >> b[i] ;

    bool flag[3][3];
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        flag[i][j] = false;
      }
    }

    for(int k=0; k<N; k++){
      for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
          if(b[k] == A[i][j])
            flag[i][j] = true;
        }
      }
    }
    bool check = false;

    for(int i=0; i<3; i++){
        if(flag[i][0] && flag[i][1] && flag[i][2]) //横
          check = true;
        else if(flag[0][i] && flag[1][i] && flag[2][i]) //縦
          check = true;
        else if(flag[0][0] && flag[1][1] && flag[2][2])
          check = true;
        else if(flag[2][0] && flag[1][1] && flag[2][0])
          check = true;
    }

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

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,k;
  cin >> n >> k;
  int b[k],a[n],su[n] = {},c = 0; 
  for (int i = 0; i < k; i++){
    cin >> b[i];
    for (int j = 0; j < b[i]; j++){
      cin >> a[j];
      su[a[j]-1] += 1;
    }
  }
  for (int i = 0; i < n; i++){
    if (su[i] == 0){
      c += 1;
    }
  }
  cout << c << '\n';
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll k;
    cin>>k;
    bitset<1000001>S(0);
    ll c = 7 % k;
    ll res = 1;

    while(!S[c])
    {
        if(c == 0)return cout<<res,0;
        S[c]=1;
        c = (10*c+7)%k;
        res++;
    }

    cout<<-1;
}


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

int A, B;

int main(){
    cin >> A >> B;
    if(A + B >= A - B){
        if(A * B >= A + B){
            cout << A * B;
        }else{
            cout << A + B;
        }
    }else if(A - B > A * B){
        cout << A - B;
    }else{
        cout << A * B;
    }
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    char last = '-', current;
    int n, sum = 0;
    cin >> n;
    cin.get();
    for (int i = 0; i < n; i++) {
        cin.get(current);
        if (current != last) {
            last = current;
            sum++;
        }
    }
    cout << sum;
}

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

int main(){
    int N, p[51], cnt =0, tmp;
    bool flag = 0;

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

    for (int i = 0; i < N; i++) {
        if ((i+1) != p[i]) cnt ++;
    }

    if (cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, 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);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};

signed main() {
	int n;
	scnaf("%d", &n);

	char str[101], str2[101];
	scanf("%s %s", str, str2);

	REP(i, n) {
		bool f = 1;
		for (int j = 0; i + j < n; j++) {
			if (str[i + j] != str2[j]) {
				f = 0;
				break;
			}
		}
		if (f) {
			printf("%d\n", n * 2 - (n - i));
			return 0;
		}
	}
	pritnf("%d\n", n*2);
	return 0;
}

Measured memory_bytes: 256