akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n;
	while(cin>>n&&n!=0)
	{
		int a[10][5]={};
		REP(i,n){REP(j,5){cin>>a[i][j];}}
		
		int ans(0);
		
		while(true)
		{
			int count(0);
			bool b[10]={};//i列目を消すならフラグ
			int c[10]={};//連続する一つ目の位置
			int d[10]={};//連続した個数
			int e[10]={};//連続した数字
			
			//一行毎に判定。○なら数字を10に変えて、ポイントを足す
			REP(i,n){
				c[i]=0;
				d[i]=1;	
				e[i]=a[i][0];
				REP(j,4)
				{
					if(a[i][j+1]==a[i][j])
					{
						d[i]++;
						if(d[i]>=3&&e[i]!=10){b[i]=true;}
					}
					else
					{
						if(b[i]){break;}
						else
						{
							c[i]=j+1;
							d[i]=1;
							e[i]=a[i][j+1];
						}
					}
				}
			}
		
			for(int i=0;i<n;i++)
			{
				if(b[i])
				{
					count++;
					ans+=e[i]*d[i];
					for(int j=c[i];j<c[i]+d[i];j++)
					{
						a[i][j]=10;
					}
				}
			}
		
			//消した行が1以上なら、タテに下詰する
			if(count>0)
			{
				for(int i=0;i<5;i++)
				{
					for(int j=0;j<n;j++)
					{
						if(a[j][i]==10)
						{
							for(int k=j;k>0;k--)
							{
								int tmp = a[k][i];
								a[k][i]=a[k-1][i];
								a[k-1][i]=tmp;
							}
						}
					}
				}
				
			}
			//消した行が0なら終わり
			if(count==0){break;}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, i, j;
	cin >> n;
	double p[n+1];
	fr(i,1,n+1)
		cin >> p[i];
	double dp[n+1][n+1];
	fr(i,0,n)
		fr(j,0,n)
			dp[i][j] = 0;
	dp[1][1] = p[1];
	dp[1][0] = 1 - p[1];
	fr(i,2,n+1)
		fr(j,0,i+1)
		{
			if(j > 0)
				dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
			else
				dp[i][j] = dp[i-1][j]*(1-p[i]);
		}
	double ans = 0;
	fr(i,n/2 + 1, n+1)
		ans += dp[n][i];
	std::cout << std::fixed << std::setprecision(10) << ans;
}

Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX 2000001

void Counting_Sort(vector<int> A,int B[],int k){
  vector<int> C(k,0);
  

  int len = (int)A.size();
  for(int j = 0 ; j < len ; j++){
    C[A[j]]++;
  }

  for(int i = 1 ; i <= k ; i++){
    C[i] += C[i-1];
  }
 
  for(int j = len-1 ; j >= 0 ; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

int main(){
  int n;

  cin >> n;

  vector<int> A(n);
  int B[MAX];
  int k = 0;

  for(int i = 0 ; i < n ; i++){
    cin >> A[i];
    k = max(k,A[i]);
  }

  Counting_Sort(A,B,k);

  for(int i = 1 ; i <= (int)A.size() ; i++){
    if(i == 1){
      cout << B[i];
    }else{
      cout << " " << B[i];
    }
  }
  cout << endl;

  return 0;
}

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

#define ankit_2305 cerr<<"\nTime taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<" sec\n";
#define START clock_t
#define TIMER time_p=clock();
#define ll long long

#define MOD 1000000007

using namespace std;

int main(){
    START TIMER
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	ll a;
	float b;
	cin>>a>>b;
	b += 0.005;
	ll b2 = b*100;
	ll ans = (a*b2)/100;
	cout<<ans<<"\n";
    ankit_2305
    return 0;
}


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

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = ab[0]; var b = ab[1];

            if (a >= 10 || b >= 10) Console.WriteLine(-1);
            else Console.WriteLine(a * b);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
ll n;
ll a[5];
int main()
{
    cin>>n;
    for(int i=0;i<5;i++) cin>>a[i];
    sort(a,a+5);
    cout<<(ll)ceil(1.*n/a[0])+4;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(1,int(n**(1/2))+1):
  if n%i==0:
    a.append(i)
    a.append(int(n/i))
print(a[-1]+a[-2]-2 if len(a)%2==0 else a[-1]*2-2)

Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    
    // 1. 入力情報.
    LL K, A, B;
    scanf("%lld %lld %lld", &K, &A, &B);
    
    // 2. ビスケットの枚数の最大値を出力.
    // 2-1. A が B - 1 以上 or K が A以下.
    if(A >= B - 1 || K <= A){
        printf("%lld\n", K + 1);
        return 0;
    }
    
    // 2-2. 上記以外.
    LL q = (K - A - 1) / 2;
    LL r = (K - A - 1) % 2;
    if(r) printf("%lld\n", B + q * (B - A) + 1);
    else  printf("%lld\n", B + q * (B - A));
    return 0;
    
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int n;
  cin >> n;
  vector<int> vec(n-1),vec_2(n,0);
  int i;
  for(i=0;i<n-1;i++){
    cin >> vec.at(i);
  }
  for(i=0;i<n-1;i++){
    vec_2.at(vec.at(i)-1)++;
  }
  for(i=0;i<n;i++){
    cout << vec_2.at(i) << endl;
  }
}
     
  

Measured memory_bytes: 4776
// AOJ 1369: Distribution Center
// 2017.11.3 bal4u@uu

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

int yp[100002];
int l[200002], r[200002];

char buf[20], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, x, xmin, xmax;

	fgets(bp=buf, 20, stdin);
	n = getint(), bp++, m = getint();
	fgets(bp=buf, 20, stdin);
	x = getint(), bp++, yp[x] = getint();
	xmin = xmax = x;
	i = m-1; while (i--) {
		fgets(bp=buf, 20, stdin);
		x = getint(), bp++, yp[x] = getint();
		if (x < xmin) xmin = x;
		else if (x > xmax) xmax = x;
	}

	for (i = 1; i <= n; i++) l[i] = i;
	memcpy(r, l, sizeof(int)*(n+1));

	for (x = xmin; x <= xmax; x++) {
		if (i = yp[x]) l[i+1] = l[i], r[i] = r[i+1];
	}
	printf("%d", r[1]-l[1]+1);
	for (i = 2; i <= n; i++) printf(" %d", r[i]-l[i]+1);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 3828
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    X, N = map(int, readline().split())
    p = set(map(int, readline().split()))
    pallset = set(range(-1, 102))
    remain = pallset - p
    dist = 200; ans = []
    for i in remain:
        if dist > abs(i-X):
            dist = abs(i-X)
            ans.append((i, dist))
    ans.sort(key=lambda x: x[1])
    print(ans[0][0])

if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include<stdio.h>
int main(){
  int i,n,j,k=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    if( i%3==0) {
      printf(" %d",i);
      continue;}
    if( i%10==3 ){
       printf(" %d",i);
       continue;
     }
    j=i;
    while(k=1){
      j=j/10;
      if(j==0) break;
      if(j%10==3  ) {
        printf(" %d",i);
        break;} 


    }
  }
  printf("\n");

return 0;
}



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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x / gcd(x, y) * y;
}

int main()
{
	ll n;
	cin >> n;
	ll ans = 1LL;
	for (int i = 0; i < n; i++) {
		ll t;
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,A;
  cin >> H >> A;
  
  if(H-H/A*A==0) {
    cout << H/A << endl;}
  else if(H-H/A*A>=0) {
    cout << H/A+1 << endl;}
  }
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main()
{
    int N, M;
    bool f = true;
    cin >> N >> M;
    vector<int> s(M), c(M), ans(N);
    rep(i, N)
    {
        if (i == 0 && N != 1)
        {
            ans.at(i) = 1;
        }
        else
        {
            ans.at(i) = 0;
        }
    }
    rep(i, M)
    {
        cin >> s.at(i) >> c.at(i);
        ans.at(s.at(i) - 1) = c.at(i);
    }
    rep(i, M)
    {
        rep(j, M)
        {
            if ((s.at(i) == s.at(j)) && (c.at(i) != c.at(j)))
            {
                f = false;
                break;
            }
            else if (N != 1 && ans.at(0) == 0)
            {
                f = false;
                break;
            }
        }
        if (f == false)
        {
            break;
        }
    }
    if (f)
    {
        rep(i, N)
        {
            cout << ans.at(i);
        }
        cout << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
flag = False
for x in reversed(range(N + 1)):
    for y in reversed(range(N + 1 - x)):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            flag = True
            break
    else:
        continue
    break
if not flag:
  print(-1, -1, -1)

Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef double db;
int Mx,Sum;
int n;

int main()
{
  cin>>n;
  int x;Mx=0;
  for(int i=1;i<=n;++i) {
	cin>>x;Sum+=x;if(Mx<x) Mx=x;
  }
  Sum-=Mx;
  if(Mx<Sum) puts("Yes");
  else puts("No");
  return 0;
}


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

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

#define MOD 998244353
ll self_square(ll a, ll b){
    if(b == 0) return 1;
    if(b%2 == 0){
        ll t = self_square(a, b/2);
        return t * t % MOD;
    }
    return a * self_square(a, b-1) % MOD;
}

const int maxn = 200000;
int fac[maxn], invfac[maxn];

long long qpow(long long a, long long b){
    long long s = 1;
    while (b > 0) {
        if (b & 1)s = s * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return s;
}
void init() {
    int n = maxn - 1;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % MOD;
    invfac[n] = qpow(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; --i) {
        invfac[i] = 1ll * invfac[i + 1] * (i + 1) % MOD;
    }
}
long long comb(int n, int m) {
    if (n < m) return 0;
    return 1ll * fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  init();
  ll n, m, k;
  ll ans = 0;
  cin >> n >> m >> k;
  for(int i = (n-1 - k); i <= n-1; i++){
    ans += (((comb(n-1, i) * m) % MOD) * self_square(m-1, i)) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, r;
  cin >> n >> r;
  cout << r + 100 * max(0, 10 - n) << endl;
}

Measured memory_bytes: 256
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	fastio;
	int n,m;
	cin>>n>>m;
	int a[m];
	int sum=0;
	f(m)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)cout<<-1;
	else cout<<n-sum;
	
		
	
	
	
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define maxn 100005
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pp;
const long long inf = 2e18;
int n,m,q; string s,t; int c1[maxn][2],c2[maxn][2];
main(){
	//ios::sync_with_stdio(false); cin.tie(0);
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);
	//freopen("inp.txt","r",stdin);
	cin>>s>>t; n=s.size(); m=t.size(); int i,j,k;
	s='?'+s; t='?'+t;
	cin>>q;
	for (i=1;i<=n;i++){
		c1[i][0]=c1[i-1][0]; c1[i][1]=c1[i-1][1];
		if (s[i]=='A') c1[i][0]++;
		else c1[i][1]++;
	}
	for (i=1;i<=m;i++){
		c2[i][0]=c2[i-1][0]; c2[i][1]=c2[i-1][1];
		if (t[i]=='A') c2[i][0]++; else c2[i][1]++;
	}
	int a,b,c,d;
	while (q--){
		cin>>a>>b>>c>>d;
		int h1=(c1[b][0]-c1[a-1][0])-(c1[b][1]-c1[a-1][1]);
		int h2=(c2[d][0]-c2[c-1][0])-(c2[d][1]-c2[c-1][1]);
		h1%=3; if (h1<0) h1+=3; 
		h2%=3; if (h2<0) h2+=3;
		if (h1==h2) cout<<"YES\n";
		else cout<<"NO\n";
	}
}

Measured memory_bytes: 3940
package main

import (
	"fmt"
)

func main() {
	var (
		s string
		c int
	)

	fmt.Scan(&s)

	l := 0
	r := len(s) - 1
	for l < r {
		if s[l] != s[r] {
			c++
		}
		l++
		r--
	}

	fmt.Println(c)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pair<LL,LL>> xy(N);
    REP(i,N){
        int x,y;
        cin >> x >> y;
        xy[i] = make_pair(x,y);
    }
    sort(xy.begin(),xy.end());
    int minus = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            int tmpminus = 0;

            LL p = xy[j].first - xy[i].first;
            LL q = xy[j].second - xy[i].second;
            REP(k,N){
                FOR(l,i+1,N){
                    if(xy[l].first-xy[k].first == p && xy[l].second-xy[k].second == q) tmpminus++;
                }
            }
            if(minus < tmpminus) minus = tmpminus;
        }

    }

    cout << N - minus << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

struct Node{
	int mx=-1;
	vector<int> from;
}; vector<Node> grp;

void build(int n,int e){
	grp.resize(n);
	int s,t;
	For(i,1,e){
		cin>>s>>t;
		s--; t--;
		grp[t].from.emplace_back(s);
	}
}

int go(int n){
	if(grp[n].mx!=-1) return grp[n].mx;
	int mx=-1;
	for(auto &i:grp[n].from){
		mx=max(mx,go(i));
	}
	grp[n].mx=mx+1;
	return grp[n].mx;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,e; cin>>n>>e;
	build(n,e);
	int m=0;
	For(i,0,n-1){
		m=max(m,go(i));
	}
	cout<<m<<"\n";
	return 0;
}


























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

#ifdef LOCAL 
#include "/home/gokul/Codes/lib/prettyprint.hpp"
#else
#define debug(...) 2
#endif

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int h, w;
  cin >> h >> w;

  vector<vector<int>> a(h+1, vector<int> (w+1));
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j)
      cin >> a[i][j];

  for (int i = 1; i <= h; ++i) {
    for (int j = 1, x; j <= w; ++j) {
      cin >> x;
      a[i][j] -= x;
      a[i][j] = abs(a[i][j]);
    }
  }

  bool dp[h+1][w+1][20000];
  dp[1][0][0] = 1;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 0; k < 20000; ++k) {
        if (dp[i-1][j][k] || dp[i][j-1][k]) {
          int l = abs(k - a[i][j]);
          int r = abs(k + a[i][j]);
          dp[i][j][l] = 1;
          if (r < 20000)  dp[i][j][r] = 1;
        } 
      }
    }
  } 

  int ans = INT_MAX;
  for (int i = 0; i < 20000; ++i)
    if (dp[h][w][i]) {
      ans = i;
      break;
    }

  cout << ans << '\n';
}

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

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

	cin >> N;
	cout << (N - 1) / 2 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
 		cin>>n;
        cout<<a[n-1];
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define M 1000000007
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define mp make_pair
#define bs binary_search
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Rishabh
  *
  */
