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

typedef long long ll ;
#define pb push_back

string s , t ;

ll n , m ;

ll dp[4000][4000] , vis[4000][4000] ;
string ans ;
ll lcs(ll i , ll j ) {
    if (i>=n or j>=m) return 0 ;
    if (vis[i][j]) return dp[i][j] ;

    if (s[i]==t[j]) {
        dp[i][j] = 1+ lcs(i+1,j+1) ;
    }
    else {
        ll on = lcs(i+1,j) ;
        ll to = lcs(i,j+1) ;
        dp[i][j] = max(on,to) ;
    }
    vis[i][j] = 1 ;
    return dp[i][j] ;

}

void print(ll i , ll j) {
    if (i>=n or j>=m) {
        cout << ans << endl ;
        return ;
    }
    if (s[i]==t[j]) {
        ans.pb(s[i]) ;
        print(i+1,j+1) ;
    }
    else {
        if (dp[i+1][j]>dp[i][j+1]) print(i+1,j) ;
        else print(i,j+1) ;
    }

}


int main() {



    cin >> s >> t ;
    n = s.size() , m= t.size() ;
    lcs(0,0) ;
    print(0,0) ;
    return 0 ;


}


Measured memory_bytes: 188544
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    l: f64
    );
    let ans = (l / 3.0).powf(3.0);
    println!("{}",ans);
}


Measured memory_bytes: 4476
#include<iostream>
#include<string.h>
using namespace std;

void trace(string A[], int N){
    int i;
    string s;
    for(i=0; i<N; i++){
        if(i>0) cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
}

void bubbleSort(string A[], int N){
    int i, j;
    string tmp;
    for(i=0; i<N; i++){
        for(j=1; j<N-i; j++){
            if((int)A[N-j][1] < (int)A[N-j-1][1]) {
                tmp = A[N-j];
                A[N-j] = A[N-j-1];
                A[N-j-1] = tmp;
            }
        }
    }
}

void sellectionSort(string A[], int N){
    int i, j, minj, swp_num=0, flag=0;
    string tmp;
    for(i=0; i<N; i++){
        minj = i;
        for(j=i; j<N; j++){
            if((int)A[j][1] < (int)A[minj][1]){
                minj = j;
                flag=1;
            }
        }
        if(flag==1){
            tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            swp_num++;
        }
        flag=0;
    }
}

string stableCheck(string A[], string B[], int N){
    int i;
    for(i=0; i<N; i++){
        if(A[i] != B[i]){
            return "Not stable";
        }
    }
    return "Stable";
}

int main(){
    int num, i;
    string s;
    cin>>num;
    string arr1[num], arr2[num], val;
    for(i=0; i<num; i++){
        cin>>val;
        arr1[i]=val;
        arr2[i]=val;
    }
    bubbleSort(arr1, num);
    trace(arr1, num);
    cout<<"Stable"<<"\n";
    sellectionSort(arr2, num);
    trace(arr2, num);
    s=stableCheck(arr1, arr2, num);
    cout<<s<<endl;
    return 0;
}

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

int d,n,tmp;

signed main()
{
	cin>>d>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>tmp;
		d-=tmp;
	}
	if (d>=0)  cout<<d<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	int n,m;
	lint s=0;
	cin>>n>>m;
	while(m--){
		int x; cin>>x; s+=x;
	}
	n -= s;
	if(n<0)cout<<"-1\n";
	else cout<<n<<"\n";
	return 0;	
}



Measured memory_bytes: 3680
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
#define INFTY 1<<29
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 2501;
static const int NMAX = 51;


int H,W,V;
bool visited[MAX];
int dis[MAX], parent[MAX], col[MAX];
int E[MAX][MAX];

void dfs(int k) {
  visited[k] = true;
  int ue, d, l, r;
  ue = (k - W < 0) ? -1:k-W;
  d = (k + W >= V) ? -1:k+W;
  l = (k % W == 0) ? -1:k-1;
  r = ((k + 1) % W == 0) ? -1:k+1;
  vector<int>move;
  move.push_back(r); move.push_back(d);
  move.push_back(l); move.push_back(ue);
  for(auto m : move) {
    // cout << "m: " << m << "\n";
    if (m == -1) continue;
    int i, j; i = m/W + 1; j = m%W + 1;
    if (E[k][m] == 1 && !visited[m]) {
      // cout << "Go to i: " << i << " j: " << j << endl;
      dfs(m);
    }
  }
}

