akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;
signed main(){

    int n,a[111111];
    cin>>n;
    rep(i,n)cin>>a[i];
    int f[111111]={0};
    rep(i,n){
        if(i==1)break;
       // cout<<i<<endl;
        if(f[i]){
            cout<<-1<<endl;
            return 0;
        }
        f[i]=1;
        i=a[i]-2;
        ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
 
int main() {
	// your code goes here
	int h, m ,s;
 
	cin >> s;
 
	h = s / 3600;
	s = s % 3600;
	m = s / 60;
	s = s % 60;
 
	cout << h << ":" << m << ":" <<s << endl;
 
	return 0;
}

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

int main(void){

  long long n;
  cin >> n ;
  vector<int> a(n);
  long long i = 0;
  for(i = 0;i<n;i++){
    cin >> a[i];
  }
  
  long long max = 0;
  long long c = 0;
  long long c1 = 0;
  for(i = n-1;i >= 0;i--){
    if(a[i] <= a[i-1]){
      c++;
    }
    else{
      if(max < c){
        max = c;
      }
      c = 0;
      c1 ++;
    }
  }
  if(c1 == n){
      cout << "0" << endl;
  }

  else if(c1 == 0){
    cout << n << endl;
  }
  else{
    cout << max << endl;
  }
  
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
 #include <stdio.h>

#define NUMBER 100

int main(void)
 {
  int x[NUMBER];
  int i;
  int n;

 do {
   scanf("%d", &n);
  } while (n < 1 || n > 100);
  for (i = 0; i < n; i++) {
   scanf("%d",&x[i]);
  }
  for (i = 0; i < (n - 1); i++) {
   printf("%d ", x[(n - 1) - i]);
  }
  printf("%d\n",x[0]);

 
  return 0;
 }

Measured memory_bytes: 596
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;


class B {
	int n;
	const int max{ 1000000007 };
public:
	B()
	{
		cin >> n;
	}
	void solve()
	{
		int mi{ max }, ma{ -max };

		int a;
		REP(i, n)
		{
			cin >> a;
			chmin(mi, a);
			chmax(ma, a);

		}

		cout << ma - mi << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

int main(){
	int n;
	int count = 0;
	cin >> n;
	int p[n];

	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	
	for(int i = 0; i < n-2; i++){
		if((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i+2] < p[i+1] && p[i+1] < p[i])){
			count++;
		}
	}
	cout << count << endl;

}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int n = sc.nextInt();
      long sum = 0;
	  for(int i = 0;i<n-1;i++){
        sum+=i+1;
      }
	  System.out.println(sum);
    }
}

Measured memory_bytes: 21712
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
vector<ll> pw2(51,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M,X; cin>>N>>M>>X;
    ll ans=INF;
    vector<ll> C(N,0);
    vector<vector<ll> > A(N,vector<ll>(M,0));
    rep(i,N){
        cin>>C[i];
        rep(j,M) cin>>A[i][j];
    }
    
    rep(i,pw2[N]){
        //BIT全探索
        vector<ll> BIT(N);
        ll tmps=i;
        rrep(i2,N){
            BIT[i2]=tmps/pw2[i2];
            tmps%=pw2[i2];
        }
        
        ll cost=0;
        vector<ll> point(M,0);
        rep(j,N){
            //買わない
            if(BIT[j]==0){
                
            }
            else{
                cost+=C[j];
                rep(k,M){
                    point[k]+=A[j][k];
                }
            }
        }
        
        //check
        bool check=true;
        rep(j,M){
            if(point[j]<X) check=false;
        }
        
        if(check) chmin(ans,cost);
    }
    
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
}



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

int main() {
	long X; cin >> X;
	long P=X/11;
	if(X%11){
	    if(X%11>6) cout << 2*P+2 << endl;
	    else cout << 2*P+1 << endl;
	}
	else cout << 2*P << endl;
	return 0;
}


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

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

int main() {
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> f(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];
	sort(a.begin(), a.end());
	sort(f.rbegin(), f.rend());
	ll l = -1, r = 1e12;
	while (l + 1 < r) {
		ll c = (l + r) / 2;
		bool ok = [&] {
			ll s = 0;
			rep(i, n) {
				s += max(0ll, a[i] - c / f[i]);
			}
			return s <= k;
		}();
		if (ok) r = c; else l = c;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1792
import re

n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  for result in re.finditer(b[0], arow):
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][result.start():result.end()]:
        falg = False
    if falg is True:
      print('Yes')
      exit()
print('No')

Measured memory_bytes: 3188
using System;
using System.Linq;

class Program
{
	static void Main()
	{
		var kn = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var p = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));

		var k = kn[0];
		var n = kn[1];

		var maxSum = 0;
		var lastSum = 0;
		var maxIndex = 0;
		var end = k - n + 1;
		for (var i = 0; i < end; ++i) {
			var sum = 0;
			if (i == 0) {
				for (var j = 0; j < n; ++j) {
					sum += p[i + j];
				}
			} else {
				sum = lastSum - p[i - 1] + p[i + n - 1];
			}

			if (sum > maxSum) {
				maxSum = sum;
				maxIndex = i;
			}

			lastSum = sum;
		}

		var expectations = p.Skip(maxIndex).Take(n).Select(number => {
			var expectation = 0.0;
			for (var i = 1; i <= number; ++i) {
				expectation += i * (1.0 / (double)number);
			}

			return expectation;
		});

		Console.WriteLine(Math.Round(expectations.Sum(), 8));
	}
}


Measured memory_bytes: 31324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	ll x; cin >> x;
	ll sum = 0;
	rep(i, INF){
		sum += i + 1;
		if(sum >= x){
			printf("%d\n", i + 1);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
static const int N = 100;

int n;
int M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] == 1 && color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_print() {
	for (int i = 0; i < n; i++) color[i] = WHITE;
	tt = 0;
	for (int i = 0; i < n; i++) {
		if (color[i] == WHITE) {
			dfs_visit(i);
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
}

int main() {
	cin >> n;
	int u, k;
	int index;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> index;
			M[u - 1][index - 1] = 1;
		}
	}
	dfs_print();
}

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

typedef long long llong;
const int MAX = 100000;
enum PATTERN {
    A = 0,
    B,
    C,
    END
};
llong a[MAX];
llong b[MAX];
llong c[MAX];
llong dp[MAX][END];

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < END; j++) {
            for (int k = 0; k < END; k++) {
                if (j == k) continue;
                llong max = 0;
                if (k == A) {
                    max = dp[i][j] + a[i];
                } else if (k == B) {
                    max = dp[i][j] + b[i];
                } else if (k == C) {
                    max = dp[i][j] + c[i];
                }
                if (dp[i + 1][k] < max) {
                    dp[i + 1][k] = max;
                }
            }
        }
    }
    
    llong res = 0;
    for (int i = 0; i < END; i++) {
        llong max = dp[N][i];
        if (res < max) {
            res = max;
        }
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int A, B;
  cin >> A >> B;

  double x = 1;
  bool flag = false;
  while(x < A * 100){
    if(A <= x * 0.08 && x * 0.08 < A+1 && B <= x * 0.1 && x * 0.1 < B+1){
      flag = true;
      break;
    }
    x++;
  }
  cout << (flag? x: -1) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int M = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int answer=0;
        for(int i = 1; i < M+1; i++){
            for(int j = 22; j < D+1; j++){
                if((j/10 * (j-j/10*10)) == i && (j-j/10*10) >= 2){
                    answer++;
                }
            }
        }
        System.out.println(answer);

    }
    }

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