int main()
{
	ibs;
	cti;
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	int c=0;
	for(int i=0;i<k;i++)
	c=c+a[i];
	cout<<c<<"\n";
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    
    vector<ll> s(n+1);
    rep(i,n) s.at(i+1)=s.at(i)+a.at(i);
    
    sort(all(s));
    ll ans=0;
    ll now=-20000000000;
    ll cnt=0;
    rep(i,n+1){
        if(s.at(i)!=now){
            ans+=cnt*(cnt-1)/2;
            now=s.at(i);
            cnt=1;
        }
        else cnt++;
    }
    ans+=cnt*(cnt-1)/2;
    
    cout<<ans<<endl;
}


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

int main()
{
    long long N, A, B; cin >> N >> A >> B;
    if (A > B || (N == 1 && A != B)) cout << 0 << endl;
    else
    {
        const auto min = (N-1)*A + B, max = A + (N-1)*B;
        cout << max-min+1 << endl;
    }
}


Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
a = [input() for i in range(n)]
b = [input() for i in range(m)]

ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            ans = "Yes"
            break
    else:
        continue
    break

print(ans)

Measured memory_bytes: 10104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
           int n = sc.nextInt();
           int x = sc.nextInt();
           int t = sc.nextInt(); // minutes

           int time = 0;
           int made = 0;
           
           while (n > made ) {
        	   made += x;
        	   time += t;
           }

           System.out.println(time);

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}


