akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define filein freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);


void fun1(int* a,int* b){
    int sum=*a+*b;
    int dif=abs(*a-*b);
    //cout<<sum<<dif<<"\n";
    *a=sum;
    *b=dif;
}


int main() {


    long long n,m;
    cin>>n>>m;
    n%=m;
    long long t=abs(n-m);
    while (t<n){
        n=t;
        t=abs(n-m);
    }
    cout<<n;




}


Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

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

int main(){
  int i,j,k,n;
  int l[10];
  int asp,bsp,sum=0,res;
  double r,p;

  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
              &l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&asp,&bsp) != EOF){
    sum = 0;
    rep(i,10) sum += l[i];
    r = (double)asp / (double)(bsp + asp);
    p = sum * r;
    sum = 0;
    rep(i,9){
      sum += l[i];
      if(sum == p) res = i+1;
      if(sum < p && p < sum + l[i+1]) res = i+2;
    }
    printf("%d\n",res);
  }

  return 0;
}

Measured memory_bytes: 0
function Main(input) {
  var tmp = input.split('');
  if ( (tmp[0] === tmp[3]) && (tmp[1] === tmp[2]) && (tmp[0] !== tmp[1])) {
    console.log('Yes');
    return;
  } else if ( (tmp[1] === tmp[3]) &&(tmp[0] === tmp[2]) && (tmp[1] !== tmp[2])) {
    console.log('Yes');
    return;
  } else if ((tmp[2] === tmp[3]) &&(tmp[0] === tmp[1]) && (tmp[0] !== tmp[2])){
    console.log('Yes');
    return;
  }
  console.log('No');
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 100000
#define rep(i,n) for(int i=0;i<n;i++)
vector<int> ans;
vector<int>  g[MAX_V];

void dfs(vector<bool>& used,int s){
	used[s] = false;
	rep(i,g[s].size() ){
	if(used[g[s][i]])	{
		dfs(used,g[s][i]);
	//	cout<<i<<endl;
	}
	}
	ans.push_back(s);
	return;
}
void	tsort(int v){
	vector<bool> used(v,true);
	rep(i,v){
	if(used[i]){
	dfs(used,i);
	}
	}
	//rep(i,v)if(used[i])cout<<i<<endl;
	return ;
}
int main(){
	int v,e;
	cin>>v>>e;
	//vector<vector<int> > g(v);	
	int s,t;
	rep(i,e){
	cin>>s>>t;
	g[s].push_back(t);
	}
	tsort(v);
	for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl;	

return 0;
}




Measured memory_bytes: 5700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		boolean flag = true;
		int ans = 0;
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		while (flag) {
			for (int j = 0; j < N; j++) {
				if (A[j] % 2 != 0) {
					flag = false;
				}
			}
			if(flag == false) break;
			for (int k = 0; k < N; k++) {
				A[k] = A[k] / 2;
			}
			ans++;

		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define LL long long
using namespace std;

int main(void){

    int a,b,t;

    int result;


    cin >> a >> b >> t;

    result = b * (t / a);

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from math import sqrt

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

a, b, c = nm()
if 4*a*b < (c-a-b)**2 and c-a-b>0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);

        String S = scanner.next();

        scanner.close();

        int count0 = 0;
        int count1 = 0;

        int length = S.length();

        // other
        String[] ch = S.split("");

        // 0101...
        for(int i=0;i<length;i++){
            boolean isEven = (i%2 == 0);
            if (isEven){
                if("0".equals(ch[i])){
                    count0++;
                }
            }else{
                if("1".equals(ch[i])){
                    count0++;
                }
            }
        }

        // 1010...
        for(int i=0;i<length;i++){
            boolean isEven = (i%2 == 0);
            if (isEven){
                if("1".equals(ch[i])){
                    count1++;
                }
            }else{
                if("0".equals(ch[i])){
                    count1++;
                }
            }
        }

        int count = (count0 < count1)? count0 :count1;

        System.out.println(count);

//        System.out.println(System.currentTimeMillis() - startTime);
    }
}


Measured memory_bytes: 32624
//g++ -std=c++14 test.cpp -o test.out

//参考：
//https://drken1215.hatenablog.com/entry/2018/06/04/120000_1

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
//const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
#define LL long long int
const LL mod = 998244353ll;
struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N,A,B,K;

mint ans = 0;

void solve(){
	combination c(N+1);
	for(LL numof_A=0;numof_A<=N;numof_A++){
		LL diff = K - numof_A*A;
		if(diff<0) break;
		if(diff%B!=0) continue;
		LL numof_B = diff/B;
		ans += c(N,numof_A)*c(N,numof_B);
	}
}

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

    solve();

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