int main() {
  vector<vector<int>> card(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> card.at(i).at(j);
    }
  }
  
  int N;
  cin >> N;
  
  vector<int> bingo(N);
  for (int i = 0; i < N; i++) {
    cin >> bingo.at(i);
  }
  
  vector<vector<bool>> card2(3, vector<bool>(3, false));
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (bingo.at(i) == card.at(j).at(k)) {
          card2.at(j).at(k) = true;
        }
      }
    }
  }
  
  for (int i = 0; i < 3; i++) {
    if (card2.at(i).at(0) && card2.at(i).at(1) && card2.at(i).at(2)) {
      cout << "Yes" << endl;
      break;
    }
    else if (card2.at(0).at(i) && card2.at(1).at(i) && card2.at(2).at(i)) {
      cout << "Yes" << endl;
      break;
    }
    else if (card2.at(0).at(0) && card2.at(1).at(1) && card2.at(2).at(2)) {
      cout << "Yes" << endl;
      break;
    }
    else if (card2.at(0).at(2) && card2.at(1).at(1) && card2.at(2).at(0)) {
      cout << "Yes" << endl;
      break;
    }
    else if (i == 2) {
      cout << "No" << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int dz[4] = {1,-1,-1,1};
int dw[4] = {1,1,-1,-1};
int main() {
    int n;cin >> n;
    vector<pair<int,int> > x(n);
    rep(i,n) cin >> x[i].first >> x[i].second;
    vector<int> a(8);
    rep(i,8) a[i]=i;
    do{
	bool board[8][8] = {false};
	for(int i=0;i<8;i++){
	    board[i][a[i]] = true;    	    
	}
	bool ok = true;
	rep(i,n){ 
	   if(board[x[i].first][x[i].second] == false) ok = false;
	}
	if(ok == false) continue;
	for(int i=0;i<8;i++){
	    for(int j=0;j<4;j++){
		int t = 1;
		while(1){
		    int s = i+dz[j]*t;
		    int r = a[i]+dw[j]*t;
		    if(s < 0 || 8 <= s || r < 0 || 8 <= r)break; 
		    if(board[s][r]==true) ok = false;
		    t++;
		}
	    }
	}
	if(ok){
	    rep(i,8){
		rep(j,8){
		    if(board[i][j]) cout <<"Q";
		    else cout <<".";
		}
		cout << endl;
	    }
	    break;
	}
    }while(next_permutation(a.begin(),a.end()));
    return 0;
}



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

using namespace std;

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> t_list(N);
    for (auto& t : t_list) {
        cin >> t;
    }
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < N - 1) {
            ans += min(t_list[i + 1] - t_list[i], T);
        } else {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();

    int cnt = 0;
    REP(i, n)
        if (s[i] == '2') cnt++;

    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,h,w = LI()
    x = LI()
    t = [0 for i in range(w*n+1)]
    for i in range(n):
        if not i%2:
            t[i*w+x[i]] += 1
            t[(i+1)*w+x[i]] -= 1
        else:
            t[i*w-x[i]] += 1
            t[(i+1)*w-x[i]] -= 1
    for i in range(w*n):
        t[i+1] += t[i]
    ans = 0
    for i in t[:-1]:
        if i == 0:
            ans += h
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()



Measured memory_bytes: 8360
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;

int n, a[Max], b[Max], cnt[Max], ans[Max];
int f[Max];

void KMP(int sh)
{
	for (int i = 1, j = 0; i < n; i++)
	{
		while (j && (b[i] & 1 << sh) != (b[j] & 1 << sh))
			j = f[j - 1];
		if ((b[i] & 1 << sh) == (b[j] & 1 << sh))
			j++;
		f[i] = j;
	}
	for (int i = 1, j = 0; i < 2 * n; i++)
	{
		while (j && (a[i] & 1 << sh) != (b[j] & 1 << sh))
			j = f[j - 1];
		if ((a[i] & 1 << sh) == (b[j] & 1 << sh))
			j++;
		if (j == n)
			cnt[i - n + 1]++, j = f[j - 1];
	}

	for (int i = 1, j = 0; i < 2 * n; i++)
	{
		while (j && (a[i] & 1 << sh) == (b[j] & 1 << sh))
			j = f[j - 1];
		if ((a[i] & 1 << sh) != (b[j] & 1 << sh))
			j++;
		if (j == n)
			cnt[i - n + 1]++, ans[i - n + 1] |= 1 << sh, j = f[j - 1];
	}
}

int main()
{
	GO;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], a[i + n] = a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < 30; i++)
		KMP(i);
	set<pair<int, int>> st;
	for (int i = 0; i < 2*n; i++)
		if (cnt[i] == 30)
			st.insert({ i % n,ans[i] });
	for (auto i : st)
		cout << i.first << ' ' << i.second << '\n';
	return 0;
}


Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
/*
int main(){
    int a,b,c;
    cin >> a >> b >>c;
    int A = __gcd(a,b);
    int C = __gcd(b,c);

    A = b/A;
    C = b/C;
    cout << (A==C? "YES":"NO") << endl;
}
// ABC060b
*/