Measured memory_bytes: 35804
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	string S;
	cin >> S;
	int r{0}, b{0};
	for (auto c : S)
	{
		if (c == '0')
		{
			++r;
		}
		else
		{
			++b;
		}
	}
	cout << 2 * min(r, b);
}

Measured memory_bytes: 1144
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node *Node;
Node root;

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){return u;}
  if(k < u->key){return treeSearch(u->left,k);}
  else{return treeSearch(u->right,k);}
}

Node treeSuccessor(Node x){
}

void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL){
    y = z;
  }

  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->p = y->p;
  }
  if(y->p == NIL){
    root = x;
  }else if(y == y->p->left){
    y->p->left = x;
  }else{
    y->p->right = x;
  }

  if(y != z){
    z->key = y->key;
  }
}
    

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

    
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root,x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20448
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int L[2000];
int y[2001];
int main(){
  int i;
  long long res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(L[Lj4PdHRW]);
    }
  }
  res = (long long) N * (N-1) * (N-2) / 6;
  for(i=(0);i<(N);i++){
    int j;
    for(j=(i+1);j<(N);j++){
      y[L[i]+L[j]]++;
    }
  }
  for(i=(1);i<(2001);i++){
    y[i] += y[i-1];
  }
  for(i=(0);i<(N);i++){
    res -= y[L[i]];
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191027-1

// --- original code ---
// int N, L[2000];
// int y[2001];
// {
//   ll res;
//   rd(N,L(N));
//   res = (ll) N * (N-1) * (N-2) / 6;
//   rep(i,N) rep(j,i+1,N) y[L[i]+L[j]]++;
//   rep(i,1,2001) y[i] += y[i-1];
//   rep(i,N) res -= y[L[i]];
//   wt(res);
// }


Measured memory_bytes: 256
object Main extends App {
  import scala.math.{min,max}
  def g(a:Long,b:Long):Long = {
    val x = min(a,b)
    val y = max(a,b)
    if (x == 0) y
    else g(x,y%x)
  }
  
  val Array(a,b) = readLine.split(" ").map{_.toLong}
  val gg = g(a,b)
  val Array(aa,bb) = Array(a/gg,b/gg)
  println(gg*aa*bb)
}

Measured memory_bytes: 25496
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int a[100][100];
int dp[22][(1<<22)];

int compute(int i, int ws, int n){
    if(i == n+1)    return (ws == 0) ? 1 : 0;
    
    if(dp[i][ws] != -1) return dp[i][ws];
    
    int ans=0;
    forI(w, 0, n-1){
        if((ws&(1<<w)) && a[i][w+1]){
            ans = (ans%mod + compute(i+1, ws^(1<<w), n)%mod)%mod;
        }
    }

    return dp[i][ws] = ans;
}

void solve(){
    int n;  cin>>n;
    forI(i, 1, n)   forI(j, 1, n)   cin>>a[i][j];
    memset(dp, -1, sizeof dp);
    cout<<compute(1, (1<<n)-1, n);
}   

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 724508
import scala.io.StdIn

object Main extends App {

  val matrixSize = 8
  val free = -1
  val notFree = 1

  val rows = Array.fill(matrixSize)(free)
  val cols = Array.fill(matrixSize)(free)
  val dpos = Array.fill(2 * matrixSize - 1)(free)
  val dneg = Array.fill(2 * matrixSize - 1)(free)

  val x = Array.fill(8, 8)(false)


  val n = StdIn.readLine().toInt
  (0 until n).foreach { _ =>
    val Array(r, c) = StdIn.readLine().split(" ").map(_.toInt)
    x(r)(c) = true
  }

  def printBoard(): Unit = {
    val rc = for (r <- 0 until matrixSize;
                  c <- 0 until matrixSize if x(r)(c)
    ) yield (r, c)
    val judge = rc.forall(e => rows(e._1) == e._2)
    if (judge) {
      for (r <- 0 until matrixSize;
           c <- 0 until matrixSize) {
        print(if (rows(r) == c) "Q" else ".")
        if (c == matrixSize - 1) println()
      }
    }
  }

  def recursive(i: Int): Unit = {
    if (i == matrixSize) {
      printBoard()
    } else {
      for (j <- 0 until matrixSize) {
        if (cols(j) != notFree
          && dpos(i + j) != notFree
          && dneg(i - j + matrixSize - 1) != notFree) {
          rows(i) = j
          cols(j) = notFree
          dpos(i + j) = notFree
          dneg(i - j + matrixSize - 1) = notFree
          recursive(i + 1)
          rows(i) = free
          cols(j) = free
          dpos(i + j) = free
          dneg(i - j + matrixSize - 1) = free

        }
      }
    }
  }

  // main start
  recursive(0)

}




Measured memory_bytes: 45664
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;

int main(void){
	ll N,K;
	cin >> N >> K;
	vector<int> pass(N,0);
	vector<int> A(N,0);
	for(int s=0;s<N;s++){
		int p;
		cin >>p;
		A[s]=p-1;
	}
	int j=0;
	int count=0;
	pass[j]+=1;
	while(1){
		j=A[j];
		K--;
		pass[j]++;
		if(pass[j]==2){
			count++;
		}
		if(pass[j]==3){
			K=K%count;
		}
		//cout <<j+1<<" "<<endl;
		if(K==0){
			cout << j+1;
			return 0;
		}
	}
}

Measured memory_bytes: 4844
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    
    string s;
    cin >> s;
    
    int cntUp = 0;
    int cntDown = 0;
    vector<int> up;
    vector<int> down;
    
    if(s[0] == '0') {
        down.push_back(0);
    }
    
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '0') {
            cntUp++;
        }
        else {
            cntDown++;
        }
        
        if(i == s.size() - 1 || s[i] != s[i + 1]) {
            if(s[i] == '0') {
                up.push_back(cntUp);
                cntUp = 0;
            }
            else {
                down.push_back(cntDown);
                cntDown = 0;
            }
        }
    }
    
    if(s[s.size() - 1] == '0') {
        down.push_back(0);
    }
    
    if(k >= up.size()) {
        cout << n << endl;
    }
    else {
        int cnt = 0;
        for(int i = 0; i < k; i++) {
            cnt += up[i];
            cnt += down[i];
        }
        cnt += down[k];
        
        int ans = cnt;
        int index = 0;
        while(k + index != up.size()) {
            cnt -= up[index];
            cnt -= down[index];
            
            cnt += up[k + index];
            if(k + index + 1 < down.size()) {
                cnt += down[k + index + 1];
            }
            
            if(ans < cnt) {
                ans = cnt;
            }
            
            index++;
        }
        
        cout << ans << endl;
    }
    
    return 0;
}


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

