akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

void chmax(string &a, string b){
    if (a == "impossible") a = b;
    else if(a.size() < b.size()) a = b;
    else if (a.size() == b.size()){
        if (a < b) a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> A(M);
    REP(i, M) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());
    ll match[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    vector<string> dp(11000, "impossible");
    dp[0] = "";
    REP(i, N){
        if (dp[i] == "impossible") continue;
        REP(j, M){
            chmax(dp[i+match[A[j]]], dp[i]+(char)('0'+A[j]));
            
        }

    }

    cout << dp[N] << "\n";
}

Measured memory_bytes: 45568
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int maxm = 1e6+5;
int dp[maxm][2];

void run_case() {
    string str;
    cin >> str;
    dp[0][0] = str[0] - '0';
    dp[0][1] = 10 - str[0] + '0' + 1;
    for(int i = 1; i < str.size(); ++i) {
        int num = str[i] - '0';
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + num;
        dp[i][1] = 10 - num + min(dp[i-1][0]+1, dp[i-1][1]-1);
    }
    cout << min(dp[str.size()-1][0], dp[str.size()-1][1]);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    //cout.setf(ios_base::showpoint);cout.precision(8);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 9116
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int a[300005];
int ccnt[300005],cnt[300005],suf[300005],ans[300005];
bool check(int sz,int res){
	int all=ans[res]+suf[res+1]*res;
	if(all>=sz*res)return true;
	return false;
}
void solve(int x){
	int L=0,R=n+5;
	while(R-L>1){
		int mid=L+R>>1;
		if(check(x,mid))L=mid;
		else R=mid;
	}
	cout<<L<<endl;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];ccnt[a[i]]++;
	}
	for(int i=1;i<=n;i++)cnt[ccnt[i]]++;
	for(int i=n;i>=1;i--)suf[i]=suf[i+1]+cnt[i];
	for(int i=1;i<=n;i++){
		ans[i]=ans[i-1]+cnt[i]*i; 
	}
	for(int i=1;i<=n;i++){
		solve(i);
	}
	return 0;
}

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



int main(void) {
    vector<int> a(5);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    vector<int> index = {0, 1, 2, 3, 4};
    int min_ans = 999999;
    do {
        int ans = 0;
        for(int i = 0; i < 5;i++){
            while(ans % 10 != 0)ans ++;
            ans += a[index[i]];
        }
        min_ans = min(ans, min_ans);
    }while(next_permutation(index.begin(),index.end()));
    cout << min_ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;
using Graph = Vvec<int>;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

void inputGraph(Graph& graph, int num_edge, bool is_bidirectional, bool is_zero_indexed = false){
    int u, v;
    for(int i=0; i<num_edge; i++){
        cin >> u >> v;
        if(!is_zero_indexed){
            u--; v--;
        }
        graph[u].emplace_back(v);
        if(is_bidirectional) graph[v].emplace_back(u);
    }
}

bool isBipartite(Graph& graph, vector<int>& vis, int tmp, int from){
    if(vis[tmp] >= 0) return true;
    bool ret = true;
    vis[tmp] = (from == -1) ? 0 : 1 - vis[from];
    for(auto& to: graph[tmp]){
        if(to != from){
            ret &= isBipartite(graph, vis, to, tmp);
            ret &= (vis[tmp] == 1-vis[to]);
        }
    }
    return ret;
}

int main()
{
    int N, M;
    cin >> N >> M;
    Graph graph(N);
    inputGraph(graph, M, true);

    ll u = 0, v = 0, w = 0;
    vector<int> vis(N, -1);
    for(int i=0; i<N; i++){
        if(vis[i] >= 0) continue;
        if(graph[i].size()==0) w++;
        else if(isBipartite(graph, vis, i, -1)) u++;
        else v++;
    }

    cout << u*u + (u+v)*(u+v) + w*(2*N-w) << endl;
}

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

int main(){
  int N,Y;
  cin>>N;
  cin>>Y;
  vector<int> ans;
  ans={-1,-1,-1};
  bool frag=false;
  for(int x=0;x<=N;++x){
    for(int y=0;y<=N-x;++y){
      if(10000*x+5000*y+1000*(N-x-y)==Y){
        ans={x,y,N-x-y};
        frag=true;
        break;
      }
    }
    if(frag){break;}
  }
  cout<<ans.at(0)<<" "<<ans.at(1)<<" "<<ans.at(2)<<endl;
}

Measured memory_bytes: 256
while True:

  try:

    a = map(int, raw_input().split())
    b = map(int, raw_input().split())

    hit = blow = 0

    for i in range(4):

      if(a[i] == b[i]):
        hit += 1

      elif(a[i] in b):
        blow += 1

    print hit, blow

  except EOFError:
    break

Measured memory_bytes: 6360
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

struct aa {
	vector<vector<char>>field;
	int time;
};

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int W, H;
vector<vector<char>>ch_color(vector<vector<char>>&field, int nextco) {
	queue<pair<int, int>>que;
	vector<vector<char>>nextfield(field);
	que.push(make_pair(0, 0));
	vector<vector<int>>memo(H, vector<int>(W));
	int fromco = field[0][0];
	nextfield[0][0] = nextco;
	while (!que.empty()) {
		auto p(que.front());
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int nextx = p.first + dx[way];
			const int nexty = p.second + dy[way];
			if (nextx >= 0 && nextx < W&&nexty >= 0 && nexty < H) {
				if (memo[nexty][nextx])continue;
				else {
					memo[nexty][nextx] = true;
					if (field[nexty][nextx] == fromco) {
						nextfield[nexty][nextx] = nextco;
						que.push(make_pair(nextx, nexty));
					}
					else {
					}
				}
				
			}
		}
	}
	return nextfield;
}

