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

#define int long long

signed main() {
    int x, y;
    cin >> x >> y;
    vector<int> v;
    int t = x;
    while(t<=y) {
        v.push_back(t);
        t*=2;
    }
    cout << v.size() << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int S;
    int h;
    int m;
    int s;
    S = 0;
    h = 0;
    s= 0;
    cin >> S;
    h = S/3600;
    m = S/120;
    s = S/60;
    cout << S/3600 << ":" << S%3600/60 << ":" << S%60 <<  endl;
    
    return 0;
}



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

// input
int N;
vector<int> C, S, F;


void input() {
    cin >> N;
    C = S = F = vector<int>(N - 1);
    rep(i, N - 1) cin >> C[i] >> S[i] >> F[i];
}


int main() {
    input();
    rep(i, N) {
        int ans = 0;
        for (int j = i; j < N - 1; j++) {
            if (ans <= S[j]) {
                ans = S[j] + C[j];
            } else {
                int x = (ans - 1) / F[j] + 1;
                ans = x * F[j] + C[j];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

struct mov {
  int y, x, yp, xp;
};

int main () {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  rep(i,H)rep(j,W) {
    cin >> a[i][j];
    a[i][j] &= 1;
  }

  vector<mov> ans;

  rep(i,H) {
    bool moving = false;
    rep(j,W) {
      if(moving) ans.push_back(mov{i,j-1,i,j});
      if(a[i][j]) moving = !moving;
    }
    if(moving && i < H - 1) {
      a[i+1][W-1] += 1;
      a[i+1][W-1] &= 1;
      ans.push_back(mov{i,W-1,i+1,W-1});
    }
  }

  cout << ans.size() << endl;
  for(mov m: ans) printf("%d %d %d %d\n", m.y+1, m.x+1, m.yp+1, m.xp+1);

  return 0;
}


Measured memory_bytes: 5232
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)

def manhattan(y1, x1, y2, x2): return abs(y1 - y2) + abs(x1 - x2)


def solve(H, W, D, A, query):
    num_pos = dict()
    for y in range(H):
        for x in range(W):
            num_pos[A[y][x]] = (y, x)

    dp = [None] * (H * W + 1)
    for i in range(1, D + 1):
        dp[i] = 0
        for j in range(i + D, len(dp), D):
            y1, x1 = num_pos[j - D]
            y2, x2 = num_pos[j]
            dp[j] = dp[j - D] + manhattan(y1, x1, y2, x2)

    for q in query:
        L, R = q
        print(dp[R] - dp[L])


def main():
    H, W, D = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(list(map(int, input().split())))
    Q = int(input())
    query = []
    for _ in range(Q):
        query.append(list(map(int, input().split())))

    solve(H, W, D, A, query)


if __name__ == "__main__":
    main()


Measured memory_bytes: 48752
N, M = map(int, input().split())
K = []
S = []

for _ in range(M):
    f = list(map(int, input().split()))
    k = f[0]
    s = f[1:]
    K.append(k)
    S.append([c-1 for c in s])

P = list(map(int, input().split()))

search = 1<<N
ans = 0
for i in range(search):
    b = [0]*N
    for j in range(N):
        if i & 1<<j:
            b[j] = 1
        else:
            b[j] = 0

    ok = True
    for q in range(M):
        n = 0
        for s in S[q]:
            n += b[s]
    
        if n%2 != P[q]:
            ok = False
            break
    
    if ok:
        ans += 1

print(ans)

    

Measured memory_bytes: 9164
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
typedef struct card{
	int s,t,n;
}card;
card x[10500],y[10500];
int main(){
	int i,j,n,m,p,q,r,a,b,c,d;//(a,b)cut c,d:absolute point
	int xn,yn,e,f,g;//f:flag g:
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		scanf("%d%d%d%d",&m,&p,&q,&r);
		xn=1;
		x[0]=(card){1,n+1,n};
		while(m--){
			scanf("%d%d",&a,&b);
			d=n+1;c=d-x[xn-1].n;
			f=0;yn=0;
			//for(i=0;i<xn;i++)printf("(%d-%d)",x[i].s,x[i].t);
			//printf("\n");
			for(i=xn-1;i>=0;){
				//printf("c:%d  d:%d\n",c,d);
				if(f==0){
					if(c==b+1){
						for(j=i;j<xn;j++)y[yn++]=x[j];
						f=1;g=i-1;i--;
					}else if(c<b+1 && b+1<d){
						y[yn++]=(card){x[i].s+b+1-c,x[i].t,x[i].t-x[i].s-b-1+c};
						for(j=i+1;j<xn;j++)y[yn++]=x[j];
						x[i]=(card){x[i].s,x[i].s+b+1-c,b+1-c};
						//for(j=0;j<=i;j++)printf("(%d-%d)",x[j].s,x[j].t);
						//printf("\n");
						f=1;g=i;d=c+x[i].n;
						continue;
					}else i--;
				}else{
					if(c==a+1){
						for(j=i;j<=g;j++)y[yn++]=x[j];
						for(j=0;j<i;j++)y[yn++]=x[j];
						break;
					}else if(c<a+1 && a+1<d){
						y[yn++]=(card){x[i].s+a+1-c,x[i].t,x[i].t-x[i].s-a-1+c};
						for(j=i+1;j<=g;j++)y[yn++]=x[j];
						x[i]=(card){x[i].s,x[i].s+a+1-c,a+1-c};
						for(j=0;j<=i;j++)y[yn++]=x[j];
						break;
					}else i--;
				}
				d=c;
				c=d-x[i].n;
			}
			//for(i=0;i<yn;i++)printf("(%d-%d)",y[i].s,y[i].t);
			//printf("\n");
			memcpy(x,y,sizeof(card)*yn);
			xn=yn;
		}
		//printf("\n");
		//for(i=0;i<xn;i++)printf("(%d - %d)",x[i].s,x[i].t);
		//printf("\n\n");
		a=0;b=1;
		for(i=0;i<xn;i++){
			/*if(b<p){
				if(q>=b){
					if(q<b+x[i].n){
						a+=(x[i].s>r)?0:( (r<=x[i].s+q-b)?(r-x[i].s+1):(q-b+1) );
						break;
					}
					else
						a+=(x[i].s>r)?0:( (r<x[i].t)?(r-x[i].s+1):(x[i].n) );
				}
			}else if(b==p){
				if(q<b+x[i].n){
					a+=(x[i].s>r)?0:( (r<=x[i].s+q-p)?(r-x[i].s+1):(q-b+1) );
					break;
				}
				else
					a+=(x[i].s>r)?0:( (r<x[i].t)?(r-x[i].s+1):(x[i].n) );
			}else if(b<p && p<b+x[i].n){
				if(q<b+x[i].n){
					a+=(x[i].s+p-b>r)?0:( (r<=x[i].s+q-b)?(r-x[i].s-p+b+1):(q-p+1) );
				}
				else
					a+=(x[i].s+p-b>r)?0:( (r<x[i].t)?(r-x[i].s-p+b+1):(x[i].n-p+b) );
			}*/
			//printf("%d ",b);
			if(p<b+x[i].n && b<=q){
				c=x[i].s;
				d=x[i].t;
				if(b<p)c+=p-b;
				if(b+x[i].n>q)d+=q-b-x[i].n+1;
				if(d>r)d=r+1;
				if(c>r)c=d+1;
				//printf("%d %d",c,d);
				
				a+=Max(0,d-c);
			}
			//printf("\n");
			b+=x[i].n;
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 912
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            var line = Input.ReadIntArray();
            int A = line[0];
            int B = line[1];
            int C = line[2];
            Console.WriteLine(Math.Min(B / A, C));
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11348
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, M, R;
	static int[] x, y, z, r;
	static long[] l;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			M = sc.nextInt();
			if (N == 0) break;
			System.out.println(solve());
		}
	}

	static int solve() {
		final int INF = 1 << 28;
		int[][] dl = new int[N][N];
		int[][] ds = new int[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				dl[i][j] = ds[i][j] = INF;
			}
			dl[i][i] = ds[i][i] = 0;
		}
		for (int i = 0; i < M; ++i) {
			int X = sc.nextInt() - 1;
			int Y = sc.nextInt() - 1;
			int T = sc.nextInt();
			boolean land = sc.next().charAt(0) == 'L';
			if (land) {
				dl[X][Y] = dl[Y][X] = Math.min(dl[X][Y], T);
			} else {
				ds[X][Y] = ds[Y][X] = Math.min(ds[X][Y], T);
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				for (int k = 0; k < N; ++k) {
					dl[j][k] = Math.min(dl[j][k], dl[j][i] + dl[i][k]);
					ds[j][k] = Math.min(ds[j][k], ds[j][i] + ds[i][k]);
				}
			}
		}
		R = sc.nextInt();
		int PZ = sc.nextInt() - 1;
		int[][] dp = new int[2][N];
		Arrays.fill(dp[0], INF);
		Arrays.fill(dp[1], INF);
		dp[0][PZ] = 0;
		int t = 1;
		for (int i = 1; i < R; ++i) {
			int Z = sc.nextInt() - 1;
			Arrays.fill(dp[t], INF);
			for (int j = 0; j < N; ++j) {
				if (dp[t ^ 1][j] == INF) continue;
				for (int k = 0; k < N; ++k) {
					dp[t][k] = Math.min(dp[t][k], dp[t ^ 1][j] + dl[PZ][j] + ds[j][k] + dl[k][Z]);
				}
				dp[t][j] = Math.min(dp[t][j], dp[t ^ 1][j] + dl[PZ][Z]);
			}
			t ^= 1;
			PZ = Z;
		}
		int ans = INF;
		for (int i = 0; i < N; ++i) {
			ans = Math.min(ans, dp[t ^ 1][i]);
		}
		return ans;
	}

}

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


int main(){long N;
cin >> N;
vector<long> a(N + 1);
erep(i, N) cin >> a.at(i);
long n4 = 0; long n2 = 0; long n1 = 0;
erep(i, N){
    if(a.at(i) % 4 == 0) n4++;
    if(a.at(i) % 2 == 0) n2++;
}
n1 = N - n2;
n2 = n2 - n4;
string ans = "No";
if(n2 == 0){
    if(n4 >= n1 - 1) ans = "Yes";
}
else{
    if(n4 >= n1) ans = "Yes";
}



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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,cnt = 0;
  cin>>a;
  if(a%10 == 1) cnt++;
  a /= 10;
  if(a%10 == 1) cnt++;
  a /= 10;
  if(a%10 == 1) cnt++;
  a /= 10;
  cout << cnt << endl;
  
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int w, n;
  cin >> w >> n;
  int lots[30];
  for (int i = 0; i < w; i ++) {
    lots[i] = i;
  }
  for (int i = 0; i < n; i ++) {
    char c;
    int a, b;
    cin >> a >> c >> b;
    swap(lots[a - 1], lots[b - 1]);
  }
  for (int i = 0; i < w; i ++) {
    cout << lots[i] + 1 << endl;
  }
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define HohleFeuerwerke using namespace std
HohleFeuerwerke;
int a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	cin>>a>>b>>c;
	if(a==b&&b!=c) cout<<"Yes"<<endl;
	else if(a==c&&a!=b) cout<<"Yes"<<endl;
	else if(b==c&&a!=b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    
    int result = (a+b)*h/2;
    
    System.out.println(result);
  }
}

Measured memory_bytes: 20560
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string t;
    cin >> t;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] == '?') {
            t[i] = 'D';
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long X){
  ll x=X%100,y=X/100;
  if(x/5+(x%5>0?1:0)<=y){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int sum = 0;
    while(true){
	int t;
	cin >> t;
	if(cin.eof()) break;
	sum += t;
    }
    printf("%d\n%d\n",sum/60,sum%60);
    return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;


struct cmp{
    bool operator() (const pp &a, const pp &b) const {
         int la = a.S-a.F+1;
    int lb = b.S-b.F+1;
    if(la==lb)return a.F<b.F;
    return la>lb;
    }
};


int main()
{


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

   int n;
   cin>>n;
   ll a[n];
   for(int i=0; i<n; i++)cin>>a[i];
   int ans = 0;
   sort(a,a+n);
   for(int i=0; i<n-2; i++){
    for(int j=i+1; j<n-1; j++){
        for(int k=j+1; k<n; k++){
        if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] && a[i]+a[j]>a[k])ans++;
        }
    }
   }
   cout<<ans<<endl;

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15+10;
const ll N=1e6+10;

int main()
{
	boost;
	ll n;
	cin>>n;
	std::vector<ll> a(n);
	ll sum=0;
	for(auto &i:a) cin>>i,sum+=i;
	//sort(all(a));
	ll ans=sum,up=0;
	for(ll i=0;i<n-1;i++)
	{
		up+=a[i];
		if(a[i]!=a[i+1])
		{
			ans=min(ans,abs(sum-up-up));
		}

	}	
	cout<<ans;		
  	return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int A,B,C,X; cin >> A >> B >> C >> X;
    int res=0;
    rep(i,A+1){
        rep(j,B+1){
            rep(k,C+1){
                if(500*i+100*j+50*k==X) res++;
            }
        }
    }
    pr(res);
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

void search(char a[51][51], int c[51][51], int h, int w, int s, int t, int v, char p)
{
  if(a[s][t] == p || a[s][t] != '.' || c[s][t] < 0 || c[s][t] == v){
    return ;
  }
  c[s][t] = (c[s][t] > 0)? -3 : v;

  if(s > 0){
    search(a, c, h, w, s-1, t, v, p);
  }
  if(s < h-1){
    search(a, c, h, w, s+1, t, v, p);
  }
  if(t > 0){
    search(a, c, h, w, s, t-1, v, p);
  }
  if(t < w-1){
    search(a, c, h, w, s, t+1, v, p);
  }

  return ;
}

void func(char a[51][51], int c[51][51], int h, int w, char p, int s, int t)
{
  int v = (p == 'W')? 1 : 2;

  if(s > 0){
    search(a, c, h, w, s-1, t, v, p);
  }
  if(s < h-1){
    search(a, c, h, w, s+1, t, v, p);
  }
  if(t > 0){
    search(a, c, h, w, s, t-1, v, p);
  }
  if(t < w-1){
    search(a, c, h, w, s, t+1, v, p);
  }

  return ;
}

int main(int argc, char **argv)
{
  int w, h, c[51][51], cw, cb;
  char a[51][51];

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0){
      break;
    }
    fill(&c[0][0], &c[h][w], 0);

    for(int i = 0; i < h; i++){
      scanf("%s", a[i]);
    }

    cw = cb = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(c[i][j] == 0 && a[i][j] != '.'){
	  func(a, c, h, w, a[i][j], i, j);
	}
      }
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(c[i][j] == 1){
	  cw++;
	} else if(c[i][j] == 2){
	  cb++;
	}
      }
    }

    cout << cb << " " << cw << endl;
  }

  return 0;
}

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

