akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

long long int gcd(int a, int b, int c)
{
    int temp;
    if(a>b)
    {
        temp=a;
        a=b;
        b=temp;
    }
    while(b%a!=0)
    {
        temp=a;
        a=b%a;
        b=temp;
    }
    if(a>c)
    {
        temp=a;
        a=c;
        c=temp;
    }
    while(c%a!=0)
    {
        temp=a;
        a=c%a;
        c=temp;
    }
    return(a);
}

int main()
{
    int K, i, j, k;
    long long int sum=0;
    scanf("%d", &K);
    for(i=1;i<=K;i=i+1)
    {
        for(j=1;j<=K;j=j+1)
        {
            for(k=1;k<=K;k=k+1)
            {
                sum = sum + gcd(i, j, k);
            }
        }
    }
    printf("%lld\n", sum);
}

Measured memory_bytes: 1728
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long[][] warshall=new long[11][11];
        int h=sc.nextInt();
        int w=sc.nextInt();
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                warshall[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    warshall[j][k]=Math.min(warshall[j][k],warshall[j][i]+warshall[i][k]);
                }
            }
        }
        long ans=0;
        int tmp;
        for(int i=0;i<h*w;i++){
            tmp=sc.nextInt();
            if(tmp>=0)ans+=warshall[tmp][1];
        }
        System.out.println(ans);
    }
}


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

int main()
{
  int h, w;
  scanf("%d%d", &h, &w);
  int a[500][500];
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      scanf("%d", a[i] + j);
    }
  }
  int initj[] = {0, w - 1};
  const int dir[] = {1, -1};
  std::stringstream ss;
  ss << "\n";
  int count = 0;
  for (int i = 0; i < h; ++i)
  {
    int d = i & 1;
    for (int j = initj[d]; j >= 0 && j < w; j += dir[d])
    {
      if (i == h - 1 && j == initj[d ^ 1]) continue;
      if ((a[i][j] & 1) == 0) continue;
      int y = i + (j == initj[d ^ 1] ? 1 : 0);
      int x = j + (j == initj[d ^ 1] ? 0 : dir[d]);
      ss << i + 1 << " " << j + 1 << " " << y + 1 << " " << x + 1 << "\n";
      a[y][x] ^= 1;
      ++count;
    }
  }
  std::cout << count << ss.str();
  return 0;
}

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

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

  int m,n;
  cin>>m>>n;
  char a[m][n];
  for (int i = 0; i < m; ++i)
  {
  	for(int j=0;j<n;j++)
  	{
  		cin>>a[i][j];
  	}
  }

  long long int dp[m][n];
  int flag=0;
  for (int i = 0; i < m; ++i)
  {
  	if(flag==0)
  	{
  		dp[i][0] = a[i][0] == '.' ? 1 : 0 ;
  		if(dp[i][0]==0)
  			flag=1;
  	}
  	else
  		dp[i][0]=0;
  }
  flag=0;
  for (int i = 0; i < n; ++i)
  {
  	if(flag==0)
  	{
  		dp[0][i] = a[0][i] == '.' ? 1 : 0 ;
  		if(dp[0][i]==0)
  			flag=1;
  	}
  	else
  		dp[0][i]=0;
  }

  for (int i = 1; i < m; ++i)
  {
  	for(int j=1;j<n;j++)
  	{
  		if(a[i][j]=='#')
  		dp[i][j]=0;
  	    else
  	    	dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(1000000007);
  	}
  }
  cout<<dp[m-1][n-1];
  return 0;
}

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

int bit[101];
void add(int k, int a) {
	while (k <= 100) {
		bit[k] += a;
		k += k&-k;
	}
}
int sum(int x) {
	int s = 0;
	while (x > 0) {
		s += bit[x];
		x -= x&-x;
	}
	return s;
}
int a[100];
int main() {
	int n; cin >> n;
	int res = 0;
	rep(i, n) {
		cin >> a[i];
		res += i - sum(a[i]+1);
		add(a[i] + 1, 1);
	}
	sort(a, a + n);
	rep(i, n) {
		if (i)cout << ' ';
		cout << a[i];
	}
	cout << endl;
	cout << res << endl;
}

Measured memory_bytes: 3152
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

class UnionFind
{
public:
    UnionFind(int N) : par(N)
    {
        for (ll i = 0; i < N; i++)
        {
            par[i] = i;
        }
    }

    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

private:
    vector<int> par;
};

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

struct Dish
{
    ll time;
    ll taste;
};

int main()
{
    ll N;
    cin >> N;
    ll sum = 0;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++)
    {
        ll ai;
        cin >> ai;
        sum ^= ai;
        A[i] = ai;
    }
    
    for (ll i = 0; i < N; i++)
    {
        cout << (sum ^ A[i]) << endl;
    }
    
}