#define st first
#define nd second
#define pb push_back

typedef long long   ll;
typedef double      db;
typedef long double ldb;

typedef pair <int, int> pii;
typedef pair <ll,  ll>  pll;
typedef pair <ll,  db>  pdb;
typedef pair <ldb, ldb> pldb;

template <typename T>
void   Debug (T begin, T end);
int    si    ();
ll     sl    ();
string ss    (int); 
db     sf    ();
ldb    slf   ();
void   pi    (int, char = '\n');
void   pl    (ll, char = '\n');
void   pf    (db, char = '\n');
void   plf   (ldb, char = '\n');
void   ps    (string, char = '\n');

ll russian(ll, ll, ll);
ll fastpow(ll, ll, ll);
ll slowpow(ll, ll, ll);
ll _gcd(ll, ll);
ll _lcm(ll, ll);
ll extgcd(ll, ll, ll&, ll&);
ll _inv(ll, ll);

const int INF  = 1e9;
const ll  LINF = 1e18;

int main()
{
    int n = si(), res = 0;
    int last = 0;

    for (int i = 0; i < n; ++i)
    {
        int a = si();
        if (a == last)
            ++res,
            last = 0;
        else
            last = a;
    }
    pi(res);

    return 0;
}

template <typename T>
void Debug(T begin, T end)
{
    printf("\nDEBUG:\n");
    while (begin != end)
        printf("%d ", *begin),
        begin++;
    printf("\n\n");
}