void dijkstra(int k = 0) {
  rep(i,V) {
    dis[i] = INFTY;
    col[i] = 0;
  }
  col[k] = 1;
  dis[k] = 0; parent[k] = -1;

  while(true) {
    int mincost = INFTY;
    int u = -1;
    for(int m = 0; m < V; m++ ) {
      if ( dis[m] < mincost && col[m] != 2 ) {
        mincost = dis[m];
        u = m;
      }
    }
    int i, j; i = u/W + 1; j = u%W + 1;
    // cout << "Move to i: " << i << " j: " << j << endl;
    if (mincost == INFTY) break;
    col[u] = 2;

    vector<int>move;
    int ue, d, l, r;
    ue = (u - W < 0) ? -1:u-W;
    d = (u + W >= V) ? -1:u+W;
    l = (u % W == 0) ? -1:u-1;
    r = ((u + 1) % W == 0) ? -1:u+1;
    move.push_back(r); move.push_back(d);
    move.push_back(l); move.push_back(ue);
    for (auto m : move) {
      if (m == -1) continue;
      if (col[m] != 2 && E[u][m] == 1) {
        if (dis[m] > 1 + dis[u]) {
          parent[m] = u;
          dis[m] = dis[u] + 1;
          col[m] = 1;
        }
      }
    }
  }
}