Measured memory_bytes: 4732
#include<bits/stdc++.h>
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
const ll inf = INT_MAX;

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  string s;
  cin >> s;
  int passed_jp = 0, passed_other = 0;
  REP (i, s.size()) {
    if (s[i] == 'a'){
      if (passed_jp + passed_other < A + B) {
        cout << "Yes" << endl;
        passed_jp++;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i] == 'b') {
      if (passed_jp + passed_other < A + B && passed_other < B) {
        cout << "Yes" << endl;
        passed_other++;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


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

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

  int ans = 10000000;
  int ansnum;

  for(int i=0;i<N;i++){
    int gap = abs(a[i]);
    if(ans>gap) {
      ans = gap; 
      ansnum = i;
    }
  }

  cout << sum-a[ansnum] << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define maxn 10000007
#define min(a,b) a<b?a:b
struct data{
	int a,b;
}consum[1003];
int dp[10004];
int main()
{
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	int h,n;
	scanf("%d %d",&h,&n);
	for(int i=0;i<n;++i)
	{
		scanf("%d %d",&consum[i].a,&consum[i].b);
	}
	consum[n].a=0;
	consum[n].b=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(consum[j].a>i) continue;
			if(dp[i-consum[j].a]!=-1) 
			{
				if(dp[i]==-1) dp[i]=dp[i-consum[j].a]+consum[j].b;
				else dp[i]=min(dp[i-consum[j].a]+consum[j].b,dp[i]);
			}
 		}
	 } 
	 int mintip=-1,nowtip=0,tiptip;
	 	for(int now=0;now<=h;now++)
	 	{
	 		if(dp[now]==-1) continue;
	 		for(int i=0;i<=n;i++)
	 	{
	 		if(now+consum[i].a>=h)
	 		{
	 			if(mintip==-1||mintip>dp[now]+consum[i].b)
	 			{
	 				mintip=dp[now]+consum[i].b;
				}
			}
	 	}
		 }
	 	printf("%d\n",mintip);
	return 0;
 } 

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=998244353;
#define N 3000000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int k,n;
    cin>>k>>n;
    if(!(k%2)){
        cout<<k/2<<" ";
        rep(i,n-1){
            cout<<k<<" ";
        }
      return 0;
    }
  if(k==1) rep(i,(n+1)/2) cout<<1<<" ";
    else{
        int a[N+1]={};
        fill(a,a+N+1,(k+1)/2);
        int res=n/2;
        while(res>0){
            if(a[n-1]) a[n-1]--;
            else{
                int pos=n-2;
                while(a[pos]==0){
                    pos--;
                }
                a[pos]--;
                if(a[pos]>0){
                    rep2(i,pos+1,n-1){
                        a[i]=k;
                    }
                }
            }
            res--;
        }
        rep(i,n){
            if(a[i]) printf("%d ",a[i]);
            else return 0;
        }
    }
    return 0;
}


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


