akhauriyash/Code-Regression huggingface dataset:
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	string	s;
	cin >> n >> s;
	int maxv = 0;
	int v = 0;
	rep(i, n)
	{
		if (s.at(i) == 'I')
			v++;
		else
			v--;
		maxv = max(maxv, v);
	}
	cout << maxv << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a,b;
  cin>>a>>b;
  int result=a-2*b;
  if(result>0){
    cout<<result<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
k = int(input())
a = [0 for _ in range(k)]
n = 7

a[0] = 7 % k
for i in range(1, k):
    a[i] = (a[i - 1] * 10 + 7) % k

for i in range(0, k):
    if a[i] == 0:
        print(i + 1)
        exit(0)
print(-1)

Measured memory_bytes: 48512
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define MOD 1000000007
//#define MOD 998244353
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INF (1LL << 60)
#define ff first
#define se second
//#define int long long

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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    string s,t;
    cin>>s>>t;
    int count=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout<<count<<endl;


}

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

int main () {
  int N;
  cin >> N;
  
  int ans = 0;
  if (N < 10) cout << N%10 << endl;
  else if (N < 100) cout << 9 << endl;
  else if (N < 1000) cout << N -99 +9 << endl;
  else if (N < 10000) cout << 909 << endl;
  else if (N < 100000) cout << N - 9999 + 909 << endl;
  else cout << 99999 - 9999 + 909 << endl;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

#define mkf(n,mod)  int *fact=(int *)malloc((n+1)*sizeof(int)); mfac((n),fact,(mod)) //enables to let x!=fact[x]
#define mkfiv(n,mod)  int *finv=(int *)malloc((n+1)*sizeof(int)); mfiv((n),finv,fact[n],(mod)) // 1/x! = finv[x]

int mmul(int p,int q,int m){ //O(1)?
    ll lp=p,lq=q; return ((lp%m)*(lq%m))%m;}

int mpow(int x,int n,int m){ //O(logN)
    ll res=x,ans=1;
    while(n!=0){
        if(n%2==0){ res = mmul(res,res,m);n>>=1;
        }else{      ans = mmul(ans,res,m);--n;}}return ans;}

int mdiv(int p,int q,int m){ //O(logMOD)
    return mmul(p,mpow(q,m-2,m),m);}

void mfac(int x,int *f,int m){//O(n)
    *f=1; for(int i=1;i<=x;++i)f[i]=mmul(f[i-1],i,m);}

void mfiv(int x,int *f,int fx,int m){//O(n)
    f[x] = mdiv(1,fx,m); 
    for(int i=x;i>0;--i)f[i-1]=mmul(f[i],i,m);}


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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin >>n>>m;

    int N_MAX=max(n,m);
    mkf(N_MAX,MOD);

    if(abs(m-n)>1){
        ans=0;
    }else{

        ans = mmul(fact[n],fact[m],MOD);
        if(abs(m-n)==0)ans = mmul(ans,2,MOD);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>

using namespace std;

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

  pair<int, int> p[n];
  pair<int, int> c[m];
  
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >>b;
    p[i] = make_pair(a, b);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    c[i] = make_pair(a, b);
  }

  for (int i = 0; i < n; i++) {
  int d = 1000000000;
  int ans = 0;
  for (int j = 0; j < m; j++) {
    int k = abs(p[i].first - c[j].first) + abs(p[i].second - c[j].second);
    if(k < d) {
      ans = j+1;
      d = k;
    }
  }
  cout << ans << endl;

  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 150
ll n,k,w[N],v[N],memo[N][(int)2e5];

ll dp(int curr , int val) {
    if (curr > n) return val == 0 ? 0 : INT_MAX;
    ll &sol = memo[curr][val];
    if (sol != -1) return sol;
    sol = dp(curr + 1 , val);
    if (val >= v[curr]) {
        sol = min(
            dp(curr + 1 , val - v[curr]) + w[curr] ,
            sol
        );
    }
    return sol;
}

int main() {
    scanf("%lld%lld" , &n , &k);
    ll sum = 0, highestw = LLONG_MIN;
    for (int i = 1 ; i <= n ; i++) {
        scanf("%lld%lld" , &w[i] , &v[i]);
        sum += v[i];
        highestw = max(highestw , w[i]);
    }
    memset (memo , -1 , sizeof memo);
    ll sol = LLONG_MIN;
    for (ll i = 1 ; i <= sum ; i++) {
        ll DP = dp(1 , i);
        if (DP == INT_MAX) continue;
        if (DP <= k)
            sol = max(sol , i);
    }
    printf("%lld\n" , sol);
}


Measured memory_bytes: 238148
N, A, B, C = gets.split.map(&:to_i)
$needs = [0, A, B, C]
$mp = []
BAMBOOS = N.times.map { gets.to_i }
# p BAMBOOS

$count = 0

def calc_mp(array)
  # 0: 使わない、 1: Aに使う、2: Bに使う、3: Cに使う
  if (array.include?(1) && array.include?(2) && array.include?(3))
    # 1, 2, 3があるパターンでないと条件を満たせない
    # p array
    mp = 0
    (1..3).each do |num|
      temp = array.map.with_index { |x, i| x == num ? BAMBOOS[i] : nil }.compact
      mp += ($needs[num] - temp.inject(:+)).abs + 10*(temp.size-1)
    end
    $mp << mp
  end
end

def dfs(array)
  if array.size == N
    $count += 1
    # puts "#{array} パターンの完成、#{$count}通り目。"
    calc_mp(array)
  else # array.size < N
    dfs(array+[0])
    dfs(array+[1])
    dfs(array+[2])
    dfs(array+[3])
  end

  if array.size == 0
    $count
  end
end

dfs([])
puts $mp.min


Measured memory_bytes: 2488
import java.util.HashSet;
import java.util.Scanner;

class UnionFind{
	int[] par;
	int N;
	public UnionFind(int n){
		N = n;
		par = new int[N];
		for(int i = 0; i < N; i++){
			par[i] = i;
		}
	}
	public int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	public Boolean same(int x, int y){
		return find(x) == find(y);
	}
	public void unite(int x, int y){
		if(find(x) == find(y)) return;
		par[find(x)] = find(y);
	}
	public int DistinctElementsNum(){
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i = 0; i < N; i++){
			find(i);
			set.add(find(i));
		}
		return set.size();
	}
}


class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		UnionFind uf = new UnionFind(N);
		for(int i = 0; i < M; i++) {
			int X = sc.nextInt();
			int Y = sc.nextInt();
			int Z = sc.nextInt();
			uf.unite(X - 1, Y - 1);
		}
		System.out.println(uf.DistinctElementsNum());
	}
}