int main(){
    int a,b,c;
    cin>> a >> b >> c;
    bool yes = false;
    for(int i=1;i<=b;i++){
        if(a*i%b==c){
            yes = true;
            break;
        }
    }
    cout << (yes? "YES" : "NO") << endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int ai;
            cin >> ai;
            ai--;
            a.at(i).at(j) = ai;
        }
    }

    vector<int> ptr(n);
    vector<int> removed(m);
    int ans = n;
    for (int i = 0; i < m; i++) {
        vector<int> cnt(m);
        for (int j = 0; j < n; j++) {
            cnt.at(a.at(j).at(ptr.at(j)))++;
        }
        int maximum = 0;
        int max_kind = 0;
        for (int j = 0; j < m; j++) {
            if (maximum < cnt.at(j)) {
                maximum = cnt.at(j);
                max_kind = j;
            }
        }
        ans = min(ans, maximum);

        removed.at(max_kind) = true;
        for (int i = 0; i < n; i++) {
            while (ptr.at(i) < m && removed.at(a.at(i).at(ptr.at(i)))) ptr.at(i)++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
# coding: utf-8


def main():
    S = input()
    l = len(S)
    r = "keyence"
    for i in range(min(l, 7)):
        if S[i] != r[i]: break
    for j in range(1, min(l, 7) + 1):
        if S[-j] != r[-j]: break
    j -= 1
    return i + j >= 7


if __name__ == "__main__":
    print(["NO", "YES"][main()])


Measured memory_bytes: 3060
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    T, A = map(int, input().split())
    H = tuple(map(lambda h: abs(T - int(h) * 0.006 - A), input().split()))
    print(H.index(min(H)) + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<map>
#include <bits/stdc++.h>
#include<cmath>
#define mod 1000000007
#define ll long long 
using namespace std;

int main() {

  ll n;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  string s3="";
  ll xx=s1.length();
  for(ll i=0;i<n;i++)
  {
  	s3=s3+s1[i];
  	s3=s3+s2[i];
  }
  cout<<s3<<endl;
	return 0;
}

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

int main() {
  ll ans1=0;
  ll ans2=0;
  ll ans3=0;
  ll sum = 0;
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  rep(i,n) sum += x[i];
  int p = sum/n;
  rep(i,n){
    ans1 += (p-x[i])*(p-x[i]);
    ans2 += (p+1-x[i])*(p+1-x[i]);
    ans3 += (p-1-x[i])*(p-1-x[i]);
  }
  cout << min(min(ans1, ans2),ans3) << endl;  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=(1<<18)+5;
set<PII>s[N];
int arr[N],par[N];
void add(int x,PII val){
	s[x].insert(val);
	if(s[x].size()>2)
		s[x].erase(s[x].begin());
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=0;i<(1<<n);i++)
		scanf("%d",arr+i);
	for(int i=0;i<(1<<n);i++){
		add(i,mp(arr[i],i));
		if(s[i].size()==2){
			tr(it,s[i])
				par[i]+=it->ff;
		}
		for(int j=0;j<n;j++)
			if(!(i>>j&1))
				tr(it,s[i])
					add(i^(1<<j),*it);
	}	
	for(int i=1;i<(1<<n);i++){
		umax(par[i],par[i-1]);
		printf("%d\n",par[i]);
	}
	return 0;
}


Measured memory_bytes: 41984
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n, a, b, sum;
  sum = 0;
  cin >> n >> a >> b;
  for(int i= 1; i <= n; i++){
    int p_sum = i%10 + i/10%10 + i/100%10 + i/1000%10 + i/10000%10;
      if(p_sum >= a && p_sum <= b)
        sum += i;
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]

k=max(A)
C=[0]*(k+1)

for i in range(n):
    C[A[i]]+=1

for i in range(1,k+1):
    C[i] = C[i] + C[i-1]

B=[0]*(n+1)

for i in [n-i-1 for i in range(n)]:
    B[C[A[i]]] = A[i]
    C[A[i]]-=1
    

print(*B[1:])


Measured memory_bytes: 224236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int MAX_N = 6000;
int dp[MAX_N],dp2[MAX_N*MAX_N];
// dp[i]は、i個のどんぐりを最大何個まで変換できるかを記録する
void chmax(int &a, int b){ if( a < b ){ swap(a,b);} return;}
signed main(void){
  int N; cin >> N;
  vector<int> a(3),b(3);
  for(int i = 0; i < 3; i++){ cin >> a[i];}
  for(int j = 0; j < 3; j++){ cin >> b[j];}
  
  for(int i = 0; i <= N; i++){ 
    // AからBの遷移にかけて、どんぐりi個を最大何個まで変換できるかを考える
    chmax(dp[i],i); //何も変換しないとき
    for(int j = 0; j < 3; j++){
      if( i-a[j] >= 0 ){ 
      chmax(dp[i], dp[i-a[j]]+b[j]);
      }
    }// fo-j
  }//for-i
  
  int M = dp[N];
  
  for(int i = 0; i <= M; i++){
    chmax(dp2[i],i);
    for(int j = 0; j < 3; j++){
      if( i-b[j] >= 0 ){
        
        chmax( dp2[i], dp2[i-b[j]]+a[j] );
      }
    }
  }
  
  cout << dp2[M] << endl;
  
  return 0;
}

Measured memory_bytes: 196864
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    while(cin >> H >> W,H+W){
        rep(i,H){
            rep(j,W)cout << ((i%2 and j%2 == 0) or (i%2 == 0 and j%2) ? ".":"#");
            cout << endl;
        }
        cout << endl;
    }
}





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

int main() {
  long long int K=0,A=0,B=0;
  long long int biscuit=1,coin=0;
  cin >> K >> A >> B;
  if(A>=B || B-A==1){ // 普通に増やし続けた方がいい
    cout << K + 1 << endl;
    return 0;
  }


  for(int i=0;i<K;++i){ //なるべくコインを増やして全部消費する
    if(coin==K-i){
      coin--;
      biscuit += B;
      // cout << i << ":" << coin << ":" << biscuit << endl;
    } else if(biscuit>=A && coin+1 < K-i ){ // 全部消費できなそうだったらコインを増やさない。
      coin++;
      biscuit -= A;
      // cout << i << ":" << coin << ":" << biscuit << endl;
    } else if(coin){
      coin--;
      biscuit += B;
      // cout << i << ":" << coin << ":" << biscuit << endl;
    }else{
      biscuit++;
      // cout << i << ":" << coin << ":" << biscuit << endl;
    }
  }
  cout << biscuit << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class RAQ_RMQ:
    def __init__(self, n, F=min, e=float("inf")):
        self.n = n
        self.n0 = 2**(n-1).bit_length()
        self.e = e
        self.F = F
        self.lazy = [0]*(2*self.n0)
        self.data = [e]*(2*self.n0)

    def construct(self, a):
        for i, x in enumerate(a):
            self.data[i+self.n0] = x
        for i in range(self.n0-1, 0, -1):
            self.data[i] = self.F(self.data[2*i], self.data[2*i+1])

    def bottomup(self, i):
        i += self.n0
        k = i//(i & -i)
        c = k.bit_length()
        for j in range(c-1):
            k >>= 1
            self.data[k] = self.F(self.data[2*k], self.data[2*k+1]) + self.lazy[k]

    def topdown(self, i):
        i += self.n0
        k = i//(i & -i)
        c = k.bit_length()
        for j in range(c-1):
            idx = k >> (c - j - 1)
            ax = self.lazy[idx]
            if not ax:
                continue
            self.lazy[idx] = 0
            self.data[2*idx] += ax
            self.data[2*idx+1] += ax
            self.lazy[2*idx] += ax
            self.lazy[2*idx+1] += ax

    def query(self, l, r):
        self.topdown(l)
        self.topdown(r)
        L = l+self.n0
        R = r+self.n0

        s = -float("inf")
        while L < R:
            if R & 1:
                R -= 1
                s = self.F(s, self.data[R])
            if L & 1:
                s = self.F(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def add(self, l, r, x):
        L = l+self.n0
        R = r+self.n0

        while L < R :
            if R & 1:
                R -= 1
                self.data[R] += x
                self.lazy[R] += x
            if L & 1:
                self.data[L] += x
                self.lazy[L] += x
                L += 1
            L >>= 1
            R >>= 1

        self.bottomup(l)
        self.bottomup(r)

n,m = map(int, input().split())
memo = [[] for i in range(n+2)]
for i in range(m):
    l,r,a = map(int, input().split())
    memo[l].append((l,a))
    memo[r+1].append((l,-a))

seg = RAQ_RMQ(n+2, F=max, e=0)
for i in range(1, n+2):
    for j, a in memo[i]:
        seg.add(0, j, a)
    tmp = seg.query(0, i)
    seg.add(i, i+1, tmp)
ans = seg.query(0, n+1)
print(ans)

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

int main(int argc, char const *argv[])
{
	int a[2];
	int m=0;
	int n=0;

	for(int i=0;i<2;i++){
	cin >> a[i];
	}

	m=a[0]*a[1];
	n=2*a[0]+2*a[1];

	cout << m;
	cout << " ";
	cout << n<< endl;
	return 0;
}


Measured memory_bytes: 3076
n,a=map(int,input().split())
x=list(map(int,input().split()))
p=min(a*n,sum(x))
dp=[[[0]*(n+1)for _ in range(p+1)]for _ in range(n+1)]
dp[0][0][0]=1
for i in range(1,n+1):
	for j in range(p+1):
		for k in range(n+1):
			dp[i][j][k]+=dp[i-1][j][k]
			if j-x[i-1]>=0 and k>=1:
				dp[i][j][k]+=dp[i-1][j-x[i-1]][k-1]
ans=0
for i in range(1,n+1):
	if i*a>p:
		break
	ans+=dp[-1][i*a][i]
print(ans)

Measured memory_bytes: 103772
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
//    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
//    const N = numList0[0];
//    const K = numList0[1];

    // 文字列取得
    const S = input[0].split(' ')[0];
    var prevChar = '';
    var flag = false;
    for (i = 0; i < S.length; i++) {
        var c = S.charAt(i);
        if (prevChar == c) {
            flag = true;
            break;
        }
        prevChar = c;
    }

    if (flag) {
        console.log('Bad');
    } else {
        console.log('Good');
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// ワーシャルフロイド法 o(|V|^3)

const int INF = 1001001001;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n, INF));
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    dist[a][b] = dist[b][a] = c;
  }

  rep(k, n) rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
  vector<vector<int>> dist2(n, vector<int>(n, INF));
  rep(i, n) rep(j, n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(k, n) rep(i, n) rep(j, n) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

  int q;
  cin >> q;
  rep(qi, q) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    int ans = dist2[s][t] - 1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
    int flg = 0;
    int cnt = 0;
    rep(i, N) {
        int a; cin >> a;
        if (a >= 3200) cnt++;
        else if (a >= 2800) flg |= (1<<0);
        else if (a >= 2400) flg |= (1<<1);
        else if (a >= 2000) flg |= (1<<2);
        else if (a >= 1600) flg |= (1<<3);
        else if (a >= 1200) flg |= (1<<4);
        else if (a >= 800)  flg |= (1<<5);
        else if (a >= 400)  flg |= (1<<6);
        else                flg |= (1<<7); 
    }
    int temp = 0;
    rep(i, 8) {
        if(flg & (1<<i)) temp++;
    }
    int m = temp;
    if(temp == 0) {
        m = 1;
    }
    cout << m << " " << temp + cnt << endl;
}

Measured memory_bytes: 256
n,a,b,c,d=map(int,input().split())
s=input()
if s[b:d].count('##')>0:
    print('No')
    exit()

if c>d:
    flg=True
    if s[b-2:d+1].count('...')>0:
        flg=False
    if flg:
        print('No')
        exit()

if s[a:c].count('##')>0:
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 3572
A = input()
B = input()
C = input()

cntA=cntB=cntC=0
next = 'a'

while True:
    if next == 'a':
        if cntA==len(A):
            print('A')
            break
        next = A[cntA]
        cntA += 1
    elif next == 'b':
        if cntB==len(B):
            print('B')
            break
        next = B[cntB]
        cntB += 1
    elif next == 'c':
        if cntC==len(C):
            print('C')
            break
        next = C[cntC]
        cntC += 1

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

typedef pair<int,int> pii;
const int inf=1e9;
const int64_t inf64=1e18;
const long double eps=1e-10;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n,long double l){
    vector<long double> s(n),t(n),u(n);
    rep(i,0,n) cin >> s[i] >> t[i] >> u[i];
    {
        vector<long double> s_,t_,u_;
        s_.push_back(0);
        t_.push_back(s.front());
        u_.push_back(0);
        s_.push_back(s.front());
        t_.push_back(t.front());
        u_.push_back(u.front());
        rep(i,1,s.size()){
            if(s[i]>t[i-1]){
                s_.push_back(t[i-1]);
                t_.push_back(s[i]);
                u_.push_back(0);
            }
            s_.push_back(s[i]);
            t_.push_back(t[i]);
            u_.push_back(u[i]);
        }
        s_.push_back(t.back());
        t_.push_back(86400);
        u_.push_back(0);
        swap(s,s_);
        swap(t,t_);
        swap(u,u_);
    }

    auto simulation=[&](long double x,long double initial_value){
        vector<long double> res;
        long double k=initial_value;
        res.push_back(k);
        rep(i,0,s.size()){
            k+=(x-u[i])*(t[i]-s[i]);
            k=min(k,l);
            res.push_back(k);
        }
        return res;
    };

    auto ok=[&](long double x){
        auto res1=simulation(x,l);
        auto res2=simulation(x,res1.back());
        rep(i,0,res1.size()) if(res1[i]<0) return false;
        rep(i,0,res2.size()) if(res2[i]<0) return false;
        rep(i,0,res1.size()) if(res1[i]<=res2[i]) return true;
        return false;
    };

    long double lb=0,ub=inf64;
    rep(i,0,128){
        auto mid=(lb+ub)/2;
        if(ok(mid)) ub=mid;
        else lb=mid;
    }
    cout << ub << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n;
        long double l;
        cin >> n >> l;
        if(!n and !l) break;
        solve(n,l);
    }
    return 0;
}