int main(){
  cin >> H >> W;
  int s[H][W];
  V = H*W;
  int cnt = 0;
  rep(i,V) rep(j,V) E[i][j] = 0;
  rep(i, H) {
    rep(j,W) {
      // if (i==0 || j == 0 || i == H+1 || j == W+1) {s[i][j] = -1; continue;}
      char c; cin >> c;
      if ( c == '.' ) cnt++;
      s[i][j] = (c == '.') ? 0:1;
      if (j > 0 && c == '.' && s[i][j-1] == 0) {
        E[i*W + j][i*W + j - 1] = 1;
        E[i*W + j - 1][i*W + j] = 1;
      }
      if(i > 0 && c == '.' && s[i-1][j] == 0) {
        E[(i-1)*W + j][i*W + j] = 1;
        E[i*W + j][(i-1)*W + j] = 1;
      }
    }
  }

  rep(i, V) visited[i] = false;
  dfs(0);
  bool flag = visited[V-1];
  if (flag) {
    dijkstra();
    // cout << "dijkstra: " <<  dis[V-1] << endl;
    cout << cnt - (dis[V-1] + 1) << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 24960
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll n,m,c;
    cin>>n>>m>>c;
    vector<ll> b(m);
    for (ll i = 0; i<m; i++){
        cin>>b[i];
    }
    
    vector<vector<ll>> a(n, vector<ll>(m));
    for (ll i = 0; i<n; i++){
        for (ll j = 0; j<m; j++){
            cin>>a[i][j];
        }
    }
    
    ll ans = 0;
    for (ll i = 0;i<n; i++){
        ll sum = 0;
        for (ll j = 0; j<m; j++){
            sum += a[i][j] * b[j];
        }
        sum += c;
        if(sum > 0)ans++;
    }
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long W,H,x,y;
  cin >> W >> H >> x >> y;
  int a = 0;
  
  if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) a = 1;
  
  if (W * H % 2 == 1) cout << W * H / 2 << ".5 " << a << endl;
  else cout << W * H / 2 << " " << a << endl; 
}

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

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=0,m=0;
        if(scan.hasNext())
            n=scan.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            if(scan.hasNext())
                arr[i]=scan.nextInt();
        }
        int min=arr[0];
        int count=1;
        for(int i=1;i<n;i++){
            if(arr[i]<=min){
                count++;
            }
            min=Math.min(arr[i],min);
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 96108
fun main(args:Array<String>) {
    val s = readLine()!!
    var ans = ""
    for(i in s.indices) {
        for(j in (i..s.lastIndex)) {
            val tmp = s.substring(i..j)
            if(tmp.any { c-> !setOf('A', 'C', 'G', 'T').contains(c) }) {
                break
            }
            if(tmp.length > ans.length) {
                ans = tmp
            }
        }
    }
    println(ans.length)
}

Measured memory_bytes: 39952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int n, p, a[maxn], pw = 1;
ll ans;
char s[maxn];
map<int, int> M;
int main()
{
	cin >> n >> p >> s + 1;
	if(p == 2)
	{
		for(int i = 1; i <= n; ++i)
			if((s[i] - '0') % 2 == 0) 
				ans += i;
	}
	else if(p == 5)
	{
		for(int i = 1; i <= n; ++i)
			if((s[i] - '0') % 5 == 0)
				ans += i;
	}
	else
	{
		M[0] = 1;
		for(int i = n; i; --i) 
		{
			a[i] = ((s[i] - '0') * pw + a[i + 1]) % p;
			ans += M[a[i]];
			M[a[i]]++;
			pw = pw * 10 % p;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
/*
5 5
10000
*/

Measured memory_bytes: 1664
from functools import lru_cache
n = int(input())
aa = list(map(int, input().split()))

@lru_cache(maxsize=10**9)
def gcd(a, b) :
    if b == 0 : return a
    elif a%b : return gcd(b, a%b)
    else : return b

l = [0]
r = [0]
for i in range(n) :
    l.append(gcd(l[-1], aa[i]))
    r.append(gcd(r[-1], aa[-i-1]))

m = [gcd(l[i],r[-i-2]) for i in range(n)]
print(max(m))

Measured memory_bytes: 14576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans=0;
const ll INF = 1LL << 60;
int main()
{
ll n , x , d ;
cin >> n >> x >> d ;
if(d==0){
cout << ((x==0)?1:n+1) << endl;
return 0;
}
if(d<0){d*=-1;x*=-1;}
map<ll,vector<pair<ll,ll>>> m;
auto mod = [&](ll modx) {modx%=d;modx+=d;modx%=d;return modx; };
rep(i,n+1){
  m[mod(i*x)].emplace_back((i*(i-1)/2)*d+i*x,((n-1+n-i)*i/2)*d+i*x);
}
for(auto r:m){
  ll p=-INF;
  sort(r.second.begin(),r.second.end());
  for(auto rr:r.second){
    ans+=max(0LL,(rr.second+d-max(p,rr.first)))/d;
    p=max(p,rr.second+d);
  }
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 22144
#include <iostream>
using namespace std;
 
int main() {
    int H,W;
    while(1){
    cin >>H>>W;
    if (H==0 && W==0) break;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if((i+j)%2==0){
                cout << "#";
            }
            else {
            cout <<".";
            }
        }
        cout << endl;
     
    }
    cout << endl;
    }
    return 0;
}

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

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

    int min = 1;
    for(int i=0;i<N;i++){
        if(min * 2 >= min + K){
            min += K;
        }
        else{
            min *= 2;
        }
    }
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;
    static void Main(string[] args)
    {
        Solve();
    }




    static int N;
    static int A;
    static int B;
    static int C;
    static int[] l;




    static int DFS(int depth ,int a,int b,int c)
    {
        if (depth == N)
        {
            if (a == 0 || b == 0 || c == 0) return INF;
            return Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c)-30;
        }
        int ret=INF;
        ret = Math.Min(ret, DFS(depth + 1, a + l[depth], b, c) + 10);
        ret = Math.Min(ret, DFS(depth + 1, a, b + l[depth], c) + 10);
        ret = Math.Min(ret, DFS(depth + 1, a, b, c + l[depth]) + 10);
        ret = Math.Min(ret, DFS(depth + 1, a, b, c ));


        return ret;
    }



    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var ss = sc.intarr;
         N = ss[0];
         A = ss[1];
         B = ss[2];
         C = ss[3];
         l = new int[N];
        for(int i = 0; i <N; ++i) l[i] = sc.intarr[0];



        wr.wri(DFS(0, 0, 0, 0));

    }


}

class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include<iostream>
using namespace std;
#define maxn 200005
#define sentinel 2000000000
typedef long long LL;
int L[maxn/2],R[maxn/2];
int a[maxn];
LL _merge(int left,int mid,int right)
{
    LL cnt=0;
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;++i) L[i]=a[left+i];
    for(int i=0;i<n2;++i) R[i]=a[mid+i];
    L[n1]=R[n2]=sentinel;
    int i=0,j=0;
    for(int k=left;k<right;++k)
    {
        if(L[i]<=R[j])
            a[k]=L[i++];
        else
        {
            a[k]=R[j++];
            cnt+=n1-i;
        }
    }
    return cnt;
}
LL mergesort(int left,int right)
{
    int mid;
    LL v1,v2,v3;
    if(left+1<right)
    {
        mid=(left+right)>>1;
        v1=mergesort(left,mid);
        v2=mergesort(mid,right);
        v3=_merge(left,mid,right);
        return v1+v2+v3;
    }
    else
        return 0;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    LL ans=mergesort(0,n);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4636
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


void fio()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | FUNCTIONS | --------------------------------------///

/*
const int N = 2e5 + 5;

vector<int> adj[N];
bool visited[N];
//int val[N];
//int depth[N];
//int parent[N];

void dfs(int v)
{
	visited[v] = true;
	for (int u : adj[v])
	{
		if (!visited[u])
		{
			//parent[u] = v;
			//depth[u] = depth[v] + 1;
			dfs(u);
		}
	}
}
*/

// left shift << multiply by 2
// right shift >> divide by 2

///----------------------------- | START FROM HERE | --------------------------------------///

#define int long long //change int main to int32_t main

const int N = 1e5 + 5;

int dp[105][N];

void solve()
{
	int n, fw; cin >> n >> fw;
	int w[105], v[105];
	fr0(i, n) cin >> w[i + 1] >> v[i + 1];
fr0(i, fw + 1)
	fr(j, 1, n + 1) 
	{
		if (i - w[j] >= 0)
			dp[j][i] = max(dp[j - 1][i], dp[j - 1][i - w[j]] + v[j]);
		else
			dp[j][i] = dp[j - 1][i];
	}
	cout << dp[n][fw] << nl;

}





int32_t main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	TIME(start, end);
	return 0;
}