int main() {
	while (1) {
		cin >> W >> H;
		if (!W)break;
		queue<aa>que;
		set < vector<vector<char>>>aset;
		{
			vector<vector<char>>field(H, vector<char>(W));
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					char c; cin >> c;
					if (c == 'R')field[i][j] = 0;
					else if (c == 'B')field[i][j] = 1;
					else field[i][j] = 2;
				}
			}
			que.push(aa{ field,0 });
			aset.emplace(field);
		}
		
		int ans;
		while (!que.empty()) {
			aa atop(que.front());
			auto afield(atop.field);
			bool ok = true;
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					if (atop.field[i][j] != atop.field[0][0])ok = false;
				}
			}
			if (ok) {
				ans = atop.time;
				break;
			}
			que.pop();
			for (int co = 0; co < 3; ++co) {
				if (co == afield[0][0])continue;
				else {
					vector<vector<char>>nextfield(ch_color(afield, co));
					if (aset.find(nextfield) == aset.end()) {
						aset.emplace(nextfield);
						que.push(aa{ nextfield,atop.time + 1 });
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(){
    int N,K;
    cin >> N >> K;
    ll ans = K;

    if(N>1){
        for(int i=0; i<N-1; i++){
            ans = ans*(K-1);
        }
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,sx,sy,tx,ty;
    cin>>h>>w>>sx>>sy>>tx>>ty;--sx,--sy,--tx,--ty;
    vector<string> s(h);
    for(auto&c:s) cin>>c;
    auto d=vector(h,vector(w,INT_MAX));
    deque<pair<int,int>> dq;
    dq.emplace_front(sx,sy);
    d[sx][sy]=0;
    while(!dq.empty()){
        auto[x,y]=dq.front();dq.pop_front();
        if(x==tx and y==ty) return cout<<d[x][y]<<'\n',0;
        if(x and s[x-1][y]=='.' and d[x-1][y]>d[x][y]){
            d[x-1][y]=d[x][y];
            dq.emplace_front(x-1,y);
        }
        if(x<h-1 and s[x+1][y]=='.' and d[x+1][y]>d[x][y]){
            d[x+1][y]=d[x][y];
            dq.emplace_front(x+1,y);
        }
        if(y and s[x][y-1]=='.' and d[x][y-1]>d[x][y]){
            d[x][y-1]=d[x][y];
            dq.emplace_front(x,y-1);
        }
        if(y<w-1 and s[x][y+1]=='.' and d[x][y+1]>d[x][y]){
            d[x][y+1]=d[x][y];
            dq.emplace_front(x,y+1);
        }
        for(int i=-2;i<=2;++i) for(int j=-2;j<=2;++j) if(0<=x+i and x+i<h and 0<=y+j and y+j<w and s[x+i][y+j]=='.' and d[x+i][y+j]>d[x][y]+1){
            d[x+i][y+j]=d[x][y]+1;
            dq.emplace_back(x+i,y+j);
        }
    }
    cout<<-1<<'\n';
}

Measured memory_bytes: 8644
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#include<set>
#include<complex>
#include<complex>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000
#define FER 0.0000000001

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

int dp[10001];
int v[100], w[100];

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

	int N, W;

	cin >> N >> W;

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

	for (int i = 0; i < N; i++)for (int j = 1; j <= W; j++)
	{
		if (j >= w[i])
		{
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}

	cout << dp[W] << endl;
	
	return 0;
}


Measured memory_bytes: 3280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
const int N = 1e5+1;
int n,fa[N];
struct nd{LL x,y;LL id;}a[N];

struct nd2{LL w;LL x,y;} edg[N*2];

bool cmp(nd a,nd b)
{
	return a.x<b.x;
}

bool cmp2(nd a,nd b)
{
	return a.y<b.y;

}

LL find(LL x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

bool operator <(nd2 a,nd2 b)
{
	return a.w>b.w;
}

priority_queue<nd2>q[2];

int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)	
		fa[i]=i;
	for(int i=1;i<=n;++i)
		cin>>a[i].x>>a[i].y;
	for(int i=1;i<=n;++i)
		a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n-1;++i)
	{
		nd2 in;
		in.w=abs(a[i].x-a[i+1].x);
		in.x=a[i].id,in.y=a[i+1].id;
		q[0].push(in);
	}
	sort(a+1,a+n+1,cmp2);
	for(int i=1;i<=n-1;++i)
	{
		nd2 in;
		in.w=abs(a[i].y-a[i+1].y);
		in.x=a[i].id,in.y=a[i+1].id;
		q[1].push(in);
	}
	LL ans=0;
	for(int i=1;i<=n-1;++i)
	{
		nd2 t=q[0].top();
		while(find(t.x)==find(t.y)&&!q[0].empty())
			q[0].pop(),t=q[0].top();
		nd2 t1=q[1].top();
		while(find(t1.x)==find(t1.y)&&!q[1].empty())
			q[1].pop(),t1=q[1].top();
		if(t.w<=t1.w)
		{
			ans+=t.w;
			fa[find(t.x)]=find(t.y);
		}
		else
		{
			ans+=t1.w;
			fa[find(t1.x)]=find(t1.y);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    string n; cin >> n;
    int sum = 0;
    rep(i,n.length()) sum += n[i] - '0';
    int N = stoi(n);
    if (N % sum == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int a[100000];

int main() {
	int n, i;
	long long sum = 0, c = 0, k, k2 = 0;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	
	if (n == 1) {
		puts("YES");
		
		return 0;
	}
	
	for (i = 0; i < n; i++) {
		sum += a[i];
		c += i + 1;
	}
	
	if (sum % c != 0) {
		puts("NO");
		
		return 0;
	}
	
	k = sum / c;
	
	for (i = 0; i < n; i++) {
		long long x = a[i], y = a[(i + 1) % n], z = x - y + k;
		
		if (z % n != 0) {
			puts("NO");
			
			return 0;
		}
		
		z /= n;
		
		if (z < 0 || z > k) {
			puts("NO");
			
			return 0;
		}
		
		k2 += z;
	}
	
	if (k != k2) {
		puts("NO");
	} else {
		puts("YES");
	}
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, A, B, x ;
  	cin >> N >> A >> B ;
  	x = N * A ;
  
  if (x == B) {
    cout << x ;
  }
  else if (x <= B) {
    cout << x ;
  }
  else {
    cout << B ;
  }
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
	

int main(){

    string s,t;
	cin>>s>>t;

	int cnt=0;
	rep(i,3){
		if(s[i]==t[i]){
			cnt++;
		}
	}

	cout<< cnt<<endl;
	return 0;
}


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

typedef long long ll;

struct str
{
    ll a,b;
};
bool operator<(str a,str b)
{
    return a.a<b.a;
}


int main()
{

    ll n,a,b,m,i,pre_a,pre_b,c=0;
    vector<str>v;
    cin >> n >> m;
    for(i=0; i<m; i++)
    {
        cin >> a >> b;
        v.push_back({a,b-1});
    }
    sort(v.begin(),v.end());
    for(i=0; i<v.size(); i++)
    {
        a=v[i].a,b=v[i].b;
        if(i==0)pre_a=a,pre_b=b;
        else
        {
            if(a>pre_b)c++,pre_a=a,pre_b=b;
            else
            {
                pre_a=max(a,pre_a);
                pre_b=min(b,pre_b);
            }
        }
    }
    c++;
    cout << c << "\n";


    return 0;
}




Measured memory_bytes: 2420
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    # D = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    t = 0
    for a in range(1, N):
        d = (N-1) // a
        t += d
    print(t)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68588
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

sa = A1 * T1
sb = B1 * T1
ea = A2 * T2
eb = B2 * T2
fa = sa + ea
fb = sb + eb

if fa < fb:
  if sa < sb:
    print(0)
  elif sa == sb:
    print(1)
  elif sa > sb:
    d1 = sa - sb
    di = fb - fa
    c = int(d1 / di) + math.ceil(d1 / di)#  + 1
    print(c)
elif fa == fb:
  print("infinity")
elif fa > fb:
  if sa < sb:
    d1 = sb - sa
    di = fa - fb
    c = int(d1 / di) + math.ceil(d1 / di)# + 1
    print(c)
  elif sa == sb:
    print(1)
  elif sa > sb:
    print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

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

ll A[200000];
ll Ans;
int N;

void dfs(int num){
    if(num>=N) return;
    
    dfs(num+1);
    
    for(int i=num+1; i<N; i++){
        Ans += A[num] * A[i];
    }
}

int main(int argc, const char * argv[]) {

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    dfs(0);
    
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 3124
main(n){while(scanf("%d",&n),n){int m[15][15]={0},x=n/2,y=n/2+1,c;for(c=1;c<=n*n;m[x++%n][y++%n]=c++)for(;m[x%n][y%n];y++)x--;for(y=0;y<n;y++){for(x=0;x<n;x++)printf("%4d",m[x][y]);printf("\n");}}exit(0);}

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

int n,q;

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

  cin>>n>>q;
  string s;
  cin>>s;
  char t[q], d[q];
  rep(i,q) {
    cin>>t[i]>>d[i];
  }

  int r_drop = n, l_drop = -1;

  int l = 0, r = n-1;
  while(l <= r) {
    int m = (l + r) / 2;
    int now = m;
    bool m_l_drop = false;
    rep(i,q) {
      if(t[i] == s[now]) {
        if(d[i] == 'L') {
          now--;
        } else {
          now++;
        }
      }
      if(now < 0) {
        m_l_drop = true;
        l_drop = m;
        break;
      } else if (now >= n) {
        break;
      }
    }
    if(m_l_drop) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }

  l = 0; r = n-1;
  while(l <= r) {
    int m = (l + r) / 2;
    int now = m;
    bool m_r_drop = false;
    rep(i,q) {
      if(t[i] == s[now]) {
        if(d[i] == 'L') {
          now--;
        } else {
          now++;
        }
      }
      if(now < 0) {
        break;
      } else if (now >= n) {
        m_r_drop = true;
        r_drop = m;
        break;
      }
    }
    if(m_r_drop) {
      r = m - 1;
    } else {
      l = m + 1;
    }
  }

  int ans = r_drop - l_drop - 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1044
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

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

    if (A.size() < B.size()) A.insert(A.begin(), '0');
    if (A.size() > B.size()) B.insert(B.begin(), '0');

    if (A > B) cout << "GREATER" << endl;
    if (A < B) cout << "LESS" << endl;
    if (A == B) cout << "EQUAL" << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

cnt = [0] * 10
for v in d.values():
    cnt[v] += 1

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")


Measured memory_bytes: 176472
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int divs[10000];
int main(){
	int n,a,b;
	cin>>n;
	cin>>a;
	for(int i=0;i<n-1;i++){
		cin>>b;
		while(true){
			if(a==b)
				break;
			if(a>b)
				a-=b;
			if(a<b)
				b-=a;
		}
	}
	int count=0;
	for(int i=1;i*i<a;i++){
		if(a%i==0){
			divs[count]=i;
			divs[count+1]=a/i;
			count+=2;
		}
	}
	if((int)sqrt((double)a+0.0)*(int)sqrt((double)a+0.0)==a){
		divs[count]=(int)sqrt((double)a+0.0);
		count++;
	}
	sort(divs,divs+count);
	for(int i=0;i<count;i++)
		cout<<divs[i]<<endl;
	//cout<<endl;
	return 0;
}

Measured memory_bytes: 1180
N = int(input())
table = list(map(int, input().split()))

BIG_N = 200000000000
total = 0
maximum = -BIG_N
minimum = BIG_N

for i in table:
    if i > maximum:
        maximum = i
    if i < minimum:
        minimum = i
    total += i
    
print(f"{minimum} {maximum} {total}")



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

string s, t;

bool match(int k) {
    rep(i, sz(t)) {
        if (s[k+i]!=t[i]&&s[k+i]!='?') {
            return false;
        }
    }
    return true;
}

string construct(int k) {
    string res = s;
    rep(i, sz(t)) {
        res[k+i] = t[i];
    }
    rep(i, sz(res)) {
        if (res[i] == '?') res[i] = 'a';
    }
    return res;
}

int main(){
    cin >> s >> t;
    string ans = {'z' + 1 };
    bool exist = false;
    rep(i, sz(s)-sz(t)+1) {
        bool ok = match(i);
        if (ok) {
            ans = min(ans, construct(i));
            exist = true;
        }
    }
    if (exist) cout << ans << endl;
    else puts("UNRESTORABLE");
    return 0;
}


Measured memory_bytes: 256
//File: abc174c.cpp
//Author: yanyanlongxia
//Date: 2020/8/3
//
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,i,now;
signed main() {
    scanf("%d",&n);
    while(i<=10000000)
    {
        i++;
        now=(now*10+7)%n;
        if(now==0)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int n, k, q;
unordered_map <int, int> mp;
int main() {
    cin >> n >> k >> q;
    int temp = q;
    while(q--) {
        int x;
        cin >> x;
        mp[x]++;
    }
    for ( int i = 1; i <= n; ++i ) {
        if ( temp - mp[i] < k ) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4772
S = input()

for i in range(2 ** (len(S) - 1)):
    op = ['-' for _ in range(len(S)-1)]
    for j in range(len(S)-1):
        if ((i >> j) & 1):
            op[j] = '+'
    
    formula = [f for i in [[n,op_] for n, op_ in zip(S, op + [''])] for f in i] 
    if eval(''.join(formula)) == 7:
        print(''.join(formula)+'=7')
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t total = 0;
  total += (N / (A + B)) * A;
  N %= A + B;
  if (N <= A) {
    total += N;
  }
  else {
    total += A;
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int a[105][105],b[10000+50];

int main ()
{
	int h,w;
	while(scanf("%d %d",&h,&w)!=EOF)
	{
		int i,j,t,k=0;
		scanf("%d",&t);
		for(i=0;i<t;i++)
			scanf("%d",&b[i]);
		for(i=0;i<h;i++)
		{
			if(i%2==0)
				for(j=0;j<w;j++)
				{
					a[i][j]=k+1;
					b[k]--;
					if(b[k]==0)
						k++;
				}
			if(i%2==1)
				for(j=w-1;j>=0;j--)
				{
					a[i][j]=k+1;
					b[k]--;
					if(b[k]==0)
						k++;
				}
		}
		for(i=0;i<h;i++)
		{
			for(j=0;j<w-1;j++)
				printf("%d ",a[i][j]);
			printf("%d\n",a[i][w-1]);
		}
	}
}

Measured memory_bytes: 256
while True :
    try :
        g, y, m, d = map(str, input().split())
        y = int(y)
        m = int(m)
        d = int(d)
        if(y <= 30) :
            print("HEISEI", y, m, d)
        elif(y == 31 and m <= 4):
            print("HEISEI",y , m, d)
        else:
            y = y - 30
            print("?", y, m, d)
    except :
        break



Measured memory_bytes: 5604
#include<stdio.h>
double n;
int x;
int main(){
	while(~scanf("%lf",&n))
	{
		x=n/1.08;
		if(x*1.08<n)
		{
			if((x+1)*1.08>=n&&(x+1)*1.08<n+1)
			printf("%d\n",x+1);
			else
		printf(":(\n");
	}
		else
		printf("%d\n",x);
	}
	return 0;
} 

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

int p[2005][2005];
int q[2005][2005];
int r[2005][2005];
int t[2005][2005];

int main(){
	int h, w;
	cin>>h>>w;
	vector<string> s(h);
	for(int i = 0; i < h; ++i)cin>>s[i];
	for(int i = 1; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(s[i][j] != '.')continue;
			else{
				if(i - 1 >= 0 && s[i - 1][j] == '.'){
					p[i][j] = p[i - 1][j] + 1;
				}
				else{
					p[i][j] = 0;
				}
			}
		}
	}
	for(int i = 0; i < h; ++i){
		for(int j = 1; j < w; ++j){
			if(s[i][j] != '.')continue;
			else{
				if(j - 1 >= 0 && s[i][j - 1] == '.'){
					q[i][j] = q[i][j - 1] + 1;
				}
				else{
					q[i][j] = 0;
				}
			}
		}
	}
	for(int i = h - 2; i >= 0; i--){
		for(int j = w - 1; j >= 0; j--){
			if(s[i][j] != '.')continue;
			else{
				if(i + 1 < h && s[i + 1][j] == '.'){
					r[i][j] = r[i + 1][j] + 1;
				}
				else{
					r[i][j] = 0;
				}
			}
		}
	}
	for(int i = h - 1; i >= 0; --i){
		for(int j = w - 2; j >= 0; --j){
			if(s[i][j] != '.')continue;
			else{				
				if(j + 1 < w && s[i][j + 1] == '.'){
					t[i][j] = t[i][j + 1] + 1;
				}
				else{
					t[i][j] = 0;
				}
			}
		}
	}
	int res = 0;
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(p[i][j] + q[i][j] + r[i][j] + t[i][j] + 1 > res){
				res = p[i][j] + q[i][j] + r[i][j] + t[i][j] + 1;
				
			}
		}
	}
	cout<<res<<endl;


	
	return 0;
}


Measured memory_bytes: 67072
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = Integer.parseInt(br.readLine());
		long[] a = new long[n];
		StringTokenizer st = new StringTokenizer(br.readLine());
		for(int i = 0; i < n; i++)
			a[i] = Long.parseLong(st.nextToken());
		Arrays.sort(a);
		long[] pre = new long[n];
		pre[0] = a[0];
		for(int i = 1; i < n; i++)
			pre[i] = pre[i-1] + a[i];
		int i = n-1;
		while(i >= 1 && 2*pre[i-1] >= a[i])
			i--;
		pw.println(n-i);
		br.close();
		pw.close();
		System.exit(0);
	}
}

Measured memory_bytes: 41980
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

const int N=2e5+5;
int n,k,a[N],go[N][60];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int j=0;j<=60;j++)
    {
        for(int i=1;i<=n;i++)
        {
            if(j==0) go[i][j]=a[i];
            else go[i][j]=go[go[i][j-1]][j-1];
        }
    }
    int cur=1;
    for(int j=0;j<=60;j++)
    {
        if(k>>j&1) cur=go[cur][j];
    }
    cout<<cur;
}


Measured memory_bytes: 98968
#include<bits/stdc++.h>
using namespace std;
const int N=2020;
bitset<N*N>b;
int n,S;
int main(){
    scanf("%d",&n);b.set(0);
    for(int i=1,x;i<=n;i++)
        scanf("%d",&x),b|=b<<x,S+=x;
    for(int i=(S+1)/2;;i++)if(b[i])cout<<i,exit(0);
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		double n=sc.nextDouble();
		double x=sc.nextDouble();
		double t=sc.nextDouble();
		double a=Math.ceil(n/x);
		System.out.println((int)(a*t));
	}
}


Measured memory_bytes: 37228
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

unordered_map<ll, ll> mp;


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = unordered_map<ll, ll>();
#pragma clang diagnostic pop
#endif

        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << min(a, b) + min(c, d) << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <iomanip>

using namespace std;

const int OKU7 = 1000000007;


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

	cin >> n;

	int y = n / 100;
	int m = n % 100;
	bool isMonthM = true;
	bool isMonthY = true;

	if (m == 0 || m > 12) {
		isMonthM = false;
	}
	if (y == 0 || y > 12) {
		isMonthY = false;
	}

	if (isMonthM && isMonthY) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (isMonthM) {
		cout << "YYMM" << endl;
	}
	else if (isMonthY) {
		cout << "MMYY " << endl;
	}
	else {
		cout << "NA" << endl;
	}



	
	
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    def hantei(A):
        for i in range(1,len(A)):
            if not A[i-1]<A[i]:
                return False
        return True
    
    if hantei(A):
        print('YES')
        return
    x=list(range(N))
    for i,j in combinations(x,2):
        cA=A.copy()
        cA[i],cA[j]=cA[j],cA[i]
        if hantei(cA):
            print('YES')
            return
    print('NO')



if __name__ == "__main__":
    main()

Measured memory_bytes: 77732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if(c-a-b <= 0){
    cout << "No" << endl;
  }
  else if(4 * a * b < (c - a - b) * (c - a - b)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#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 vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll N, M, X;
	ll A[1000] = {0};
	ll A1;
	ll sum = 0;
	ll sum1 = 0;
	cin >> N >> M >> X;
	REP(i, M) {
		cin >> A1;
		A[A1] = 1;
	}
	
	FOR(i, X, N) {
		if (A[i + 1] == 1) {
			sum += 1;
		}
	}
	for (int i = X; i > 0; i--) {
		if (A[i - 1] == 1) {
			sum1 += 1;
		}
	}
	if (sum < sum1) {
		cout << sum;
	}
	else {
		cout << sum1;
	}

	return 0;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	char map[10][10];
};

struct Data{
	Data(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
char base_map[10][10];
bool FLG;

char to_color[3] = {'R','G','B'};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void back_track(Info info,int depth,int max_depth){

	if(FLG)return;

	if(depth == max_depth){
		bool is_cleared = true;
		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(info.map[row][col] != info.map[0][0]){
					is_cleared = false;
					break;
				}
			}
			if(!is_cleared)break;
		}

		if(is_cleared){
			FLG = true;
		}
		return;
	}

	char pre_color = info.map[0][0];

	queue<Data> Q;
	int adj_row,adj_col;

	for(int loop = 0; loop < 3; loop++){
		if(to_color[loop] == pre_color)continue;

		Info next_info;
		for(int row = 0;row < H; row++){
			for(int col = 0; col < W; col++){
				next_info.map[row][col] = info.map[row][col];
			}
		}

		next_info.map[0][0] = to_color[loop];

		Q.push(Data(0,0));

		while(!Q.empty()){

			for(int i = 0; i < 4; i++){
				adj_row = Q.front().row + diff_row[i];
				adj_col = Q.front().col + diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				if(next_info.map[adj_row][adj_col] == pre_color){
					next_info.map[adj_row][adj_col] = to_color[loop];
					Q.push(Data(adj_row,adj_col));
				}
			}

			Q.pop();
		}
		back_track(next_info,depth+1,max_depth);
	}
}

void func(){

	char buf[2];

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%s",buf);
			base_map[row][col] = buf[0];
		}
	}

	FLG = false;
	int ans = 0;

	for(int i = 0; ; i++){
		Info info;

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				info.map[row][col] = base_map[row][col];
			}
		}
		back_track(info,0,i);

		if(FLG){
			ans = i;
			break;
		}
	}

	printf("%d\n",ans);
}


int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<vector<int> > input(int n) {
    vector<vector<int> > G(n);
    for (int i = 0 ;  i< n - 1 ; i++) {
        int u, v; cin >> u >> v; u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    return G;
}
vector<int> bfs(vector<vector<int> > &G, int s) {
    vector<int> d(G.size(), -1);
    queue<int> q; q.push(s); d[s] = 0;
    while (q.size()) {
        int p = q.front(); q.pop();
        for (auto &v : G[p]) {
            if (~d[v])
                continue;
            d[v] = d[p] + 1;
            q.push(v);
        }
    }
    return d;
}
void odd(int n, int k) {
    vector<vector<int> > G = input(n);
    int ans = n;
    for (int u = 0 ; u < n ; u++) {
        for (auto &v : G[u]) {
            vector<int> du = bfs(G, u);
            vector<int> dv = bfs(G, v);
            int cnt = 0;
            for (int j = 0 ; j < n ; j++)
                if (min(du[j], dv[j]) > (k - 1) / 2)
                    cnt++;
            ans = min(ans, cnt);
        }
    }
    cout << ans << '\n';
}
void even(int n, int k) {
    vector<vector<int> > G = input(n);
    int ans = n;
    for (int i = 0 ; i < n ; i++) {
        vector<int> d = bfs(G, i);
        int cnt = 0;
        for (int j = 0 ; j < n ; j++)
            if (d[j] > k / 2)
                cnt++;
        ans = min(cnt, ans);
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    if (k % 2) {
        odd(n, k);
    } else {
        even(n, k);
    }
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Map<String,Integer>po=new HashMap<String,Integer>();
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        boolean ppp=true;
        sc.nextLine();
        String g=sc.nextLine();
        po.put(g,0);
      String nstr=g.substring(g.length()-1,g.length());
        for(int i=0;i<n-1;i++){
        	String str=sc.nextLine();
            if(po.containsKey(str)){
                ppp=false;
                break;
            }
            else {
                if(nstr.equals(str.substring(0,1))){
                    nstr=str.substring(str.length()-1,str.length());
                    po.put(str,0);
                }
                else{
                    ppp=false; break;
                }
                
            }
        }
      System.out.println((ppp)?"Yes":"No");
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;

  V<pair<int, char>> v;
  char p = s[0];
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (p != s[i]) {
      v.push_back({cnt, p});
      p = s[i];
      cnt = 0;
    }
    cnt++;
  }
  v.push_back({cnt, p});

  int num = v.size();
  V<int> cs(num);
  int sum = 0;
  rep(i, num) {
    sum += v[i].first;
    cs[i] = sum;
  }

  int ans = 0;
  rep(i, num) {
    int r;
    if (v[i].second == '1') {
      r = min(i + 2 * k, num - 1);
    } else {
      r = min(i + 2 * k - 1, num - 1);
    }
    int val = cs[r] - cs[i] + v[i].first;
    ans = max(ans, val);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	ll ans = 0;
	int f = 0;
	string s; cin >> s;
	rep(i, s.size()) if(s[i] == 'W'){
		ans += i - f;
		f++;
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;
#define ll long long
int num[1005];
int chs[1005];
int main()
{
    ll n;
    cin >> n;
    int cnt=0;
    while(n)
    {
        int t=n%26;
        chs[cnt++]=t;
        if(!t)
            n--;
        n/=26;
    }
    for(int i=cnt-1;i>=0;i--)
        printf("%c",((chs[i]+25)%26)+'a');
    return 0;
}


Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int r = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int[][] spreadSheet = new int[r+1][c+1];

		for(int i = 0; i<r; i++){
			
			for(int j = 0; j<c; j++){
				
				spreadSheet[i][j] = Integer.parseInt(sc.next());
				spreadSheet[i][c] += spreadSheet[i][j];
				spreadSheet[r][j] += spreadSheet[i][j];
				spreadSheet[r][c] += spreadSheet[i][j];
			}
		}
		
		print(spreadSheet,r,c);
		
		sc.close();
		
	}

	private static void print(int[][] spreadSheet, int r, int c) {
		
		StringBuilder sb = new StringBuilder((c+1) *r);
		
		for(int i=0;i<r+1;i++){
			
			for(int j=0;j<c+1;j++){
				
				sb.append(spreadSheet[i][j]);
				
				if(j == c){
					sb.append("\n");
				}else{
					sb.append(" ");
				}
				
			}
			
		
		}
		
		System.out.print(sb);
		
	}

}



Measured memory_bytes: 37208
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string S[3];
int main() {
  string res = "";
  for (int i = 0; i < 3; ++i) cin >> S[i], res += S[i][0];
  for (int i = 0; i < 3; ++i) {
	res[i] = res[i] + 'A' - 'a';
  }
  cout << res << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int N;
vector<vint> G;
ll g[5010];
ll dp[5010][5010][2];
ll size[5010];
ll tmp[5010][2];

void dfs(int v,int par){
  size[v]=1;
  dp[v][1][0]=1;
  for(int chi:G[v])if(chi!=par){
    dfs(chi,v);
    repeat(i,5010){
      tmp[i][0]=tmp[i][1]=0;
    }
    for(int x=1;x<=size[v];x++){
      for(int y=1;y<=size[chi];y++){
        tmp[x+y][0] = (tmp[x+y][0]+(dp[v][x][0]*dp[chi][y][0]%MOD+dp[v][x][1]*dp[chi][y][1]%MOD)%MOD)%MOD;
        tmp[x+y][1] = (tmp[x+y][1]+(dp[v][x][0]*dp[chi][y][1]%MOD+dp[v][x][1]*dp[chi][y][0]%MOD)%MOD)%MOD;

        tmp[x][1] = (tmp[x][1]+(dp[v][x][0]*dp[chi][y][0]%MOD+dp[v][x][1]*dp[chi][y][1]%MOD)%MOD*g[y]%MOD)%MOD;
        tmp[x][0] = (tmp[x][0]+(dp[v][x][0]*dp[chi][y][1]%MOD+dp[v][x][1]*dp[chi][y][0]%MOD)%MOD*g[y]%MOD)%MOD;
      }
    }
    swap(tmp,dp[v]);
    size[v]+=size[chi];
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  G.resize(N);
  g[0]=1;
  repeat(i,N/2){
    g[2*(i+1)] = g[2*i]*(2*i+1)%MOD;
  }
  repeat(i,N-1){
    int x,y;cin>>x>>y;x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0,-1);
  ll ans = 0;
  repeat(i,N){
    ans = (ans+dp[0][i+1][0]*g[i+1]%MOD)%MOD;
    ans = (ans-(dp[0][i+1][1]*g[i+1]%MOD)+MOD)%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 392832