const int INF = 1000000000;

typedef pair<int, int> P;


int H, W;
char maze[20][20];
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};





int bfs (int sx, int sy, int gx, int gy) {
  queue<P> que;
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      d[i][j] = INF;
    }
  }
  
  que.push(P(sx, sy));
  d[sx][sy] = 0;
  
  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == gx && p.second == gy) break;
    
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      
      if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF) {
        que.push(P(nx, ny)); 
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}


int main() {
  
  cin >> H >> W;
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> maze[i][j];
    }
  }
  
  
  
  int ans = 0;
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      for (int k = 0; k < H; k++){
        for (int l = 0; l < W; l++){
          if (maze[i][j] != '#' && maze[k][l] != '#' && bfs(i, j, k, l) != INF) {
        ans = max(ans, bfs(i,j,k,l));
          }
        }
      }
    }
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    struct P
    {
        public int h;
        public int w;
        public P(int h,int w)
        {
            this.h = h;
            this.w = w;
        }
    }
    static void Main(string[] args)
    {
        var hw = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        
        var res = new int[hw[0]][];
        for (var i = 0; i < hw[0]; i++)
            res[i] = new int[hw[1]];
        var isY = true;
        var h = 0;
        var w = 0;
        var set = new HashSet<P>();
        var index = 0;
        var count = 0;
        var dif = 1;
        while (index != num)
        {
            res[h][w] = index + 1;
            count++;
            set.Add(new P(h, w));
            if (count == ar[index])
            {
                index++;
                count = 0;
            }
            var p = new P(h, w);
            if (isY)
                p.h += dif;
            else p.w += dif;
            if (isY && (p.h < 0 || p.h >= hw[0] || set.Contains(p)))
                isY = !isY;
            else if (!isY && (p.w < 0 || p.w >= hw[1] || set.Contains(p)))
            {
                isY = !isY;
                dif = -dif;
            }
            if (isY)
                h += dif;
            else w += dif;
        }
        WriteLine(string.Join("\n", res.Select(c => string.Join(" ", c))));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}