Measured memory_bytes: 90416
#include <stdio.h>
#include <math.h>

int main()
{
    int t, x1, x2, x3, x4, y1, y2, y3, y4;
    double  m1, m2, temp;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d %d %d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);

        if(((x2-x1)*(x4-x3))+((y2-y1)*(y4-y3))==0)
        {
            printf("1\n");
        }
        else if(((x2-x1)*(y4-y3))==((y2-y1)*(x4-x3)))
        {
            printf("2\n");
        }
        else
        {
            printf("0\n");
        }
    }
}



Measured memory_bytes: 2136
// AOJ 1063: Watchin' TVA
// 2017.9.30 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HSIZ 1009
typedef struct { char *w; int k; } HASH;
HASH hash[HSIZ + 5], *hashend = hash + HSIZ;

int lookup(char *w)
{
	int l = strlen(w);
	int i = (101 * *w + 103 * *(w + l - 1) + 107 * l) % HSIZ;
	HASH *tp = hash + i;
	while (tp->w != NULL) {
		if (!strcmp(tp->w, w)) return tp->k;
		if (++tp == hashend) tp = hash;
	}
	return -1;
}

int insert(char *w, int k)
{
	int l = strlen(w);
	int i = (101 * *w + 103 * *(w + l - 1) + 107 * l) % HSIZ;
	HASH *tp = hash + i;
	while (tp->w != NULL) {
		if (!strcmp(tp->w, w)) return -1;
		if (++tp == hashend) tp = hash;
	}
	tp->w = w, tp->k = k;
	return 0;
}

typedef struct { int s, e, f; char nm[35]; } T;
T tbl[502];

int cmp(T *a, T *b) { if (a->s - b->s) return a->s - b->s; return b->f - a->f; }

