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

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

	int ret = 0;
	for(int i=0; i<N; i++)
	{
		int l, r;
		cin >> l >> r;

		ret += r - l + 1;
	}

	cout << ret << endl;

	return 0;
}


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

int a, b, c;

int main() {
    std::cin >> a >> b >> c;
    if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
        std::cout << "Possible" << std::endl;
    }
    else {
        std::cout << "Impossible" << std::endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = Vector.fill(n - 1)(sc.nextInt())


    val store = ArrayBuffer.fill[Int](n)(0)

    a.foreach { an =>
      store(an - 1) += 1
    }

    store.foreach(println)

  }
}


Measured memory_bytes: 67768
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

//Rock Man
public class Main{

	int n, COUNT, INF = 1<<29, res;
	
	List<E>[] edge, rev;
	Map<String, Integer> ref;
	int get(String s){
		if(ref.containsKey(s))return ref.get(s);
		ref.put(s, COUNT);
		return COUNT++;
	}
	
	class E{
		int t, c;
		public E(int t, int c) {
			this.t = t;
			this.c = c;
		}
	}
	
	boolean[] visited;
	List<Integer> list;
	void dfs(int k){
		if(visited[k])return;
		visited[k] = true;
		for(E e:edge[k])dfs(e.t);
		list.add(k);
	}
	int[] scc;
	void rdfs(int k, int ID){
		if(visited[k])return;
		visited[k] = true;
		scc[k] = ID;
		for(E e:rev[k])rdfs(e.t, ID);
	}
	
	int cycle(int k, int start, boolean f){
		if(k==start&&f||rev[k].isEmpty())return 0;
		E e = rev[k].get(0);
		return e.c+cycle(e.t, start, true);
	}
	void make(int k){
		for(E e:edge[k]){
			if(visited[e.t])continue;
			res += e.c; visited[e.t] = true; make(e.t);
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			edge = new List[n]; rev = new List[n];
			ref = new HashMap<String, Integer>();
			COUNT = 0;
			for(int i=0;i<n;i++){
				edge[i] = new ArrayList<E>();
				rev[i] = new ArrayList<E>();
			}
			int[] cost = new int[n];
			for(int i=0;i<n;i++){
				int x = get(sc.next());
				cost[x] = sc.nextInt();
				int y = get(sc.next()), c = sc.nextInt();
				if(x==y)continue;
				edge[y].add(new E(x, c)); rev[x].add(new E(y, c));
			}
			visited = new boolean[n];
			list = new ArrayList<Integer>();
			for(int i=0;i<n;i++)if(!visited[i])dfs(i);
			int ID = 0;
			scc = new int[n];
			visited = new boolean[n];
			for(int i=list.size()-1;i>=0;i--){
				int v = list.get(i);
				if(visited[v])continue;
				rdfs(v, ID); ID++;
			}
			int[] deg = new int[ID];
			for(int i=0;i<n;i++)for(E e:edge[i]){
				if(scc[i]!=scc[e.t])deg[scc[e.t]]++;
			}
			res = 0;
			visited = new boolean[n];
			for(int i=0;i<n;i++){
				if(deg[scc[i]]>0||visited[i])continue;
				int p = -1;
				if(rev[i].isEmpty()){
					p = i;
				}
				else{
					int c = cycle(i, i, false);
					p = i;
					int min = c-rev[i].get(0).c+cost[i];
					for(int j=0;j<n;j++){
						if(scc[i]!=scc[j])continue;
						int v = c-rev[j].get(0).c+cost[j];
						if(v<min){
							min = v; p = j;
						}
					}
				}
				visited[p] = true; res+=cost[p];
				make(p);
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17000
N = int(input())
X = [list(map(int, input().split())) for n in range(N)]
X = sorted(X, key=lambda x: x[0])
X = sorted(X, key=lambda x: x[1])
cnt = 0
isLimitOver = False
for x in X:
    cnt += x[0]
    if cnt > x[1]:
        isLimitOver = True
        break
if isLimitOver:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 55960
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

int n, q;
string s;
int l[100100], r[100100];
int cnt[100100];

int solve(int l, int r) {
  int res = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      res++;
    }
  }
  return res;
}

int main() {

  cin >> n >> q;
  cin >> s;
  s[n] = 'X';
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }
  int c = 0;
  cnt[0] = 0;
  cnt[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (s[i-2] == 'A' && s[i-1] == 'C') {
      c++;
    }
    cnt[i] = c;
  }

  for (int i = 0; i < q; i++) {
    cout << cnt[r[i]] - cnt[l[i]] << endl;
  }

}


Measured memory_bytes: 2176
A,B,C,X,Y=map(int,input().split())
m=min(X,Y)
d=A+B
c=2*C
ans=0
if d>c:
    ans+=c*m
else:
    ans+=d*m
l=max(X,Y)
if X>Y:
    if A>c:
        ans+=c*(l-m)
    else:
        ans+=A*(l-m)
else:
    if B>c:
        ans+=c*(l-m)
    else:
        ans+=B*(l-m)
print(ans)

Measured memory_bytes: 3064
// cpp219 - the 712534
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
const ll base = 7;
const ll N = 2e3 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

ll s;
ll a[100];
int main(){
    ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin>>s;
    while(s > 0){
        a[s%10]++;
        s /= 10;
    }
    if (a[7] > 0) cout<<"Yes\n";
    else cout<<"No\n";
}


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

int main() {
    int n, k;
  	cin >> n >> k;
    vector<int> l(n);
    rep(i, n) cin >> l.at(i);
    sort(l.begin(), l.end(), greater<int>());

    int sum = 0;
    rep(i, k) sum += l.at(i);

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    k, t = map(int, input().split())
    a = list(map(int, input().split()))
    if t == 1:
        print(a[0] - 1)
    else:
        maxa = max(a)
        hoka = sum(a) - maxa
        if maxa <= hoka:
            print(0)
        else:
            print(maxa - hoka - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5628
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;

using namespace std ;

string LCS( string str1 , string str2 , int N , int M ){
    
    int dp[N+1][M+1] ;
    for( int i = 0 ; i <= N ; i++ ){
        for( int j = 0 ; j <= M ; j++ ){
            if( i == 0 || j == 0 )
                dp[i][j] = 0 ;
        }
    }
    for( int i = 1 ; i <= N ; i++ ){
        for( int j = 1 ; j <= M ; j++ ){
            if( str1[i-1] != str2[j-1] )
                dp[i][j] = max( dp[i-1][j] , dp[i][j-1] ) ;
            else
                dp[i][j] = 1 + dp[i-1][j-1] ;
        }
    }
    int i = N , j = M ;
    string ans = "" ;
    if( dp[N][M] == 0 )
        return ans ;
    while( i != 0 && j != 0 ){
        if( str1[i-1] == str2[j-1] ){
            ans += str1[i-1] ;
            i-- ; j-- ;
        }
        else if( dp[i][j] == dp[i][j-1] ){
                j-- ;
            }
        else if( dp[i][j] == dp[i-1][j] ){
            i-- ;
        }
    }
    reverse(ans.begin(), ans.end() ) ;
    return ans ;
}
    
int main(){
    FAST();
    string str1 , str2 ; cin >> str1 >> str2 ;
    cout << LCS( str1 , str2 , ( int )str1.size() , ( int )str2.size() ) << endl ;
    return 0 ;
}




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

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0)
            printf(" %d", i);
        else
        {
            int x = i;
            for (int x = i; x > 0; x /= 10)
            {
                if (x % 10 == 3)
                {
                    printf(" %d", i);
                    break;
                }
            }
        }
    }
    printf("\n");
}


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

