akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

const int N = 100 * 1000 + 5;
vector <int> A[N];
vector <int> tree[4 * N];
vector<int> merge(vector<int> &x, vector<int> &y) {
	int a = 0, b = 0;
	vector <int> z;
	while(a < (int) x.size() && b < (int) y.size()) {
		if (x[a] < y[b]) {
			z.push_back(x[a++]);
		}
		else {
			z.push_back(y[b++]);
		}
	}
	
	while(a < (int) x.size())
		z.push_back(x[a++]);
	while(b < (int) y.size())
		z.push_back(y[b++]);
	
	return z;
}	
void build(int l, int r, int i) {
	if (l == r) {
		tree[i] = A[l];
		return;
	}
	int mid = (l + r) / 2;
	build(l, mid, 2 * i);
	build(mid + 1, r, 2 * i + 1);
	tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
}
int query(int ql, int qr, int l, int r, int i) {
	if (ql > r || qr < l)
		return 0;
	if (ql <= l && r <= qr) {
		int val = int(tree[i].end() - lower_bound(all(tree[i]), qr));
		return val;
	}
	int mid = (l + r) / 2;
	return query(ql, qr, l, mid, 2 * i) + query(ql, qr, mid + 1, r, 2 * i + 1);
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		A[l].push_back(r);
	}
	for (int i = 1; i <= m; i++) {
		sort(all(A[i]));
	}
	build(1, m, 1);
	for (int i = 1; i <= m; i++) {
		int ans = 0;
		for (int j = i; j <= m; j += i) {
			ans += query(j - i + 1, j, 1, m, 1);
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 44304
fn main() {
    proconio::input! {
        n: usize,
        a: [usize; n]
    }

    let maxn: usize = 1000000;
    let mut dp: Vec<usize> = vec![0; maxn + 1];

    for i in (2..).take_while(|&x| x * x <= maxn) {
        if dp[i] != 0 { continue; }
        for j in (i..maxn).step_by(i) {
            if dp[j] == 0 { dp[j] = i; }
        }
    }
 
    let mut used: Vec<bool> = vec![false; maxn + 1];

    let paircoprime = a.iter()
        .find(|&&a| {
            let mut x = a;
            while x != 1 {
                let y = if dp[x] != 0 { dp[x] } else { x };

                if y != 1 && used[y] { return true; }
                used[y] = true;

                while x % y == 0 { x /= y; }
            }

            return false;
        });

    if paircoprime.is_none() {
        println!("pairwise coprime");
        return;
    }

    let setwise = a.iter()
        .fold(a[0], |x , &y| num::integer::gcd(x, y));

    if setwise == 1 {
        println!("setwise coprime");
        return;
    }

    println!("not coprime");
    return;
}


Measured memory_bytes: 25452
#６回目、2020-0612
#2重ループ　＋O(1)
#i,jがループの中か外で場合分け

#初期入力
N, x, y = map(int, input().split())

ans ={i:0 for i in range(1,N)}
for i in range(1,N):
    for j in range(i+1,N+1):
         #（i,jがループより共に左、ともに右）
        if (j <=x or y <=i) :
            ans[j-i] +=1
        # （iがループより左 and jがループより右）
        elif i <=x and y <=j:
            ans[x-i +1 +j-y] +=1
        # i,jが共にループの中
        elif x <i and j <y:
            dist =min(j-i,i-x + y-j +1) #時計回りと反時計回りの短いほう、+1はxとyを結んだ部分
            ans[dist] +=1
        # iがループより左、jがループの中
        elif i <=x and j < y:
            dist =x-i + min(j-x , y+1-j)
            ans[dist] +=1 
        # iがループの中、jがループの右
        elif x <i and y <=j:
            dist =min(y-i , 1 +i-x) + j-y
            ans[dist] +=1 

#答え出力
for i in range(1,N):        
    print(ans[i])

Measured memory_bytes: 3572
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int N,ans;

	scanf("%d",&N);

	for(ans = 0; pow(3,ans) < N;ans++);

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 2912
#include <stdio.h>
#include <string.h>

int main(){
    char str[10]; 
    char *s1 = "Sunny";
    char *s2 = "Cloudy";
    char *s3 = "Rainy";

    scanf("%s", str);

    if( strcmp(str,s1)== 0 ){
        printf("Cloudy");
    } 
    if( strcmp(str,s2)== 0 ){
        printf("Rainy");
    }
    if( strcmp(str,s3)== 0 ){
        printf("Sunny");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    int a, b, c; cin>>a>>b>>c;
    cout<<(a+b)*c/2;
	return 0;

}


Measured memory_bytes: 256
def popcount(x):
    return bin(x).count("1")

def f(x):
    if x == 0:
        return 0
    return f(x%popcount(x))+1

n = int(input())
x = input()
xx = int(x,2)
p = x.count("1")
stand1 = xx%(p+1)
if p != 1:
    stand2 = xx%(p-1)
for i in range(n):
    if x[i] == "1":
        if p != 1:
            k = stand2
            k -= pow(2,n-i-1,p-1) 
            k %= p-1
        else:
            print(0)
            continue
    else:
        k = stand1
        k += pow(2,n-i-1,p+1)
        k %= p+1
    print(1+f(k))

Measured memory_bytes: 9404
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int main (){
        long long N;
        long long Ans;
        cin >> N;
        
        
        if(N == 1000000000){
            cout << "Yes";
        }else{
         Ans = N%10 + N%100/10 + N%1000/100 +N%10000/1000 +N%100000/10000 +N%1000000/100000 +N%10000000/1000000 +N%100000000/10000000  +N%1000000000/100000000 ;

        if(N%Ans == 0){
            cout << "Yes";
        }else {
            cout << "No";
        }
        }

}


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

typedef long long int ll;
#define deb(x) cout << #x << " " << x << endl;
#define debtwo(x,y) cout << #x << " " << x << ", " << #y << " " << y << endl;
#define mod 1000000000

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, val;
	cin >> n;

	ll sum = 0;

	cin >> val;
	int mval = val;

	for (int i = 1; i < n; i++) {
		cin >> val;
		if (val >= mval) mval = val;
		else {
			sum += mval - val;
		}
	}
	cout << sum;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>

int main()
{
    char card[201], bottom[201], top[201];
    int m, h, ok, j = 0;

    do
    {
        scanf("%s", card);
        if (strcmp(card, "-") != 0)
        {

            scanf("%d", &m);
        for (int i = 0; i < m; i++){
            scanf("%d", &h);
            for (int j = 0; j < h; j++)
            {
                bottom[j] = card[j];
                bottom[h] = '\0';
            }
                int j = 0;
            while (card[h + j] != '\0')
            {
                top[j] = card[h + j];
                j++;
            }
            top[j] = '\0';
         strcpy(card, top);
         strcat(card, bottom);
        }

        printf("%s\n", card);
        }

    } while (strcmp(card, "-") != 0);
    return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>



int main()
{
	int a[ 3 ] ;

	int i ;
	for( i = 0 ; i < 3 ; ++i )
	{
		scanf( "%d" ,&a[ i ] ) ;
	}



	if( a[ 2 ] == 1 || a[ 0 ] + a[ 1 ] == 2 )
	{
		puts( "Open" ) ;
	}


	else
	{
		puts( "Close" ) ;
	}



	return 0 ;
}

Measured memory_bytes: 2580
/**
 *    author:  skmonir
 *    created: 05-Oct-2017 22:53:37
**/
#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}
template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = (int) 1e5 + 5;
const int INF = (int) 1e9 + 7;
const long long MOD = (long long) 1e9 + 7;


int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if ((a[0] == a[1]) and a[0] == 5 and a[2] == 7) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// c++include
#include <iostream>
#include <algorithm>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(ll i = 0; i < (n); i++)
typedef long long ll;

// main関数
int main(void) {
	int sx, sy, ex, ey;
	cin >> sx >> sy >> ex >> ey;

	int dx, dy;
	dx = ex - sx; dy = ey - sy;
	int flagx = 0, flagy = 0;
	if (dx < 0) {
		flagx = 1;
		dx = dx * (-1);
	}
	if (dy < 0) {
		flagy = 1;
		dy = dy * (-1);
	}

	rpt(i, 4) {
		if (i == 2) {
			cout << 'D';
			dx++; dy++;
		}
		else if (i == 3) cout << 'U';
		if (flagx == 0) {
			rpt(j, dx) cout << 'R';
			flagx = 1;
		}
		else if (flagx == 1) {
			rpt(j, dx) cout << 'L';
			flagx = 0;
		}
		if (flagy == 0) {
			rpt(j, dy) cout << 'U';
			flagy = 1;
		}
		else if (flagy == 1) {
			rpt(j, dy) cout << 'D';
			flagy = 0;
		}
		if (i == 2) cout << 'L';
		else if (i == 3) cout << 'R';
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

#define N 1024
#define MIN(D,S) \
  (D) = ( (S) < (D) ? (S) : (D) )
#define MAX(D,S) \
  (D) = ( (S) > (D) ? (S) : (D) )

int main (
  void
  )
{
  int n;

  scanf ( "%d", &n );

  while ( n-- )
  {
    char buf[ N + 1 ];
    char res[ N * 2 + 2 ];
    char *s = buf;
    char *p = res + N + 1;
    char *b = p, *e = p;

    scanf ( " %s", buf );
    while ( isalpha ( *s ) )
    {
      *p = *( s++ );
      if ( s[ 0 ] == '-' && s[ 1 ] == '>' )
      {
        s += 2;
        ++p;
      }
      if ( s[ 0 ] == '<' && s[ 1 ] == '-' )
      {
        s += 2;
        --p;
      }
      MIN( b, p );
      MAX( e, p );
    }

    fwrite ( b, sizeof ( char ), e - b + 1, stdout );
    puts ( "" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GS(s);
  int n = s.size();
  int p = 0, g = 0;
  FOR(i, n) {
    if (s[i] == 'p') {
      p++;
    } else {
      g++;
    }
  }
  print(g - (n + 1) / 2);
  return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
const int N=105;
int n,m,ax,ay,bx,by;
char s[N][N];
short g[N][N],dp[N][N][N][N];
short Get(int x1,int y1,int x2,int y2){
	return g[x2][y2]-g[x2][y1-1]-g[x1-1][y2]+g[x1-1][y1-1];
}
short max(short a,short b){
	return a>b?a:b;
}
short DP(int x1,int y1,int x2,int y2){
//	printf("DP %d %d %d %d\n",(int)x1,(int)y1,(int)x2,(int)y2);
	short &v=dp[x1][y1][x2][y2];
	if (~v)
		return v;
	if (x1>x2||y1>y2)
		return v=0;
	short xL=max(x2-bx+1,x1),xR=min(x1+ax-1,x2);
	short yL=max(y2-by+1,y1),yR=min(y1+ay-1,y2);
	return v=max(
			max(DP(x1,y1,x2,y2-1)+((yR==y2)?Get(xL,y2,xR,y2):0),
				DP(x1,y1+1,x2,y2)+((yL==y1)?Get(xL,y1,xR,y1):0)),
			max(DP(x1,y1,x2-1,y2)+((xR==x2)?Get(x2,yL,x2,yR):0),
				DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0)));
}
int main(){
	memset(g,0,sizeof g);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (s[i][j]=='o')
				g[i][j]++;
			else if (s[i][j]=='E')
				ax=i,bx=n-i+1,ay=j,by=m-j+1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			g[i][j]=g[i][j]+g[i][j-1]+g[i-1][j]-g[i-1][j-1];
	memset(dp,-1,sizeof dp);
	printf("%d",(int)DP(1,1,n,m));
	return 0;
}

Measured memory_bytes: 237696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//x^nを出力
int pw(int x, int n){
    int res = 1;
    rep(i, n) res *= x;
    return res;
}

int main(){
    string s;
    cin >> s;
    int N = s.size();
    int ans = 0;
    rep2(i, 3, N-1){
        ans += pw(3, i)-3*pw(2, i)+3;
    }
    char x[] = {'3', '5', '7'};
    rep(i, pw(3, N)){
        string a = "";
        int used[] = {0, 0, 0};
        rep(k, N){
            int j = (i%pw(3, k+1))/pw(3, k);
            a = a+x[j];
            used[j]++;
        }
        if(a <= s && used[0]*used[1]*used[2]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 2e5+7;
const int maxM = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;

int n,k;
 
int a[maxN];
ll C[2010][2010];
ll power(ll x,ll p)
{
	if( p == 0)
		return 1;
	ll t = power(x,p/2);
	t = t*t%MOD;
	if(p&1 == 1)
		t = t*x%MOD;
	return t;
}
int main()
{
	scanf("%d%d",&n,&k);
	int cnt = 0;
	C[0][0] = 1;   
    for(int i=1;i<=2000;i++)
    {
        C[i][0] = 1;
        for(int j = 1;j<=2000;++j)   
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
    }
    
    for(int i=1;i<=k;i++)
    {
    	ll cnt = 0;
    	if(i == 1)
    	{
    		cnt = n-k+1;
    		cout<<cnt<<endl;
    		continue;
		}
    	for(int m = i-1;m<=n-k;m++)
    	{
    		cnt += C[k-1][i-1] * C[m-1][i-2] %MOD * (n-k-m+1)%MOD;
    		cnt %= MOD;
		}
		cout<<cnt<<endl;
	}
	return 0;
}


Measured memory_bytes: 31616
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(x):
  if x == 1:
    return 1
  else:
    return tami(x//2)*2 + 1

H = I()
print(tami(H))

Measured memory_bytes: 5332
#include <cstdio>
#include <algorithm>
#include <string>
#include <utility>
#include <cassert>

int main() {
  char buf[131072];
  scanf("%s", buf);
  std::string s=std::move(buf);

  std::string s_nonx="";
  for (char c: s)
    if (c != 'x')
      s_nonx += c;

  std::string s_nonx_rev=s_nonx;
  std::reverse(s_nonx_rev.begin(), s_nonx_rev.end());
  if (s_nonx != s_nonx_rev) {
    printf("-1\n");
    return 0;
  }

  std::string t=s;
  std::reverse(t.begin(), t.end());

  int res=0;
  for (size_t i=0, j=0; i+j<=s.length();) {
    if (s[i] == t[j]) {
      ++i;
      ++j;
    } else if (s[i] == 'x') {
      ++res;
      ++i;
    } else if (t[j] == 'x') {
      ++res;
      ++j;
    } else {
      assert(0);
    }
  }


  printf("%d\n", res);
  return 0;
}


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

/** defines and macros */
#define ll long long
#define ull unsigned long long
#define loop(n) for(int i = 0; i < n; i++)
#define loop1(n) for(int i = 1; i <= n; i++)
#define all(v) ((v).begin()), ((v).end())
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vvi vector<vi>
#define vvpii vector<vii>
#define PB push_back

#define fw(fileName) freopen(fileName, "w", stdout)
#define fr(fileName) freopen(fileName, "r", stdin)
#define fc(stream) fclose(stream);

#define faster_IO_stream ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"

/*To compile and run

	g++ -o main main.cpp && ./main

*/

/*
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣀⡀⠄⠄⠄⠄⠄⣰⣷⡀⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠄⠄⢠⣿⣿⣷⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠤⠒⠛⠛⠛⠛⠻⠷⣦⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣿⣿⣿⠟⠁⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢀⣤⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡤⠐⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⢀⣶⣿⣿⠿⢛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⢠⣿⠟⠉⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠘⠁⠄⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠻⣿⣿⣿⣿⣿⣿⣿⡛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⣾⣿⡿⣽⡿⢹⣿⣿⣟⣿⢻⠇⢀⢹⣿⢿⣿⣿⣿⣿⣿⣦⣙⢿⣿⢷⣈⠻⢿⣟⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢿⡿⠁⡿⠁⢸⣿⣿⢹⡇⢸⠄⠈⠄⠻⣏⠻⣿⡿⣿⣿⣿⣌⠛⢿⡌⠙⢧⣀⠙⢳⡹⢻⣿⣿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠘⡇⠄⡇⢠⣼⣿⣿⠈⡇⠘⠤⠤⠤⠤⢜⣢⣘⡻⢮⡛⢿⣿⣷⣬⡤⠤⠤⠤⠥⠤⠥⢬⣿⣧⡄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠁⠄⠄⠘⢿⡏⠛⠄⠄⠄⠄⠄⠄⠄⠄⠄⠙⣿⣿⣿⡿⠋⠉⠛⠉⠄⠄⠄⠄⠄⠄⠄⢹⡿⠃⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⡟⠁⠈⢳⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠱⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⡜⠁⠄⠄⠈⢇⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⠦⢄⣀⣀⣀⣀⣀⠴⠊⠄⠄⠄⠄⠄⠄⠑⠤⢀⣀⣀⣀⡀⠠⠔⠋⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣶⣦⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣤⣶⣆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣶⣄⣀⣀⣀⣀⣤⣾⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⣿⠟⠁⠄⠄⠄⠄⠙⢿⣿⣿⣿⡟⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⠟⠋⠁⠄⠄⠄⠄⠄⠄⠄⠄⠉⠛⠿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
*/

const double pi = 3.14159265358979323846;
const int module = 1e9 + 7;

int main() {
	faster_IO_stream

	int n;
	cin >> n;

	int num1, num2, c = 0;
	loop(n) {
		cin >> num1 >> num2;
		if(num1 != num2 && c < 3) c = 0;
		else c++;
	}

	if(c >= 3) cout << "Yes\n"; else cout << "No\n";

	return 0;
}


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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<vector<int> > g;
int n;
string s;
pair<pair<int,int>,int> dfs(int k,int pre){
    vector<pair<pair<int,int>,int > > v;
    for(auto x:g[k]){
        if(x==pre)continue;
        auto y = dfs(x,k);
        v.push_back(MP(MP(y.first.first+y.second,y.first.second),y.second));
    }
    if(v.size()==0){
        if(s[k]=='1'){
            return MP(MP(0,0),1);
        }else{
            return MP(MP(0,0),0);
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int sm = 0;
    int sss = v[0].second;
    for(int i=1;i<v.size();i++){
        sm += v[i].first.first;
        sss += v[i].second;
    }
    if(sm >= v[0].first.first-v[0].first.second){
        if((sm+v[0].first.first)%2==0){
            if(s[k]=='1'){
                return MP(MP(sm+v[0].first.first,sm+v[0].first.first),sss+1);
            }else{
                return MP(MP(sm+v[0].first.first,sm+v[0].first.first),sss);
            }
        }else{
            if(s[k]=='1'){
                return MP(MP(sm+v[0].first.first,sm+v[0].first.first-1),sss+1);
            }else{
                return MP(MP(sm+v[0].first.first,sm+v[0].first.first-1),sss);
            }
            return MP(MP(sm+v[0].first.first,sm+v[0].first.first-1),sss);
        }
    }else{
        if(s[k]=='1'){
            return MP(MP(sm+v[0].first.first,sm*2+v[0].first.second),sss+1);
        }else{
            return MP(MP(sm+v[0].first.first,sm*2+v[0].first.second),sss);
        }
        return MP(MP(sm+v[0].first.first,sm*2+v[0].first.second),sss);
    }
}


int main(){
    cin >> n;
    cin >> s;
    g.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int mi = inf;
    rep(i,n){
        auto x = dfs(i,-1);
        //cout << x.first.first << " " << x.first.second << " " << x.second<< endl;
        if(x.first.first==x.first.second){
            mi = min(mi,x.first.first);
        }
    }
    if(mi==inf){
        cout << -1 << endl;
    }else{
        cout << mi/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+3;
int arr[MAXN];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin >> k >> n;
	for(int i=0;i<n;i++) cin >> arr[i];
	int ans = k-arr[n-1]+arr[0];
	for(int i=1;i<n;i++) ans = max(ans,arr[i]-arr[i-1]);
	cout << k-ans << '\n'; 
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0); }

int main() {
  ull a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    Yes(s[2] == s[3] && s[4] == s[5]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.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(void) {
	int N;
	cin >> N;
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		if(N%i==0) ans += N / i - 1;
		else ans += N / i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main(){
  lint A,B,N,ans,M;
  cin >> A >> B >> N;
  M = N - N%B - 1;
  ans = max((A*N)/B - A*(N/B),(A*M)/B - A*(M/B));
  co(ans);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll dpall[100009][109];
ll dplim[100009][109];
ll a[100009];
ll mod = 1e9+7;
ll n, d;
string s1;
ll calc(ll x){
    x %= mod;
    if(x < 0)
        x += d;
    return x;
}
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> s1;

    cin >> d;

    n = s1.size();

    for(ll i = 0; i < n; ++i)
        a[i] = s1[i]-'0';
    dpall[n][0] = dplim[n][0] = 1;

    for(ll i = n-1; i >= 0; --i)
        for(ll j = 0; j < d; ++j)
            for(ll k = 0; k <= 9; ++k){
                dpall[i][j] += dpall[i+1][calc(j-k%d)];
                dpall[i][j] %= mod;
                if(k < a[i])
                    dplim[i][j] += dpall[i+1][calc(j-k%d)];
                if(k == a[i])
                    dplim[i][j] += dplim[i+1][calc(j-k%d)];
                dplim[i][j] %= mod; 
            }
    ll ans = dplim[0][0]-1;
    if(ans < 0)
        ans += mod;
    cout << ans << "\n";
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}
typedef tuple<int, int, int> P3;

int main()
{
    ll k, q;
    cin >> k >> q;
    vector<ll> d(k);
    rep(i, k) { ll tmp; cin >> tmp; d[i] = tmp;}
    rep(i, q){
        ll n, x, m;
        cin >>n>>x>>m;
        vector<ll> d_ = d;
        rep(j, k) d_[j] %= m;
        x %= m;

        vector<ll> mut(k, 0);
        rep(j, k) mut[j] = (n+(k-2)-j)/k;
        //show(mut);
        //show(d_);
        ll ans = n - 1;
        ll x_fin = x;
        rep(j, k) x_fin += mut[j] * d_[j];
        //cout << (x_fin/m) << " " << (x/m) << endl;
        ans -= (x_fin/m) - (x/m);
        rep(j, k) if(!d_[j]) {ans -= mut[j];}
 
        cout << ans << endl;
    }
}


Measured memory_bytes: 512
import sys
import subprocess
import re
import datetime
import os

N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice = Alice + A[i]
    else:
        Bob = Bob + A[i]

ans = (Alice - Bob)

print(ans)

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

int N;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    int m = 1000000000;
    int mi = -1;
    int M = -1000000000;
    int Mi = -1;
    rep(i, N) {
        int a; cin >> a;
        if (m>a) {
            m = a;
            mi = i;
        }
        if (M<a) {
            M = a;
            Mi = i;
        }
    }
    
    cout << 2*N-1 << endl;
    if (abs(M)>=abs(m)) {
        rep(i, N) cout << Mi+1 << " " << i+1 << endl;
        rep(i, N-1) cout << i+1 << " " << i+2 << endl;
    }
    else {
        rep(i, N) cout << mi+1 << " " << i+1 << endl;
        for (int i=N-2; i>=0; i--) cout << i+2 << " " << i+1 << endl;
    }
}

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

int main() {
	
	int n,k = 0,ans = 0;
	cin>>n;
	for(int i = 1; i <= n; i+=2)
	{
		k = 0;
		for(int j = 1; j <= i; j++)
		{
			if(i % j == 0)
			{
				k++;
			}
		}
		if(k == 8)
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3652
s=input()
K=int(input())

s1list=[]
for i in range(len(s)):
  s1list.append((s[i],i))
s1list.sort()
#print(s1list)

cold=s1list[0][0]
sset=set()
for i in range(len(s1list)):
  c1,index=s1list[i]
  if cold!=c1 and len(sset)>=5:
    break
  else:
    cold=c1
  
  for j in range(5):
    sub=s[index:index+j+1]
    sset.add(sub)
    
slist=list(sset)
slist.sort()
print(slist[K-1])

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

signed main(){
  int A,B;
  cin>>A>>B;
  int ans=0,i=1;
  while(i<B){
    --i;
    i+=A;
    ++ans;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {

            int N = in.nextInt();
            int K = in.nextInt();

            long[] x = new long[N];
            long[] y = new long[N];
            for (int i = 0; i < N; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
            }

            long area = Long.MAX_VALUE;
            for (int i = 0; i < N; i++) {
                for (int i2 = 0; i2 < N; i2++) {
                    for (int j = 0; j < N; j++) {
                        for (int j2 = 0; j2 < N; j2++) {

                            int count = 0;
                            for (int k = 0; k < N; k++) {
                                if (x[k] < x[i] || x[k] > x[i2] || y[k] < y[j] || y[k] > y[j2]) {
                                    continue;
                                }
                                count++;
                            }
                            if (count >= K) {
                                area = Math.min(area, (x[i2] - x[i]) * (y[j2] - y[j]));
                            }
                        }
                    }
                }
            }

            System.out.println(area);
        }
    }

}


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

ll solve() {
    ll K;
    cin >> K;
    string ans;
    for ( int i = 0; i < K; i++ ) {
        ans.append("ACL");
    }
    cout << ans << "\n";
    return 0;
}

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

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

int main() {
  int N;
  cin >> N;
  int b[N + 1], w[N + 1];
  string S;
  cin >> S;
  b[0] = 0;
  w[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    b[i] = b[i - 1];
    w[i] = w[i - 1];
    if (S[i - 1] == '#')
      b[i]++;
    else
      w[i]++;
  }
  int ans = INT32_MAX;
  for (int i = 0; i < N + 1; i++) {
    ans = min(b[i] + w[N] - w[i], ans);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//map<pair<int,int>,int> dp;
vector<int> dp(10e5+1);
int solve(vector<int> value,vector<int> weight,int v,int l){
    map<pair<int,int>,int> dp;
    
    int i=0;
    while(v!=0){
        for(int w=0;w<=l;w++){
            if(w>=weight[v-1]) dp[mp(i+1,w-weight[v-1])]=max(dp[mp(i,w-weight[v-1])]+value[v-1],dp[mp(i,w)]);
            else dp[mp(i+1,w)]=dp[mp(i,w)];
        }
        v/=2;
        i++;
    }

    return dp[mp(i,l)];
}

signed main(){ 
    int i=1;

    for(int j=0;j<5;j++){
        int ai;
        cin>>ai;
        if(ai==0){
            cout<<i<<endl;
            return 0;
        }
        i++;
    }
}  

Measured memory_bytes: 10984
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		List<String> grade = new ArrayList<>();
		int a, b, c;
		while (true) {
			a = scanner.nextInt();
			b = scanner.nextInt();
			c = scanner.nextInt();
			if (a == -1 && b == -1 && c == -1) {
				break;
			}
			if (a == -1 || b == -1) {
				grade.add("F");
			} else if (a + b >= 80) {
				grade.add("A");
			} else if (a + b < 80 && a + b >= 65) {
				grade.add("B");
			} else if (a + b < 65 && a + b >= 50) {
				grade.add("C");
			} else if (a + b <= 50 && a + b >= 30) {
				if (c >= 50) {
					grade.add("C");
				} else {
					grade.add("D");
				}
			} else if (a + b < 30) {
				grade.add("F");
			}
		}
		for (int i = 0; i < grade.size(); i++) {
			System.out.println(grade.get(i));
		}

	}
}

Measured memory_bytes: 26296
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
int main(){
	int n; cin >> n;
	vector<long> A(n);
	vector<long> B(n);
	for (int i = 0; i < n; i++){
		cin >> A[i] >> B[i];
	}
	long ans = 0;
	long tmp = 0;
	for (int i = n-1; i >= 0; i--){
		A[i] += ans;
		tmp = B[i] -  (A[i] % B[i]);//*********让A[i]+n能被B[i]整除最小增量
		ans += tmp;
		if (A[i] % B[i] == 0) ans -= B[i];
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    int n, lens, lent;
    string s, t;
    cin >> n;
    cin >> s >> t;
    lens = s.length();
    lent = t.length();
    for (int i = 0; i < lens; i++) {
        cout << s[i];
        cout << t[i];
    }
    return 0;
}




Measured memory_bytes: 256
n,m = map(int, input().split(" "))
a=[list(map(str, input().split(" "))) for i in range(m)]
check = [False for i in range(n + 1)]
times = [False for i in range(n + 1)]

for i in range(m):
  #print(check)
  #print(a[i])
  if check[(int)(a[i][0])] == False and a[i][1] == "AC":
    #print("OK")
    check[(int)(a[i][0])] = True
  elif check[(int)(a[i][0])] == False and a[i][1] == "WA":
    times[(int)(a[i][0])] += 1
    #print("MISS")

for i in range(n + 1):
  if check[i] == False:
    times[i] = 0
print(check.count(True), sum(times))

Measured memory_bytes: 35144
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    
    cout << a[0] + a[1] << endl;

    return 0;
}

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

using namespace std;

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

	vector<pair<string, int>> st(n);
	for (int i = 0; i < n; i++) {
		cin >> st[i].first >> st[i].second;
	}

	string x;
	cin >> x;

	bool flag = false;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (flag) {
			sum += st[i].second;
		}
		else if (st[i].first == x) {
			flag = true;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ss = n.times
  .map { gets.chomp[0] }
  .select { |s| %w(M A R C H).include?(s) }

counts = %W(M A R C H).each_with_object(Hash.new(0)) { |c, h| h[c] = 0 }
ss.each { |s| counts[s] += 1 }

ans = counts.keys.combination(3).inject(0) do |r, (a, b, c)|
  r + counts[a] * counts[b] * counts[c]
end

puts ans


Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

// [ _StructModConb2 ]
// Combination を求める構造体
// いろいろできる (e.g. P, C, H)
// Combination hoge(size); で宣言
// 上のより速い
// memo: 1 / (N - 1)! = (1 / N!) * N
struct Combination {
    vector<int64_t> fact, rfact;
	const int64_t MOD = 1000000007;

    Combination(int sz) : fact(sz + 1), rfact(sz + 1) {
        fact[0] = 1;
        for(int i = 1; i < fact.size(); i++){
            fact[i] = fact[i - 1] * i % MOD;
        }
        rfact[sz] = inv(fact[sz]);
        for(int i = sz - 1; i >= 0; i--){
            rfact[i] = rfact[i + 1] * (i + 1) % MOD;
        }
    }
    int64_t inv(int x) const {
        return pow(x, MOD - 2);
    }
    int64_t pow(int64_t x, int64_t n) const {
        int64_t ret = 1;
        while (n > 0) {
            if (n & 1) { (ret *= x) %= MOD; }
            (x *= x) %= MOD;
            n >>= 1;
        }
        return (ret);
    }

    int64_t P(int n, int r) const {
        if (r < 0 || n < r) { return 0; }
        return (fact[n] * rfact[n - r] % MOD);
    }

    int64_t C(int p, int q) const {
        if (q < 0 || p < q) { return 0; }
        return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
    }

    int64_t H(int n, int r) const {
        if (n < 0 || r < 0) { return 0; }
        return (r == 0 ? 1 : C(n + r - 1, r));
    }
};

int main() {
	const Int MOD = 1e9 + 7;
	Int X, Y;
	cin >> X >> Y;

	if ((X + Y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	Combination cb(1000000 + 10);
	int a = (2*Y - X) / 3;
	int b = (2*X - Y) / 3;
	Int ans = cb.C(a + b, a) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {


	static int S[];
	static int n;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		S = new int[n];
		for(int i = 0;i < n;i++)S[i] = scan.nextInt();
		int q = scan.nextInt();
		int c = 0;
		for(int i = 0;i < q;i++) {
			if(search(scan.nextInt()))c++;

		}

		System.out.println(c);
		scan.close();

	}

	static boolean search(int t) {
		int l = 0, r = n, mid;
		if(S[0] > t || S[n-1] < t)return false;

		while(l<r) {
			mid = (l+r)/2;
			if(S[mid] > t) {
				r = (l+r)/2;
			}else if(S[mid] < t){
				l = (l+r)/2+1;
			}else if(S[mid] == t)return true;

		}

		return false;

	}

}


Measured memory_bytes: 80072
#include<iostream>
#include<cmath>
using namespace std;
#define MAX 720

int m, n;
int D[MAX];

double getArea(int size ){
    D[size-1] = 360;
    for ( int i = 0; i < size-1; i++ ) D[size-1] -= D[i];
    double a = 0.0;
    for ( int i = 0; i < size; i++ ){
	a += sin(D[i]*acos(-1)/180.0)/2.0;
    }
    return a;
}

main(){
    int d;
    double S1, S2;
    while(1){
	cin >> m;
	if ( m == 0 ) break;
	for ( int i = 0; i < m-1; i++ ) {
	    cin >> D[i];
	}
	S1 = getArea(m);
	cin >> n;
	for ( int i = 0; i < n-1; i++ ) {
	    cin >> D[i];
	}
	S2 = getArea(n);
	if ( fabs(S1 - S2) < 0.0000001 ) cout << 0 << endl;
	else if ( S1 > S2 ) cout << 1 << endl;
	else cout << 2 << endl;
    }
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

b_sum = 0
for j in range(n):
    i = a[j]-1
    b_sum += b[i]
    if j >= 1 and a[j] == a[j-1]+1:
        b_sum += c[a[j-1]-1]
print(b_sum)


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

int main(){
    int X,Y;
    cin >> X >> Y;
    int prize = 0;
    if (X == 3) prize += 100000;
    if (Y == 3) prize += 100000;
    if (X == 2) prize += 200000;
    if (Y == 2) prize += 200000;
    if (X == 1) prize += 300000;
    if (Y == 1) prize += 300000;
    if (X == 1 && Y == 1) prize += 400000;
    cout << prize << endl;
}


Measured memory_bytes: 3624
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 20000
int a[MAXN+5],b[MAXN+5];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=i*(n+1),b[i]=(n-i+1)*(n+1);
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        a[x]-=n-i+1;
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
    for(int i=1;i<=n;i++)
        cout<<b[i]<<' ';
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint a;
	for(int i = 1; i <= n; i++){
		cin >> a;
		if(a % 2 || a % 3 == 0 || a % 5 == 0) continue;
		cout << "DENIED" << endl;
		return 0;
	}
	cout << "APPROVED" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MN 200000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int d,x,n;
long double f[MN+5],g[MN+5],ans=0;
int main()
{
	n=read();d=read();x=read();
	long double a=4*x,b=2*d-3*x;
	for(int i=n;i;--i)
	{
		ans+=(a+b+i*a+b)/2;
		long double na=2*a;
		long double nb=b+0.5*a;
		a+=na/i;b+=nb/i;
	}
	printf("%.15lf",(double)ans/2);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
  s.append(int(input()))
 
ss = sum(s)
if ss % 10 == 0:
  # sの中で10で割り切れない最小の数を引けば良い
  s.sort()
  m = [t for t in s if t%10!=0]
  if len(m) == 0:
    print(0)
  else:
    print(ss-min(m))
else:
  print(ss)

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

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll E = C * D / gcd(C, D);
    ll x = B / C - (A - 1) / C;
    ll y = B / D - (A - 1) / D;
    ll z = B / E - (A - 1) / E;
    cout << B - A + 1 - x - y + z << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int n = a+b;
    if(n < 10){
      System.out.println(n);
    }else if(n >= 10){
      System.out.println("error");
    }
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string s,t;
int st,n;
int main(void){
    cin>>s;
    n=s.size();
    for(int i=1;i<=n;i++)t+=s[n-i];
    while(st<n){
        if(t.substr(st,5)=="maerd")st+=5;
        else if(t.substr(st,7)=="remaerd")st+=7;
        else if(t.substr(st,5)=="esare")st+=5;
        else if(t.substr(st,6)=="resare")st+=6;
        else {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


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

int n, a;
bool flag;

int main() {
    cin >> n;
    flag = true;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (a % 2 == 0){
            if (a % 3 != 0 && a % 5 != 0) flag = false;
        }
    }
    if (flag) cout << "APPROVED\n";
    else cout << "DENIED\n";
}


Measured memory_bytes: 256
//Author : Gaara

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

#define ll long long
#define pb push_back
#define endl "\n"
#define fo(i,n) for(ll i=0;i<n;i++)
#define ro(i,n) for(ll j=n-1;i>=0;i--)
#define vll vector<long long>

int main(){
    int t=1;
    //cin>>t;
    while(t--){
	  int d,t,s;
      cin>>d>>t>>s;
      if(d<=t*s) cout<<"Yes";
      else cout<<"No";
    }
    return 0;
}

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

bool Xor(bool b1, bool b2){
  if(b1 && b2){
    return false;
  }else if(!b1 && !b2){
    return false;
  }else{
    return true;
  }
}

int main(){
  string s;
  int q;
  cin >> s >> q;
  int t, f;
  string c;
  string s1, s2;
  s1 = "";
  s2 = "";
  bool rev = false;
  for(int i;i<q;i++){
    cin >> t;
    if(t==1){
      rev = !rev;
    }else{
      cin >> f >> c;
      if(Xor(f==1, rev)){
        s1 += c;
      }else{
        s2 += c;
      }
    }
  }
  if(rev){
    reverse(s2.begin(),s2.end());
    reverse(s.begin(), s.end());
    cout << s2 + s + s1;
  }else{
    reverse(s1.begin(),s1.end());
    cout << s1 + s + s2;
  }
}


Measured memory_bytes: 1348
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main(){
    int n,m;
    cin>>n>>m;
    if(n==m){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

ll N,M,K;
ll A[200001], B[200001];

int main(){
    cin>>N>>M>>K;
    repn(i,N) cin>>A[i];
    repn(i,M) cin>>B[i];

    repn(i,N) A[i]+=A[i-1];
    repn(i,M) B[i]+=B[i-1];

    ll ans=0;
    rep(i,N+1){
        if(A[i]>K) continue;
        ll res=i;
        ll time=K-A[i];
        auto p=lower_bound(B,B+M+1,time+1);
        res+=(p-B)-1;
        ans=max(ans,res);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6744