template <typename T>
T scanf_t(string s)
{
    T a;
    scanf(s.c_str(), &a);
    return a;
}

template <typename T>
void printf_t(T a, string s, char end_l)
{
    s.push_back(end_l);
    printf(s.c_str(), a);
}

int si() { return scanf_t<int>("%d"); }
ll sl() { return scanf_t<ll>("%lld"); }
db sf() { return scanf_t<db>("%f"); }
ldb slf() { return scanf_t<ldb>("%Lf"); }

void pi(int a, char end_l) { printf_t<int>(a, "%d", end_l); }
void pl(ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); }
void pf(db a, char end_l) { printf_t<db>(a, "%lf", end_l); }
void plf(ldb a, char end_l) { printf_t<ldb>(a, "%Lf", end_l); }

void ps(string a, char end_l)
{
    string s = "%s";
    s.push_back(end_l);
    printf(s.c_str(), a.c_str());
}

string ss(int NN)
{
    char T[NN];
    scanf("%s", T);
    return (string)T;
}

ll fastpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = (r * a) % m;
        a = (a * a) % m;
        k >>= 1LL;
    }
    return r;
}

ll slowpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = russian(r, a, m);
        a = russian(a, a, m);
        k >>= 1LL;
    }
    return r;
}

ll russian(ll a, ll k, ll m)
{
    ll r = 0LL;
    while (k)
    {
        if (k & 1LL)
            r = (r + a) % m;
        a = (a + a) % m;
        k >>= 1LL;
    }
    return r;
}