string s;
int ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s;
    for(int i=0,j=s.size()-1;i<j;i++,j--){
        ans+=s[i]!=s[j];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

using namespace std;
using ll = long long;

int main()
{
    ll x,y;
    cin>>x>>y;

    ll ans=1;
    while(y/x>=2){
        ans++;
        x*=2;
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int main() {
  LL H, W;
  scanf("%lld%lld", &H, &W);

  LL result = H * W;

  REP(q,2) {
    result = min(result, W % 3 == 0 ? 0 : W);
    FOR(i,1,W) {
      LL one = i * H;
      LL mini = min(one, H/2 * (W - i));
      LL maxi = max(one, (H+1)/2 * (W - i));
      result = min(result, maxi - mini);
    }

    swap(H,W);
  }
  printf("%lld\n", result);
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define bg begin
namespace IO{
	
cs int RLEN=1<<20|1;
char ibuf[RLEN],*ib,*ob;
inline char gc(){
	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}

}
using IO::read;
using IO::readstring;
using IO::readchar;
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int N=128,C=62;
inline bool comp(cs string &a,cs string &b){
	return a.size()<b.size();
}
inline char id(int x){
	if(x<26)return 'a'+x;
	if(x>51)return '0'+(x-52);
	return 'A'+(x-26);
}
inline int query(string x){
	cout<<"? "<<x<<endl;
	return read();
}
int n;
bool check(string x){
	return query(x)+x.size()==n;
}
int main(){
	vector<string>tp;
	for(int i=0;i<C;i++){
		string x(N,id(i));
		int vl=N-query(x);
		n+=vl;
		if(vl)tp.pb(string(vl,id(i)));
	}
	while(tp.size()>1){
		sort(tp.bg(),tp.end(),comp);
		string a=tp[0],b=tp[1],res;
		tp.erase(tp.bg(),tp.bg()+2);
		while(a.size()&&b.size()){
			if(check(res+a[0]+b)){
				res+=a[0],a.erase(a.bg());
			}
			else res+=b[0],b.erase(b.bg());
		}
		res+=a,res+=b;
		tp.pb(res);
	}cout<<"! "<<tp[0]<<endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define MEM(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int mod = 1e9 + 7;
int main() {
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

int c[10][10];	//c[i][j] cost of making  i->j
vector <int> d(10,INT_MAX);		//mincost of making i->1
vector <bool> vis(10,false);	

int main(){
	int h,w,ans,k;
	cin>>h>>w;
	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cin>>c[i][j];
	
	d[1]=0; 
	for(int i=0;i<10;i++){
		
		int Min = INT_MAX,Min_j;
		for(int j=0;j<10;j++){
			if(vis[j]==false && d[j]<Min){
				Min_j = j;
				Min = d[j];
			} 
		}
		vis[Min_j]=true;
		
		for(int j=0;j<10;j++){
			if(vis[j]==false && j!=Min_j)
				d[j] = min(d[j],c[j][Min_j]+d[Min_j]);
		}
	}
	
	ans=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			cin>>k;
			if(k!=-1)
				ans+=d[k];
			}
			
	cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main()
{
  long long N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  for (long long m = 0; m <= N - 1; m++) {
    long long n = N - 1 - m;
    if (m*C - n*D <= B - A && B - A <= m*D - n*C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun isPalindrome(s: String): Boolean {
  val n = s.length
  for (i in 0 until n / 2) {
    if (s[i] != s[n - i - 1]) return false
  }
  return true
}

fun main(args: Array<String>) {
  val s = readLine()!!
  val n = s.length
  val a = s.substring(0, (n - 1) / 2)
  val b = s.substring((n + 3) / 2 - 1, n)
  if (a == b && isPalindrome(a) && isPalindrome(b)) {
    println("Yes")
  } else {
    println("No")
  }
}


Measured memory_bytes: 33832
import bisect

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

t, r = divmod(A[-1], 2)
idx = bisect.bisect_left(A, t)

if r == 1:
    if idx != 0:
        if abs(A[idx - 1] - t) < abs(A[idx] - t):
            idx = idx - 1
else:
    if idx != 0:
        if abs(A[idx - 1] - t) <= abs(A[idx] - t):
            idx = idx - 1

print(' '.join([str(A[-1]), str(A[idx])]))



Measured memory_bytes: 19992
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pp pop_back
#define maximo 1e18
using namespace std;
static const long long INF=1e18;

int main(){
    int n; cin>> n;
    ll nums[n];
    bool zero = false;
    for(int i = 0; i < n; i++){
        cin>> nums[i];
        if(nums[i] == 0) zero = true;
    }
    ll ans = 1;
    if(zero) cout << 0 << "\n";
    else{
        for(int i = 0; i < n; i++){
            if(nums[i] <= INF/ans){
                ans = nums[i]*ans;
            }
            else{
                cout << -1 << "\n";
                return 0;
            }
            
        }
        cout << ans << "\n";
    }   
    return 0;
}

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

int main(){
    vector<long long> result,tmp;
    for(int i=1;i<=9;i++){
        result.push_back(i);
        tmp.push_back(i);
    }
    for(int i=0;i<9;i++){
        vector<long long> tmp2=tmp;
        tmp.clear();
        for(int j=0;j<tmp2.size();j++){
            long long num=tmp2[j]*10+tmp2[j]%10;
            if(tmp2[j]%10!=0){
                tmp.push_back(num-1);
                result.push_back(num-1);
            }
                tmp.push_back(num);
                result.push_back(num);
            if(tmp2[j]%10!=9){
                tmp.push_back(num+1);
                result.push_back(num+1);
            }
        }
    }
    int n;
    cin>>n;
    cout<<result[n-1]<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
	vector<vector<int> > A;
	for(int i = 0; i < 3; ++i) {
		vector<int> row;
		for(int j = 0; j < 3; ++j) {
			int a;
			cin >> a;
			row.push_back(a);
		}
		A.push_back(row);
	}
	int N;
	cin >> N;
	vector<vector<bool> > B(3, vector<bool>(3, false));
	for(int k = 0; k < N; ++k) {
		int b;
		cin >> b;
		for(int i = 0; i < 3; ++i) {
			for(int j = 0; j < 3; ++j) {
				if(A[i][j] == b) {
					B[i][j] = true;
				}
			}
		}
	}
	if(
		(B[0][0] && B[0][1] && B[0][2]) || (B[1][0] && B[1][1] && B[1][2]) || (B[2][0] && B[2][1] && B[2][2]) ||
		(B[0][0] && B[1][0] && B[2][0]) || (B[0][1] && B[1][1] && B[2][1]) || (B[0][2] && B[1][2] && B[2][2]) ||
		(B[0][0] && B[1][1] && B[2][2]) || (B[2][0] && B[1][1] && B[0][2])) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}



Measured memory_bytes: 256
import math
N = [int(e) for e in input().split()]
a = (math.pi/360)*(60*N[2] + N[3])
b = (math.pi/30)*N[3]
if(a>b):
    ans = math.sqrt(N[0]**2 + N[1]**2 - 2*N[0]*N[1]*math.cos(a-b))
else:
    ans = math.sqrt(N[0]**2 + N[1]**2 - 2*N[0]*N[1]*math.cos(b-a))
print('{:.020f}'.format(ans))

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

int n,m;
int A[2000];

bool solve(int depth,int sum) {
  if (sum==m) {
    return true;
  }
  if (depth>=n) {
    return false;
  }
  bool result=solve(depth+1,sum+A[depth])||solve(depth+1,sum);
  return result;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>A[i];
  }
  int q;
  cin>>q;
  while (q--) {
    cin>>m;
    cout<<(solve(0,0)?"yes":"no")<<endl;
  }
  return 0;
}



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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{
	int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {

		fy(26) {
			cin >> table[x][y];

		}
	}
	ll ans = 0;
	fx(D) {
		int t;
		cin >> t;
		ans += table[x][t-1];
		Las[t - 1] = x+ 1;
		fy(26) {
			ans -= C[y] * (x + 1 - Las[y]);
		}
		ce(ans);
	}
    return 0;
}



Measured memory_bytes: 3584
#include <stdio.h>

int main(){
   int k,n,i,m,a,b,f;

   scanf("%d %d",&k,&n);
   scanf("%d",&b);
   f=b;
   m=0;
   for (i=1;i<n;i++) {
      scanf("%d",&a);
      if (a-b>m) m=a-b;
      b=a;
   }
   a=k-b+f;
   if (a>m) m=a;
   printf("%d\n",k-m);
   return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

const ll MAX = 5100000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll a[101010];
int solve()
{
    ll n;
    cin >> n;
    map<ll, ll> m;
    ll v;
    for(int i=0; i < n + 1; i++){
        cin >> a[i];
        m[a[i]]++;
        if(m[a[i]] == 2){
            v = a[i];
        }
    }

    ll l=-1, r;
    for(int i=0; i < n + 1; i++){
        if(a[i] == v && l == -1){
            l = i;
        }else if(a[i] == v){
            r = i;
        }
    }

    COMinit();
    for(ll i=0; i < n + 1; i++){
        ll k=COM(l + (n - r), i);
        ll p = (COM(n + 1, i + 1) - k + MOD)%MOD;
        cout << p << endl;
    }

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}



Measured memory_bytes: 127744
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    ll  a, b, c;
    cin >> a >> b >> c;
    if(b + a >= c) cout << b + c << endl;
    else if(a + b < c) cout << a + 2 * b + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e5+5;
const int INF = 2e18+5;
//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif
vector< string > s;
vector< vector<bool> > vis;
vector< vector<int> > dis;
int x, y , x2 , y2;
int dx[] = {0 , 0 , 1  , -1 };
int dy[] = {-1 , 1 , 0  , 0 };
int n , m, k;
bool check(int xi , int yi ){
    return xi>=0 && xi<n && yi>=0 && yi<m;
}

void bfs()
{
    queue< pii > q;
    q.push({x, y});
    vis[x][y] = true;
    dis[x][y] = 0;
    while(!q.empty()){
        auto p = q.front();
        int px = p.first , py = p.second;
        q.pop();
        for(int i=0 ; i<4 ; i++){
            for(int len = 1; len<=k ; len++){
                int new_x = px + dx[i]*len;
                int new_y = py + dy[i]*len;
                if(!check(new_x , new_y)) break;
                if(vis[new_x][new_y] && dis[new_x][new_y] < dis[px][py]+1) break;
                if(s[new_x][new_y]!='.') break;

                if(vis[new_x][new_y]) continue;
                vis[new_x][new_y] = true;
                dis[new_x][new_y] = dis[px][py]+1;
                q.push({new_x , new_y});

            }
        }
    }
}

void solve(){
    cin >>n >> m >> k;
    cin >> x >> y >> x2 >> y2;
    x--;
    y--;
    x2--;
    y2--;
    s.resize(n+1);
    vis.resize(n+1 , vector<bool >(m+1 , 0));
    dis.resize(n+1 , vector<int>(m+1 , 0));
    for(int i=0 ; i<n ;i++) cin >> s[i];

    bfs();
    if(!vis[x2][y2]){
        cout <<-1;
        return;
    }
    cout << dis[x2][y2]<< endl;
}


signed main(){
    FAST;
    //TODO: check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}
/* Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

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

typedef long long ll;

int main () {
	char S[10];
	cin >> S;
	int cnt = 0;
	int max = 0;
	for (int i=0; i<3; i++) {
		if (S[i]=='R')
			cnt ++;
		else {
			if (cnt>max)
				max = cnt;
			cnt = 0;
		}
	}
	if (cnt > max)
		max = cnt;
	cout << max << endl;
	return 0;
}

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

int main(){
    int N,s,i;
    cin >> N;
    vector<int> a;
    if(N == 0) cout << "0" << endl;
    else{
        while(N != 1){
            if(N%2==0){
                N /= -2;
                a.push_back(0);
            }else{
                N -= 1;
                N /= -2;
                a.push_back(1);
            }
        }
        a.push_back(1);
        s = a.size();
        for(i=s-1;i>=0;i--) cout << a.at(i);
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np

X, Y, Z, K = map(int, input().split())
A = np.array(tuple(map(int, input().split())), dtype=np.int64)
B = np.array(tuple(map(int, input().split())), dtype=np.int64)
C = np.array(tuple(map(int, input().split())), dtype=np.int64)

AB = (A + B.reshape((Y, 1))).flatten()
AB.sort()

ABC = (AB[::-1][:K] + C.reshape((Z, 1))).flatten()
ABC.sort()

print(*ABC[::-1][:K], sep="\n", end="")


Measured memory_bytes: 67376
#include<bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
int n,W;
ll w[100005],v[100005],memo[105][100005];
using namespace std;
ll dp(int i,int free_weight)
{
    if(memo[i][free_weight]!=-1)
    {
        return memo[i][free_weight];
    }
    if(i==n)
    {
        return 0;
    }
    ll ret1=0,ret2;
    if(free_weight-w[i]>=0)
        ret1=v[i]+dp(i+1,free_weight-w[i]);
    ret2=dp(i+1,free_weight);
    return memo[i][free_weight]=max(ret1,ret2);
}
int main()
{
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;++i)
    {
        scanf("%lld%lld",&w[i],&v[i]);
    }
    memset(memo,-1,sizeof memo);
    printf("%lld",dp(0,W));
    return 0;
}


Measured memory_bytes: 82304
#include<iostream>
#include<string>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define YN(f) (f?"YES":"NO")
#define yn(f) (f?"Yes":"No")	
#define INF 123456789123456
#define MOD (int)(1e9+7)
#define MAX_N 10
#define MAX_V 1



signed main(){
	string S[60];
	int temp[60][60] = {};
	int H, W;
	
	cin>>H>>W;
	
	for(int i = 0; i < H; i++){
		cin>>S[i];
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] != '#') continue;
			for(int k = -1; k <= 1; k++){
				for(int l = -1; l <= 1; l++){
					if(!l&&!k) continue;
					int x = l + j , y = k + i;
					if(x < 0 || x > W || y < 0 || y > H) continue;
					temp[y][x]++;
				}
			}
		}
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] == '#') cout<<'#';
			else cout<<temp[i][j];
		}cout<<endl;
	}
	
	
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(V),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> v(26, 0);
	string s;
	cin >> s;
	REP(i, s.size())v[s[i] - 'a']++;
	int res = 1;
	REP(i, 26)res *= v[i] + 1;
	if (res % 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  ll N;
  string S;
  cin >> N >> S;
  for (ll i = 0; i < S.length(); i++) {
    S[i] = S[i] + N;
    if (S[i] > 'Z') S[i] -= 26;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
//Range Sum Query
//reference https://www.slideshare.net/hcpc_hokudai/rmq-47663507
#include<iostream>
#include<vector>

using namespace std;

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

template <typename  T>
struct RSQ {
    T n;
    vector<T> node;

    RSQ(T *a_,T n_) {
        vector<T> a(a_,a_+n_);
        initialize(a);
    }
    RSQ(vector<T> a) {
        initialize(a);
    }

    void initialize(vector<T> a) {
        T n_ = a.size();
        n = 1;
        while(n < n_)n *= 2;

        node.clear();
        node.resize(2*n,0);

        rep(i,n_) node[n + i] = a[i];
        for(int i=n-1;i > 0;i--)node[i] = node[2 * i] + node[2 * i + 1];
    }

    void update(T k,T a) {// k番目(0-indexed)の値をaに更新
        add(k,a - node[k]);
    }

    void add(T k,T x) {// k番目(0-indexed)の値をxだけ増やす
        k += n;

        while(k > 0) {
            node[k] += x;
            k /= 2;
        }
    }

    T query(T a,T b,T k=1,T l=0,T r=0) {//query(a,b) ∑_{i ∈ [a,b)} node[i] を返す
        if(a >= b) {
          cerr << "warning wrong range" << endl;
          return 0;
        }
        //k 節点のインデックス
        //その節点が[l,r)に対応づいている。
        if(l>=r)r = n;//外から呼ばれる時 l=0,r=nとする必要があるのでこうなる。
        if(r <= a || b <= l)return 0;//範囲外
        if(a <= l && r <= b)return node[k];//[a,b)に[l,r)が含まれる

        T vl = query(a,b,2*k,l,(l + r) / 2);
        T vr = query(a,b,2*k + 1,(l + r) / 2,r);
        return vl + vr;
    }
    void print() {
        for(int i = 1;i < 2 * n;i++) {
            if(__builtin_popcount(i) == 1)
                cerr << endl;
            cerr << node[i] << " ";
        }
        cerr << endl;
    }
};

typedef long long ll;
ll n,q;

int main() {
    cin >> n >> q;
    
    vector<ll> a;
    rep(i,n)a.push_back(0);

    RSQ<ll> rsq(a);

    rep(i,q) {
        ll c,x,y;
        cin >> c >> x >> y;

        if(c) {
            x--,y--;
            cout << rsq.query(x,y+1) << endl;
        }else {
            x--;
            rsq.add(x,y);
        }
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	int n, m, k;
	cin >> n >> m >> k;
	if (n < m) {
		swap(n, m);
	}
	cout << (k + n - 1) / n << endl;
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
int k,dist[100000];
deque<int> todo;
int main()
{
	cin>>k;
	for(int i=0;i<k;i++)dist[i]=MOD;
	dist[1]=1;
	todo.push_back(1);
	while(todo.size()){
		int x=todo.front();todo.pop_front();
		if(dist[(10*x)%k]>dist[x]){
			dist[(10*x)%k]=dist[x];
			todo.push_front((10*x)%k);
		}
		if(dist[(x+1)%k]>dist[x]+1){
			dist[(x+1)%k]=dist[x]+1;
			todo.push_back((x+1)%k);
		}
	}
	cout<<dist[0]<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;

ll p(int x){
  ll ret = 1;
  for(int i=2;i<=x;i++)ret=ret*i%mod;
  return ret;
}

void gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}

ll inv(ll a,ll n)  {
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x,y;
  cin>>x>>y;
  int tt = 2 * y - x;
  if(tt<0||tt%3!=0){
    cout<<0<<endl;
    return 0;
  }
  int a = tt/3;
  int tt2 = x - a;
  if(tt2<0||tt2%2!=0){
    cout<<0<<endl;
    return 0;
  }
  int b = tt2/2;
  ll fenzi = p(a+b);
  ll fenmu = p(a)*p(b)%mod;
  ll ret = fenzi*inv(fenmu, mod)%mod;
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int,input().split()))
#print(w)
a=[]
for i in range(n):
  before = sum(w[:i+1])
 # print(before)
  after = sum(w[i+1:])
  #print(after)
  a.append(abs(before - after))
print(min(a))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <functional>

using std::array;
using std::vector;

constexpr int H = 4, W = 10;

using Block = vector<vector<char>>;
using Board = array<array<char, W>, H>;

int main() {
    array<Block, 4> blocks;
    for (auto& block : blocks) {
        int h, w;
        std::cin >> h >> w;
        block.resize(h);
        for (auto& s : block) {
            s.resize(w);
            for (auto& c : s) {
                std::cin >> c;
            }
        }
    }

    int q;
    std::cin >> q;
    for (int i = 0; i < q; ++i) {
        Board board;
        for (auto& s : board) {
            for (auto& c : s) {
                std::cin >> c;
            }
        }

        std::function<bool(int)> dfs =
            [&](int idx) {
                if (idx == 4) {
                    for (int x = 0; x < H; ++x) {
                        for (int y = 0; y < W; ++y) {
                            if (board[x][y] == '.') {
                                return false;
                            }
                        }
                    }
                    return true;
                } else {
                    if (dfs(idx + 1)) return true;

                    auto& block = blocks[idx];
                    int h = block.size(), w = block.front().size();

                    for (int x = 0; x + h - 1 < H; ++x) {
                        for (int y = 0; y + w - 1 < W; ++y) {
                            bool puttable = true;

                            // check
                            for (int dx = 0; dx < h; ++dx) {
                                for (int dy = 0; dy < w; ++dy) {
                                    if (block[dx][dy] == '.') continue;
                                    if (board[x + dx][y + dy] != '.') puttable = false;
                                }
                            }

                            if (!puttable) continue;

                            // paint
                            for (int dx = 0; dx < h; ++dx) {
                                for (int dy = 0; dy < w; ++dy) {
                                    if (block[dx][dy] == '.') continue;
                                    board[x + dx][y + dy] = 'A' + idx;
                                }
                            }

                            bool result = dfs(idx + 1);

                            // reverse
                            for (int dx = 0; dx < h; ++dx) {
                                for (int dy = 0; dy < w; ++dy) {
                                    if (block[dx][dy] == '.') continue;
                                    board[x + dx][y + dy] = '.';
                                }
                            }

                            if (result) return true;
                        }
                    }
                    return false;
                }
            };

        std::cout << (dfs(0) ? "Yes" : "No") << std::endl;
    }
    return 0;
}



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

int main(){
	int n, m, i, j;

	cin>>n>>m;
	
	int a[n][m], b[m], c ;
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin>>a[i][j];
		}
	}
	
	for(i = 0; i < m; i++){
		cin>>b[i];
	}
	
	for(i = 0; i < n; i++){
		c = 0;
		for(j = 0; j < m; j++){
			c += a[i][j] * b[j];
		}
		cout<<c<<endl;
	}

	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
using namespace std;
long long a[100005], pre, ans, ANS;
int n;
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		a[i] += a[i-1];
	}
	pre = 0;
	for (int i = 1; i <= n; ++i)
		if (i&1) {
			if (pre + a[i] <= 0ll) {
				ans += 1ll - pre - a[i];
				pre += 1ll - pre - a[i];
			}
		}
		else {
			if (pre + a[i] >= 0ll) {
				ans += pre + a[i] + 1ll;
				pre -= pre + a[i] + 1ll;
			}
		}
	ANS = ans;
	ans = pre = 0;
	for (int i = 1; i <= n; ++i)
		if (i&1) {
			if (pre + a[i] >= 0ll) {
				ans += pre + a[i] + 1ll;
				pre -= pre + a[i] + 1ll;
			}
		}
		else {
			if (pre + a[i] <= 0ll) {
				ans += 1ll - pre - a[i];
				pre += 1ll - pre - a[i];
			}
		}
	printf("%lld", min(ANS, ans));
}

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

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

    int num = 0;
    char last = '@';
    for (int i = 0; i < n; i++){
        if (last != str.at(i)){
            num++;
            last = str.at(i);
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;


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

int main(){
	int N,M;
	int a[100];
	int b[100];

	int out[100] = {0};

	scanf("%d",&N);
	scanf("%d",&M);

	REP(M){
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		out[a[i]-1]++;
		out[b[i]-1]++;
	}

	REP(N){
		printf("%d\n",out[i]);
	}

}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(){
	string s;
	int now=0; //????????????
	int ans=0;
	
	cin >> s;
	
	while(now<=s.size()){
		long p=0, q=0;
		stringstream ss1, ss2;
		
		if(s[now]!='0'){ //?????????0??????????????¨?????????
			
			for(int i=0; i<now; ++i) ss1<<s[i];
			for(int i=now; i<s.size(); ++i) ss2<<s[i];
			
			ss1>>q;
			ss2>>p;
			
			//printf("p=%ld, q=%ld\n", p, q);
			
			if(p-q>=0 && (p+q)%2==0) ++ans;
		}
		now++;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 1228
(ns Atcoder.ABC088-B)
(require '[clojure.string :as str])
(def N (read-string (read-line)))                                         ; N
(def A (map read-string (str/split (read-line) #" ")))      ; A
(def A (sort > A))

(def alice (reduce + (map (fn [x] (nth A x)) (filter even? (range 0 N)))))
(def bob (reduce + (map (fn [x] (nth A x)) (filter odd? (range 0 N)))))

(println (- alice bob))

Measured memory_bytes: 65580
#include <string>
#include <iostream>

using namespace std;
int p=1;
string s;
int a,b;
int main(){
    cin>>a>>b;
    for(int i=0;i<a;i++,p++){
        char q='A';
        for(int j=0;j<b;j++,q++){
            cin>>s;
            if(s=="snuke"){
                cout<<q<<p;
                return 0;
            }
        }
    }
}

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

// Z_array の構築, 「S と S[i:|S|-1] の最長共通接頭辞の長さ」
vector<int> Z_array(string S){
    int n = S.size();
    vector<int>res(n, 0);
    res[0] = -1;
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < n && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) { ++i; continue; }
        int k = 1;
        while (i+k < S.size() && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k; j -= k;
    }
    return res;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N-1; ++i) { // l_1 = i
        auto v = Z_array(S);
        for (int j = 1; j < v.size(); ++j) { // l_2 = i + j
            int len = min(v[j], j);
            ans = max(len, ans);
        }
        S.erase(S.begin());
    }
    cout << ans;
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> nums(N, 0);
	for (int i = 0; i < N; i++){
		cin >> nums[i];
	}
	int odd_num = 0;
	for (int i = 0; i < N; i++){
		if (nums[i] % 2 == 1){
			odd_num++;
		}
	}
	if (odd_num % 2 == 1){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
constexpr int inf = (1 << 30) - 1;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-10;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> constexpr void print(const T& t) {cout << t << "\n";}
template<typename T, typename U> constexpr bool chmax(T& a, const U& b) {if (a < b) a = b; return a < b;}
template<typename T, typename U> constexpr bool chmin(T& a, const U& b) {if (a > b) a = b; return a > b;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {rep(i, sz(v)) is >> v[i]; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) os << v[i] << (i + 1 != sz(v) ? " " : ""); return os;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    rep(dy) cout << "U";
    rep(dx) cout << "R";
    rep(dy) cout << "D";
    rep(dx) cout << "L";
    rep(1) cout << "L";
    rep(dy+1) cout << "U";
    rep(dx+1) cout << "R";
    rep(1) cout << "D";
    rep(1) cout << "R";
    rep(dy+1) cout << "D";
    rep(dx+1) cout << "L";
    rep(1) cout << "U";
    cout << "\n";
}

Measured memory_bytes: 3652
n = int(raw_input())
l = [[[0 for i in range(10)]for j in range(3)]for k in range(4)]
for i in range(n):
    b,f,r,v = map(int,raw_input().split())
    l[b-1][f-1][r-1] += v
for i in range(4):
    if i != 0:
        print "####################"
    for j in range(3):
        print "",
        for k in range(9):
            print "%d" %l[i][j][k] ,
        print l[i][j][9]

Measured memory_bytes: 6468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool flag = 1;
    while(a > 0 && c > 0)
    {
    if (flag) c -= b;
    else a -= d;
    flag = !flag;
    }
    if (a > 0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n;
  cin>>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  ll b[n];
  rep(i,n) {
    b[i] = a[i] - (i + 1);
  }
  sort(b, b + n);
  ll t = b[n/2];
  ll ans = 0;
  rep(i,n) {
    ans += abs(a[i] - (t + i + 1));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    INF = 10**9

    H, W, K = map(int, input().split())
    chocolate = [ input() for _ in range(H) ]
    
    loop_H = range(H)
    loop_W = range(W)
    min_cut = INF-1
    for div in range(1 << (H-1)):
        # 横割りでグループ分け
        group = [[]]
        group_number = 0
        for i in loop_H:
            group[group_number].append(i)
            if div >> i & 1:
                group.append([])
                group_number += 1
        # 縦に切っていく
        cut = group_number
        zeros = [0] * len(group)
        cnt = zeros.copy()
        w = 0
        while w < W:
            now = zeros.copy()
            for g in range(len(group)):
                for i in group[g]:
                    if chocolate[i][w] == '1':
                        now[g] += 1
                if now[g] > K:
                    cut = INF
                    break
                if cnt[g] + now[g] > K:
                    cut += 1
                    w -= 1
                    cnt = zeros.copy()
                    break
                cnt[g] += now[g]
            w += 1
        if cut < min_cut:
            min_cut = cut
    print(min_cut)

main()

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


def divisors(n, m):
	for i in range(m//n, 0, -1):
		if m % i == 0:
			return(i)


N, M = map(int, input().rstrip().split())
print(divisors(N, M))	

Measured memory_bytes: 3188
#include <iostream>
#include <string>

int main()
{
    std::string s;

    std::cin >> s;

    if (s.back() != 's')
    {
        std::cout << s << 's' << std::endl;
    }
    else
    {
        std::cout << s << "es" << std::endl;
    }
    
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, C, X, Y int
	fmt.Scan(&A, &B, &C, &X, &Y)

	ans := 1000000000
	for i := 0; i <= 2*max(X, Y); i++ {
		a := max(0, int(math.Ceil(float64(X-i/2))))
		b := max(0, int(math.Ceil(float64(Y-i/2))))
		c := i

		ans = min(a*A+b*B+c*C, ans)
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if (A >= 13) ans = B;
  else if (A >= 6) ans = B / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256