Measured memory_bytes: 15140
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, x int
	var l = make([]int, 0, n)
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		line := sc.Text()
		arr := strings.Fields(line)
		n, _ = strconv.Atoi(arr[0])
		x, _ = strconv.Atoi(arr[1])
	}
	if sc.Scan() {
		line := sc.Text()
		for _, s := range strings.Fields(line) {
			n, _ := strconv.Atoi(s)
			l = append(l, n)
		}
	}

	var bounds = make([]int, 0, n+1)
	bounds = append(bounds, 0)
	for i := 0; i < n; i++ {
		bounds = append(bounds, bounds[i]+l[i])
	}

	ans := 0
	for _, b := range bounds {
		if b <= x {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
class Node:
    def __init__(self):
        self.p = -1
        self.l = -1
        self.r = -1

n = int(input())
T = [Node() for _ in range(n)]
for _ in range(n):
    i,left,right = map(int,input().split())
    T[i].l = left
    T[i].r = right
    if left != -1: T[left].p = i
    if right != -1: T[right].p = i

sib = [-1]*n
deg = [0]*n
dep = [0]*n
hei = [0]*n
ntype = ["internal node"]*n

def rec(u,d):
    dep[u] = d
    l = T[u].l
    r = T[u].r
    h1 = h2 = 0
    if l != -1:
        sib[l] = r
        deg[u] += 1
        h1 = rec(T[u].l,d+1)
    if r != -1:
        sib[r] = l
        deg[u] += 1
        h2 = rec(T[u].r,d+1)
    if deg[u] == 0:
        if ntype[u] != "root": ntype[u] = "leaf"
        hei[u] = 0
        return 1
    else:
        h = max(h1,h2)
        hei[u] = h
        return h+1

root = 0
while T[root].p != -1: root += 1
ntype[root] = "root"
rec(root,0)

for i in range(n):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i,T[i].p,sib[i],deg[i],dep[i],hei[i],ntype[i]))