Measured memory_bytes: 16964
using System;

public class HelloWorld
{
    static public void Main ()
    {
        var S = Console.ReadLine();
        var flag = true;
        for(int i = 1;i < 4 ;i++){
            if(S[i] == S[i-1]){
                flag = false;
                break;
            }
        }
        
        if(flag){
            Console.WriteLine ("Good");
        }else{
            Console.WriteLine ("Bad");
        }
        

    }

}


Measured memory_bytes: 13140
#include <cstdio>
#include <cstring>
const int MAXS = 105;
char S[MAXS];
int N;

bool solve() {
  N = strlen(S);
  for (int i = 0; i < N; ++i) {
    if (i & 1) {
      if (S[i] == 'R') {
        return false;
      }
    } else if (S[i] == 'L') {
      return false;
    }
  }
  return true;
}

int main() {
  scanf("%s", S);
  puts(solve() ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] a=new int[3];
HashMap<Integer,Integer> m=new HashMap<>();
for(int i=0;i<3;i++){
    a[i]=sc.nextInt();
    m.put(a[i],0);
}
for(int i=0;i<3;i++){
    int c=m.get(a[i]);
    c++;
    m.put(a[i],c);
}
for(int i:m.keySet()){
    if(m.get(i)==1){
    System.out.println(i);
    break;
    }
}
}}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