int main(){
    int W, H, x, y, r;
    bool horizontal, vertical;
    cin >> W >> H >> x >> y >> r;
    horizontal = r <= x && x <= W-r;
    vertical = r <= y && y <= H-r;
    if (horizontal && vertical) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;

    int ans = 0;

    string k = a;
    string t = b;
    int len = n;
    for(int i = 0; i < n; i++){
        if(k == t){
            ans = i;
            break;
        }else{
            k.erase(0, 1);
            t.erase(len - 1, 1);
            len--;
        }
    }

    cout << 2 * n - len << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
from collections import Counter
from math import factorial

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = np.array(rl())
A_cum = A.cumsum()
A_cum %= M
A_cum = A_cum.tolist()
c = Counter(A_cum)
answer = 0

for k, v in c.items():
    if k == 0:
        answer += v
    if v >= 2:
        answer += factorial(v) // factorial(2) // factorial(v-2)

print(answer)
#13


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

int main(int argc, char **argv)
{
	ll K, N;
	cin >> K >> N;
	vector<ll> A(N), diff(N, 0);
	for (ll i = 0; i < N; ++i) cin >> A[i];
	for (ll i = 0; i < N-1; ++i)
	{
		diff[i] = abs(A[i] - A[i+1]);
	}
	diff[N-1] = K - abs(A[N-1] - A[0]);
	std::cout << K - *max_element(diff.begin(), diff.end()) << std::endl;
	
}

Measured memory_bytes: 3328
//
/*
//*/
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define lowbit(x) ((x)&-(x))
struct IO{
	inline char gc() {static char buf[10000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000000,stdin),p1==p2)?EOF:*p1++;}
    #ifdef ONLINE_JUDGE
    #else
    	#define gc getchar
    #endif
	template<typename T>inline IO operator>>(T &n){n=0; bool s=0; char c=gc();while(c<'0'||c>'9') s|=c=='-',c=gc();while(c>='0'&&c<='9') n=(n<<3)+(n<<1)+(c^48),c=gc();if(s) n=-n;return *this;}
	template<typename T>inline IO operator<<(T x){if (x<0) x=-x,putchar('-');static T sta[35];T top = 0;do{sta[top++] = x % 10, x /= 10;}while (x);while (top) putchar(sta[--top] + '0');return *this;}
}cin,cout;
int a,b;
int main ()
{
	#ifdef ONLINE_JUDGE
	#else
	//freopen("E:\\testdata.in","r",stdin);
	//freopen("E:\\testdata.out","w",stdout);
	#endif
	cin>>a>>b;
	if(a>9||b>9)
	{
		cout<<-1;
		return 0;
	}
	cout<<a*b;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  
  if(c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int n,a,b,c;
int l[8];
const int INF = 1 << 28;

int solve(int t, vector<int> &L) {
  if(L.size() == 0) return INF;
  int ret = INF;
  int N = L.size();
  rep(i, 1, (1<<N)) {
    int mp = 10 * (__builtin_popcount(i) - 1);
    int s = 0;
    rep(j, N) if((1<<j) & i) s += L[j]; 
    mp += abs(s-t);
    umin(ret, mp);
  }
  return ret;
}

int dfs(int d, vector<int> &A, vector<int> &B, vector<int> &C) {
  int ret = INF;
  if(d==n) return solve(a, A) + solve(b, B) + solve(c, C);
  A.push_back(l[d]);
  umin(ret, dfs(d+1, A, B, C));
  A.pop_back();
  B.push_back(l[d]);
  umin(ret, dfs(d+1, A, B, C));
  B.pop_back();
  C.push_back(l[d]);
  umin(ret, dfs(d+1, A, B, C));
  C.pop_back();
  umin(ret, dfs(d+1, A, B, C));
  return ret;
}

//https://atcoder.jp/contests/abc119/tasks/abc119_c
int main() {
 cin >> n >> a >> b >> c; 
 rep(i,n) cin >> l[i];

 vector<int> A, B, C;
 cout << dfs(0, A, B, C) << endl;;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n); for(long long i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
int main(){
  ll n; cin >>n;
  vector<ll>d(n); rep(i,n)cin >> d[i];
  ll ans = 0;
  for(int i = 0;i < n;i++){
    for(int j = i + 1;j < n;j++){
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
}

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

int main() {
	int w, h, n; cin >> w >> h >> n;
	int xy[105][105];
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			xy[i][j] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		int x, y, a; cin >> x >> y >> a;
		if (a == 1) {
			for (int xi = 0; xi < x; xi++) {
				for (int yi = 0; yi < h; yi++) {
					if (xy[xi][yi] == 1)xy[xi][yi]--;
				}
			}
		}
		else if (a == 2) {
			for (int xi = x; xi < w; xi++) {
				for (int yi = 0; yi < h; yi++) {
					if (xy[xi][yi] == 1)xy[xi][yi]--;
				}
			}
		}
		else if (a == 3) {
			for (int xi = 0; xi < w; xi++) {
				for (int yi = 0; yi < y; yi++) {
					if (xy[xi][yi] == 1)xy[xi][yi]--;
				}
			}
		}
		else {
			for (int xi = 0; xi < w; xi++) {
				for (int yi = y; yi < h; yi++) {
					if (xy[xi][yi] == 1)xy[xi][yi]--;
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			ans += xy[i][j];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"
signed main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<int> s(A + 2, 0), t(B + 2, 0);
    s[0] = -INF; t[0] = -INF;
    s[A + 1] = INF; t[B + 1] = INF;
    for (int i = 0; i < A; ++i) {
        cin >> s[i + 1];
    }
    for (int i = 0; i < B; ++i) {
        cin >> t[i + 1];
    }
    for (int i = 0; i < Q; ++i) {
        int x;
        cin >> x;
        auto shrineIter = lower_bound(s.begin(), s.end(), x);
        auto templeIter = lower_bound(t.begin(), t.end(), x);
        // cout << *shrineIter << endl;
        int shrine1 = abs(x - *shrineIter);
        int shrine2 = abs(x - *(shrineIter - 1));
        int temple1 = abs(x - *templeIter);
        int temple2 = abs(x - *(templeIter - 1));
        int answer = max(shrine1, temple1);
        answer = min(answer, max(shrine2, temple2));
        answer = min(answer, min(shrine1, shrine2) + min(temple1, temple2) + min({shrine1, shrine2, temple1, temple2}));
        cout << answer << endl;
    }
}

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

int main (){
    int r, c;
    cin >> r >> c;
    int tc[r+1][c+1];
    for (int i = 0; i < r + 1; i++)
		tc[i][c] = 0;
	for (int j = 0; j < c + 1; j++)
		tc[r][j] = 0;
    for(int i = 0; i < r; i++)
        for(int j = 0; j < c; j++) {
            cin >> tc[i][j];
            tc[i][c] += tc[i][j];
        }
    for(int j = 0; j < c+1; j++)
        for(int i = 0; i < r; i++)
            tc[r][j] += tc[i][j];
    for(int i = 0; i < r+1; i++) {
        for(int j = 0; j < c; j++)
            cout << tc[i][j] << ' ';
        cout << tc[i][c] << endl;
    }
    return 0;
}


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

int main(){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e-a > k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
a=gets.split
sta=[]
while a.first do
  case a.first
  when "+"
    sta.push(sta.pop.to_i+sta.pop.to_i)
  when "-"
    sta.push(-1*sta.pop.to_i+sta.pop.to_i)
  when "*"
    sta.push(sta.pop.to_i*sta.pop.to_i)
  when "/"
    sta.push(sta.pop.to_i/sta.pop.to_i)
  else
    sta.push(a.first.to_i)
  end
  a.delete_at(0)
end
puts sta.pop



Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char aa[N],a[N],mp[9]="ABC";
int be[N],en[N],tp[N];
int nn,i,j,k,n,ct[3],ctt[3],id[N],xb1,xb2,he,ta,p[N];
bool bb[N];
inline void swapp(int x,int y){
	swap(ct[x],ct[y]);swap(mp[x],mp[y]);
	for(int i=1;i<=n;++i)
		if(a[i]-'A'==x)a[i]='A'+y;
			else if(a[i]-'A'==y)a[i]='A'+x;
}
inline void ins(int l,int r){
	be[++xb2]=l;en[xb2]=r;
	++ct[tp[xb2]=l<r?0:a[l]-'A'];
}
inline void build(){
	memset(ct,0,12);xb1=xb2=0;
	for(i=1;i<=n;++i)if(a[i]=='A')id[++xb1]=i;
	if(id[1]>1)ins(1,id[1]-1);
	for(i=1;i<xb1;++i)ins(id[i]+1,id[i+1]-1);
	if(id[xb1]<n)ins(id[xb1]+1,n);
}
int main(){
	scanf("%s",aa+1);nn=strlen(aa+1);
	for(i=1;i<=nn;++i)if(!n || aa[i]!=a[n])a[++n]=aa[i];
	for(i=1;i<=n;++i)++ct[a[i]-'A'];
	if(ct[1]<ct[0] && ct[1]<=ct[2])swapp(0,1);
		else if(ct[2]<=ct[1] && ct[2]<ct[0])swapp(0,2);
	if(!ct[0]){
		puts("");
		return 0;
	}
	build();
	if(ct[2]<ct[1])swapp(1,2),build();
	he=1;ta=n;memcpy(aa+1,a+1,n);
	if(ct[0]+ct[1]<ct[2] && aa[ta]=='C' && aa[ta-1]=='A')--xb2,--ct[2],--ta;
	if(ct[0]+ct[1]<ct[2] && aa[he]=='C' && aa[he+1]=='A')--xb2,--ct[2],++he;
	n=0;
	for(i=he;i<=ta;++i){
		a[++n]=aa[i];
		if(n>2 && a[n-2]=='A' && a[n-1]=='C' && a[n]=='A' && 
			ct[0]+ct[1]<ct[2])--ct[2],n-=2;
	}
	build();
for(i=1;i<xb1;++i)if(id[i]+1==id[i+1])
++i,--i;
	for(i=1;i<=xb2;++i){
		p[i]=be[i];
		if(tp[i])++p[i];else if(ct[1]<ct[2]){
			if(a[be[i]]=='B')++p[i];
				else p[i]+=2,bb[i]=1;
			++ct[1];--ct[0];
		}
	}
	for(i=1;i<=xb2;++i)if(p[i]+1<=en[i] && p[i]==be[i] && ct[1]<xb1)++ct[1],p[i]+=2;
	for(i=1;i<=xb2;++i)
		for(;p[i]+1<=en[i] && ct[1]<xb1;++ct[1])p[i]+=2;
	vector<int>v[2];
	for(i=1;i<=xb2;++i){
		if(bb[i])v[a[be[i]]-'B'].push_back(i);
		if(p[i]<=en[i])v[a[en[i]]-'B'].push_back(i);
	}
	for(;ct[1]<xb1;v[0].pop_back(),v[1].pop_back(),++ct[1]){
		int x=v[0].back(),y=v[1].back();
		if(bb[x] && a[be[x]]=='B')bb[x]=0;else ++p[x];
		if(bb[y] && a[be[y]]=='C')bb[y]=0;else ++p[y];
	}
int ff=0;
	for(i=j=1;i<=xb2;++i)if(p[i]>be[i]){
		for(;j<=xb1 && id[j]<be[i];++j){
if(id[j]==215)
++j,--j;
if(ff)
++i,--i;
			putchar(mp[0]),++ff;
		}
		for(k=bb[i]?be[i]+1:be[i];k<p[i];++k)putchar(mp[a[k]-'A']),ff=0;
	}
	for(;j<=xb1;++j)putchar(mp[0]);
	return 0;
}

Measured memory_bytes: 16896
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
a.sort()
ln = len(bin(max(k,a[-1]))) - 2 #2進数に直した時の桁数
bit = [0 for i in range(ln)]
res = 0
ans = 0
for x in a:
    for i in range(ln):
        if i: 
            (x>>1) % 2
            x = x>>1
        if x%2:
            bit[i] += 1
    # print(bit)
for i,j in enumerate(bit):
    if j < n/2:
        bit[i] = 1
    else:
        bit[i] = 0
# print(bit)
for i in range(ln):
    if bit[ln-i-1]:
        c = pow(2,ln-i-1)
        if k >= c:
            res += c
            k -= c

for i in a:
    ans += i^res
print(ans)


Measured memory_bytes: 92116
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,X;
  cin >> N >> X;
  vector<int> m(N);
  rep(i,N)
  {
    cin >> m[i];
  }
  int sum =0;
  int n = 1000;
  rep(i,N)
  {
    sum += m[i];
    n = min(n,m[i]);
  }
  X -= sum;
  cout << N+X/n << endl;
  return 0;
}


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

typedef long long LL;  
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const int M = (int)1e9+7;

int main()
{
//ios_base::sync_with_stdio(0); 
cout.precision(15);
cout.setf(ios::fixed);

int n;

cin >> n;

int i;

int k,cnt = 0;

for(i=0;i<n;i++)
	{
	cin >> k;
	if(k%2==1) cnt++; 	
	}

if(cnt%2==0)
	cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false INT_MAX INT_MIN insert erase clear pop push compare INT64_MAX INT64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const int mod = 1e9 + 7 ;
const int inf =
 1e9 + 5 ;
 //1e18L + 5;
const int nax = 2e5 + 5;
void min_self(int&a , int b){a=min(a,b);}
void max_self(int&a , int b){a=max(a,b);}
void add_self(int&a , int b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)

vector<int> dx = {1,-1,0,0} , dy = {0,0,-1,1} ;

signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int h , w ; cin >> h>> w ; 
vector<string> arr(h) ;
for(int i = 0 ;i< h ; i++){
	cin >> arr[i] ;
}	

auto is_good = [&](int row1 , int col1){
	return row1 <0 || col1 <0 || row1>=h || col1 >=w || arr[row1][col1] == '#';
};
int ans = 0 ; 
for(int row = 0  ;row < h ; row++){
	for(int col = 0 ; col <w ; col ++){
		vector<vector<int>> dp (h , vector<int> (w ,inf ));
		dp[row][col]  = 0;
		vector<vector<bool>> visited(h , vector<bool>(w , false ));
		queue<pair<int,int>> q ;
		q.push({row ,col});
		while(!q.empty()){
			pair<int ,int> node = q.front() ; 
			q.pop(); 
			if(is_good(node.first , node.second) || visited[node.first][node.second])continue ; 
			visited[node.first][node.second] = true; 
			for(int dir = 0 ; dir < 4 ; dir ++){
				int newrow  = node.first + dx[dir] ; 
				int newcol  = node.second +dy[dir] ;
				if(is_good(newrow , newcol))continue;
				// cout << row <<col << newrow <<newcol << endl;

				q.push({newrow , newcol});
				min_self(dp[newrow][newcol] , dp[node.first][node.second] + 1); 
				max_self(ans , dp[newrow][newcol]);
			}
		}
		// for(auto i:dp){for(auto j:i)cout<<j<<" " ;cout << endl;}cout << endl<<endl;
	}
}
cout << ans ;

	
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int h[n];
  for(int i = 0; i < n; i++) cin >> h[i];

  int ans = 0;
  int s = 0;;
  while(s < n){
    int t = s;
    while(t + 1 < n && h[t] >= h[t + 1]) ++t;
    ans = max(ans, t - s);
    s = t + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        List<Integer>[] edge = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            edge[i] = new ArrayList<>();
        }
        for (int i = 1; i < n; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;
            edge[a].add(b);
            edge[b].add(a);
        }

        Deque<Integer> deque = new ArrayDeque<>();
        deque.add(0);
        int[] dist1 = new int[n];
        boolean[] visited1 = new boolean[n];
        while (!deque.isEmpty()) {
            int i = deque.poll();
            for (int j : edge[i]) {
                if (!visited1[j]) {
                    visited1[j] = true;
                    dist1[j] = dist1[i] + 1;
                    deque.add(j);
                }
            }
        }

        deque.add(n - 1);
        int[] dist2 = new int[n];
        boolean[] visited2 = new boolean[n];
        while (!deque.isEmpty()) {
            int i = deque.poll();
            for (int j : edge[i]) {
                if (!visited2[j]) {
                    visited2[j] = true;
                    dist2[j] = dist2[i] + 1;
                    deque.add(j);
                }
            }
        }

        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < n; i++) {
            if (dist1[i] <= dist2[i]) {
                count1++;
            } else {
                count2++;
            }
        }
        System.out.println(count1 > count2 ? "Fennec" : "Snuke");
    }
}

Measured memory_bytes: 103716
#include<iostream>
using namespace std;
int main(){
  
  int a,b,d;
  char c;
  
  cin >>a;
  
  while(1){
    
    cin >>c;
    
    if( c == '=' )break;    
    
    cin >>b;
    
    if( c == '+'){
      a=a+b;
    }else if( c == '-'){
      a=a-b;
    }else if( c == '/'){
      a=a/b;
    }else if( c == '*'){
      a=a*b;
    }
    
  }
  
  cout <<a<<endl;
  
  return 0;
  
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXN = 2e5 + 2;
const ll MAXK = 1e3 + 5;
const ll MOD = 1e9 + 7;
const ll MODH = 1e9 + 9;
const int MAXLG = 20;
const long double PI = acos(-1);
const ll p = 41;
const long double EPS = 1e-4;
#define x first
#define y second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
ll binpow(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
}return res;}


vector<int> g[MAXN];
ll dp[MAXN][3];

void dfs(int u,int p,int col)
{

 
   dp[u][0] = dp[u][1] = 1;
   for(auto &k : g[u])
   {
   	if(k == p)
   		 continue; 
   		dfs(k,u,1);
   		 
   	dp[u][0]*=(dp[k][1] + dp[k][0]);
   	dp[u][1]*=dp[k][0];
   	dp[u][0]%=MOD;
   	dp[u][1]%=MOD;
   }
   
  
   
}



int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for(int i = 0 ; i < n - 1; i++)
  {
  	int u,v;
  	cin >> u >> v;
  	g[u].push_back(v);
  	g[v].push_back(u);
  }
  dfs(1,0,-1);
  cout << (dp[1][0] + dp[1][1])%MOD;

  
 
  
}

Measured memory_bytes: 19284
n, m = gets.chomp.split.map(&:to_i)
dp = [0] * (n + 1)

dp[0] = 1
dp[1] = 1

m.times do
  a = gets.to_i
  dp[a] = -1
end
mod = 10**9 + 7

2.upto(n) do |i|
  next if dp[i] == -1
  v1 = dp[i - 1] == -1 ? 0 : dp[i - 1]
  v2 = dp[i - 2] == -1 ? 0 : dp[i - 2]
  dp[i] = (v1 + v2) % mod
end

puts dp[n]

Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define FoR(i,x,y,z) for(int i=(x);i<=(y);i+=(z))
#define RoF(i,x,y,z) for(int i=(x);i>=(y);i-=(z))
#define Edge(x) for(int i=head[x],to=e[i].v;i;i=e[i].nxt,to=e[i].v)
typedef long long ll;
const int N=100005;
const int mod=1e9+7;
using namespace std;
char s[N];
int pre[N],f[N],pos[3],hve[N];
void add(int &x,int y){ x+y>=mod?x=x+y-mod:x=x+y; }
int main(){
	scanf("%s",s+1); int n=strlen(s+1);
	For(i,1,n){
		pre[i]=(pre[i-1]+s[i]-'a'+1)%3;
		if(i!=n) hve[i]=(s[i]==s[i+1]);
	}
	For(i,1,n) hve[i]+=hve[i-1];
	if(!hve[n]) return puts("1"),0;
	f[0]=1;pos[0]=0,pos[1]=pos[2]=-1;
	For(i,1,n){
		if(!pre[i] && i!=n) add(f[i],1);
		add(f[i],f[i-1]);
		int fr=pos[(pre[i]+s[i]-'a'+1)%3];
		if(~fr && hve[i]-hve[fr]) add(f[i],f[fr]);
		pos[pre[i]]=i;		
	}
	printf("%d\n",f[n]);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int a,b; cin>>a>>b;
  if (a>9 || b>9) {
    cout << -1 << endl;
    return 0;
  }
  cout << a*b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[15], memo[15][10010];
int need[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp(int pos, int sisa)
{
	int ret;
	if(sisa==0)
		return 0;
	if (pos==0)
		return -1000000000;
	if (memo[pos][sisa] != -1)
		return memo[pos][sisa];
	ret = dp(pos - 1, sisa);
	if (sisa >= need[a[pos]])
		ret = max(ret, dp(pos,sisa-need[a[pos]])+1);
	memo[pos][sisa] = ret;
	return ret;
}
int main()
{
	int n, m, ans;
	cin>>n>>m;
	for (int i = 1; i <= m; i++)
		cin>>a[i];
	sort(a + 1, a + m + 1);
	memset(memo, -1, sizeof (memo));
	ans=dp(m,n);
	for(int i = 1; i <= ans; i++)
	{
		while (dp(m,n-need[a[m]])!=ans-i)
			m--;
		cout<<a[m];
		n-=need[a[m]];
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int a = ni();
        int b = ni();

        if (a == 1) a = 14;
        if (b == 1) b = 14;

        if (a == b) {
            out.println("Draw");
        } else if (a < b) {
            out.println("Bob");
        } else {
            out.println("Alice");
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 21460
#include<stdio.h>
#include<string.h>
void select(int t[],int q);
/*int erfen(int t[],int key,int q);*/ 
int main() {
	int n,q,i,j,time=0,key;
	scanf("%d",&n);
	int s[n];
	for(i=0; i<n; i++)
	scanf("%d",&s[i]);
	scanf("%d",&q);
	int t[q];
	for(i=0; i<q; i++)
	scanf("%d",&t[i]);//输入
	//select(s,n);
	for(i=0; i<q; i++) {
		key=t[i];
		time=time+erfen(s,key,n);
	}
	printf("%d\n",time);
	return 0;
}
/*void select(int t[],int q) {
	int i,j,min,mid;
	for(i=0; i<q; i++) {
		min=i;
		for(j=i; j<q; j++) {
			if(t[j]<t[min])
				min=j;
		}
		if(min!=i) {
			mid=t[i];
			t[i]=t[min];
			t[min]=mid;
		}
	}
}*/ 
int erfen(int t[],int key,int q) {
	int left=0,right=q;
	while(left<right) {
		int mid=(left+right)/2;
		if(t[mid]==key)
			return 1;
		else if(t[mid]>key) {
			right=mid;
		} else if(t[mid]<key) {
			left=mid+1;
		}
	}
	return 0;
}


Measured memory_bytes: 2328
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

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

using namespace std;

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

  long long x1, x2, x3, y1, y2, y3;
  const long long int b = 1000000000;

  x1 = 0; y1 = 0;
  x2 = b; y2 = 1;
  x3 = (b-s%b)%b;
  y3 = (s+x3)/b; 

  cout << x1 << " " << y1 << " ";
  cout << x2 << " " << y2 << " ";
  cout << x3 << " " << y3 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000000
#define mod 2019

int main(){
	ll n,i;cin>>n;
	vector<string> s(n);
	vector<ll> num;
	for(i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}

	sort(s.begin(),s.end());

	s.push_back("-1");//sentinel

	ll number=1;
	for(i=0;i<n-1;i++){
		if(s[i]==s[i+1]){
			number++;
			if(i==n-2){num.push_back(number);}
		}else{
			num.push_back(number);
			number=1;
		}
	}

	ll ans=0;
	for(i=0;i<num.size();i++){
		if(num[i]!=1){ans+=num[i]*(num[i]-1)/2;}
	}

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

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

int yakusukosu(int x){
	int count=0;
	for(int i=1;i<=x;i++){
		if(x%i==0)count++;
	}
	return count;
}

int main() {
	int n,count=0;
	cin>>n;
	
	for(int i=1;i<=n;i+=2){
		if(yakusukosu(i)==8)count++;
	}
	
	cout<<count<<endl;
	
}


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

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

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

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

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

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

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

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

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

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

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

    string s;
    cin >>s;

    if(s.length()%2==0)flag=true;
    else {cout<<"No"<<endl;return 0;}

    rep(i,s.length()){
        ++i;
        if(s[i-1]=='h' && s[i]=='i')continue;
        else{
            flag=false;
            break;
        }
    }

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


Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    h, w, k = ns()
    mat = [list(input()) for _ in range(h)]

    # if h == 1:
    #     tmp = max(0, mat[0].count("1") - 1)
    #     print(tmp // k)
    #     exit(0)

    ans = INF
    for i in range(2 ** (h - 1)):
        cut = format(i, "b").count("1")
        row = cut + 1

        cnt = [0 for _ in range(row)]

        idx_dic = dict()
        tmp_idx = 0
        for j in range(h):
            idx_dic[j] = tmp_idx
            if i >> j & 1:
                tmp_idx += 1

        tmp_ans = cut
        xi = 0
        brkflg = True
        while xi < w:
            yi = 0
            prev_brkflg = brkflg
            brkflg = False
            while yi < h:
                if mat[yi][xi] == "1":
                    cnt[idx_dic[yi]] += 1
                    if cnt[idx_dic[yi]] > k:
                        cnt = [0 for _ in range(row)]
                        xi -= 1
                        brkflg = True
                        tmp_ans += 1
                        break

                yi += 1
            if brkflg and prev_brkflg:
                tmp_ans = INF
                break
            xi += 1
        ans = min(ans, tmp_ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10812
def lcs(x, y):
    a = len(x)
    b = len(y)
    c1 = [0] * (b + 1)
    for i in range(a):
        c2 = c1[:]
        for j in range(b):
            if x[i] == y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]


if __name__ == "__main__":
    N = int(input())
    for _ in range(N):
        x = input()
        y = input()
        print(lcs(x, y))



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

using namespace std;

long long n, a, b, c, d;

int main() {
	cin >> n >> a >> b >> c >> d;
	--n;
	if (c + d == 0) {
		puts(a == b ? "YES" : "NO");
		return 0;
	}
	long long dist = b - a;
	long long lt = max(0LL, (c * n - dist + c + d - 1)/(c + d));
	long long rt = min(n, (d * n - dist)/(c + d));
	puts(lt <= rt ? "YES" : "NO");
	return 0;
}



Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int,input().split()))

count_dict = collections.Counter(A)
c_list = [0]*(N+1)
ans_list = [-1]*(N+1)
ans = [0]*(N)

for k,v in count_dict.items():
    c_list[k] = max(v*(v-1)/2,0)
S = sum(c_list)

for i in range(N):
    x = A[i]
    if ans_list[x] != -1:
        ans[i] = ans_list[x]
        continue
    v = count_dict[x]
    tmp = S - c_list[x] + max((v-2)*(v-1)/2,0)
#    print("tmp:",tmp,"S:",S,"c_list:",c_list[x],"v:",v)
    ans_list[x] = int(tmp)
    ans[i] = int(tmp)

for i in range(N):
    print(ans[i])

Measured memory_bytes: 98636
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var A = Number.parseInt(inputStr[0]);
  var B = Number.parseInt(inputStr[1]);
  var T = Number.parseInt(inputStr[2]) + 0.5;
  
  console.log(Math.floor(T/A)*B);
  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  int N,M,A;
  long cnt = 0;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= M; i++) {
    scanf("%d", &A);
    N -= A;
  }
  if (N >= 0) {
    printf("%d\n",N);
  } else {
    printf("-1\n");
  }
  return 0;
}


Measured memory_bytes: 2136
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;

ll mod_pow(ll k, ll p)
{
    if (k == 0)
    {
        return 1 % p;
    }
    if (k == 1)
    {
        return 2 % p;
    }

    if (k % 2 == 0)
    {
        ll tmp = mod_pow(k / 2, p);
        return tmp * tmp % p;
    }
    else
    {
        ll tmp = mod_pow((k - 1) / 2, p);
        tmp *= tmp;
        tmp %= p;
        tmp *= 2;
        tmp %= p;
        return tmp;
    }
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2) % MOD;
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, (k - 1) / 2);
        return tmp * tmp * n;
    }
}
map<ll, ll> sosuu(ll n)
{
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            n /= i;
            mp[i] += 1;
        }
    }
    if (n != 1)
    {
        mp[n] += 1;
    }
    return mp;
}

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

    cout <<  (N) * (N - 1) /2  << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e6 + 10, mod = 998244353;
 
namespace {
  inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
  inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
  inline int mul(int x, int y) { return 1LL * x * y % mod; }
  inline int kissme(int x, int y) {
    int c = 1;
    for(; y; y >>= 1, x = mul(x, x)) {
      if(y & 1) {
    c = mul(c, x);
      }
    }
    return c;
  }
}
 
int inv[N], ifac[N], fac[N], n, m;
 
void prework(void) {
  inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for(int i = 2; i < N; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = mul(mod - mod / i, inv[mod % i]);
    ifac[i] = mul(ifac[i - 1], inv[i]);
  }
}
 
int binom(int x, int y) {
  assert(x >= y);
  return mul(fac[x], mul(ifac[y], ifac[x - y]));
}
 
int main(void) {
  prework();
  scanf("%d%d", &n, &m);
  int ans = 0;
  for(int i = 1; i <= min(n, m); i++) {
    ans = add(ans, mul(binom(2 * i, i), binom(n + m - 2 * i, n - i)));
  }
  ans = mul(ans, kissme(2 * binom(n + m, n) % mod, mod - 2));
  cout << add(max(n, m), ans) << endl;
  return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=x;i<=y;i++)

long long C[100][100];
int n,a,b;
long long f[100];
int cmp(long long  a,long long  b)
{
	return a>b;
}
int main()
{
	C[0][0]=1;
	rep(i,1,50) rep(j,0,i) C[i][j]=C[i-1][j-1]+C[i-1][j];
	scanf("%d%d%d",&n,&a,&b);
	rep(i,1,n) cin>>f[i];
	sort(f+1,f+n+1,cmp);
	long long ans=0;
	rep(i,1,a) ans+=f[i];
	long double pp=ans;
	pp/=a;
	printf("%.8Lf\n",pp);
	int x=0,y=0;
	rep(i,1,n) if (f[i]==f[a]) y++;
	rep(i,1,a) if (f[i]==f[a]) x++;	
	ans=0;
	if (x!=a) ans+=C[y][x]; else rep(i,x,b) ans+=C[y][i];
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>


using namespace std;


int main() {

	int n, a[100009];
	int num[100009] = {0};
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		num[a[i]]++;
		num[a[i] + 1]++;
		num[a[i] - 1]++;
	}

	sort(num, num + 100009, greater<int>());
	cout << num[0] << endl;
	return 0;

}



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

int main(){
    ll n;
    vector<ll> a(5);
    cin >> n;
    rep(i, 5)cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 5 + (n-1)/a[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;
typedef unsigned int UINT;
typedef int INT;

int main()
{
	INT L;
	cin >> L;

	double a = L / 3.0;
//	cout << a * a * a << endl;
	printf("%lf\n", a*a*a);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

//入力
int N;
long long a[100010][3]; //a[i], b[i], c[i]をそれぞれまとめて、a[i][0], b[i][1], c[i][2]にして考える

//DPテーブル
long long dp[100010][3];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < 3; ++j)
            cin >> a[i][j];

    //初期化は既に、0に初期化させる
    //初期条件も既に0でok

    //ループ
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 3; ++k)
            {
                if (j == k)
                    continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    long long res = 0;
    for (int j = 0; j < 3; ++j)
        chmax(res, dp[N][j]);
    cout << res << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

ll dp[15][21][160] = {{{}}};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,s;
  dp[0][0][0] = 1;
  rep(j,21){
    rep(i,11){
      rep(k,155){
        dp[i+1][j+1][k+j+1] += dp[i][j][k];
        dp[i][j+1][k] += dp[i][j][k];
      }
    }
  }
  while(cin >> n >> k >> s && n + k + s){
  /* rep(i,5){                            */
  /*   rep(j,k+1){                        */
  /*     rep(l,s+1){                      */
  /*         cout << dp[i][j][l] <<  ' '; */
  /*       }                              */
  /*       cout << endl;                  */
  /*     }                                */
  /*     cout << endl;                    */
  /*   }                                  */
    cout << dp[k][n][s] << endl;
  }
  return 0;
}

Measured memory_bytes: 3416
import sys
input = sys.stdin.readline
def print_ans(input_line):
    """Test Case
    >>> print_ans(2)
    8
    >>> print_ans(1)
    1
    """
    print(str(input_line ** 3))

if __name__ == '__main__':
    s = int(input().rstrip())
    print_ans(s)

Measured memory_bytes: 3060
#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
   return map(int, stdin.readline().split())
#lines = stdin.readlines()

a = input()
b = input()
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
   print("YES")
else:
   print("NO")

Measured memory_bytes: 3060