int main()
{
	int n, p, i, j, k, e, ans;
	T *t;

	while (scanf("%d", &n) && n > 0) {
		memset(hash, 0, sizeof(hash));
		for (t = tbl, i = 0; i < n; i++, t++) {
			int w, s, h, m;
			scanf("%s%d%d", t->nm, &w, &s);
			h = s / 100, m = s % 100;
			t->s = (1440*w + h*60 + m) % 10080, t->e = t->s + 30; 
			t->f = 0;
			insert(t->nm, i);
		}
		scanf("%d", &p);
		while (p-- > 0) {
			char nm[35];
			scanf("%s", nm);
			k = lookup(nm); if (k < 0) k = 0;  // panic
			tbl[k].f = 1;
		}
		if (n == 1) { puts("1"); continue; }
		qsort(tbl, n, sizeof(T), cmp);

		for (k = 0; k < n; k++) if (tbl[k].f) break;
		if (k >= n) k = 0;		// panic
		for (ans = 1, i = k, j = k+1; ; j++) {
			if (i >= n) i = 0; if (j >= n) j = 0;
			if (j == k) break;
			if (tbl[i].e >= 10080) e = tbl[i].e - 10080; else e = 0;
			if ((tbl[i].s <= tbl[j].s && tbl[j].s < tbl[i].e) || tbl[j].s < e) {
				if (tbl[j].f && tbl[i].f) { ans = -1; break; }
				else if (tbl[j].f) i = j;
			} else if (tbl[j].s <= tbl[k].s && tbl[k].s < tbl[j].e) ; // do nothing
			else {
				ans++, i = j;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 1000001;
const ll M = 1;

struct point {
    ll x, y;
};

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

bool c(string s)
{
    ll n = s.size();
    for(int i = 0; i < n / 2; i++)
    {
        if(s[i] != s[n - i - 1]) return false;
    }
    return true;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, ans = 0, x, y, k, v;
        long double l;
        cin >> l;
        l = (l / 3.0);
        l = l * l * l;
        cout << fixed << setprecision(10) << l << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
a=make_divisors(n)
#print(a)
if a[-1]**2==n:
    print(a[-1]*2-2)
else:
    print(a[-1]+a[-2]-2)

Measured memory_bytes: 3268
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
import heapq

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

h = sorted(a[:N])
sum_h = sum(h)
h2 = sorted([-x for x in a[2*N:]])
sum_h2 = sum(h2)
max_h = [0]*(N+1)
max_h[0] = sum_h
min_h2 = [INF]*(N+1)
min_h2[-1] = sum_h2

for i in range(N, 2*N):
	if h[0] < a[i]:
		sum_h -= heapq.heappop(h)
		sum_h += a[i]
		heapq.heappush(h, a[i])
	max_h[i-N+1] = sum_h


for i in range(2*N-1, N-1, -1):
	if h2[0] < -a[i]:  # h2:最大値
		sum_h2 -= heapq.heappop(h2)
		sum_h2 += -a[i]
		heapq.heappush(h2, -a[i])
	min_h2[i-N] = sum_h2
# print(max_h)
# print(min_h2)
ans = -INF
for i in range(N+1):
	ans = max(ans, max_h[i]+min_h2[i])
print(ans)


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

int main(){
	string s;cin>>s;
	rep(i,3){
		if(s[i]==s[i+1]){
			puts("Bad");return 0;
		}
	}
	puts("Good");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);

	//0502
	static class Dice {
		int[] ndice= {1,5,2,3,0,4}, edice= {3,1,0,5,4,2};
		int[] wdice= {2,1,5,0,4,3}, sdice= {4,0,2,3,5,1};
		int[] rdice= {0,2,4,1,3,5}, ldice= {0,3,1,4,2,5};
		int sum;
		void topSum() {
			for(;;) {
				int n = Integer.parseInt(sc.nextLine());
				if(n==0) break;
				int[] dice = {1,2,3,4,5,6};
				sum = 1; //dice[0]
				for(int i=0; i<n; i++) {
					dice = turn(sc.nextLine(), dice);
					sum += dice[0];
				}
				System.out.println(sum);
			}
		}

		int[] turn(String comd, int[] dice) {
			int[] nd = new int[6];
			if(comd.equals("North")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[ndice[i]];
				}
			}else if(comd.equals("East")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[edice[i]];
				}
			}else if(comd.equals("West")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[wdice[i]];
				}
			}else if(comd.equals("South")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[sdice[i]];
				}
			}else if(comd.equals("Right")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[rdice[i]];
				}
			}else if(comd.equals("Left")) {
				for(int i=0; i<6; i++) {
					nd[i] = dice[ldice[i]];
				}
			}
			return nd;
		}
	}

	public static void main(String[] args) {
		//0502
		Dice d = new Dice();
		d.topSum();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	s = readline() |> chomp
	x = 0
	f = 0
	for i in 1:n
		if s[i]=='A'
			f = 1
		elseif f==1&&s[i]=='B'
			f = 2
		elseif f==2&&s[i]=='C'
			f = 0
			x += 1
		else
			f = 0
		end
	end
	println(x)
end

main()

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

int main() {
	// your code goes here
	int n=100000,money;
	cin >> money;
	for(int i=0;i<money;i++){
		n*=1.05;
		n+=999;
		n-=n%1000;
	}
	cout << n << endl;
	return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;

#define MAX 120

int main(void)
{
	char str[MAX];
	double x[MAX];
	double y[MAX];
	double diff[MAX];
	int i;
	int num;
	double mmax = 0;
	double sum[3] = {0};

	scanf("%d", &num);

	for (i=0; i<num; i++) {
		scanf("%lf", &x[i]);
	}
	for (i=0; i<num; i++) {
		scanf("%lf", &y[i]);
	}

	for (i=0; i<num; i++) {
		diff[i] = abs(x[i] - y[i]);
		sum[0] += diff[i];
		sum[1] += pow(diff[i],2);
		sum[2] += pow(diff[i],3);
		mmax = max(mmax,diff[i]);
	}

	printf("%lf\n", sum[0]);
	printf("%lf\n", sqrt(sum[1]));
	printf("%lf\n", pow(sum[2],1.0/3.0));
	printf("%lf\n", mmax);

	return 0;
}


Measured memory_bytes: 2944
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(s) (intt)s.size()

#define ms0(arr) memset(arr,0,sizeof arr)
#define ms63(arr) memset(arr,63,sizeof arr)

#define forn(i,a,b) for(intt i=a;i<=b;i++)
#define rofn(i,a,b) for(intt i=a;i>=b;i--)
#define setf(it,myset) for(set<intt>::iterator it=myset.begin();it!=myset.end();it++)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define VI vector<intt>
#define PII pair<intt,intt>
#define VPII vector< PII >

#define posl(ch) (int)(ch-'a'+1)
#define posL(ch) (int)(ch-'A'+1)

#define IO ios_base::sync_with_stdio(false);cin.tie();
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a,intt b){return __gcd(a, b);}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}