ll fact(ll n) {
	ll res = 1;
	for(ll i=1;i<=n;i++) {
		res *= i;
		res %= MOD;
		if(res==0) res = MOD;
	}
	return res;
}

//aのb乗
ll powMod(ll a, ll b) {
	ll res = 1;
	while(b > 0) {
		if(b & 1) res = res * a % MOD;
		if(res==0) res = MOD;
		a = a * a % MOD;
		if(a==0) a = MOD;
		b >>= 1;
	}
	return res;
}

ll comb(ll a, ll b){
	if(a==b || b==0) return 1;
	return (((fact(a)*powMod(fact(b),MOD-2))%MOD)*powMod(fact(a-b),MOD-2))%MOD;
}

vector<pair<ll,ll>> makePrimeFactors(ll rest) {
	vector<pair<ll,ll>> pf;

	for(ll n=2;n * n <= rest;n++) {
		ll cnt = 0;
		while(rest % n == 0) {
			rest /= n;
			cnt++;
		}
		if(cnt > 0) {
			pf.push_back({n, cnt});
		}
	}
	if(rest != 1) pf.push_back({rest, 1});
	
	return pf;
}

int main() {
	ll N, M;
	cin >> N >> M;
	// 素因数分解
	vector<pair<ll,ll>> pf;
	pf = makePrimeFactors(M);
	ll ans = 1;
	for(int i=0;i<pf.size();i++) {
		ll sum = pf[i].second;
		// sum個をN個に分ける
		// sum個とN-1個の仕切り
		// sum+N-1Csum
		ans *= comb(sum+N-1, sum);
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
    char ch;
    while((ch = getchar()) != EOF){
            if(ch >= 97 && ch <= 122)
                printf("%c",ch-32);
            else if(ch >= 65 && ch <= 90)
                printf("%c",ch+32);
            else
                printf("%c",ch);
    }
}


Measured memory_bytes: 2564
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int z = 0, o = 0;
    rep(i,s.size()){
        if(s[i] == '0') z++;
        else o++;
    }
    int ans = s.size() - abs(z-o);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
<?php
$N = trim(fgets(STDIN));  

$Ns = str_split($N);
$count = 0;
foreach($Ns as $value){
  $count += $value;
}

$waru = $count%9;


if ($waru == 0) {
    echo 'Yes';
} else {
    echo 'No';
}

Measured memory_bytes: 28520
# -*- coding:utf8 -*-

n = int(input())
h = list(map(int, input().split()))
p = h[0]
l = [p]
for i in range(1,n):
    c = h[i]
    if i == 1 and p - 1 == c:
        l[0] == c
    if p < c:
        c -= 1
    l.append(c)
    p = c
ans = 'Yes' if l == sorted(l) else 'No'
print(ans)

Measured memory_bytes: 14396
import Control.Monad
import Control.Monad.ST
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
listToTuple (x : y : _) = (x, y)

main = do
    [n, t] <- getIntList
    abs <- sort . map listToTuple <$> replicateM n getIntList
    dp <- VUM.replicate 3001 0
    ans <- forM abs $ \(a, b) -> do
               b' <- VUM.read dp (t - 1)
               forM_ [3000,2999..0] $ \i -> do
                   when (i - a >= 0) $ do
                       s <- VUM.read dp i
                       t <- VUM.read dp (i - a)
                       VUM.write dp i $ max s (t + b)
               return $ b' + b
    print $ maximum ans

Measured memory_bytes: 2684
a =gets
a1 = a[0..1].to_i
a2 = a[2..3].to_i
n=0

if a1 > 0 && a1 <= 12
n+=1
end

if a2 > 0 && a2 <= 12
    n+=2
end

if n == 0
    puts 'NA'
elsif n == 1
    puts 'MMYY'
elsif n == 2
    puts 'YYMM'
elsif n == 3
    puts 'AMBIGUOUS'
end


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

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

  int i=1,x;
  while(i<=n){
    x = i;
    if(x%3==0){
      cout << " " << i;
    }else{
      while(x!=0){
        if(x%10 == 3){
          cout << " " << i;
          break;
        }
         x /= 10;
      }
    }
    i++;
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

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

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A,K;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll a, k; cin >> a >> k;
        A.push_back(a);
        K.push_back(k);
    }
}