Measured memory_bytes: 81712
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n/100==n%100%10)ou("Yes");
  else ou("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin >> N >> A >> B;
  vector<int> P(N);
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < N; i++){
    cin >> P[i];
    if (P[i] <= A){
      a++;
    } else if (P[i] >= B + 1){
      c++;
    } else {
      b++;
    }
  }
  cout << min(a,min(b,c));
}

Measured memory_bytes: 256
import sys

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            swap(A, i, j)
    swap(A, i + 1, r)

    return i + 1

def swap(array, i, j):
    tmp = array[i]
    array[i] = array[j]
    array[j] = tmp

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    q = partition(A, 0, len(A) - 1)

    pre = ""
    suf = ""
    for i in range(len(A) - 1):
        if i == q:
            pre = "["
            suf = "]"
        print pre + str(A[i]) + suf,
        pre = ""
        suf = ""
    print A[i + 1]

Measured memory_bytes: 15212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define _GLIBCXX_DEBUG
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  int K;cin >> K;
  string S;cin >> S;
  if(S.size() <= K) cout << S << endl;
  else {
    rep(i,K) cout << S.at(i);
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
const int maxn = 100005;

inline int read() {
    reg int s = 0, ch;
    while (!isdigit(ch = getchar())) ;
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s;
}

int n, fa[maxn];
map < pii, int > Map;
set < int > s[maxn];
queue < pii > q;

inline int find(reg int x) { return (fa[x] == x) ? x : (fa[x] = find(fa[x])); }

inline void init(reg int x, reg int y) {
    s[x].insert(y), s[y].insert(x);
    Map[pii(x, y)]++, Map[pii(y, x)]++;
    if (Map[pii(x, y)] == 2) q.push(pii(x, y));
}

inline void solve() {
    while (!q.empty()) {
        reg int x = q.front().first, y = q.front().second; q.pop();
        x = find(x), y = find(y), s[x].erase(y), s[y].erase(x);
        if (s[x].size() < s[y].size()) swap(x, y);
        for (auto it : s[y]) {
            Map[pii(it, y)] = Map[pii(y, it)] = 0,
            s[it].erase(y), s[it].insert(x), s[x].insert(it),
            Map[pii(it, x)]++, Map[pii(x, it)]++;
            if (Map[pii(it, x)] == 2) q.push(pii(it, x));
        }
        fa[y] = x, s[y].clear();
    }
}

int main() {
    ios::sync_with_stdio(false);
    n = read(); reg int u, v;
    for (reg int i = 1; i <= 2 * n - 2; i++) u = read(), v = read(), init(u, v);
    for (reg int i = 1; i <= n; i++) fa[i] = i;
    solve(); reg int ans = 0;
    for (reg int i = 1; i <= n; i++) ans += fa[i] == i;
    if (ans == 1) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 57984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lec09B
{
    class Program
    {
        static int size;

        static void Main(string[] args)
        {
            //setting part
            size = int.Parse(Console.ReadLine());
            int[] array = new int[size];
            string input = Console.ReadLine();
            string[] split = input.Split(' ');

            for (int i = 0; i < size; i++)
            {
                array[i] = int.Parse(split[i]);
            }

            //heap part
            BuildMaxHeap(array);

            //printf part
            foreach (int element in array){
                Console.Write(" {0}",element);
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static void BuildMaxHeap(int [] arr )
        {
            for (int i = size / 2 ; i > 0; i--)
            {
                MaxHeapify(arr, i);
            }
        }

        static void MaxHeapify (int [] arr , int i)
        {
            int l = i * 2;
            int r = i * 2 + 1;
            int largest;

            if ( l <= size && arr[l-1] > arr[i-1])
            {
                largest = l;
            } else
            {
                largest = i;
            }
            if ( r <= size && arr[r-1] > arr[largest-1])
            {
                largest = r;
            } 

            if (largest != i)
            {
                int temp = arr[i-1];
                arr[i-1] = arr[largest-1];
                arr[largest-1] = temp;

                MaxHeapify(arr , largest);
            }
        }
    }
}


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

int main(){
int N; cin >> N;
pair<pair<string, int>, int> table[110];

for (int i = 0; i < N; i++) {
    string S;
    int p;
    cin >> S >> p;
    table[i] = make_pair(make_pair(S, -p), i + 1);
}

sort(table, table + N);
for (int i = 0; i < N; i++) {
    cout << table[i].second << endl;
}

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	rep(i, n) {
		cout << s[i] << t[i];
	}


}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, ma, mb = sc.nextInt()
  val x = Array.fill(n)((sc.nextInt(), sc.nextInt(), sc.nextInt()))
  val (x1, x2) = x.splitAt(n/2)
  val h = 10 * ((n+1)/2)

  def compose(x1: Int, x2: Int): Int = {
    x1 * (h+1) + x2
  }

  def prepare(x: Array[(Int, Int, Int)]): Array[Int] = {
    val l = x.length
    val res = Array.fill((h+1) * (h+1))(Int.MaxValue)
    for (i <- 1 until 1 << l) {
      var aSum = 0
      var bSum = 0
      var cSum = 0
      for (j <- 0 until l if ((i >> j) & 1) == 1) {
        val (a, b, c) = x(j)
        aSum += a
        bSum += b
        cSum += c
      }
      val d = (aSum / ma).min(bSum / mb)
      val ar = aSum - (ma * d)
      val br = bSum - (mb * d)
      res(compose(ar, br)) = res(compose(ar, br)).min(cSum)
    }
    res
  }

  val r1 = prepare(x1)
  val r2 = prepare(x2)

  var ans = Int.MaxValue
  if (r1(0) != Int.MaxValue) {
    ans = ans.min(r1(0))
  }
  if (r2(0) != Int.MaxValue) {
    ans = ans.min(r2(0))
  }
  for {
    a1 <- 0 to h
    b1 <- 0 to h
    if (a1 != 0 || b1 != 0) && r1(compose(a1, b1)) != Int.MaxValue
  } {
    val d = ((a1 + ma - 1) / ma).max((b1 + mb - 1) / mb)
    val a2 = (ma * d) - a1
    val b2 = (mb * d) - b1
    if (a2 <= h && b2 <= h && r2(compose(a2, b2)) != Int.MaxValue) {
      ans = ans.min(r1(compose(a1, b1)) + r2(compose(a2, b2)))
    }
  }

  println(if (ans == Int.MaxValue) -1 else ans)
}


Measured memory_bytes: 58492
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<bool>> map(w,vector<bool>(h,false));
    for(int y = 0;y < h;++y){
        string s;
        cin >> s;
        for(int x = 0;x < w;++x){
            if(s[x] == '#')map[x][y] = true;
        }
    }

    vector<vector<long>> hyo(w,vector<long>(h,0));
    for(int x = 0;x < w;++x){
        int c = 0;
        int lc = -1;
        for(int y = 0;y < h;++y){
            if(map[x][y] && c > 0){
                for(int y1 = lc;y1 < y;++y1)if(hyo[x][y1] < c)hyo[x][y1] = c;
                c = 0;
                lc = 0;
            }
            if(!map[x][y]){
                if(c == 0){
                    lc = y;
                }
                ++c;
            }
        }
        if(c > 0)for(int y1 = lc;y1 < h;++y1)if(hyo[x][y1] < c)hyo[x][y1] = c;
    }


    vector<vector<long>> wyo(w,vector<long>(h,0));
    for(int y = 0;y < h;++y){
        int c = 0;
        int lc = -1;
        for(int x = 0;x < w;++x){
            if(map[x][y] && c > 0){
                for(int x1 = lc;x1 < x;++x1)if(wyo[x1][y] < c)wyo[x1][y] = c;
                c = 0;
                lc = 0;
            }
            if(!map[x][y]){
                if(c == 0){
                    lc = x;
                }
                ++c;
            }
        }
        if(c > 0)for(int x1 = lc;x1 < w;++x1)if(wyo[x1][y] < c)wyo[x1][y] = c;
    }

    long max = 0;

    /*for(int y = 0;y < h;++y) {
        string s;
        for (int x = 0; x < w; ++x) {
            s += to_string(hyo[x][y]);
            s += ' ';
        }
        cout << s << endl;
    }


    cout << ' ' << endl;

    for(int y = 0;y < h;++y) {
        string s;
        for (int x = 0; x < w; ++x) {
            s += to_string(wyo[x][y]);
            s += ' ';
        }
        cout << s << endl;
    }
*/

    for(int x = 0;x < w;++x){
        for(int y = 0;y < h;++y){
            if(max < hyo[x][y] + wyo[x][y])max = hyo[x][y] + wyo[x][y];
        }
    }
    cout << (max - 1) << endl;
}




Measured memory_bytes: 63488
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B;
    cin >> A >> B;
    int ans = 0;
    rep(i, 0, 2)
    {
        if (A > B)
        {
            ans += A--;
        }
        else
        {
            ans += B--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
for i in range(n):
    H[i]=abs(t-H[i]*0.006-a)
L=list(enumerate(H,start=1))
L=sorted(L,key=lambda x:x[1])
print(L[0][0])

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


def main():
    k = int(input().strip())
    a, b = map(int, input().split())

    if b // k == a // k and a % k != 0 and b % k != 0:
        print("NG")
    else:
        print("OK")


if __name__ == '__main__':
    main()


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

string s, t;
string dp2[2][3030] = {};
int main(){
  cin >> s >> t;
  int n = s.size(), m = t.size();
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(s.at(i - 1) == t.at(j - 1)){
        dp2[i & 1][j] = dp2[(i - 1) & 1][j - 1];
        dp2[i & 1][j].push_back(t.at(j - 1));
      }else{
        if(dp2[(i - 1) & 1][j].size() > dp2[i & 1][j - 1].size()){
          dp2[i & 1][j] = dp2[(i - 1) & 1][j];
        }else{
          dp2[i & 1][j] = dp2[i & 1][j - 1];
        }
      }
    }
  }
  cout << dp2[n & 1][m] << endl;
  return 0;
}

Measured memory_bytes: 16816
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    ll s = 0;
    rep(i,n) {
        cin>>a[i];
        s ^= a[i];
    }
    vector<ll> ans(n);
    rep(i,n) {
        ans[i] = s^a[i];
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 6424
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n;
  cin >> n;
  vector<string> vec(n);
  for (int i=0; i<n; i++){
    cin >> vec.at(i);
  }

  int c0=0, c1=0, c2=0, c3=0;
  for (int i=0; i<n; i++){
    if (vec.at(i)=="AC"){
      c0++;
    }
    else if (vec.at(i)=="WA"){
      c1++;
    }
    else if (vec.at(i)=="TLE"){
      c2++;
    }
    else {
      c3++;
    }
  }

  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define repr(i, b) for (int i = (b) - 1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n; cin >> n;
    string s; cin >> s;
    vector<int> a[3]; //r,g,bの順
    rep(i,0,n){
        if(s[i]=='R') a[0].push_back(i+1);
        if(s[i]=='G') a[1].push_back(i+1);
        if(s[i]=='B') a[2].push_back(i+1);
    }
    ll ans=0;
    //jを定めてなんかする
    int t,y,u;
    t=0,y=1,u=2;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    t=0,y=2,u=1;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    t=1,y=0,u=2;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    t=1,y=2,u=0;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    t=2,y=0,u=1;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    t=2,y=1,u=0;
    rep(i,0,a[y].size()){
        rep(j,0,a[t].size()){
            if(a[y][i]<a[t][j]) break;
            auto tmp1 = lower_bound(all(a[u]),a[y][i]);
            auto tmp2 = lower_bound(all(a[u]),2*a[y][i]-a[t][j]);
            //cout << *tmp2 << endl;
            ans += a[u].end()-tmp1;
            if(tmp2 != a[u].end() &&*tmp2 == 2*a[y][i]-a[t][j])  ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include<iostream>
using namespace std;
 
int changee(int n){
		int change;
		if(n%1000==0){change =0;}
		else{change = 1000 - (n%1000);}
		return change;
}
 
int main() {
	int n;
	cin>>n;
	int cha = changee(n);
	cout<<cha;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
	int N,D,A[100],X;
	cin>>N>>D>>X; 
	for(int i=0;i<N;i++) 
	{
		cin>>A[i];
	}
	int sum=0;
	for(int i=0;i<N;i++)
	{
		int j=1;
		while(((j-1)*A[i]+1)<=D)
		{
			sum++;
			j++;
		}
	}
	sum = sum+X;
	cout<<sum;
	return 0;
}



Measured memory_bytes: 256
# AOJ 1609: Look for the Winner!
# Python3 2018.7.13 bal4u

while True:
	n = int(input())
	if n == 0: break
	c = list(input().split())
	c = [ord(i)-ord('A') for i in c]
	f = [0]*26
	max1 = max2 = 0
	x1 = x2 = -1
	k, i = n, 0;
	while i < n:
		x = c[i]
		i, k = i+1, k-1
		f[x] += 1;
		if f[x] > max1:
			if x1 < 0 or x == x1: max1 = f[x]; x1 = x
			else: max2 = max1; x2 = x1; max1 = f[x]; x1 = x
		elif f[x] > max2: max2 = f[x]; x2 = x
		if max2+k < max1: break
	if max1 == max2: print("TIE")
	else: print(chr(x1+ord('A')), i)



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    string s;cin>>s;
    int ans=0;
    rep(i, s.size()/2){
        if(s[i]!=s[s.size()-1-i])ans++;
    }
    co(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int s = scanner.nextInt();
		
		int cnt=0;
		for(int i=s;i>0;i/=10) {
			int tar=i%10;
			if(tar==1) cnt++;
		}
		
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22868
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a="CODEFESTIVAL2016";
	string b;
	int s=0;
	cin>>b;
	for(int i=0;i<a.size();i++){
		if(b[i]!=a[i])s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll H, W, K;
	cin >> H >> W >> K;

	vector<string> Ss(H);
	for (ll i = 0; i < H; ++i) {
		cin >> Ss[i];
	}

	vector<vector<ll>> accum_white_counts(H, vector<ll>(W + 1));
	for (ll i = 0; i < H; ++i) {
		for (ll j = 0; j < W; ++j) {
			accum_white_counts[i][j + 1] = accum_white_counts[i][j] + (Ss[i][j] == '1' ? 1: 0);
		}
	}

	ll res = 1000000000LL, bits, begin, split, white_counts;
	bool impossible;
	for (ll i = 0; i < (1LL << (H - 1)); ++i) {
		bits = i;
		begin = 0;
		split = 0;
		impossible = false;
		for (ll k = 0; k < H; ++k) {
			if (((bits >> k) & 1LL) == 1LL) ++split;
		}

		for (ll j = 1; j <= W; ++j) {
			white_counts = 0;
			for (ll k = 0; k < H; ++k) {
				white_counts += accum_white_counts[k][j] - accum_white_counts[k][begin];
				if (white_counts > K) {
					if (begin == (j - 1LL)) impossible = true;
					begin = j - 1LL;
					++split;
					break;
				}
				if (((bits >> k) & 1LL) == 1LL) white_counts = 0;
			}
			if (impossible) break;
		}
		if (!impossible) res = min(res, split);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Yes(bool Yes){cout << (Yes ? "Yes" : "No") << endl;};
void YES(bool YES){cout << (YES ? "YES" : "NO") << endl;};


int main(){
    
    string a, b, c;
    cin >> a >> b >> c;
    YES(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]);

    return 0;
}


Measured memory_bytes: 256
/*
 * @Date         : 2020-07-28 23:41:58
 * @Author       : ssyze
 * @Description  :
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
map<pair<ll, ll>, int> dp;
ll n;

ll dfs(ll u, ll v)
{
    if (v < 0) return 0;
    if (v == 0) return 1;
    if (dp[{u, v}]) return dp[{u, v}];
    ll ans = 0;
    ans = (ans + dfs(u >> 1, v >> 1)) % mod;
    ans = (ans + dfs((u - 1) >> 1, (v - 1) >> 1)) % mod;
    if (v >= 2) ans = (ans + dfs(u >> 1, (v - 2) >> 1)) % mod;
    return dp[{u, v}] = ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    cout << dfs(n, n) << '\n';
}

Measured memory_bytes: 3672
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int N = int.Parse(words[0]);
        int K = int.Parse(words[1]);
        String S;
        S = Console.ReadLine();
        string answer = "";
        for(int i = 0; i < N; i++)
        {
            if (i == K - 1)
            {
                answer += (char)(S[i] - ('A' - 'a'));
            }
            else answer += S[i];
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
// A - Multiple Array

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[100000];
ll B[100000];

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

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

	ll cnt = 0;

	for (int i=N-1; i>=1; i--) {
		if (A[i] % B[i] > 0) cnt += B[i] - (A[i] % B[i]);
		A[i-1] += cnt;
	}

	if (A[0] % B[0] > 0) cnt += B[0] - (A[0] % B[0]);

	ll ans = cnt;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5184
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m;
char p[10];
int main() {
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%s", p);
			if (strcmp(p, "snuke") == 0) {
				printf("%c%d\n", 'A' + j, i + 1);
			}
		}
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e18;
//const int INF=(1<<30);

vector<ll> s;
vector<ll> t;

ll solve(ll x){
  auto sr = upper_bound(ALL(s),x);
  auto tr = upper_bound(ALL(t),x);

  ll ret = INF;

  chmin(ret, max(*sr - x,*tr - x));
  chmin(ret, max(x - *(sr-1),x - *(tr-1)));

  chmin(ret, 2*(*sr - x) + x - *(tr - 1));
  chmin(ret, 2*(x - *(sr-1)) + *tr - x);
  chmin(ret, 2*(*tr - x) + x - *(sr - 1));
  chmin(ret, 2*(x - *(tr-1)) + *sr - x);

  return ret;
}


int main(){
  int a,b,q;
  cin >> a >> b >> q;

  s.resize(a+2);
  t.resize(b+2);
  s[0] = t[0] = -INF;
  s[a+1] = t[b+1] = INF;

  REP(i,a)cin >> s[i+1];
  REP(i,b)cin >> t[i+1];

  REP(i,q){
    ll x;
    cin >> x;
    cout << solve(x) << endl;
  }

}



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

using namespace std;

int main(void)
{
    int n;
    char s;
    cin >> n;
    bool four = false;
    for (int i = 0;i < n;i++)
    {
        cin >> s;
        if (s == 'Y')
        {
            four = true;
        }
    }

    cout << (four? "Four":"Three") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 55;
const int M = 1e9 + 7;

int dp[N][N][N * N];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	int k;
	cin >> n >> k;
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int c = 2 * j; c <= k; ++c) {
				dp[i][j][c] += (2 * j + 1) * dp[i - 1][j][c - 2 * j] + (j + 1) * (j + 1) * dp[i - 1][j + 1][c - 2 * j];
				if (j) {
					dp[i][j][c] += dp[i - 1][j - 1][c - 2 * j];
				}
				dp[i][j][c] %= M;
			}
		}
	}
	cout << dp[n][0][k] << "\n";
	return 0;
}


Measured memory_bytes: 66560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll INF = 1e18;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    VVL d(n, VL(n, INF));
    REP(i,n) d[i][i] = 0;
    REP(i,m){
        int u = in() - 1, v = in() - 1, x = in();
        d[u][v] = d[v][u] = x;
    }
    REP(i,n) REP(j,n) REP(k,n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
    VVL e(n, VL(n, INF));
    REP(i,n) REP(j,n){
        if (i == j) e[i][j] = 0;
        else if (d[i][j] <= l) e[i][j] = 1;
    }
    REP(i,n) REP(j,n) REP(k,n) e[j][k] = min(e[j][k], e[j][i] + e[i][k]);
    int q;
    cin >> q;
    while (q--){
        int x = in() - 1, y = in() - 1;
        ll ans = e[x][y];
        if (ans == INF) ans = -1;
        else ans--;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1920