Measured memory_bytes: 4864
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<queue>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
typedef double lf;
typedef unsigned un;
typedef int in;
#define mian main
#define maxn 10000+10
#define maxm 10000+10
#define _(a) read(a)
#define non void
#define inf 2147483647
#define bre break
#define con continue
#define prq priority_queue
#define re register
#define bu bool
#define cz char
#define cst const
#define ope operator
#define inl inline
#define upp upper_bound
#define low lower_bound
#define next_per next_permutation
cz obuf[1<<23],*O=obuf,buf[1<<23],*L=buf,*R=buf;
inl cz gc(){return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;}
template<typename T>inl T Max(T a,T b){return a>b?a:b;}
template<typename T>inl T Min(T a,T b){return a<b?a:b;}
template<typename T>inl T Abs(T a){return a<0?-a:a;}
template<typename T>inl non read(T &a){a=0;T k=1;char c=gc();while(c<'0'||c>'9')k=c=='-'?-1:k,c=gc();while(c>='0'&&c<='9')a=a*10+(c^48),c=gc();if(c!='.'){a*=k;return;}T t=0.1;while(c<'0'||c>'9')c=gc();while(c>='0'&&c<='9')a+=t*(c^48),c=gc(),t*=0.1;a*=k;}
template<typename T>non print(T x){if(x>9)print(x/10);*O++=x%10+'0';}
template<typename T>non out(T a,cz t='\n'){print(a);*O++=t;}
non fresh(){fwrite(obuf,O-obuf,1,stdout);}
string s;
in n,i;
bu a;
in main()
{
	cin>>s;
	n=s.size();
	for(i=0;i<n;++i)if(s[i]=='C')bre;
	for(;i<n;++i)if(s[i]=='F')a=1;
	if(a)*O++='Y',*O++='e',*O++='s';
	else *O++='N',*O++='o';
	*O++='\n',fresh();
	//freopen("a.in","r",stdin);
	//freopen(".out","w",stdout);
}


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