/**************************/
const intt MAX = 100005;

intt xr[MAX];
intt trie[MAX][2], cnt[MAX], nxt = 1;

void add (string s) {
    intt node = 0;
    forn (i, 0, s.size() - 1)
        if (trie[node][s[i] - 48] == 0)
            node = trie[node][s[i] - 48] = nxt;
        else
            node = trie[node][s[i] - 48];
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    /*
    intt n, x, k;
    cin >> n >> x;
    forn (i, 1, n) {
        cin >> k;
        xr[i] = k ^ xr[i - 1];
    }
    */
    intt n, ans = 100;
    cin >> n;
    forn (a, 1, sqrt (n))
        if (n % a == 0)
            ans = min (ans, max ((intt)log10 (a) + 1, (intt)log10 (n / a) + 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
int main(void)
{
    ll N, A[1000001], i, count, ans=0;
 
    cin >> N;
 
    for(i=1; i<=N; i++){
        cin >> A[i];
    }
 
    sort(A+1, A+N+1);
 
    count = 1;
 
    for(i=2; i<=N; i++){
        if(A[i-1]==A[i]){
            count++;
        }
 
        else{
            if(count % 2 == 1){
                ans++;
            }
 
            count = 1;
        }
    }
 
    if(/*A[N-1] == A[N] && */count%2==1){
        ans++;
    }
 
    if(N==1) ans = 1;
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>

using namespace std;

int main(){
    int N;
    cin >> N;
    
    vector <double> x;
    double sub1;
    vector <string> u;
    string sub2;
    for(int i = 0; i < N; i++){
        cin >> sub1;
        x.push_back(sub1);
        cin >> sub2;
        u.push_back(sub2);
    }
    
    double ans = 0;
    
    for(int i = 0; i < N; i++){
        if(u[i] == "JPY"){
            ans += x[i];
        }
        else{
            ans += x[i] * 380000;
        }
    }
    
    cout << ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 


#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

int main() {
    
    fastio;
    string s;
    cin >> s;
    int freq[26] = {0};
    rep(i, 4)
    freq[s[i]-'A']++;
    bool ans = true;
    rep(i, 4)
    if(freq[s[i]-'A'] != 2)
        ans = false;
    if(ans)
        cout << "Yes";
    else
        cout << "No";
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    vector<int> v(3);
    REP(i,3){
        cin>>v[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    int result=0;
    FOR(i,1,3){result+=v[i-1]-v[i];}
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 256
"""
~~ Author : Bhaskar
~~ Dated : 07~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi,log
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")

def solve():
    a = list(map(int,sys.stdin.readline().split()))
    print(a.index(0)+1)

if __name__ == "__main__":
    try:
        sys.stdin = open("input.txt","r")
    except :
        pass
    solve()


Measured memory_bytes: 9196
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int n, max = 0;
	int a[2][100];
	cin >> n;
	FOR(i, 0, 2) {
		FOR(j, 0, n) {
			cin >> a[i][j];
		}
	}
	int tmp = 0;
	FOR(j, 0, n) {
		FOR(s, 0, j+1) {
			tmp += a[0][s];
		}
		FOR(t, j, n) {
			tmp += a[1][t];
		}
		if (tmp >= max) max = tmp;
		tmp = 0;
	}
	cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

   int cnt=0;
   rep(i, n-2){
      if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
   }

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


Measured memory_bytes: 3604
n=gets.to_i
s=gets.chomp.chars
n.times do |i|
  if s[i]=="o"
    s[i]=0
  else
    s[i]=1
  end
end
[[0,0],[0,1],[1,0],[1,1]].each do |b0,b1|
  l=[b0,b1]
  1.upto(n-2) do |i|
    if (s[i]+l[i]+l[i-1]).even?
      l << 0
    else
      l << 1
    end
  end
  if (s[n-1]+l[n-1]+l[n-2]-l[0]).even?&&(s[0]+l[0]+l[n-1]-l[1]).even?
    n.times do |i|
      if l[i]==0
        print "S"
      else
        print "W"
      end
    end
    print "\n"
    exit
  end
end
puts "-1"


Measured memory_bytes: 23464
n, q = gets.split.map &:to_i
s = gets.chomp
# s = 'CACACACA'
begin_count = 0
begin_count_arr = Array.new(n+10, 0)

0.upto(n-2) do |i|
  if (s[i] + s[i+1]) == 'AC'
    begin_count += 1
  end
  begin_count_arr[i] = begin_count
end
q.times do
  l, r = gets.split.map(&:to_i)
  # p [l,r]
  # p [begin_count_arr[r], begin_count_arr[l]]
  # p [begin_count_arr[r-2], begin_count_arr[l-2]]
  # p [begin_count_arr[r-1], begin_count_arr[l-1]]
  # p [begin_count_arr[r+1], begin_count_arr[l+1]]
  # p [begin_count_arr[r+2], begin_count_arr[l+2]]
  p begin_count_arr[r-2] - begin_count_arr[l-2]
end

=begin
8 3
ACACTACG
3 7
2 3
1 8
=====
2
0
3
=end


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

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

    std::cin >> n;

    std::priority_queue<double, std::vector<double>, std::greater<double>> que;
    for (int i = 0; i < n; ++i) {
        double v;

        std::cin >> v;

        que.push(v);
    }

    while (que.size() != 1) {
        auto p1 = que.top();
        que.pop();
        auto p2 = que.top();
        que.pop();

        que.push((p1 + p2) / 2);
    }

    std::cout << std::fixed << std::setprecision(10) << que.top() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL)
int main() {
   int n,t;
   cin>>n>>t;
   string s;
   cin>>s;

   
   s[t-1]='a'+s[t-1]-'A';
   cout<<s;
    
   		 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr lli inf = 2e18;
 
int main(void){
    int n; scanf("%d", &n);
    lli s = 0, t = inf;
    REP(i, n){
        int a, b; scanf("%d%d", &a, &b);
        if(a > b and t > b) t = b;
        s += a;
    }
    if(t == inf) puts("0");
    else printf("%lld\n", s - t);
    return 0;
}

Measured memory_bytes: 504
def main():
    a, b = map(int, input().split())
    
    h = ((max(a, b) - 1) // 16 + 1) * 3
    w = 96 # 3 * 32

    print(h, w)

    ans = []
    line1 = ['.', '.', '.', '#', '#', '#'] * 16
    line2 = ['#', '#', '#', '.', '.', '.'] * 16

    for i in range(h//3):
        if i % 2 == 0:
            ans.append(line1.copy())
            ans.append(line1.copy())
            ans.append(line1.copy())
        else:
            ans.append(line2.copy())
            ans.append(line2.copy())
            ans.append(line2.copy())

    if a <= b:
        a, b = b, a
        flag = True
    else:
        flag = False

    if a % 16 > 0:
        for i in range(6 * (16 - a % 16) + 3):
            ans[-1][i] = '.'

    if h == 3:
        for i in range(6 * (16 - b) + 3):
            ans[0][i] = '#'
    else:
        num = h//3 * 16 - b
        for i in range(num // 16):
            if ans[2 + 3*i][0] == '.':
                for j in range(16):
                    ans[2 + 3*i][2 + 6*j] = '#'
            else:
                for j in range(16):
                    ans[2 + 3*i][3 + 6*j] = '#'

        if ans[-3][0] == '.':
            for i in range(num % 16):
                ans[-3][6 + 6*i] = '#'
        else:
            for i in range(num % 16):
                ans[-3][5 + 6*i] = '#'

    if flag:
        for i in range(h):
            for j in range(w):
                if ans[i][j] == '.':
                    ans[i][j] = '#'
                else:
                    ans[i][j] = '.'

    for i in ans:
        print(''.join(i))

main()

Measured memory_bytes: 65172
N = input()[::-1]
l = len(N)

n0 = int(N[0])
dp = [[0, 0] for i in range(l)]
dp[0] = [n0, 11-n0]

for i, n in enumerate(N[1:], 1):
  n = int(n)
  dp[i][0] = min(dp[i-1][0]+n, dp[i-1][1]+n)
  dp[i][1] = min(dp[i-1][0]+1+(10-n), dp[i-1][1]+(9-n))


print(min(dp[-1]))

Measured memory_bytes: 172076
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	int x, y;
	cin >> x >> y;
	cout << min({x * a + y * b, min(x, y) * c * 2 + (x - min(x, y)) * a + (y - min(x, y)) * b, 
	max(x, y) * c * 2});
}
int main(){
	speed;
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 256
# input
n = int(input())
S = [input() for _ in range(n)]

INF = float('inf')
alphabets = [INF] * 26

for i in range(n):
    alphabets[0] = min(S[i].count('a'), alphabets[0])
    alphabets[1] = min(S[i].count('b'), alphabets[1])
    alphabets[2] = min(S[i].count('c'), alphabets[2])
    alphabets[3] = min(S[i].count('d'), alphabets[3])
    alphabets[4] = min(S[i].count('e'), alphabets[4])
    alphabets[5] = min(S[i].count('f'), alphabets[5])
    alphabets[6] = min(S[i].count('g'), alphabets[6])
    alphabets[7] = min(S[i].count('h'), alphabets[7])
    alphabets[8] = min(S[i].count('i'), alphabets[8])
    alphabets[9] = min(S[i].count('j'), alphabets[9])
    alphabets[10] = min(S[i].count('k'), alphabets[10])
    alphabets[11] = min(S[i].count('l'), alphabets[11])
    alphabets[12] = min(S[i].count('m'), alphabets[12])
    alphabets[13] = min(S[i].count('n'), alphabets[13])
    alphabets[14] = min(S[i].count('o'), alphabets[14])
    alphabets[15] = min(S[i].count('p'), alphabets[15])
    alphabets[16] = min(S[i].count('q'), alphabets[16])
    alphabets[17] = min(S[i].count('r'), alphabets[17])
    alphabets[18] = min(S[i].count('s'), alphabets[18])
    alphabets[19] = min(S[i].count('t'), alphabets[19])
    alphabets[20] = min(S[i].count('u'), alphabets[20])
    alphabets[21] = min(S[i].count('v'), alphabets[21])
    alphabets[22] = min(S[i].count('w'), alphabets[22])
    alphabets[23] = min(S[i].count('x'), alphabets[23])
    alphabets[24] = min(S[i].count('y'), alphabets[24])
    alphabets[25] = min(S[i].count('z'), alphabets[25])

ans = ''
ans += 'a' * alphabets[0]
ans += 'b' * alphabets[1]
ans += 'c' * alphabets[2]
ans += 'd' * alphabets[3]
ans += 'e' * alphabets[4]
ans += 'f' * alphabets[5]
ans += 'g' * alphabets[6]
ans += 'h' * alphabets[7]
ans += 'i' * alphabets[8]
ans += 'j' * alphabets[9]
ans += 'k' * alphabets[10]
ans += 'l' * alphabets[11]
ans += 'm' * alphabets[12]
ans += 'n' * alphabets[13]
ans += 'o' * alphabets[14]
ans += 'p' * alphabets[15]
ans += 'q' * alphabets[16]
ans += 'r' * alphabets[17]
ans += 's' * alphabets[18]
ans += 't' * alphabets[19]
ans += 'u' * alphabets[20]
ans += 'v' * alphabets[21]
ans += 'w' * alphabets[22]
ans += 'x' * alphabets[23]
ans += 'y' * alphabets[24]
ans += 'z' * alphabets[25]

print(ans)

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

int main() {
  int n, array[100];
  int pointer = 0;
  while (cin >> n) {
    if (n == 0) {
      cout << array[--pointer] << endl;
    } else {
    array[pointer++] = n;
    }
  }
  return 0;
}


Measured memory_bytes: 3096
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1110111110111
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppl                      pair < int , pii>              
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,m;
    cin>>n>>m;
    if(n>m)
        swap(n,m);
    f(i,1,m)
        cout<<n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin >> n;
    if(n[0] == '9' || n[1] == '9')
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 10010
typedef long long ll;
typedef long double ld;
const ll inF=1e18;
int a,b,c,d;
int main(){
    cin>>a>>b>>c>>d;
    while (true){
        c-=b;
        if (c<=0){
                cout << "Yes"<< endl;
                exit(0);
        }
        a-=d;
        if (a<=0){
                cout << "No"<< endl;
                exit(0);
        }
    }
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   string s;
   cin >> s;

   set<char> ans;
   bool found = false;
   for(char c = 'a'; c <= 'z'; c++){
      found = false;
      for(int i = 0; i < s.size(); i++){
         if(c == s[i]){
            found = true;
            break;
         }
      }
      if(not(found)){
         cout << c << endl;
         return 0;
      }
   }
   cout << "None" << endl;

   return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define INF 1000000
void warshall_floyd(void);
int min(int,int);
int graph[101][101];
int n,c,d;

int main(void){
  int k,i,j,x,e,a,b;

  while(1){

    scanf("%d %d",&n,&k);
    if(n==0 && k==0)break;

    for(i=0;i<=n;i++)
      for(j=0;j<=n;j++)
	graph[i][j] = (i==j?0:INF);

    for(i=0;i<k;i++){
      scanf("%d",&x);
      
      if(x){
	scanf("%d %d %d",&c,&d,&e);
	if(graph[c][d]>e){
	graph[c][d]=graph[d][c]=e;
	warshall_floyd();
	}
      }
      else{
	scanf("%d %d",&a,&b);
	if(graph[a][b]<INF)printf("%d\n",graph[a][b]);
	else printf("-1\n");
      }
    }
  }
  
  return 0;
}

void warshall_floyd(void){
  int i,j;

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
      }
    }
}

int min(int x,int y){
  return (x<y)?x:y;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, res = 1;
    cin >> n;
    string s;
    cin >> s;
    char cur = s[0];
    for (int i = 1; i < s.size(); ++i) {
    	if (s[i] == cur) continue;
    	res++;
    	cur = s[i];
    }
    cout << res << '\n';
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <vector>
using namespace std;
 
int main()
{
	int n;
	map<long long, int> s;
	vector<long long> v;
	while(cin >> n)
	{
		s.clear();
		v.clear();
		for(int i=0; i<n; i++)
		{
			long long x;
			cin >> x;
			s[x]++;
		}
		map<long long, int>::reverse_iterator it;
		for(it=s.rbegin(); it!=s.rend(); it++)
		{
			//cout << it->first << endl;
			//cout << it->second << endl;
			if(it->second>=4&&(int)v.size()==0)
			{
				cout << it->first*it->first << endl;
			    return 0;
			}
			if(it->second>=2)
				v.push_back(it->first);
			if((int)v.size()==2)
				break;
		}
		if((int)v.size()==2)
			cout << v[0]*v[1] << endl;
		else
			cout << "0" << endl;
		return 0;
	}
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[4];
  string ans = "Good";
  for(int i=0;i<4;++i) cin >> s[i];
  for(int i=0;i<3;++i) {
    if(s[i]==s[i+1]) ans = "Bad";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
k,a,b = map(int,input().split())
biscuits = 1

if b - a <= 1:
        biscuits = k+1
else:
    p = k - a + 1
    biscuits = a + (b - a) * (p // 2)
    biscuits = biscuits + (k - a + 1) % 2

print(biscuits)

Measured memory_bytes: 2940
using System;
using static System.Console;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        int n = int.Parse(ReadLine());
        string[] arare = ReadLine().Split(' ');
        var Hash = new HashSet<string>();
        for(int i = 0;i < n;i++){
            Hash.Add(arare[i]);
        }
        if(Hash.Count == 3){
            WriteLine("Three");
        }else if(Hash.Count == 4){
            WriteLine("Four");
        }else{
            
        }
    }
}

Measured memory_bytes: 13280
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int a, b;
  cin >> a >> b;
  ll res = linf;
  if(a % 3 == 0 || b % 3 == 0){
    cout << 0 << endl;
    return 0;
  }else{
    res = min(a, b);
  }
  for(int i = -2; i < 3; i++){
    ll k = b / 3 + i;
    if(k >= b || k <= 0)continue;
    ll l = a * k;
    ll r1 = (b - k) * (ll)(a / 2);
    ll r2 = (b - k) * a - r1;
    res = min(res, max(l, max(r1, r2)) - min(l, min(r1, r2)));
  }
  for(int i = -2; i < 3; i++){
    ll k = a / 3 + i;
    if(k >= a || k <= 0)continue;
    ll l = b * k;
    ll r1 = (a - k) * (ll)(b / 2);
    ll r2 = (a - k) * b - r1;
    res = min(res, max(l, max(r1, r2)) - min(l, min(r1, r2)));
  }
  cout << res << endl;
	return 0;
}


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << "\n"

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    rep(i,9) q.push(i+1);

    ll x;
    rep(i,k){
        x = q.front(); q.pop();
        if(x%10!=0) q.push(10*x+x%10-1);
        q.push(10*x+x%10);
        if(x%10!=9) q.push(10*x+x%10+1);
    }
    print(x);
    
    return 0;
}

Measured memory_bytes: 1792
import sys
from functools import lru_cache
sys.setrecursionlimit(500000)
mod = 10**9+7
@lru_cache(maxsize=None)
def partition(n, k):  # 自然数 n を k 個の自然数の和で表す場合の数
    if n < 0 or n < k:
        return 0
    elif k == 1 or n == k:
        return 1
    else:
        return (partition(n-k, k) + partition(n-1, k-1)) % mod  # 1 を使わない場合と使う場合の和
n, k = map(int, input().split())
print(partition(n, k))



Measured memory_bytes: 29712
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << 1 << endl;
		return;
	}
	vector<pair<long, long>> ps(n);
	set<pair<long, long>> ds;
	for (int i = 0; i < n; i++)
	{
		cin >> ps[i].first >> ps[i].second;
	}
	sort(ps.begin(), ps.end());
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
	{
		if (ps[j].first!=ps[i].first || ps[j].second!=ps[i].second)
		{
			ds.insert({ps[j].first-ps[i].first, ps[j].second-ps[i].second});
		}
	}
	int ans = 1024;
	for (auto p : ds)
	{
		long dx = p.first, dy = p.second;
		vector<int> vst(n), par(n, -1);
		for (int i = 0; i < n; i++)
		{
			if (!vst[i])
			{
				par[i] = i;
			}
			vst[i] = 1;
			for (int j = i+1; j < n; j++)
			{
				if ((ps[i].first+dx == ps[j].first) && (ps[i].second+dy == ps[j].second))
				{
					par[j] = par[i];
					vst[j] = 1;
				}
			}
		}
		set<int> cnt;
		for (int v : par)
		{
			cnt.insert(v);
		}
		ans = min(ans, (int)cnt.size());
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	map<int, int> mp;
	for(int i = 0; i < n; ++i) {
		int k;
		cin >> k;
		for(int j = 0; j < k; ++j) {
			int a;
			cin >> a;
			
			mp[a - 1]++;
		}
	}
	
	int ans = 0;
	for(int i = 0; i < m; ++i) {
		if( mp[i] == n ) ans++;
	}

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


Measured memory_bytes: 256
import Data.List

ans :: [Int] -> Int
ans t =
  let s = reverse $ sort t
      z = zip [0..] s
      o = foldl (\s (a,b) -> s + a*b) 0 z
  in
    o

play :: [Int] -> [Int]
play [] = []
play (0:_) = []
play (n:x) =
  let i' = take n x
      xs = drop n x
      o  = ans i'
  in
    (o:play xs)

main = do
  c <- getContents
  let i  = map read $ lines c :: [Int]
      o  = play i
  mapM_ print o

  

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

int main() {
	int r, g, b;
	cin >> r >> g >> b;

	if((100 * r + 10 * g + 1 * b) % 4 == 0)	cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
char t[10000000];
int len;
int main()
{
	cin>>s;
	len=s.size();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='b') t[len-i-1]='d';
		else if(s[i]=='d') t[len-i-1]='b';
		else if(s[i]=='p') t[len-i-1]='q';
		else if(s[i]=='q') t[len-i-1]='p';
	}
//	cout<<endl;
//	cout<<"s="<<s<<endl;
//	cout<<"t="<<t<<endl;
	for(int i=0;i<len;i++)
		if(s[i]!=t[i])
		{
			cout<<"No\n";
			return 0;
		}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 512
def GCD(x, y):
    if y == 0:
        return x
    return GCD(y, x % y)


def LCM(x, y):
    return x // GCD(x, y) * y


def F(X, C, D):
    res = X // C + X // D
    res -= X // LCM(C, D)
    return res


if __name__ == "__main__":
    A, B, C, D = map(int, input().split())
    can_div = F(B, C, D) - F(A - 1, C, D)
    print(B - A + 1 - can_div)

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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  string ans = "NO";
  int A, B, X;
  cin >> A >> B >> X;

  if (A <= X && X <= (A + B)) {
    ans = "YES";
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256