ll grundyNumber(ll x, ll k){
  vector<ll> next;// = { posから遷移できる全ての座標 };
  for (ll i = 1; i <= x/k; i++) next.push_back(x-i);
  
  set<int> s; // 集合を用意します
  for(ll y : next)
    s.insert( grundyNumber(y,k) ); //遷移先のgrundy numberを集合に追加します
  //集合sに含まれない非負の整数の中で最小値を、このposのgrundy numberとします
  int res = 0;
  while( s.find(res)!=s.end() ) res++;
  return res;
}


int solve(){  
    vector<ll> gd(N);
    ll g=0;
    for (int i = 0; i < N; i++)
    {
        if(A[i]%K[i]==0) gd[i] = A[i]/K[i];
        else {
            // gd[i] = grundyNumber(A[i], K[i]);
            bool ok=false;
            while(A[i]>=K[i]){
                ll l =  A[i]/K[i];
                ll k = ((A[i]%K[i])+l)/(l+1);
                A[i]-=k*(l+1);
                if(A[i]%K[i]==0) {ok=true; gd[i]=A[i]/K[i]; break;}
            }
            if(A[i]<K[i] && !ok) gd[i]=0;
        }

        g ^= gd[i];
    }
    string winner = g ? "Takahashi" : "Aoki";
    cout << winner << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  Vi V(3);
  VIN(V)
  RSORT(V);
  bool ng = true;
  int maxE = V[0];
  while(ng){
    if(V[1]==maxE) break;
    FOR(i,1,3){
      V[i]++;
    }
    a++;
  }
  if(V[0]==V[1] && V[1]==V[2]){
    OUT(a);
    return 0;
  }
  int diff = V[1]-V[2];
  if(diff%2==0){
    OUT(a + diff/2);
  } else {
    OUT(a + (diff+2-1)/2 + 1);
  }
}

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