int main() {
  vector<vector<int>> vec(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  int N;
  cin >> N;
  vector<int> b(N);

  for (int i = 0; i < N; i++) {
    cin >> b.at(i);
  }
  vector<vector<int>> atari(3, vector<int>(3, -1));
  //合ってるとこの座標の取得
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < N; k++) {
        if (b.at(k) == vec.at(i).at(j)) {
          atari.at(i).at(j) = 1;
        }
      }
    }
  }
  //  ビンゴ探索
  //横
  for (int i = 0; i < 3; i++) {
    bool bingo = true;
    for (int j = 0; j < 3; j++) {
      if (atari.at(i).at(j) == -1) {
        bingo = false;
      }
    }
    if (bingo) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  //縦
  for (int j = 0; j < 3; j++) {
    bool bingo = true;
    for (int i = 0; i < 3; i++) {
      if (atari.at(i).at(j) == -1) {
        bingo = false;
      }
    }
    if (bingo) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  //斜
  if (atari.at(1).at(1) == 1) {
    if (atari.at(0).at(0) == 1 && atari.at(2).at(2) == 1) {
      cout << "Yes" << endl;
      return 0;
    }
    if (atari.at(0).at(2) == 1 && atari.at(2).at(0) == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef unsigned long long ll;

int n;
vector<string> g;

ll dp[40][40][40][40], dp2[40][40][40][40];

ll DP2(int a, int b, int c, int d);

ll DP(int a, int b, int c, int d) {
  bool firstEmpty = (a > b);
  bool secondEmpty = (c > d);
  if (firstEmpty || secondEmpty) {
    return firstEmpty && secondEmpty;
  }
  ll& result = dp[a][b][c][d];
  if (result != -1) return result;
  result = 0;
  for (int p = a; p <= b; ++p) for (int q = c; q <= d; ++q) {
    if (g[p][q] == '0') {
      continue;
    }
    result += DP2(a, p - 1, p + 1, b) * DP2(c, q - 1, q + 1, d);
  }
  return result;
}

ll DP2(int a, int b, int c, int d) {
  bool firstEmpty = (a > b);
  bool secondEmpty = (c > d);
  if (firstEmpty || secondEmpty) {
    return firstEmpty && secondEmpty;
  }
  ll& result = dp2[a][b][c][d];
  if (result != -1) return result;
  result = 0;
  for (int p = a; p <= b; ++p) for (int q = c; q <= d; ++q) {
    result += DP(a, p, q, d) * DP2(p + 1, b, c, q - 1);
  }
  return result;
}

int main()
{
  cin >> n;
  g.resize(2 * n);
  for (int i = 0; i < 2 * n; ++i) {
    cin >> g[i];
  }

  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));

  ll result = 0;

  for (int a = 1; a < 2 * n; ++ a) {
    if (g[0][a] == '0') {
      continue;
    }
    result += DP2(1, a - 1, a + 1, 2 * n - 1);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 40192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    svec s(3);
    rep(i,3) cin>>s[i];//0->A,1->B,2->C
    vec a(3);
    rep(i,3) a[i]=s[i].size();
    vec cnt(3,0);
    char c='a';
    int t=0;
    while(true){
        if(cnt[t]==a[t]){
            break;
        }
        c=s[t][cnt[t]];
        cnt[t]++;
        if(c=='a') t=0;
        if(c=='b') t=1;
        if(c=='c') t=2;
    }
    if(c=='a') c='A';
    if(c=='b') c='B';
    if(c=='c') c='C';
    cout<<c<<endl;
}

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

using namespace std;

int main() {
  int n;
  int sleep_s;
  string sleep;
  int ans=0;

  cin >> n;
  vector<int> time(n);
  vector<string> str(n);
  
  for(int i=0;i<n;i++){
    cin >> str[i];
//    cout << str[i] << endl;
    cin >> time[i];
//   cout << time[i] << endl;
  }  
  cin >> sleep;

  for(int i=0;i<n;i++){
     if(str[i] == sleep){
        sleep_s = i; 
     }
  }
 
  for(int i=sleep_s+1;i<n;i++){
    ans += time[i];
  } 

  cout << ans << endl;
}




Measured memory_bytes: 888
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int n,op[2][N];
vector<int> G[N];

int used[1<<3][1<<3][1<<3][N],mem[1<<3][1<<3][1<<3][N];
int calc(int X,int Y,int T,int pos){
  int XY = op[0][pos]=='X'? X:Y;
  if(op[1][pos] == '|') return T | XY;
  if(op[1][pos] == '&') return T & XY;
  if(op[1][pos] == '^') return T ^ XY;
}

int dfs(int X,int Y,int T=0,int pos=0,int turn=0){
  if(G[pos].empty()) return T;
  if(used[X][Y][T][pos]++) return mem[X][Y][T][pos];
  
  int res = turn==0? 0:7;
  for(int nx:G[pos]) {
    int nT = calc(X,Y,T,nx);
    int r = dfs(X, Y, nT, nx, !turn);
    res = turn==0? max(res,r) : min(res,r);
  }
  return mem[X][Y][T][pos] = res;
}

int main(){
  int m;
  cin>>n>>m;
  
  for(int i=1;i<n;i++){
    string str;
    cin>>str;
    op[0][i] = str[4];
    op[1][i] = str[3];
  }
  
  for(int i=0,a,b;i<n-1;i++)cin>>a>>b,G[a].push_back(b);

  while(m--){
    int X,Y;
    cin>>X>>Y;
    
    int x = 0,y = 0,xy[2][2] = {},cnt=0;
    for(int i=19;i>=0;i--){
      int a = X>>i&1, b = Y>>i&1;
      if(a == 0 && b == 0)continue;
      if(xy[a][b]||cnt++ >= 3) continue;
      xy[a][b] = 3 - cnt;
      x = x*2 + a;
      y = y*2 + b;
    }
    while(cnt++<3) x*=2,y*=2;
    int r = dfs(x,y), ans = 0;
    for(int i=0;i<20;i++) {
      int a = X>>i&1, b = Y>>i&1;
      if(a == 0 && b == 0)continue;
      ans += (r>>xy[a][b]&1)<<i;
    } 
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 81532
from collections import defaultdict
from collections import deque
import time
import sys

input = sys.stdin.readline

# start = time.time()
n, q = map(int, input().strip().split())
edges = [list(map(int, input().strip().split())) for _ in range(n - 1)]
values = [list(map(int, input().strip().split())) for _ in range(q)]

# elapsed = time.time() - start
# print("elapsed_time:{0}".format(elapsed) + "[sec]")

edge_dict = defaultdict(list)
value_dict = defaultdict(int)
total_value_dict = defaultdict(int)
visited = [False] * n

for a, b in edges:
    edge_dict[a].append(b)
    edge_dict[b].append(a)

for p, x in values:
    value_dict[p] += x


qu = deque([1])
total_value_dict[1] = value_dict[1]
visited[0] = True

while len(qu) > 0:
    node = qu.popleft()
    next_nodes = [m for m in edge_dict[node] if not visited[m - 1]]
    for m in next_nodes:
        total_value_dict[m] = total_value_dict[node] + value_dict[m]
        visited[m - 1] = True
        qu.append(m)

print(' '.join([str(total_value_dict[i]) for i in range(1, n + 1)]))


Measured memory_bytes: 195700
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int n,m,past[55][55],now[55][55],ans;
vector<pii>v;
bool vis[55];
void dfs(int x)
{
	vis[x]=true;
	for(int i=0;i<n;i++)
	{
		if(now[x][i] && !vis[i])
		{
			dfs(i);
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		v.push_back(pii(x,y));
		past[x][y]=1;
		past[y][x]=1;
		now[x][y]=1;
		now[y][x]=1;
	}
	for(int i=0;i<v.size();i++)
	{
		pii p=v[i];
		now[p.first][p.second]=0;
		now[p.second][p.first]=0;
		memset(vis,false,sizeof(vis));
		dfs(0);
		bool ok=true;
		for(int j=0;j<n;j++)
		{
			ok&=vis[j];
		}
		if(!ok)
		{
			ans++;
		}
		now[p.first][p.second]=1;
		now[p.second][p.first]=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
multiset<int> l,r;
int cal(){
	int L = *l.rbegin();
	int R = *r.begin();
	if(R>=L)return R-L+1;
	return 0;
}
pii a[maxn];
int main()
{
	int n;cin>>n;
	int minr = 1e9; 
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].fi,&a[i].se);
		minr = min(minr,a[i].se);
	}
	sort(a+1,a+1+n);
	int x,y;
	for(x=1;x<=n;x++)if(a[x].se==minr)break;
	int ans = 0;
	for(int i=1;i<=n;i++){
		l.insert(a[i].fi);
		r.insert(a[i].se);
	}
	for(int i=1;i<=n;i++){
		l.erase(l.find(a[i].fi));
		r.erase(r.find(a[i].se));
		ans = max(ans,cal()+a[i].se-a[i].fi+1);
		l.insert(a[i].fi);
		r.insert(a[i].se);
	}
	l.clear();r.clear();
//	cout << "!"<< ans << endl;
	for(int i=x;i<=n;i++){
		l.insert(a[i].fi);
		r.insert(a[i].se);
	}
	for(int i=x;i<n;i++){
		l.erase(l.find(a[i].fi));
		r.erase(r.find(a[i].se));
		int tmp = 0;
		if(a[i].fi<=minr)tmp = minr-a[i].fi+1;
//		cout<<"!"<<i<<" "<<tmp<<" "<<cal()<<endl;
		tmp += cal();
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

bool kaibun(string s){
    size_t len = s.length();
    for(int i = 0; i < len/2; i++){
        if(s[i] != s[len-i-1]) return false;
    }
    return true;
}

int main(){
    long long N,A,B;
    long long a1,a2=0;
    cin >>N>> A>>B;

    a1=N/(A+B);
    a1=A*a1;

    if((N%(A+B)) >= A){
        a1 += A;
    }else{
        a1 += N%(A+B);
    }
    cout << a1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

const ll mod = 998244353;
ll modpow(ll a, ll b, ll p = mod){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

// 式を書いていたのにそれが二項係数であることに気付けなかった、反省
int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0, inv = modpow(2, mod-2);
    ll beki = modpow(2, n);
    for(int i = 0; i < n; i++){
        ll x;   cin >> x;
        beki *= inv;    beki %= mod;
        ans += beki * x % mod * modpow(x+1, i) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < t.length(); i++) cout << s[i] << t[i];
    if (s.length() != t.length()) cout << s.back();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            long now = 0;
            long i = 0;
            while (now < n)
            {
                now += i;
                i++;
            }
            WriteLine(i-1);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int D;
vector<ll> c(26);
vector<vector<ll>> s;

ll score(vector<int> t){
  vector<ll> last(26,0);
  ll ans=0;
  for(ll i=0;i<D;i++){
    ans+=s.at(i).at(t.at(i));
    last.at(t.at(i))=i+1;
    for(ll j=0;j<26;j++){
      ans-=c.at(j)*((i+1)-last.at(j));
    }
  }
  return ans;
}


int main(){
  cin>>D;
  for(int i=0;i<26;i++){
    cin>>c.at(i);
  }
  s.resize(D);
  for(int i=0;i<D;i++){
    s.at(i).resize(26);
    for(int j=0;j<26;j++){
      cin>>s.at(i).at(j);
    }
  }

  vector<int> last(26,0);
  for(int i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(((i+1)-last.at(j))*c.at(j)+s.at(i).at(j)>((i+1)-last.at(k))*c.at(k)+s.at(i).at(k)){
        k=j;
      }
    }
    last.at(k)=i+1;
    cout<<k+1<<endl;
  }
}


Measured memory_bytes: 3704
N, W = map(int, input().split())

value, weight = [], []

for _ in range(N):
    v, w = map(int, input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])


Measured memory_bytes: 41888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int h, w;
    while(cin >> h >> w) {
        if (h == 0 && w == 0) break;
        rep(i, h) {
            rep(i, w) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pi acos(-1)
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000001
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<pll,ll>
#define vplll vector<plll>
#define vpll vector<pll>
using namespace std;
using namespace std::chrono; 
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

map<pll,ll> color;
ll parcolor[100010];
vll graph[100010];
ll ans=-1;

void DFS(ll start,ll parent)
{
    ll size=graph[start].size();
    ll store,col1;
    col1=1;
    set<ll>::iterator it;
    for(ll i=0;i<size;i++)
    {
        store=graph[start][i];
        if(store==parent)
        {
            continue;
        }
        if(col1==parcolor[start])
        {
            col1++;
        }
        color[{start,store}]=color[{store,start}]=col1;
        parcolor[store]=col1;
        ans=max(ans,col1);
        col1++;
        DFS(store,start);
    }
}

int main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll vertice;
    cin>>vertice;
    pll edges[vertice-1];
    for(ll i=0;i<vertice-1;i++)
    {
        cin>>edges[i].first>>edges[i].second;
        graph[edges[i].first].push_back(edges[i].second);
        graph[edges[i].second].push_back(edges[i].first);
    }
    DFS(1,-1);
    cout<<ans<<endl;
    for(ll i=0;i<vertice-1;i++)
    {
        cout<<color[edges[i]]<<endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    long long int n,m,a,b,temp;
    cin >> n;

    long double l=sqrt(n);
    a=1;
    b=n;
    m=(a+b)-2;
    for(long long int i=2;i<=l;i++)
    {
        if(n%i==0){
        a=i;
        b=n/i;
        temp=(a+b)-2;
        if(temp<m){ m=temp; }
        }
    }
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
heights = list(map(int, input().split()))

result = True
for i in range(N-2,-1,-1):
    if heights[i] >= heights[i+1]+2:
        result = False
        break
    elif heights[i] == heights[i+1]+1:
        heights[i]-=1

print("Yes" if result else "No")

Measured memory_bytes: 14252
local DBG = true
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

local function use_strict()
    local mt = {
        __index = function(t,k) error("_G __index:" .. k) end,
        __newindex = function(t,k,v) error("_G __newindex:" .. k) end
    }
    setmetatable(_G, mt)
end

-- http://www.lua.org/pil/11.4.html
List = {}
function List.new()
    return setmetatable({first = 0, last = -1}, {__index = List})
end

--[[
function List:pushleft(value)
    local first = self.first - 1
    self.first = first
    self[first] = value
end
]]

function List:pushright(value)
    local last = self.last + 1
    self.last = last
    self[last] = value
end

function List:popleft()
    local first = self.first
    if first > self.last then error("list is empty") end
    local value = self[first]
    self[first] = nil        -- to allow garbage collection
    self.first = first + 1
    return value
end

--[[
function List:popright()
    local last = self.last
    if self.first > last then error("list is empty") end
    local value = self[last]
    self[last] = nil         -- to allow garbage collection
    self.last = last - 1
    return value
end
]]

function List:count()
    return self.last - self.first + 1
end
--
use_strict()
local N = io.read("n")
local weights = {}
local adj_list = {}
for i=1,N do
    adj_list[i] = {}
end
local function key(u,v)
    return u .. "," .. v
end
local function getw(u,v)
    return weights[key(u,v)] or weights[key(v,u)]
end
for i=1,N-1 do
    local u,v,w = io.read("n", "n", "n")
    weights[key(u,v)] = w
    table.insert(adj_list[u], v)
    table.insert(adj_list[v], u)
end

local distance_from_1 = {}
distance_from_1[1] = 0
do
    local seen = {}
    seen[1] = true
    local accum = 0
    local q = List.new()
    q:pushright(1)
    local count = 1
    while count < N do
        local from = q:popleft()
        local w_before = distance_from_1[from]
        for _, to in ipairs(adj_list[from]) do
            if not seen[to] then
                seen[to] = true
                local w = getw(from, to)
                distance_from_1[to] = w_before + w
                count = count + 1
                q:pushright(to)
            end
        end
    end
end
--dbgpr_t(distance_from_1)
for i=1,N do
    if distance_from_1[i] % 2 == 0 then
        print(0)
    else
        print(1)
    end
end

Measured memory_bytes: 38244
import math
n, m = map(int, input().split())
X=1

for i in range(1,int(math.sqrt(m))+1):
	if m%i==0:
		if i*n<=m:
			X=max(X, i)
		if (m//i)*n<=m:
			X=max(X, m//i)
print(X)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			
			Map<Integer,Integer>map = new TreeMap<Integer,Integer>();
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				if(map.containsKey(A[i])) {
					map.put(A[i], map.get(A[i])+1);
				}else {
					map.put(A[i], 1);
				}
			}
			
			ArrayList<Integer>are = new ArrayList<Integer>();
			
			for(Integer key:map.keySet()) {
				if(map.get(key)>=2) {
					if(map.get(key)>=4) {
						are.add(key);
						are.add(key);
					}else {
					are.add(key);
					}
				}
			}
			
			Collections.sort(are, Collections.reverseOrder());
			
			if(are.size()==0||are.size()==1) {
				System.out.println(0);
			}else {
				System.out.println((long)are.get(0)*(long)are.get(1));
			}
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 65868
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };
 
signed main() {
	int N, K;
	cin >> N >> K;

	vector<int> a(N);
	rep(i, N) cin >> a[i];

	int ret = 0;

	int sum = 0;
	int tmp = 0;
	rep(i, K - 1) tmp += a[i];
	REP(i, K - 1, N - 1) sum += max(0LL, a[i]);

	REP(i, K - 1, N - 1) {
		tmp += a[i];
		sum -= max(0LL, a[i]);

		ret = max(ret, tmp + sum);

		tmp -= a[i - K + 1];
		sum += max(0LL, a[i - K + 1]);
	}

	sum = 0;
	REP(i, K - 1, N - 1) sum += max(0LL, a[i]);

	REP(i, K - 1, N - 1) {
		sum -= max(0LL, a[i]);
		ret = max(ret, sum);
		sum += max(0LL, a[i - K + 1]);
	}

	cout << ret << endl;
}


Measured memory_bytes: 1024
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
print(C(n/2))


Measured memory_bytes: 67584
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    string s; cin>>s; 
    int len=sz(s),c=0;
    bool  ok = true ; 
    for (int i=0;i<len;i++){
        if ((s[i] != 'A' and s[i] != 'C' and isupper(s[i])))ok=false;
        if (i==0 and s[i] != 'A') ok=false;
        if (i != 0 and s[i]=='A') ok=false;
        if ((i <=1 or i==len-1) and (s[i]=='C')) ok=false;
        if (s[i]=='C') c++;
    }
    cout << (ok and c==1?"AC":"WA") << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int k;
  cin>>k;

  string s;
  cin>>s;

  if((int)s.size()>k)
    s=s.substr(0,k)+"...";

  cout<<s<<newl;
  return 0;
}


Measured memory_bytes: 3640
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main(N):
    ans = 0

    for n in range(1,N+1):
        ans += (N // n) * n * (1 + (N // n)) // 2

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K <= A) cout << K;
  else if (A < K && K < (A + B)) cout << A;
  else if (B <= K) cout << 2*A - K + B ;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int dp[1010][1010]={0};

int main()
{
  int H,W;cin>>H>>W;
  vector<vector<char>> a(H,vector<char>(W));
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
       cin>>a[i][j];
    }
  }
  
  //dp[i][j]=(i,j)までの経路の個数
  dp[0][0]=1;
  
  for (int i=1;i<H;i++)
  {
    if (a[i-1][0]=='.')
    {
      dp[i][0]+=dp[i-1][0];
      dp[i][0]%= MOD;
    }
  }
  
  for (int i=1;i<W;i++)
  {
    if (a[0][i-1]=='.'){
      dp[0][i]+=dp[0][i-1];
      dp[0][i]%=MOD;
    }
  }
  for (int i=1;i<H;i++){
    for (int j=1;j<W;j++){
      if (a[i-1][j]=='.'){
        dp[i][j]+=dp[i-1][j];
        dp[i][j]%=MOD;
      }
      if (a[i][j-1]=='.')
      {
        dp[i][j]+=dp[i][j-1];
        dp[i][j]%=MOD;
      }
    }
  }
  cout<<dp[H-1][W-1]<<endl;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main(){
   int n,m;
   cin >> n >> m ;
   
   vector<ll> a(n+1);
   rep(i,n+1)a[i]=0;
   a[0] = a[1] = 1;
   rep(i,m){
       int b;
       cin >> b;
       a[b]=-1;
   }
  for(int i=1;i<=n;i++)
  {
      
      if(a[i]==-1){
          a[i]=0;
      }
      else if(i==1){
          a[i] = a[i-1];
      }
      else{
          a[i] = a[i-1]%MOD + a[i-2]%MOD;
        a[i]%=MOD;
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        } 
      }
  }
   
  cout << a[n] <<endl;
    return 0;
}


Measured memory_bytes: 1024
import math
N,M=map(int,input().split())
def f(n):
    n=math.factorial(n)
    return n
if abs(N-M)==1:
    s=f(N)*f(M)
elif N==M:
    s=2*f(N)**2
else:
    s=0
print(s%(10**9+7))   

Measured memory_bytes: 5160
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void AscRadix(int A[],const int sz,const int minus)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>8*k&255]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>8*k&255]]=temp[sz-1-i];
  }
  rep(i,minus)temp[i]=A[sz-minus+i];
  rep(i,sz-minus)temp[minus+i]=A[i];
  rep(i,sz)A[i]=temp[i];
}
int main()
{
  int A[200000],N=IN(),K=IN(),l,m=0,r,accum=1,sign=1;long x,y;
  rep(i,N)A[i]=IN(),m+=A[i]<0?1:0;
  AscRadix(A,N,m);
  if(K&1)accum=A[N-1],sign=(A[N-1]<0?-1:1),N--,K--;
  l=0,r=N-1;
  while(K)
  {
    x=1l*A[l]*A[l+1],y=1l*A[r]*A[r-1];
    if(x*sign>y*sign)x%=MOD,accum=1l*accum*x%MOD,l+=2;
    else y%=MOD,accum=1l*accum*y%MOD,r-=2;
    K-=2;
  }
  return printf("%ld\n",(1l*accum%MOD+MOD)%MOD),0;
}

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

using namespace std;
long double a,b,h,m;
long double x1,Y1,x2,y2;
const long double pi=acos(-1);
string s;
int main()
{
    cin>>a>>b>>h>>m;
    x1=sin(pi*2*(h*60+m)/12/60-pi/2)*a;
    Y1=cos(pi*2*(h*60+m)/12/60-pi/2)*a;
    x2=sin(pi*2*m/60-pi/2)*b;
    y2=cos(pi*2*m/60-pi/2)*b;
    cout<<fixed<<setprecision(10)<<sqrt((x2-x1)*(x2-x1)+(y2-Y1)*(y2-Y1));
    return 0;
}


Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, ab, cd;
  cin >> a >> b >> c >> d;
  ab = a*b;
  cd = c*d;
  if(ab > cd){
    cout << ab << endl;
  }
  else{
    cout << cd << endl;
  }
}

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

const string str = "keyence";

string s;

int main()
{
    cin >> s;
    for (int i = 0; i <= 7; i++) {
        int j = 7 - i;
        bool ok = true;
        if (i > 0 && str.substr(0, i) != s.substr(0, i))
            ok = false;
        if (j > 0 && str.substr(int(str.length()) - j) != s.substr(int(s.length()) - j))
            ok = false;
        if (ok) { printf("YES\n"); return 0; }
    }
    printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    for(int i=1;i<4;i++){
        if(s[i]==s[i-1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s;
    cin >> s;
    if (s[1] == 'R') cout << "ABC" << endl;
    else cout << "ARC" << endl;
}


Measured memory_bytes: 3656
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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

vector<vector<ll>> used,color;

vector<vector<char>> s;

const ll INF=1e18;

ll h,w;

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

ll ddx[5]={-2,-1,0,1,2};
ll ddy[5]={-2,-1,0,1,2};

void dfs(ll i,ll j,ll num){
    used[i][j]=1;
    color[i][j]=num;
    rep(k,4){
        ll nx=i+dx[k];
        ll ny=j+dy[k];
        if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && s[nx][ny]=='.' && used[nx][ny]==0){
            dfs(nx,ny,num);
        }
    }
}

int main(){
    
    cin >> h >> w;
    ll ch,cw,dh,dw;
    cin>> ch >> cw >> dh >> dw;
    ch--; cw--;
    dh--; dw--;
    used=vector<vector<ll>>(h,vector<ll>(w));
    color=vector<vector<ll>>(h,vector<ll>(w));
    s=vector<vector<char>>(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='#') color[i][j]=-1;
        }
    }
    ll cnt=0;
    rep(i,h){
        rep(j,w){
            if(used[i][j]==1) continue;
            if(color[i][j]==-1) continue;
            dfs(i,j,cnt);
            cnt++;
        }
    }
    /*rep(i,h){
        rep(j,w){
            cout << color[i][j] << " ";
        }
        cout << endl;
    }*/
    map<pll,ll> t;
    //vector<set<ll>> to(cnt);
    vector<vector<ll>> m;
    m.resize(cnt);
    rep(i,h){
        rep(j,w){
            rep(a,5){
                rep(b,5){
                    if(ddx[a]==0 && ddy[b]==0) continue;
                    if(color[i][j]==-1) continue;
                    ll nx=i+ddx[a];
                    ll ny=j+ddy[b];
                    if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && color[nx][ny]!=-1 && color[nx][ny]!=color[i][j] && t.count(make_pair(color[i][j],color[nx][ny]))==false){
                        m[color[i][j]].push_back(color[nx][ny]);
                        m[color[nx][ny]].push_back(color[i][j]);
                        t[make_pair(color[i][j],color[nx][ny])]=1;
                        t[make_pair(color[nx][ny],color[i][j])]=1;
                    }
                }
            }
        }
    }
    
    vector<ll> vs(cnt);
    vector<ll> d(cnt,INF);
    queue<ll> que;
    que.push(color[ch][cw]);
    d[color[ch][cw]]=0;
    while(!que.empty()){
        ll x=que.front();
        que.pop();
        vs[x]=1;
        for(auto v:m[x]){
            if(d[v]!=INF) continue;
            d[v]=d[x]+1;
            que.push(v);
        }
    }
    if(d[color[dh][dw]]==INF){
        cout << -1 << endl;
        return 0;
    }
    cout << d[color[dh][dw]] << endl;
    return 0;
}


