akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;


void solve() {
    int n, m;
    cin >> n >> m;
    auto club = [&](int x){
        return x/m;
    };
    vector<int> a[101][101];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x; cin >> x; x--;
            a[i][club(x)].emplace_back(x);
        }
    }
    int b[101][101];
    for (int j = 0; j < m; j++) {
        vector<vector<int>> g(n);
        for (int i = 0; i < n; i++) {
            for (int c = 0; c < n; c++) {
                if (!a[i][c].empty())
                    g[i].emplace_back(c);
            }
        }
        vector<bool> trk(n, false);
        vector<int> left(n, -1);
        function<bool(int)> dfs = [&](int l){
            if (trk[l]) return false;
            trk[l] = true;
            for (int r: g[l]) {
                if (left[r] == -1 || dfs(left[r])) {
                    left[r] = l;
                    return true;
                }
            }
            return false;
        };
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            fill(trk.begin(), trk.end(), false);
            if (dfs(i)) cnt++;
        }
        assert(cnt == n);
        for (int c = 0; c < n; c++) {
            int i = left[c];
            b[i][j] = a[i][c].back(); a[i][c].pop_back();
        }
    }
    int c[101][101];
    for (int j = 0; j < m; j++) {
        for (int i = 0; i < n; i++) {
            c[j][i] = b[i][j];
        }
        sort(c[j], c[j]+n, [&](int x, int y){return club(x) < club(y);});
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << b[i][j]+1 << ' ';
        }cout << "\n";
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << c[j][i]+1 << ' ';
        }cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int orig_n = n;
  vector<int> prime;
  for (int d = 2; d * d <= n; ++d) {
    if (n % d == 0) {
      prime.push_back(d);
      while (n % d == 0) n /= d;
    }
  }
  if (n != 1) prime.push_back(n);
  int m = prime.size(), ans = 0;
  for (int bit = 1; bit < (1 << m); ++bit) {
    int cnt = 0, mul = 1;
    REP(i, m) {
      if (bit >> i & 1) {
        cnt++;
        mul *= prime[i];
      }
    }
    if (cnt % 2) {
      ans += orig_n / mul;
    } else {
      ans -= orig_n / mul;
    }
  }
  ans = orig_n - ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
using namespace std;
 
double calc(double t,double h,double a){
  double tem = t - h * 0.006;
  if(tem >= a)
    return tem - a;
  else
    return a - tem;
}
 
int main(void){
  int N,T,A;
  cin >> N >> T >> A;
 
  vector<double>height(1000,0);
 
  for(int i=0;i<N;i++){
    cin >> height[i];
  }
 
  double min = 9999999;
  int ans =0;
 
  for(int i=0;i<N;i++){
    if(min > calc(T,height[i],A)){
      min = calc(T,height[i],A);
      ans = i;
    }
  }
 
 	cout << ans+1 << endl;
 
       return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	if ((1 <= A && A <= 9) && (1 <= B && B <= 9)) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
	

}






Measured memory_bytes: 256
package main

import "fmt"
import "strconv"