Measured memory_bytes: 5612
/*
	If you only do what you can do, 
	You will never be more than you are now!
	----------------------------------------
	We must all suffer from one of two pains: the pain of discipline or the pain of regret. 
	The difference is discipline weighs grams while regret weighs tons.
4*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2000;
const int INF = 1e9;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int n, m;
char a[N][N];
int d[N][N];
queue <pii> q;

bool ok(int x, int y) {
	return (1 <= x && x <= n && 1 <= y && y <= m);
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	fo(i, 1, n, 1) {
		fo(j, 1, m, 1) {
			cin >> a[i][j];
			d[i][j] = INF;
			if(a[i][j] == '#') {
				d[i][j] = 0;
				q.push(mkp(i, j));
			}
		}
	}
	while(sz(q)) {
		int x2 = q.front().F;
		int y2 = q.front().S;
		q.pop();
		fo(i, 0, 3, 1) {
			int x = x2 + dx[i];
			int y = y2 + dy[i];
			if(ok(x, y) && d[x][y] > d[x2][y2] + 1) {
				d[x][y] = d[x2][y2] + 1;
				q.push(mkp(x, y));	
			}
		}
	}
	int ans = 0;
	fo(i, 1, n, 1) {
		fo(j, 1, m, 1) {
			ans = max(ans, d[i][j]);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 20752
a = int(input())
b = int(input())
if a == 1 and b == 2:
    print(3)
    exit()
if a == 2 and b == 1:
    print(3)
    exit()
if a == 1 and b == 3:
    print(2)
    exit()
if a == 3 and b == 1:
    print(2)
    exit()
if a == 2 and b == 3:
    print(1)
    exit()
if a == 3 and b == 2:
    print(1)
    exit()

Measured memory_bytes: 3064
N = gets.to_i
ABs = readlines.map{|l| l.split.map(&:to_i)}
M = 10**9 + 7
I2 = (M + 1)/2

@g = ABs.each_with_object(Array.new(N + 1){[]}){|(a, b), h| h[a] << b; h[b] << a}
st, pr, od = [1], [nil, 0], []
while !st.empty?
  od.unshift(u = st.pop)
  @g[u].each do |v|
    next if v == pr[u]
    pr[v] = u
    st << v
  end
end
sz = od.each_with_object(Array.new(N + 1, 1)){|v, o| o[pr[v]] += o[v]}
i2 = N.times.each_with_object([1]){|i, o| o << o.last * I2 % M}
I2N = i2[N]
puts (sz.drop(1).inject(0){|s, x| (s + (1 - i2[x] - i2[N - x] + I2N)) % M} - N*I2 - I2N + 1) % M

Measured memory_bytes: 45896
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using PQ = priority_queue<long long>; //erase  (でキーごと削除) push pop top 
using PQG = priority_queue<long long,L,greater<long long>>; //erase  (でキーごと削除) push pop top 
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define inf 1000000000000000000+10
#define setans long long ans=0;

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}


//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君


unordered_map<long long , L> u;
U cost;
U TF;


void dfs(long long point){
    for (auto item:u[point]){
        if (TF[item]){
            continue;
        }else{
            TF[item]=1;
            cost[item]+=cost[point];
            dfs(item);
            TF[item]=0;
        }
    }
}


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
    long long n,q,tmp1,tmp2,point=1;
    
    cin>>n>>q;
    
    TF[1]=1;

    for(long long i=0  ;i<n-1  ;i++){
        cin>>tmp1>>tmp2;
        u[tmp1].push_back(tmp2);
        u[tmp2].push_back(tmp1);
    }
    for(long long i=0  ;i<q  ;i++){
        cin>>tmp1>>tmp2;
        cost[tmp1]+=tmp2;
    }
    


    dfs(point);
    L ans(n+1,0);
    for(auto itr=cost.begin() ;itr!=cost.end() ;itr++){
        ans[itr->first]=itr->second;
    }
    for(long long i=1  ;i<n+1  ;i++){
        cout<<ans[i]<<" ";
    }
}


Measured memory_bytes: 53704
#include <stdio.h>

int quo,rem;

void divide_by_2(int x) {

  quo=x/2;
  rem=x%2;

}

int main(void) {

  int w;

  int count;

  while(scanf("%d",&w)!=EOF) {

    count=1;
    quo=w;

    while(quo>0) {

      divide_by_2(quo);
      
      if(rem==1) {
	
	if(quo==0) printf("%d\n",count);
	else printf("%d ",count);

      }

      count*=2;

    }

    //printf("\n");

  }

  return 0;

}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int a[maxn], b[maxn];
int main(){
	int n, k;
	cin >> n >> k;
	int sta = 0, stb = 0;
	for (int e = 0; e < n; e++){
		int x;
		cin >> x;
		if (x < 0)
			a[sta++] = x;
		if (x == 0)
			k--;
		if (x > 0)
			b[stb++] = x;
	}
	reverse(a, a + sta);
	int ans = 1 << 30;
	if (k > 0) {
		if (sta >= k)
			ans = min(ans, -a[k - 1]);
		if (stb >= k)
			ans = min(ans, b[k - 1]);
		for (int e = 0; e < min(sta, k - 1); e++){
			int rv = k - (e + 1);
			if(rv <= stb) ans = min(ans, -2 * a[e] + b[rv - 1]);
			if(rv <= stb) ans = min(ans, -a[e] + 2 * b[rv - 1]);
		}
	}
	else
		ans = 0;
	cout << ans << endl;
	return 0;
}


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

int a[26];

int main(){
    
    int n;
    string s;
    cin>>n>>s;
    ll ans=1;
  
    for(int i=0; i<n; i++){
        a[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        ans*=a[i]+1;
        ans%=mod;
    }
    cout<<ans-1<<endl;
}

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

int main(){
  
  int N, M, sum = 0, count = 0;
  
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++)
    cin >> s.at(i);
  
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++)
    cin >> t.at(i);

  for (int i=0; i<N; i++){

    for(int j=0; j<N; j++){
      if(s.at(i) == s.at(j))
        count++;
    }
    for(int j=0; j<M; j++){
      if(s.at(i) == t.at(j))
        count--;
    }
    
    sum = max(sum,count);
    count = 0;
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int max_happiness(int n,int arr[][3])
{
  int dp[n][3];
  dp[0][0]=arr[0][0];
  dp[0][1]=arr[0][1];
  dp[0][2]=arr[0][2];
  for(int i=1;i<n;i++)
  {
      dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
      dp[i][2] = arr[i][2] + max(dp[i-1][0],dp[i-1][1]);
  }
  return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{
  int n;
  cin>>n;
  int arr[n][3];
  for(int j=0;j<n;j++)
  {
    for(int i=0;i<3;i++)
    {
        cin>>arr[j][i];
    }
  }
  cout<<max_happiness(n,arr)<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
#define EPS (1E-10)
const int maxn=100000+10;
int n;

struct Point
{
    int x,y;
    Point() {}
    Point(int _x,int _y):x(_x),y(_y) {}
    Point operator -(Point p)
    {
        return Point(x-p.x,y-p.y);
    }
    bool operator <(Point p)
    {
        return x==p.x?y<p.y:x<p.x;
    }
    int cross(Point p)
    {
        return x*p.y-y*p.x;
    }
    int dot(Point p)
    {
        return x*p.x+y*p.y;
    }
    int norm()
    {
        return x*x+y*y;
    }

};
vector<Point> ps;

int ccw(Point p,Point p1,Point p2)
{
    #define COUNT_CLOCKWISE 1
    #define CLOCKWISE -1
    #define ONLINE_FRONT 2
    #define ONLINE_BACK -2
    #define ON_SEGMENT 0
    Point a=p1-p;
    Point b=p2-p;
    if(a.cross(b)<-EPS) return CLOCKWISE;
    if(fabs(a.cross(b)<EPS)) return CLOCKWISE;
    if(a.cross(b)>EPS) return COUNT_CLOCKWISE;
    if(a.dot(b)<-EPS) return ONLINE_BACK;
    if(a.norm()<b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;

}

bool is_convex(vector<Point> ps)
{
    int n=(int)ps.size();
    for(int i=0;i<n;i++)
    {
        if(ccw(ps[(i+1)%n],ps[(i)%n],ps[(i+2)%n])==COUNT_CLOCKWISE) return false;
    }
    return true;
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int x,y;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        ps.push_back(Point(x,y));
    }
//    vector<Point> qs=convex_hull(ps);
    if(is_convex(ps)) printf("1\n");
    else printf("0\n");


    return 0;

}

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

using namespace std;
typedef long long LL;
const int MaxN = 1e5;



int main()
{
	int n;
	cin >> n;
	LL ans;
	while(n--)
	{
		LL a, b,dd;
		cin >> a >> b;
		dd = a * b;
		LL t = sqrt(dd);
		if(t * (t + 1) < dd)
		{
			ans = t * 2 - 1;
		}
		else if(t * t == dd)
		{
			if(a == b)
			{
				ans = (t - 1) * 2;
			}
			else
			{
				ans = (t - 1) * 2 - 1;
			}
		}
		else
		{
			ans = (t - 1) * 2;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256