ll _gcd(ll a, ll b)
{
    while (b)
        swap(a %= b, b);
    return a;
}

ll _lcm(ll a, ll b)
{
    return a / _gcd(a, b) * b;
}

ll extgcd(ll a, ll b, ll& k, ll& l)
{
    if (b == 0)
    {
        k = 1; l = 0;
        return a;
    }    
    ll res = extgcd(b, a % b, l, k);
    l -= a / b * k;
    return res;
}

ll _inv(ll a, ll p)
{
    return fastpow(a, p - 2, p);
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long t = sc.nextLong();
		long ans = 1;
		t--;
		long three = t / 3;
		ans += t % 3;
		while (three >= 2) {
			ans += 2;
			three -= 2;
			ans += three % 3;
			three /= 3;
		}
		ans += three;
		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}



Measured memory_bytes: 24400
#include <iostream>
#include <string>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)

string s;
int main() {
	cin >> s;
	REP(i, 0, s.size() - 2) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << ' ' << i + 2 << endl;
			return 0;
		}else if (s[i] == s[i + 2]) {
			cout << i + 1 << ' ' << i + 3 << endl;
			return 0;
		}
	}
	if (s[s.size() - 2] == s[s.size() - 1]) {
		cout << s.size() - 1 << ' ' << s.size() << endl;
		return 0;
	}
	cout << -1 << ' ' << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#define int long long