func main() {
	var A string
	fmt.Scan(&A)

	var sum int = 0
	var num int

	for i := 0; i < len(A); i++{
		num, _= strconv.Atoi(A[i:i+1])
		sum += num
	}

	if (sum % 9) == 0{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

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

vector<string> S;

int main(){
  string s;
  cin >> s;
  char ans[10];
  int len=0;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='0'){
      ans[len]='0';
      len++;
    }
    else if(s[i]=='1'){
      ans[len]='1';
      len++;
    }
    else if(s[i]=='B'){
      if(len!=0){
        len--;
      }
    }
  }
  for(int i=0; i<len; i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
s=list(input())
ans=0
wf=0
bf=0
for i in range(len(s)):
    if s[i]=='W':
        ans+=i
        wf+=1
    else:
        bf=1
if wf==0 or bf==0:
    print(0)
else:
    print(ans-wf*(wf-1)//2)


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);

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


    rep(i,N-1){
        if(A.at(i)==A.at(i+1)){
            cout<<"NO"<<endl;
            return 0;
        }

    }

            cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	ll n,i,l[1000006],j,k;
	cin>>n>>k;
	for(i=0;i<n;i++)
	cin>>l[i];
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(l[1]-l[0]);
	ll mi;
	for(i=2;i<n;i++)
	{
		mi=INT_MAX;
		for(j=1;j<=k&&i-j>=0;j++)
		mi=min(mi,dp[i-j]+abs(l[i]-l[i-j]));
		dp[i]=mi;
	}
	cout<<dp[n-1]<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3712
#87
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    if 500*i<=x:
        for j in range(b+1):
            if 500*i+100*j<=x:
                for k in range(c+1):
                    if(500*i+100*j+50*k==x):
                        count += 1
                    
print(count)

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

class Dice {
	public int[] value;
	public Dice(String[] info) {
		this.value = new int[6];
		for (int i = 0; i < value.length; i++) {
			this.value[i] = Integer.parseInt(info[i]);
		}
	}

	public int getTop( ) {
		return value[0];
	}

	public void rollingNorth() {
		int work = this.value[0];
		this.value[0] = this.value[1];
		this.value[1] = this.value[5];
		this.value[5] = this.value[4];
		this.value[4] = work;
	}

	public void rollingWest() {
		int work = this.value[0];
		this.value[0] = this.value[2];
		this.value[2] = this.value[5];
		this.value[5] = this.value[3];
		this.value[3] = work;
	}

	public void changeTop(int index) {
		if (index < 3) {
			rollingNorth();
		} else if (index == 3) {
			rollingWest();
		} else if (index == 4) {
			rollingWest();
			rollingWest();
		}
	}

	public void turn(String direction) {
		int work = 0;;
		if (direction.equals("S")) {
			// ?????????????¨??????¢
			work = this.value[1];
			this.value[1] = this.value[3];
			this.value[3] = this.value[4];
			this.value[4] = this.value[2];
			this.value[2] = work;
		} else {
			// ????????????????????¢
			work = this.value[0];
			this.value[0] = this.value[2];
			this.value[2] = this.value[5];
			this.value[5] = this.value[3];
			this.value[3] = work;
		}
	}

	public boolean isMatch(Dice target) {
		for (int i = 1; i < this.value.length; i++) {
			if (this.value[i] != target.value[i]) {
				return false;
			}
		}
		return true;
	}

	public boolean compare(Dice target) {
		boolean isMatch = false;
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 4; j++) {
				if (this.getTop() != target.getTop()) break;
				isMatch = this.isMatch(target);
				if (isMatch) break;
				target.turn("S");
			}
			if (isMatch) break;
			target.changeTop(i);
		}
		if (isMatch) return true;
		else return false;
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Dice[] diceArray = new Dice[n];
		for (int i = 0; i < n; i++) {
			diceArray[i] = new Dice(br.readLine().split(" "));
		}
		boolean isMatch = false;

		for (int i = 0; i < diceArray.length - 1; i++) {
			for (int j = i + 1; j < diceArray.length; j++) {
				isMatch = diceArray[i].compare(diceArray[j]);
				if (isMatch) break;
			}
			if (isMatch) break;
		}

		if (isMatch) System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 25484
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;

signed main(){
    string s; cin>>s;
    if(s.size()<26){
        vector<bool> alpha(26,false);
        rep(i,s.size()){
            alpha.at(s.at(i)-'a') = true;
        }
        rep(i,26){
            if(!alpha.at(i)){
                char c=i+'a';
                s+=c;
                break;
            }
        }
        cout<<s<<endl;
    }else{
        string t=s;
        reverse(all(t));
        t+='a';
        int cnt=0;
        rep(i,t.size()-1){
            cnt++;
            if(t.at(i)>=t.at(i+1)){
                break;
            }
        }
        if(cnt==26){
            cout<<-1<<endl;
            return 0;
        }
        char c='z';
        for(int i=26-cnt; i<26; i++){
            if(s.at(i)>s.at(25-cnt)){
                if(s.at(i)<c) c=s.at(i);
            }
        }
        string ans="";
        rep(i,25-cnt){
            ans+=s.at(i);
        }
        ans+=c;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

long long powmod(long long a, long long b) {
	if (b == 0) return 1;
	long long t = powmod(a, b / 2);
	if ((b & 1) == 0) return t * t % M;
	return t * t % M * a % M;
}

long long inv(long long a) {
	return powmod(a, M - 2);
}


int main() {
	int n;
	cin >> n;
	long long factn = 1;
	for (int i = 2; i <= n; ++i) {
		factn = factn * i % M;
	}
	vector<long long> sum(n + 1);
	for (int i = 1; i <= n; ++i) {
		sum[i] = (sum[i - 1] + factn * inv(i + 1) % M) % M;
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		long long a;
		cin >> a;
		ans = (ans + a * ((factn + sum[i] + sum[n - i - 1]) % M)) % M;
	}
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
ans=0
for v in itertools.combinations_with_replacement(list(range(1,m+1)),n):
    sub=0
    for a in l:
        if v[a[1]-1]-v[a[0]-1]==a[2]:
            sub+=a[3]
    ans=max(ans,sub)
print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=10,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        
        int s=0,t=0;
        
        for(int i=1;i*i<=N;i++){
            if(N%i!=0) continue;
            
            int a=i,b=N/i;
            
            if(a%2==1){
                if(b-a/2>=1){
                    if(t<=a){
                        s=b-a/2;
                        t=a;
                    }
                }
                
                if(b%2==1){
                    if(a-b/2>=1){
                        if(t<=b){
                            s=a-b/2;
                            t=b;
                        }
                    }
                    
                    if(b/2-a+1>=1){
                        if(t<=a*2){
                            s=b/2-a+1;
                            t=a*2;
                        }
                    }
                }else{
                    if(a/2-b+1>=1){
                        if(t<=b*2){
                            s=a/2-b+1;
                            t=b*2;
                        }
                    }
                }
            }
            
            
            swap(a,b);
            
            if(a%2==1){
                if(b-a/2>=1){
                    if(t<=a){
                        s=b-a/2;
                        t=a;
                    }
                }
                
                if(b%2==1){
                    if(a-b/2>=1){
                        if(t<=b){
                            s=a-b/2;
                            t=b;
                        }
                    }
                    
                    if(b/2-a+1>=1){
                        if(t<=a*2){
                            s=b/2-a+1;
                            t=a*2;
                        }
                    }
                }else{
                    if(a/2-b+1>=1){
                        if(t<=b*2){
                            s=a/2-b+1;
                            t=b*2;
                        }
                    }
                }
            }
        }
        
        cout<<s<<" "<<t<<endl;
    }
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

ul l(ul a, ul b) {
  if (a<b) swap(a, b);
  while (a%b!=0) {
    a %= b;
    swap(a, b);
  }
  return b;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int t;
  cin >> t;
  for (int ep = 0; ep < t; ++ep) {
    ul a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a<b || b>d) {
      cout << "No" << endl;
      continue;
    }
    ul s = l(b, d);
    ul lowest = a-(a-c-1)/s*s;
    cout << (lowest < b ? "No" : "Yes") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n,m,k;
    cin >> n >> m >> k;
    vi a(n);
    rep(i,n)cin >> a[i];
    vi dp(n+1,LINF);
    rep(i,n){
        int ma = 0;
        int mi = INF;
        rep(j,m)if(i-j >= 0){
            //i-jについてかんがえる
            ma = max(ma, a[i-j]);
            mi = min(mi, a[i-j]);
            int cost = k + (j+1)*(ma-mi);
            if(i-j)cost += dp[i-j-1];
            dp[i] = min(dp[i], cost);
        }
        //cout << i << " " << dp[i] << endl;
    }
    cout << dp[n-1] << endl;
}



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

const int MAX = 8;
vector<int> G[MAX];
int ans = 0;

void dfs(int now, int n, vector<int> order) {
  order.emplace_back(now);
  if (order.size() == n) {
    ans++;
    return;
  }
  for (int i = 0; i < G[now].size(); i++) {
    bool flag = true;
    for (int j = 0; j < order.size(); j++) {
      if (G[now][i] == order.at(j)) flag = false;
    }
    if (flag) {
      dfs(G[now][i], n, order);
    }
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  vector<int> x;
  dfs(0, n, x);
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int H=0;
	int W=0;

	scanf("%d %d",&H,&W);
	char a[H][W];

	for(int k=0; k<W+2; k++){
		printf("#");
	}

		printf("\n");

	for(int i=0; i<H; i++){
		//printf("#");
			scanf("%s",&a[i]);
			printf("#%s#\n",a[i]);
		//printf("#\n");
	}

	for(int l=0; l<W+2; l++){
		printf("#");
	}

	return 0;

}

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

string s;
Int ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	string t = "";
	t += s[0];
	++ans;
	for(size_t i=1; i<s.size(); ++i){
//		cout << i << " " << t << "\n";
		string u = "";
		u += s[i];
		size_t j=1;
		while(t == u && i+j < s.size()){
			u += s[i+j];
			++j;
		}
		if(t != u){
			t = u;
			++ans;
			i += j-1;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 720
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
d = [0]
for i in range(n):
    d.append(gil())
dp = [[0 for _ in range(3)] for _ in range(n+1)]
for dx in range(1, n+1):
    ndp = dp[dx]
    #print(ndp)
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            ndp[i] = max(ndp[i], d[dx][i] + dp[dx-1][j])
    dp[dx] = ndp
#print(dp)
print(max(dp[-1]))

#DP tabular, setting current day dp by comparing previous days costs and finding max to
# pair current cost with prev days

Measured memory_bytes: 101612
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(B/A<C) OUT(B/A);
  else OUT(C);
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int n;
	cin >> n;
	ll dp[N];
	dp[0] = 2;
	dp[1] = 1;
	ffor(i, 2, n+1) {
		dp[i] = dp[i - 1] + dp[i - 2];
	}
	c(dp[n]);
	ed;
	return 0; 
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import datetime

#----------
S = input().strip()
#----------
S_list=[int(i) for i in S.split("/")]

d = datetime.date( S_list[0],S_list[1],S_list[2] )
d_base=datetime.date(2019,4,30)
diff = d - d_base

if diff <= datetime.timedelta():
    print("Heisei")
else:
    print("TBD")


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
    int s = 1;
    vector<bool> visited(n+1, false);
    bool ok = false;
    int ans = -1;
    while(1) {
        ans++;
        if(s==2) {
            ok = true;
            break;
        }
        if(visited[s]) break;
        visited[s] = true;
        s = a[s];
    }
    if(ok) cout << ans;
    else cout << -1;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()

#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long

int32_t main(){ fast;
	
	int a, b, c, d; cin>>a>>b>>c>>d;
	while(true){
		c -=  b;
		if(c <= 0){
			cout<<"Yes"<<endl;
			return 0;
		}
		a -=d;
		if(a <= 0){
			cout<<"No"<<endl;
			return 0;
		}
		//debug(a);
		//debug(c);
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fitr(it,it1,itr2) for(auto it=itr1;it!=itr2;++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int,int>> vvin;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}

int main () {
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
int n,x,t;
cin>>n>>x>>t;
ll ans;
if (n%x) ans=n/x+1;
else ans=n/x;
cout << ans*t;
return 0;
}




Measured memory_bytes: 3568
/*
 * Created by Dipta Das on 08-05-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

const int inf = 1e9 + 5;

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

    int n;
    cin >> n;
    vector<int> h(n);
    for (auto &i : h) {
        cin >> i;
    }
    vector<int> dp(n, inf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j : {i + 1, i + 2}) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;
}

#define IOS ios::sync_with_stdio(false), cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()
#define MAX(a) *max_element(all(a))

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vc = vector<char>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vvi;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

const int MAX_N = 110;
const int MAX_V = 100010;

int N;
ll W, weight[MAX_N], value[MAX_N];
ll dp[MAX_N][MAX_V];

int main() {
  IOS;
  constexpr char endl = '\n';

  int N, M;
  vi a;
  cin >> N >> M;
  a.resize(M);
  rep(i, M) cin >> a[i];

  int sum = accumulate(all(a), 0);
  int res = (N - sum >= 0) ? N - sum : -1;
  cout << res << endl;
}

Measured memory_bytes: 3656
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	count := 0
	for _, a := range as {
		for a%2 == 0 {
			count++
			a /= 2
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    int w,s;
    cin>>s>>w;

    if(w>=s){
        cout<<"un";
    }
    cout<<"safe\n";

   

}

Measured memory_bytes: 3660
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s <- C.getLine
  print $ solve s

solve s = min (bo + we) (be + wo)
  where
    n = C.length s
    evens = (n `div` 2)
    odds = (evens + n `mod` 2)
    countx cnt i c = if i >= n 
      then cnt
      else if C.index s i == c
        then countx (cnt + 1) (i + 2) c
        else countx cnt (i + 2) c
    bo = countx 0 0 '0'
    be = countx 0 1 '0'
    wo = odds - bo
    we = evens - be

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 636
#include<iostream>
#include<cmath>

using namespace std;

int N;

int main() {
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= 5; i++) {
		int x = pow(10, i);
		if (i % 2 == 0) { 
			if (N < x) { break; }
			else { continue; }
		}
		if (N < x) { 
			ans += N - (x / 10 - 1);
			break;
		}
		else { 
			ans += x - (x / 10);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BHinaArare solver = new BHinaArare();
        solver.solve(1, in, out);
        out.close();
    }

    static class BHinaArare {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(IntStream.range(0, in.nextInt()).mapToObj(x -> in.next()).distinct().count() == 3 ? "Three" : "Four");
        }

    }
}



Measured memory_bytes: 27216
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, k;
	string s;
	cin >> n >> k >> s;
	if (s[k - 1] == 'A')s[k - 1] = 'a';
	if (s[k - 1] == 'B')s[k - 1] = 'b';
	if (s[k - 1] == 'C')s[k - 1] = 'c';
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3][3];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
            cin>>a[i][j];
    }
    int n;
    cin>>n;
    int b[n];
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            for(int k=0; k<3; k++)
            {
                if(a[j][k]==b[i])
                    a[j][k]=0;
            }
        }
    }
    for(int i=0; i<3; i++)
    {
        int m=0,p=0;
        for(int j=0; j<3; j++)
        {
            if(a[i][j]==0)
                m++;
             if(a[j][i]==0)
                p++;
        }
        if(m==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        if(p==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    int t=0;
    for(int i=0; i<3; i++)
    {
        if(a[i][i]==0)
            t++;
    }
    if(t==3)
    {
         cout<<"Yes"<<endl;
         return 0;
    }
    int g=0;
    for(int i=0; i<3; i++)
    {
        if(a[i][2-i]==0)
            g++;
    }
    if(g==3)
    {
         cout<<"Yes"<<endl;
         return 0;
    }
    
    else
        cout<<"No"<<endl;
}


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

using namespace std;

struct Team {
    Team(int team_number) {
        tn_ = team_number;
        n_ = 0;
        t_ = 0;
        pc_ = 0;
    }
    int tn_;
    int n_;
    int t_;
    int pc_;
    vector<int> p_list_;
};

int main (int argc, char *argv[]) {
    int M, T, P, R;
    int m, t, p, j;
    int count = 0;
    vector<Team> tv;

    while (cin>>M>>T>>P>>R) {
        if (count != 0 )cout<<endl;
        count++;
        for (int i = 0; i < T; ++i) {
            tv.push_back(Team(i+1));
        }
        for (int i = 0; i < R; ++i) {
            cin>>m>>t>>p>>j;
            if (j != 0) {
                tv[t-1].p_list_.push_back(p);
            }
            else {
                for (auto e : tv[t-1].p_list_) {
                    if (e == p) {
                        tv[t-1].pc_++;
                    }
                }
                tv[t-1].n_++;
                tv[t-1].t_ += m;
            }
        }
        for (auto& e : tv) {
            e.t_ += e.pc_ * 20;
        }

        // for (auto e : tv) {
        //     cout<<"-----------"<<endl;
        //     cout<<e.tn_<<endl;
        //     cout<<e.n_<<endl;
        //     cout<<e.t_<<endl;
        //     cout<<e.pc_<<endl;
        //     for (auto c : e.p_list_) {
        //         cout<<c<<" ";
        //     }
        //     cout<<endl;
        //     cout<<"-----------"<<endl;
        // }

        sort(tv.begin(), tv.end(), [](const auto& lhs, const auto& rhs) -> bool{
            if (lhs.n_ != rhs.n_ ) {
                return lhs.n_ > rhs.n_;
            }
            else if (lhs.n_ == rhs.n_ && lhs.t_ != rhs.t_) {
                return lhs.t_ < rhs.t_;
            }
            else return lhs.tn_ > rhs.tn_;
        });

        const int size = static_cast<int>(tv.size());
        for (int i = 0; i < size; ++i) {
            cout<<tv[i].tn_;
            if(i != size -1) {
                if (tv[i].n_ != tv[i+1].n_ || tv[i].t_ != tv[i+1].t_ ) {
                    cout<<",";
                }
                else cout<<"=";
            }
        }
        tv.clear();
    }

    return 0;
}

Measured memory_bytes: 3120
H, W, D = map(int, input().split())
mass = [0]*(H*W+1)
for y in range(1,H+1):
    for x,i in enumerate(input().split()):
        mass[int(i)]= (y,x+1)

Q = int(input())
dp = [H*W+2]*(H*W+1)

for i in range(1,H*W+1):
    if i > D:
        dp[i] = dp[i-D] + abs(mass[i][0] - mass[i-D][0]) + abs(mass[i][1] - mass[i-D][1])
    else:
        dp[i] = mass[i][0] + mass[i][1]

for _ in range(Q):
    L, R = map(int, input().split())
    print(dp[R] - dp[L])

Measured memory_bytes: 14264
h, w = map(int, input().split())
a = [["#"] + list(input()) for _ in range(h)]
a.insert(0, ["#"] * (w + 1))
mod = 10 ** 9 + 7
dp = [[0] * (w + 1) for _ in range(h + 1)]
dp[0][1] = 1
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j] == ".":
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
            dp[i][j] %= mod
print(dp[h][w])

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

#define INF 1e18
#define int long long

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

    int ans = n * (n - 1) / 2;

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


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, m;
	static int[][] cost;
	static int[] mincost;
	static boolean[] used;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		m = sc.nextInt();
		if(n == 0 && m == 0)return false;
		cost = new int[n][n];
		mincost = new int[n];
		used = new boolean[n];
		for(int[] formatting: cost)Arrays.fill(formatting, 1<<29);
		Arrays.fill(mincost, 1<<29);
		Arrays.fill(used, false);
		for(int i = 0; i < m; i++){	
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			cost[a][b] = c;
			cost[b][a] = c;
		}
		return true;
	}
	
	static void solve(){
		mincost[0] = 0;
		int res = 0;
		
		while(true){
			int v = -1;
			for(int i = 0; i < n; i++){
				if(!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i;
			}
			
			if(v == -1)break;
			used[v] = true;
			res += mincost[v];
			
			for(int i = 0; i < n; i++){
				mincost[i] = Math.min(mincost[i], cost[v][i]);
			}
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[4][4];
int main(){
	scanf("%s",a[1]+1);
	scanf("%s",a[2]+1);
	scanf("%s",a[3]+1);
	cout<<a[1][1]<<a[2][2]<<a[3][3];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_NUM = 3000000;

ll X, Y;

ll modinv(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

vector<ll> mf(MAX_NUM, -1);
ll modfact(ll n, ll mod) {
    if (mf[n] != -1) return mf[n];
    if (n == 0) return mf[0] = 1;
    return mf[n] = (n * modfact(n-1, mod)) % mod;
}

vector<ll> mif(MAX_NUM, -1);
ll modinvfact(ll n, ll mod) {
    if (mif[n] != -1) return mif[n];
    if (n == 0) return mif[0] = 1;
    return mif[n] = (modinv(n, mod) * modinvfact(n-1, mod)) % mod;
}

ll modcomb(ll n, ll k, ll mod) {
    return ((modfact(n, mod) * modinvfact(k, mod)) % mod * modinvfact(n-k, mod)) % mod;
}

int main() {
    cin >> X >> Y;
    ll ans;
    if (2*Y - X >= 0 && 2*X - Y >= 0 && (2*X - Y) % 3 == 0) {
        ll a = (2*Y - X) / 3;
        ll b = (2*X - Y) / 3;
        ans = modcomb(a+b, a, MOD);
    }
    else {
        ans = 0;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 70792
#include<iostream>
#include<cmath>
using namespace std;
int a,b;
int main(){
  cin >> a >> b;
  int S;
  for( int i=1; i<=3; ++i){
    if (b < pow(10, i) && b >= pow(10, i-1)) S = a*pow(10, i) +b;
  }
  bool flag = false;
  for (int i=0; i<400000; ++i){
    if ( S == pow(i, 2)) flag = true;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
'use strict';

function main(stdin) {
  const input = stdin.split('\n');
  const N = Number(input.shift());
  const params = input[0].split(' ').map(v => parseInt(v, 10));

  const a = [];
  for (let i = 0; i < N; ++i) a[i] = Infinity;

  params.forEach((b, i) => {
    a[i] = Math.min(b, a[i]);
    a[i + 1] = b;
  })
  
  console.log(a.reduce((a, b) => a + b));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string a, b, c; cin >> a >> b >> c;
  string s{};
  s += (a[0] + ('A' - 'a'));
  s += (b[0] + ('A' - 'a'));
  s += (c[0] + ('A' - 'a'));

  cout << s << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
K = int(input())
table = [n + 1 for n in range(9)]
for i in table:
    if len(table) > K:
        break
    x = i % 10
    for j in range(max(0, x - 1), min(x + 2, 10)):
        table.append(i * 10 + j)
print(table[K - 1])


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

#define      ll      long long int

const int N = 300005;
int east[N];
int west[N];

int main( )
{
    int n, i, j, k, l;
    string s;
    cin >> n >> s;
    l = (int) s.size();
    s = "@" + s;
    for (i = 1; i <= n; i++) {
        west[i] += west[i - 1];
        if (s[i] == 'W') {
            west[i]++;
        }
    }
    for (i = n; i >= 1; i--) {
        east[i] += east[i + 1];
        if (s[i] == 'E') {
            east[i]++;
        }
    }
    int mn = 1e9;
    for (i = 1; i <= n; i++) {
        mn = min(mn, west[i - 1] + east[i + 1]);
    }
    cout << mn << '\n';
    return 0;
}


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

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;


void solve(long long K){
    rep(i,K){
        cout <<"ACL";
    }
    cout << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    
    int x = A%B;
    bool can = false;
    
    
    if (x ==0) {
        cout << "NO" << endl;
        exit(0);
    }
    
    for (int n=1; n <1000; n++) {
        int y = (n * x)%B;
        
        if (y == C) {
            can = true;
            break;
        }
    }

    
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 5e3 + 11, mod = 1e9 + 7, mod2 = 998244353;
const ll MAX = 1e15 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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


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

int n, z[N], ans;
string s;
main() {
    file("rmq");
    ios;
    cin >> n >> s;
    for (int it = 0; it < n; ++it) {
        memset(z, 0, sizeof z);
//        cout << s << "CH\n";
        for (int i = 1, l = 0, r = 0; i < s.size(); ++i) {
            if (i <= r) z[i] = min(z[i - l], r - i + 1);
            while (i + z[i] < s.size() and s[z[i] + i] == s[z[i]]) ++z[i];
            if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
        }
        for (int i = 1; i < s.size(); ++i) {
            chmax(ans, min(z[i], i));
        }
        if (it < n - 1) s.erase(s.begin());
    }
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


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

int gcd(int , int );

int main(){
  int a,b,c;
 
  scanf("%d%d",&a,&b);
  if(b > a){
    c = a; 
    a = b; 
    b = c;
  }
  if(b != 0){
    c = gcd(a,b);
  }
  printf("%d\n",c);
  return 0;
}

int gcd(int a, int b)
{
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}

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

template <typename T>
class FenwickTreeAdd{
  using value_type = T;
  
  int size;
  std::vector<value_type> data;
  
public:
  FenwickTreeAdd(){}
  FenwickTreeAdd(int size): size(size), data(size + 1, 0){}
  
  void update(int i, value_type val){
    i += 1; // 1-index
    
    while(i <= size){
      data[i] = data[i] + val;
      i += i & (-i);
    }
  }
  
  value_type get(int i) const { // [0, i)
    value_type ret = 0;
    i += 1; // 1-index

    while(i > 0){
      ret = ret + data[i];
      i -= i & (-i);
    }

    return ret;
  }

  value_type get(int l, int r) const { // [l, r)
    return get(r-1) - get(l-1);
  }
};


template <typename T>
struct RangeCountQuery{
  std::vector<int> a;
  std::vector<std::tuple<int, int, int>> qs;
  int N;

  RangeCountQuery(std::vector<T> a_): N(a_.size()){
    auto temp = a_;
    std::sort(temp.begin(), temp.end());
    temp.erase(std::unique(temp.begin(), temp.end()), temp.end());

    for(auto x : a_){
      int i = std::lower_bound(temp.begin(), temp.end(), x) - temp.begin(); 
      a.push_back(i);
    }
  }

  void add(int l, int r){ // [l, r)
    int i = qs.size();
    qs.emplace_back(r, l, i);
  }

  auto solve(){
    std::sort(qs.begin(), qs.end());

    FenwickTreeAdd<int> b(N);

    const int Q = qs.size();
    std::vector<int> last_index(N, -1);
    std::vector<int> ret(Q);
  
    int cur = 0;
    for(auto [r, l, i] : qs){
      while(cur < r){
        if(last_index[a[cur]] != -1){
          b.update(last_index[a[cur]], -1);
        }

        last_index[a[cur]] = cur;
        b.update(last_index[a[cur]], 1);

        ++cur;
      }

      ret[i] = b.get(l, r);
    }
    
    return ret;
  }
};


int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N, Q; std::cin >> N >> Q;
  std::vector<int> c(N);
  for(int i = 0; i < N; ++i) std::cin >> c[i];

  RangeCountQuery<int> rcq(c);

  for(int i = 0; i < Q; ++i){
    int l, r; std::cin >> l >> r;
    rcq.add(l - 1, r);
  }

  auto ans = rcq.solve();

  for(auto x : ans) std::cout << x << "\n";

  return 0;
}


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

int h,w;
string str[30];

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

int dfs(int y,int x){
    str[y][x] = '#';
    int res = 0;
    for(int i=0;i<4;i++){
        if(y+dy[i]<0 || y+dy[i]>=h || x+dx[i]<0 || x+dx[i]>=w || str[y+dy[i]][x+dx[i]]!='.') continue;
        res += dfs(y+dy[i],x+dx[i])+1;
    }
    return res;
}

int main()
{
    
    while(cin >> w >> h,w!=0&&h!=0){
        for(int i=0;i<h;i++) cin >> str[i];
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(str[i][j] == '@'){
                    cout << dfs(i,j)+1 << endl;
                }
            }
        }
    }

    return(0);
}



Measured memory_bytes: 3200
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let ab: Vec<(i32, i32)> = (0..n).map(|_| (read(), read())).collect();

    let maxi = ab.iter().max_by_key(|&&k| k.0).unwrap();
    let ans = maxi.0 + maxi.1;

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))

total = sum(A)

selcnt = 0
for a_i in reversed(sorted(A)):
    if a_i < total * (1/(4*M)):
        break
    selcnt += 1

if selcnt >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
int N, d[7], a[320], s, g;
vector<pair<int, int>> dp[320];
int main() {
	cin >> N;
	for (int i = 1; i <= 6; i++)cin >> d[i];
	cin >> s >> g;
	for (int i = 1; i <= N; i++)cin >> a[i];
	for (int i = 0; i < 320; i++) {
		for (int j = 0; j < 330; j++)dp[i].push_back(make_pair(0, 0));
	}
	dp[s].clear(); queue<int>Q; Q.push(s);
	while (!Q.empty()) {
		int to = Q.front(); Q.pop();
		for (int i = -1 * N; i <= N; i++) {
			int e = abs(i); int OK = 0;
			for (int j = 1; j <= 6; j++) {
				if (e == d[j])OK = 1;
			}
			if (i == 0 || OK == 0)continue;
			if (to + i <= 0 || to + i > N)continue;
			int v = to + i + a[to + i];
			if (dp[v].size() > dp[to].size() + 1) {
				dp[v] = dp[to];
				if (i <= -1)dp[v].push_back(make_pair(-1, -i));
				if (i >= 1)dp[v].push_back(make_pair(1, i));
				Q.push(v);
			}
		}
	}
	for (int i = 0; i < dp[g].size(); i++) {
		while (true) {
			int p; cin >> p;
			if (d[p] == dp[g][i].second) {
				cout << dp[g][i].first << endl;
				break;
			}
			else {
				cout << "0" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>();
    vector<int> a(n+1);
    for (int i = 1;i <= n; i++)
        a[i] = get<int>();

    int nballs = 0;
    vector<int> b(n+1);
    for (int i = n; i >= 1; i--) {
        int parity = 0;
        for (int j = i; j <= n; j += i) {
            parity = (b[j] + parity) % 2;
        }
        if (parity != a[i]) {
            nballs++;
            b[i] = 1;
        }
    }

    cout << nballs << endl;
    if (nballs == 0) return 0;
    for (int i = 1; i <= n; i++) {
        if (b[i]) {
            cout << i;
            nballs--;
        }
        if (nballs == 0) {
            cout << endl;
            break;
        } else
            cout << " ";
    }

    return 0;
}


Measured memory_bytes: 2560