Measured memory_bytes: 55120
while 1:
    m,f,r=map(int,raw_input().split())
    if m==f==r==-1 :break
    ans=''
    if m==-1 or f==-1 :ans= 'F'
    else :
        mp=m+f
        if mp>=80:ans='A'
        elif mp>=65:ans='B'
        elif mp>=50 or (mp>=30 and r>=50):ans='C'
        elif mp>=30:ans='D'
        else :ans='F'
    print ans

Measured memory_bytes: 4216
#include<cstdio>
int n,k,m,j,p,i;long f[333][333][333];main(){scanf("%d%d%d",&n,&k,&m);for(f[i=0][1][0]=1;i<=n;++i)for(j=0;k/++j;)for(p=i;~p;--p)(f[i+1][j][p]+=f[i][j][p]*(p+1))%=m,((p?f[i][j][p-1]:f[i][j+1][i])+=f[i][j][p])%=m;printf("%d",f[n][k+1][n]);}

Measured memory_bytes: 262144
use proconio::input;
use std::cmp::*;

fn main() {
    input! {
        a: i64,
        b: i64,
        _c: i64,
        mut k: i64,
    };
    let mut ans = min(a, k);
    if k > a + b {
        ans -= k - a - b;
    }
    println!("{}", ans);
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<int,int>
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM=1e5+4;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};