int main()
{
  char s[10];
  scanf("%s", s);
  sort(s, s + 4);
  printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  string s; cin>>s;
  int ans{};
  for(auto i:s){
    if(i=='+') ans++;
    else ans--;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3576
S = input()

count = 0
a = 0
b = 0
for i in range(len(S)):
    if count % 2 != 0:
        if S[i] == 'L' or S[i] == 'U' or S[i] == 'D':
            pass
        else:
            b -= 1
    else:
        if S[i] == 'R' or S[i] == 'U' or S[i] == 'D':
            pass
        else:
            a -=1

    count += 1

if a + b == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
N,Q=map(int,input().split())
S=input()
L=[0]*N
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=L[i-1]+1
  else:
    L[i]=L[i-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(L[b-1]-L[a-1])

Measured memory_bytes: 77112
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum=0;
	for(int i=0;cin>>ch;i++){
		if(ch=='\\') S1.push(i);
		else if(ch=='/'&&S1.size()>0){
			int j=S1.top(); S1.pop();
			sum +=i-j;
			int a=i-j;
			while(S2.size()>0 && S2.top().first>j){
				a +=S2.top().second; S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}


	vector<int>ans;
	while(S2.size()>0){ans.push_back(S2.top().second); S2.pop();}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	for(int i=0;i<ans.size();i++){
		cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }

  int n;

  char c[100100][10];
  string s[100100];
  map<string,ll> m;
  set<string> memo;
  ll ans;

int main() {

  cin >> n;

  fill(s,s+100100,"");

  FOR(i,0,n-1) {
    string into;
    cin >> into;
    // cout << into << endl;
    char input[10];
    FOR(j,0,9) {
      input[j] = into[j];
      // cout << input[j] << endl;
    }
    sort(input,input+10); 
    FOR(j,0,9) {
      c[i][j] = input[j];
      s[i] += c[i][j];
      // cout << s[i] << endl;
    }
    ++m[s[i]];
    if(m[s[i]]>=2) {
      memo.insert(s[i]);
      // cout << s[i] << endl;
    }
  }

  for(string i: memo){
    ans += m[i]*(m[i]-1)/2;
    // cout << m[i] << endl;
  }

  cout << ans << endl;
    



}



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

class rec{
public:
  int height,width,length;

  bool operator < (const rec& right) const {
    if ( length != right.length ) {
      return length < right.length;
    }else {
      return height < right.height;
    }
  }

};

int main() {

  vector<rec> recs;
  rec add;

  for ( int i = 1; i < 150; i++ ) {
    for ( int j = i+1; j < 150; j++ ) {
      add.height = i;
      add.width = j;
      add.length = i*i + j*j;
      recs.push_back(add);
    }
  }
  sort( recs.begin(), recs.end() );

  while(true) {

    int h,w;
    cin >> h >> w;
    if ( h == 0 ) break;

    for ( int i = 0; i < recs.size(); i++ ) {
      if ( recs[i].height == h && recs[i].width == w ) {
	cout << recs[i+1].height << " " << recs[i+1].width << endl;
	break;
      }
    }

  }

  return 0;

}

Measured memory_bytes: 1352
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
ma = x // 500
mb = x // 100
mc = x // 50
na = min([a, ma])
nb = min([b, mb])
nc = min([c, mc])
for i500 in range(na+1):
  for i100 in range(nb+1):
      current = x-500*i500-100*i100
      if current >= 0 and current <= 50*nc:
          cnt += 1
          #print(i500,i100,cnt)
print(cnt)

Measured memory_bytes: 3064
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] p = new long[n];
		long[] l = new long[n];
		long[][] cum = new long[n][2];
		for (int i = 0; i < n; ++i) {
			p[i] = sc.nextLong();
			cum[i][0] = (i > 0 ? cum[i - 1][0] : 0) + p[i];
			cum[i][1] = i;
		}
		for (int i = 0; i < n; ++i) {
			l[i] = sc.nextLong();
		}
		Arrays.sort(cum, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return Long.compare(o1[0], o2[0]);
			}
		});
		boolean f = true;
		for (int i = 0; i < n; ++i) {
			f &= cum[i][0] - (i > 0 ? cum[i - 1][0] : 0) >= l[i];
		}
		long ans = 0;
		BIT bit = new BIT(n + 1);
		for (int i = 1; i <= n; ++i) {
			bit.add(i, 1);
		}
		for (int i = 0; i < n; ++i) {
			ans += bit.sum((int) cum[i][1]);
			bit.add((int) cum[i][1] + 1, -1);
		}

		System.out.println(f ? ans : -1);
	}

	class BIT {
		int n;
		int[] v;

		public BIT(int n_) {
			n = n_;
			v = new int[n + 1];
		}

		void add(int k, int val) {
			while (k <= n) {
				v[k] += val;
				k += k & -k;
			}
		}

		int sum(int k) {
			int ret = 0;
			while (k > 0) {
				ret += v[k];
				k -= k & -k;
			}
			return ret;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

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

#define MAX_N 100003

int INF = (1 << 30);
vector< vector<int> > grid;
vector<int> dis;
vector<int> signpost;

int calCulateMove(int source){
    //cout<<"Calclating move for "<<source<<endl;

    dis[source] = 0;
    queue<int> Q;

    Q.push(source);

    while(!Q.empty()){
        int u = Q.front();
        Q.pop();

        for(int i=0; i<grid[u].size(); i++){
            int v = grid[u][i];
            if( dis[u] + 1 < dis[v]){
                dis[v] = dis[u] + 1;
                signpost[v] = u;
                Q.push(v);
            }
        }
    }

    return 0;
}


int main(){

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int N, M;

    cin>>N>>M;
    grid = vector< vector<int> >(N+1);
    dis = vector<int>(N+1, INF);
    signpost = vector<int>(N+1, -1);

    int a, b;
    for(int i=0; i<M; i++){
        cin>>a>>b;
        grid[a].push_back(b);
        grid[b].push_back(a);
    }

   // cout<<INF << endl;

    // for(int i=1; i<=N; i++){
    //     cout<<"Fors "<<i<<" -> ";
    //     for(int j=0; j<grid[i].size(); j++){
    //         cout<<grid[i][j] <<" ";
    //     }
    //     cout<<endl;
    // }

    calCulateMove(1);

    bool allTraversed = true;
    for(int i =1; i<=N; i++){
        if( dis[i] == INF){
            allTraversed = false;
            break;
        }
    }

    if(allTraversed){
        cout<<"Yes\n";
        for(int i=2; i<=N; i++){
            cout<<signpost[i]<<endl;
        }
    }else{
        cout<<"No\n";
    }
    
    return 0;
}

Measured memory_bytes: 10216
#include <iostream>
#include <sstream>

using namespace std;
typedef long long ll;
const ll INIT = 100000000000000000ll;

ll calc_length(ll x){
	ll dig, len, answer = 0;
	for(dig = 1, len = 1; dig * 10 < x; dig *= 10, ++len){
		answer += dig * 9 * len;
		answer -= ((dig * 10 - 1) / 3 - (dig - 1) / 3) * len;
		answer += ((dig * 10 - 1) / 3 - (dig - 1) / 3) * 4;
		answer -= ((dig * 10 - 1) / 5 - (dig - 1) / 5) * len;
		answer += ((dig * 10 - 1) / 5 - (dig - 1) / 5) * 4;
		answer += ((dig * 10 - 1) / 15 - (dig - 1) / 15) * len;
	}
	answer += (x - dig) * len;
	answer -= ((x - 1) / 3 - (dig - 1) / 3) * len;
	answer += ((x - 1) / 3 - (dig - 1) / 3) * 4;
	answer -= ((x - 1) / 5 - (dig - 1) / 5) * len;
	answer += ((x - 1) / 5 - (dig - 1) / 5) * 4;
	answer += ((x - 1) / 15 - (dig - 1) / 15) * len;
	return answer;
}

int main(){
	ll s;
	cin >> s;
	--s;
	ll left = 1, right = INIT;
	while(left < right){
		ll center = (left + right) / 2;
		ll len = calc_length(center);
		if(len > s){
			right = center;
		}else{
			left = center + 1;
		}
	}
	stringstream ss;
	ll base = calc_length(left - 1), cur = left - 1;
	while(ss.str().size() < 50){
		if(cur % 15 == 0){
			ss << "FizzBuzz";
		}else if(cur % 3 == 0){
			ss << "Fizz";
		}else if(cur % 5 == 0){
			ss << "Buzz";
		}else{
			ss << cur;
		}
		++cur;
	}
	for(int i = 0; i < 20; ++i){ cout << ss.str()[s - base + i]; }
	cout << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 2e5 + 10;
int n;
vector<int> g[MAXN];

void read() {
	cin >> 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);
	}
}

vector<int> comp[2];

void dfs(int v, int p, int c) {
	comp[c].push_back(v);
	for (auto i : g[v]) {
		if (i == p) continue;
		dfs(i, v, c ^ 1);
	}
}

vector<int> cnt[3];
vector<int> ans;

void run() {
	dfs(0, -1, 0);
	if (comp[0].size() > comp[1].size()) swap(comp[0], comp[1]);
	
	for (int i = 1; i <= n; i++) {
		cnt[i % 3].push_back(i);
	}
	
	ans.resize(n);
	
	if (comp[0].size() <= cnt[0].size()) {
		for (auto i : comp[0]) {
			ans[i] = cnt[0].back();
			cnt[0].pop_back();
		}
		for (auto i : comp[1]) {
			if (!cnt[0].empty()) {
				ans[i] = cnt[0].back();
				cnt[0].pop_back();
			}
			else if (!cnt[1].empty()) {
				ans[i] = cnt[1].back();
				cnt[1].pop_back();
			}
			else if (!cnt[2].empty()) {
				ans[i] = cnt[2].back();
				cnt[2].pop_back();
			}
		}
		return;
	}


	for (auto i : comp[0]) {
		if (!cnt[1].empty()) {
			ans[i] = cnt[1].back();
			cnt[1].pop_back();
		}
		else {
			assert(!cnt[0].empty());
			ans[i] = cnt[0].back();
			cnt[0].pop_back();
		}
	}

	assert(cnt[1].empty());
	
	for (auto i : comp[1]) {
		if (!cnt[2].empty()) {
			ans[i] = cnt[2].back();
			cnt[2].pop_back();
		}
		else {
			assert(!cnt[0].empty());
			ans[i] = cnt[0].back();
			cnt[0].pop_back();
		}
	}
}

void write() {
	for (auto i : ans) {
		cout << i << " ";
	}
	cout << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 22388
from collections import deque
h,w = map(int,input().split())
s = []
s.append(["#"]*(w+2))
for i in range(h):
    s.append(["#"]+list(input())+["#"])
s.append(["#"]*(w+2))
dx = [1,0,-1,0]
dy = [0,-1,0,1]
q = deque([(1,1)])
dis = [[-1]*(w+2) for _ in range(h+2)]
dis[1][1] = 0
while q:
    x,y = q.popleft()
    for i in range(4):
        if s[x+dx[i]][y+dy[i]] == "." and dis[x+dx[i]][y+dy[i]] == -1:
                dis[x+dx[i]][y+dy[i]] = dis[x][y] +1
                q.append((x+dx[i],y+dy[i]))
count = 0
if dis[h][w] == -1:
    print(-1)
else:
    for i in range(h+2):
        for j in range(w+2):
            if s[i][j] == ".":
                count += 1
    print(count-dis[h][w]-1)

Measured memory_bytes: 3316
float x[100],y[100],t,u,a,b;n,i,j,k,c,z,s;main(m){for(;m=scanf("%d",&n),z=i=n;printf("%d\n",m))for(;!z?j=--i:scanf("%f,%f",x+z,y+--z);)for(;s=!z&&j--;)for(u=acos(hypot(a=x[j]-x[i],b=y[j]-y[i])/2),t=atan2(b,a);c=0,u<9&&s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  ll N;
  in(N);
  print(N * (N - 1) / 2);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,cnt,len;
	char n[200001];
	scanf("%s",n);
	len=strlen(n);
	cnt=0;
	for(i=0;i<len;i++)	{
		cnt+=n[i]-'0';
	}
	if(cnt%9==0)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1812
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
const ll INF = 10e9;

int main(){
  int n; cin>>n;
  vector<int>A(n); rep(i,n) cin>>A[i];
  ll money = 1000;
  ll stock = 0;
  rep(i, n-1){
    if (A[i]<A[i+1]){
      stock = money/A[i];
      money %= A[i];
      money += A[i+1]*stock;
    }
  }
  cout << money;
}

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

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            long a = long.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            long kota = 1;
            long min = long.Parse(str[0]);
            for(long i=1; i<a; i++)
            {
                if(long.Parse( str[i]) <= min)
                {
                    min = long.Parse(str[i]);
                    kota++;
                }
            }
            Console.WriteLine(kota);
        }
    }
}


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

int main(){
	int x;
	vector<int> l;
	for(int i=0; i<3; i++){
		cin >> x;
		l.push_back(x);
	}
	sort(l.begin(), l.end());
	l.pop_back();
	int s = 0;
	s = l[0]*l[1]/2;
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

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

    int tl = l;
    int dl = 0;
    bool te[20];
    int ce = 0;
    memset(te, 0, sizeof(te));
    while (l) {
        if (l & 1) {
            te[dl] = true;
            ce++;
        }
        l >>= 1;
        dl++;
    }
    cout << dl << " " << (dl-1)*2+ce-1 << endl;
    l = tl;
    int t = 1;
    for (int i = 1; i < dl; i++) {
        cout << i << " " << i+1 << " " << 0 << endl;
        cout << i << " " << i+1 << " " << t << endl;
        if (te[i-1]) {
            cout << i << " " << dl << " " << l - t << endl;
            l -= t;
        }
        t <<= 1;
    }

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc096b()
}

fun abc096b() {
    val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val k = readLine()!!.toInt()


    val answer = a + b + (c * Math.pow(2.0, k.toDouble()).toInt())

    println(answer)
}


Measured memory_bytes: 37912