#define uint unsigned long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

signed main()
{
	int N;
	cin >> N;

	int min = INT_MAX;
	for (int i = 1; i <= (int)sqrt(N); i++)
	{
		if (N % i == 0)
		{
			int a = MAX(i, N / i);
			int k = 0;
			while (a > 0)
			{
				k++;
				a /= 10;
			}
			if (k < min)
			{
				min = k;
			}
		}
	}
	cout << min << endl;;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n;
    ll a,b;
    ll k,t;
    string str;
    ll h;
    char c,ko;
    cin>>a>>b;
    if(a%b==0){
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=a;i<10e18+1;i+=a){
        if(i%b){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;;
}


Measured memory_bytes: 3608
import bisect
def put(a,b): #結果の表示
    l=max(len(a),len(b)) #aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく
    a="0"*l+a
    b="0"*l+b
    s=""
    for i in range(-1,-l-1,-1): #長さの偶奇を考えたくないので逆順に生成してあとで反転
        s+=a[i]+b[i]
    s=s[-1::-1] #反転
    ind=s.find("1")
    print(s[ind:]) #頭にたくさんついている0を除いて表示

def quad(i): #数値を4進数表記の文字列に直す。16→"100"など。
    s=""
    while i>0:
        s+=str(i%4)
        i//=4
    return s[-1::-1]

l=[0,1]
for i in range(1,20): #候補の生成。最長で20ビット。
    l+=[4**i+j for j in l]

n=int(input())
if n==0: #n==0は出力が空文字になってしまうので別に扱う
    print("0")
else:
    for i in range(len(l)):
        ind=bisect.bisect_left(l,(l[i]-n)//2)
        if l[i]-2*l[ind]==n:
            put(quad(l[i]),quad(l[ind]))
            break

Measured memory_bytes: 116976
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

#define ll unsigned long long
const ll N = 1000000000;

void solve() {
}

int main(){
    int n, m;
    cin >> n >> m;
    int h[n];
    for (int i = 0; i < n; ++i) cin >> h[i];
    vector<int> ans(n, 1);

    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        if (h[a] <= h[b]) ans[a] = 0;
        if (h[b] <= h[a]) ans[b] = 0;
    }

    int s = 0;
    for(int i : ans) s += i;
    cout << s;
    return 0;
}

Measured memory_bytes: 4048
import itertools
N = input()
K = int(input())
l = len(N)
S = list(map(int, N))
N = int(N)

if K == 1:
    ans = S[0] + 9*(l-1)
elif K == 2 and l >= 2:
    # 最大桁がN未満のとき
    ans = (S[0]-1)*9*(l-1)
    # 最大桁がNのとき
    for i in range(1, l):
        if S[0]*10**(l-1)+9*10**(l-i-1) <= N:
            ans += 9
        else:
            ans += S[i]
    # 最大桁が0のとき
    if l > K:
        ans += (l-1)*(l-2)//2*9**2
elif K == 3 and l >= 3:
    # 最大桁がN未満のとき
    ans = (S[0]-1)*(l-1)*(l-2)//2*9**2
    # 最大桁がNのとき
    for a, b in itertools.combinations(range(1, l), 2):
        if S[0]*10**(l-1)+9*10**(l-a-1) <= N:
            if S[0]*10**(l-1)+9*10**(l-a-1)+9*10**(l-b-1) <= N:
                ans += 9**2
            else:
                ans += 8*9 + S[b]
        else:
            if S[0]*10**(l-1)+S[a]*10**(l-a-1)+9*10**(l-b-1) <= N:
                ans += S[a]*9
            else:
                if S[a] == 0:
                    pass
                else:
                    ans += (S[a]-1)*9 + S[b]
    # 最大桁が0のとき
    ans += (l-1)*(l-2)*(l-3)//6*9**3
else:
    ans = 0
print(ans)


Measured memory_bytes: 3064
n = int(input())

bitdp = [0 for i in range(n+1)]

bitdp[0] = 1
for i in range(n):
    s = int(input())
    bitdp[i+1] |= bitdp[i] | bitdp[i] << s

ans = 0
for i in range(100*100):
    if (bitdp[-1] >> i & 1):
        if i % 10 != 0:
            ans = max(ans, i)

print(ans)


Measured memory_bytes: 3060
import qualified Data.IntSet as S
import Data.List
import Data.Maybe

main = do
  n <- readLn
  a <- map read . words <$> getLine
  let f s (x,i) = g l (Just i) + g (Just i) r
        where
          l = S.lookupLT i s
          r = S.lookupGT i s
          g (Just i) (Just j) = x * (r-j) * ((i+1)-(l+1))
            where 
              l = fromMaybe 0 $ S.lookupLT i s
              r = fromMaybe (n+1) $ S.lookupGT j s
          g _ _ = 0
      xs = reverse $ sort $ zip a [1..]
      ss = scanl (flip S.insert) S.empty $ map snd xs
  print $ sum $ zipWith f ss xs

Measured memory_bytes: 41340
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
    
    return 0;
}


Measured memory_bytes: 256
def f(x, cnt):
    if x % 2 != 0 or x == 0:
        return cnt
    else:
        cnt += 1
        return f(x//2, cnt)

N = int(input())
ans, cnt = 0, 0
for i in range(1, N+1):
    c = f(i, 0)
    if c >= cnt:
        ans, cnt = i, c
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 998244353;

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n / 2) {
    if (s[i] != s[n / 2 + i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int n;
string a,b,c;

int main()
{
  cin >> n >> a >> b >> c;
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i] && b[i] == c[i]) {
      res += 0;
    } else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
      res += 1;
    } else {
      res += 2;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, a;
  scanf("%lld", &n);
  multiset<ll> s;
  multiset<ll>::iterator it;
  for(i = 0; i < (1 << n); ++i) scanf("%lld", &a), s.insert(a);
  it = s.end();
  it--;
  vector<ll> vec;
  vec.push_back(*it);
  s.erase(it);
  for(i = 0; i < n; ++i) {
    for(j = 0; j < (1 << i); ++j) {
      it = s.lower_bound(vec[j]);
      if(it == s.begin()) {
        printf("No");
        return 0;
      }
      it--;
      vec.push_back(*it);
      s.erase(it);
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 15736
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

typedef pair <int, int>P;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P>a(M);
	rep(i, M) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a.begin(), a.end());
	int end = 0;
	int ans = 0;
	rep(i, M) {
		if (a[i].second >= end) {
			ans++;
			end = a[i].first;
		}
	}
	print(ans);
}

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

int main() {

  int R; cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  }
  else if (R < 2800) {
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    double n, k;
    cin >> n >> k;
    double ans = 0.0;
    for (double i = 1.0; i <= n;i++){
        double sum = i, two = 0.0;
        while(sum<k){
            sum *= 2.0;
            two+=1.0;
        }
        double tmp = 1.0;
        while(two>0.0){
            tmp *= 1.0 / 2.0;
            two--;
        }
        ans += 1.0 / n * tmp;
    }
    cout << setprecision(9) << ans << endl;
    return 0;
}


Measured memory_bytes: 256