int main()
{
	fio;
	int n;cin>>n;
	int k;cin>>k;
	vector<int> h(101);
	vector<int> dp(101,inf);
	int ke=0;
	int h1;cin>>h1;
	for(int i=0;i<n-1;i++)
	{
		h[i%k]=h1;
		dp[i%k]=ke;
		cin>>h1;
		ke=inf;
		for(int j=0;j<k;j++)
		{
			ke=min(ke,dp[j]+abs(h[j]-h1));
		}
	}
	cout<<ke<<"\n";
}

Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readLong
	val T = math.sqrt(N).toLong

	@inline def check(x: Long): Int = {
		var ans = 1
		var tp1 = x
		var tp2 = 10L
		while(tp1/tp2 != 0){
			ans += 1
			tp2 *= 10L
		}
		return ans
	}

	var ans = Int.MaxValue

	for(x<-1L to T){
		if(N%x == 0){
			val y = N/x
			val p = math.max(check(x), check(y))
			ans = math.min(ans, p)
		}
	}

	println(ans)

	
}

Measured memory_bytes: 32092
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            int h,w;
            {
                var tmp = Console.ReadLine().Split(' ')
                .Select(i=>int.Parse(i)).ToArray();
                h = tmp[0];
                w = tmp[1];
            }
            {
                string[] str = new string[h];
                for(int i = 0;i<h;i++)
                {
                    str[i] = Console.ReadLine();
                }
                var p = str.Select((s,i)=>s.ToCharArray().Select((c,j)=>new{c,i,j})).SelectMany(v=>v).GroupBy(v=>v.j).Where(v=>v.Any(x=>x.c=='#')).SelectMany(v=>v).GroupBy(v=>v.i).Where(v=>v.Any(x=>x.c=='#')).Select(v=>v.OrderBy(x=>x.j).ToArray()).OrderBy(v=>v[0].i).ToArray();
                for(int i = 0;i<p.Length;i++)
                {
                    for(int j = 0;j<p.First().Length;j++)
                    {
                       Console.Write(p[i][j].c);
                    }
                   Console.WriteLine();
                }
            }
        }
    }
}


Measured memory_bytes: 13916
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines);
});

function main(lines) {
  const [a, b, c] = parseLines(lines);  
  const sorted = [a, b, c].sort((a, b) => b - a);
  console.log(formula(sorted));
}

function formula(sorted) {
  return parseInt('' + sorted[0] + sorted[1]) + sorted[2];
}

function parseLines(lines) {
  const [a, b, c] = lines[0].trim().split(' ').map(s => parseInt(s));
  return [a, b, c];
}


Measured memory_bytes: 7628
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String strArr;
        int a;
        int times=0;

        while(true){
        	times++;
        	strArr = br.readLine();
            a=Integer.parseInt(strArr);

            if(a!=0){
            	System.out.println("Case "+times+": "+a);
            }
            else{
            	System.exit(0);
            }
        }
    }
}

Measured memory_bytes: 31484
#include <iostream>

using namespace std;

int main()
{
    int n, max = 0, ans = 1;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int cnt = 0, idx = i;
        while (idx % 2 == 0) {
            idx /= 2;
            ++cnt;
        }
        if (cnt > max) {
            max = cnt;
            ans = i;
        }
    }
    cout << ans << endl;
}

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

int N;
int main(){
	cin >> N;
	vector<int> ans;
	while(N>0){
		ll l = 0,r = N;
		while(l+1<r){
			ll m = (l+r)/2;
			if(N-m<=m*(m-1)/2) r = m;
			else l = m;
		}
		ans.push_back(r);
		N -= r;
	}
	for(int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 384