akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 102;

int a[N][N];

void solv()
{
    int q;
    scanf("%d", &q);
    while (q--)
    {
        char s[20];
        scanf(" %s", s);
        int n = strlen(s);

        ll x = 0;

        bool z = false;
        for (int i = 0; i < n; ++i)
        {
            if (s[i] == '.')
            {
                int q = 9 - (n - i - 1);
                for (i = i + 1; i < n; ++i)
                {
                    x = x * 10 + s[i] - '0';
                }
                while (q--)
                {
                    x = x * 10;
                }
                z = true;
                break;
            }
            x = x * 10 + s[i] - '0';
        }
        if (!z)
        {
            for (int i = 0; i < 9; ++i)
                x = x * 10;
        }
        int q2 = 0;
        int q5 = 0;
        while (x % 2 == 0)
        {
            ++q2;
            x /= 2;
        }
        while (x % 5 == 0)
        {
            ++q5;
            x /= 5;
        }
        a[q2][q5]++;
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            if (!a[i][j])
                continue;
            for (int i1 = 0; i1 < N; ++i1)
            {
                for (int j1 = 0; j1 < N; ++j1)
                {
                    if (min(i + i1, j + j1) >= 18)
                    {
                        if (!(i == i1 && j == j1))
                            ans += a[i][j] * 1LL * a[i1][j1];
                        else
                            ans += (a[i][j] * 1LL * a[i][j] - a[i][j]);
                    }
                }
            }
        }
    }
    ans /= 2;
    printf("%lld\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long Int;
string str;
int dp[1080], n;

int main(){
	int r[1080], w[1080];
	while(cin >> n, n){
		int m = 0, sr = 0, sw = 0;
		for(int i = 0;i < n;i++){
			cin >> r[i] >> w[i];
			m = max(m, r[i]);
			sr += r[i];
			sw += w[i];
		}
		if(m * 2 <= sr){
			cout << sr + sw << endl;
			continue;
		}
		fill(dp, dp + 1080, 0);
		dp[0] = 1;
		for(int i = 0;i < n;i++){
			if(r[i] == m)continue;
			for(int j = 1079;j - w[i] >= 0;j--){
				dp[j] |= dp[j - w[i]];
			}
		}
		int ok = m * 2 - sr;
		while(dp[ok] == 0)ok--;
		cout << m + m + sw - ok << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int k = fs.nextInt();
		int a = fs.nextInt();
		int b = fs.nextInt();
		
		for(int i = a;i <= b; i++) {
			if(i % k == 0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32672
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,l,r) for (int i=l;i<=r;++i) 
#define mp(x,y) make_pair(x,y)
#define ft first
#define sd second 
#include <map>
#include <string>
#include <iostream>
#define GG return printf("-1"),0;
using namespace std;
const int N=1e5+5;
void read(int &x)
{
	x=0;
	char ch=getchar();int f=1;
	while (ch<'0'||ch>'9') ch=='-'?f=-1:0,ch=getchar();
	while ('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x*=f;return ;
}

int n,a[N],b[N],c[N],d[N];
int tmp,cnt;
int zzk;
int check(int x)
{
	return (upper_bound(d+1,d+1+n,x)-d)-(lower_bound(d+1,d+1+n,x)-d)>0;
}

struct xx
{
	int V,next;
}B[N<<2];
int head[N],bel[N],G;
void add(int x,int y)
{
	B[++G]=(xx){y,head[x]};
	head[x]=G;
}

#define F(x) for (int i=head[x];i;i=B[i].next)
#define v B[i].V
int dfn[N],low[N],T,In[N],st[N];
void dfs(int x)
{
	low[x]=dfn[x]=++T;
	st[++st[0]]=x;In[x]=1;
	F(x) if (!dfn[v]) dfs(v),low[x]=min(low[x],low[v]);
	else if (In[v]) low[x]=min(low[x],dfn[v]);
	#define now st[st[0]]
	if (dfn[x]==low[x])
	{
		for (++cnt;now^x;--st[0]) In[now]=0,bel[now]=cnt;
		bel[x]=cnt,--st[0],In[x]=0;
	}
	return ;
}
int ans;
int gg;
map <int,int>ma,mb;
int main()
{
	read(n);
	rep(i,1,n) read(a[i]),++ma[a[i]],tmp^=a[i],c[i]=a[i];
	c[n+1]=a[n+1]=tmp;sort(c+1,c+1+n+1);
	tmp=0;
	rep(i,1,n) read(b[i]),++mb[b[i]],tmp^=b[i],d[i]=b[i];
	b[n+1]=d[n+1]=tmp;sort(d+1,d+1+n+1);
	rep(i,1,n+1) if (c[i]^d[i]) GG;
	zzk=unique(c+1,c+1+n+1)-c;
	tmp=lower_bound(c+1,c+zzk,tmp)-c;
	rep(i,1,n+1) a[i]=lower_bound(c+1,c+zzk,a[i])-c;
	rep(i,1,n) b[i]=lower_bound(c+1,c+zzk,b[i])-c;
	rep(i,1,n) if (a[i]!=b[i]) add(a[i],b[i]);
	if (!G) return printf("0"),0;
	cnt=0;
	for (int i=1;i<zzk;++i)
	  if (head[i]&&!bel[i]) 
	    dfs(i);
	ans=cnt;
	rep(i,1,n) if (a[i]!=b[i]&&bel[a[i]]==bel[b[i]]) 
	  ++ans;
	return printf("%d",ans-(bel[a[n+1]]?1:0)),0;
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    multiset<int> s;
    s.insert(0);
    s.insert(0);
    s.insert(n + 1);
    s.insert(n + 1);
    vector<pair<int, int>> v(n);
    rep(i, n) {
        int tmp;
        cin >> tmp;
        v[i] = make_pair(tmp, i + 1);
    }
    sort(all(v));
    reverse(all(v));
    ll ans = 0;
    rep(i, n) {
        ll num = v[i].first;
        int id = v[i].second;
        auto it = s.lower_bound(id);
        int r1 = *it++;
        int r2 = *it--;
        it--;
        int l1 = *it--;
        int l2 = *it;
        ans += num * max(0, id - l1) * (r2 - r1);
        ans += num * max(0, r1 - id) * (l1 - l2);
        // printf("id=%d, num=%lld, r1=%d, r2=%d, l1=%d, l2=%d, ans=%lld\n", id, num, r1, r2, l1, l2, ans);
        s.insert(id);
    }
    cout << ans << endl;
    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  ll ans = 0;
  if (N < K)
    cout << 1 << endl;
  else
  {
    vector<int> b;
    for (int i = 0; i <= N; i++)
      b.push_back(i);
    ll l = 0, r = 0;
    ll ltmp = accumulate(b.begin(), b.begin() + K, 0LL);
    ll rtmp = accumulate(b.end() - K, b.end(), 0LL);
    cerr << ltmp << " " << rtmp << endl;
    for (int i = K; i <= N; i++)
    {
      ans += rtmp - ltmp + 1;
      ans %= MOD;
      ltmp += b[i];
      rtmp += b[N - i];
    }
    ans++;
    cout << ans << endl;
  }
  return 0;
}


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

void input(int& rnAchieve, vector<int>& rvnPrice, vector<vector<int>>& rvvnSkill)
{
  int nPriceSiz, nSkillSiz;
  cin >> nPriceSiz >> nSkillSiz >> rnAchieve;
  rvnPrice.resize(nPriceSiz);
  rvvnSkill.resize(nPriceSiz, vector<int>(nSkillSiz));

  for (int ny = 0; ny < rvvnSkill.size(); ny++)
  {
    cin >> rvnPrice[ny];

    for (int nx = 0; nx < rvvnSkill[ny].size(); nx++)
      cin >> rvvnSkill[ny][nx];
  }
}

int calcMinPriceSkillup(int nAchieve, const vector<int> cnrvnPrice, 
                                      const vector<vector<int>>& cnrvvnSkill)
{
  int nMinPrice = INT_MAX;

  for (int nCtl = 0; nCtl < ( 1 << cnrvnPrice.size() ); nCtl++)
  {
    int nPrice = 0;
    vector<int> vnSumSkill(cnrvvnSkill[0].size());

    for (int ny = 0; ny < cnrvnPrice.size(); ny++)
      if (nCtl & ( 1 << ny ))
      {
        for (int nx = 0; nx < cnrvvnSkill[ny].size(); nx++)
          vnSumSkill[nx] += cnrvvnSkill[ny][nx];

        nPrice += cnrvnPrice[ny];
      }

    bool bRslt = true;

    for (int nSumSkill : vnSumSkill)
      if (nSumSkill < nAchieve)
      {
        bRslt = false;
        break;
      }

    if (bRslt)
      nMinPrice = min(nMinPrice, nPrice);
  }
  if (nMinPrice == INT_MAX)
    return -1;
  else
    return nMinPrice;
}
  
int main()
{
  int nAchieve;
  vector<int> vnPrice;
  vector<vector<int>> vvnSkill;

  input(nAchieve, vnPrice, vvnSkill);
  cout << calcMinPriceSkillup(nAchieve, vnPrice, vvnSkill) << endl;

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0;i<N;i++) {
        cin >> S.at(i);
    }
    int C0,C1,C2,C3;
    C0 = 0;
    C1 = 0;
    C2 = 0;
    C3 = 0;
    for(int i=0;i<N;i++) {
        if (S[i] == "AC") {
            C0++;
        }else if (S[i] == "WA") {
            C1++;
        }else if(S[i] =="TLE") {
            C2++;
        }else if(S[i] =="RE") {
            C3++;
        }
    }
    cout << "AC x " << C0 << endl;
    cout << "WA x " << C1 << endl;
    cout << "TLE x " << C2 << endl;
    cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 6356
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		 Scanner sc = new Scanner(System.in);
	     int h = sc.nextInt();
	     int w = sc.nextInt();
	     int a;
	     int l;
	     a = h*w;
	     l = h+w;
	     System.out.println(a+ " " +2*l);

	}

}



Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(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 PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
using namespace std;
string s;
int k;
int main(){
	cin>>s>>k;
	int n=SZ(s);
	set<string>z;
	for(int i=0;i<n;i++){
		string t="";
		for(int j=i;j<n;j++){
			if(j-i+1>k)break;
			t+=s[j];
			z.insert(t);
		//	cout<<t<<endl;
		}
	}
	auto it=z.begin();
	REP(i,k-1)it++;
	cout<<*it<<endl;

}

Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

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


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

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int a[1010];
  int b[1010];
  rep(i,n) {
    cin >> a[i];
    cin >> b[i];
  }
  int ans = 0;
  rep(i,n) {
    bool tf = true;
    if (a[i] < h) tf = false;
    if (b[i] < w) tf = false;
    if(tf) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
    int N, c;

    vector<pair<int, int>> res;

    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> c;
        res.push_back(make_pair(c, i + 1));
    }

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

    for (auto &p : res) {
        cout << p.second << "\n";
    }


}

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

int main(){
  
  string S;
  cin >> S;
  int cnt = 0;
  
  for(int i = 0; i < 3; i++){
    if(S[i] == 'o') cnt++;
  }
  cout << 700 + 100 * cnt << endl;
  return 0;
}

Measured memory_bytes: 3580
#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 30;
const int MOD = 1e9 + 7;

int n, a[N][N], dp[(int) 5e6];

int bit(int i, int mask) {return (mask >> i) & 1;}
int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) cin >> a[i][j];

    dp[0] = 1;
    for (int mask = 0; mask < (1 << n); ++mask) {
        int nxt = __builtin_popcount(mask) + 1;
        if (nxt > n) continue;

        for (int i = 1; i <= n; ++i) if (!bit(i - 1, mask) && a[i][nxt]) {
            int n_mask = mask ^ (1 << (i - 1));
            dp[n_mask] = (dp[n_mask] + dp[mask]) % MOD;
        }
    }

    cout << dp[(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 10496
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int *minA, *then_num;

typedef struct {
	int N;
	int *u;
	int *u_rank;
}union_find;

union_find *make_union_find(int N){
	int i;
	union_find *uf = (union_find *)malloc(sizeof(union_find));
	uf->N = N;
	uf->u = (int *)malloc(sizeof(int) * N);
	uf->u_rank = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		(uf->u)[i] = i;
		(uf->u_rank)[i] = 1;
	}
	return uf;
}

int root_uf(int x, union_find *uf){
	int *u = uf->u;
	if(u[x] == x){
		return x;
	}
	else{
		u[x] = root_uf(u[x], uf);
		return u[x];
	}
}

void combine_uf(int x, int y, union_find *uf){
	int x_root = root_uf(x, uf);
	int y_root = root_uf(y, uf);
	int *u = uf->u;
	int *u_rank = uf->u_rank;
	if(x_root == y_root){
		return;
	}
	else if(u_rank[x_root] < u_rank[y_root]){
		u[x_root] = y_root;
		u_rank[y_root] += u_rank[x_root];
		u_rank[x_root] = 0;
		if(minA[x_root] < minA[y_root]){
			minA[y_root] = minA[x_root];
			then_num[y_root] = then_num[x_root];
		}
	}
	else{
		u[y_root] = x_root;
		u_rank[x_root] += u_rank[y_root];
		u_rank[y_root] = 0;
		if(minA[y_root] < minA[x_root]){
			minA[x_root] = minA[y_root];
			then_num[x_root] = then_num[y_root];
		}
	}
}

//xとyが同じ集合に属していれば1を,そうでなければ0を返す
int is_same_union_uf(int x, int y, union_find *uf){
	if(root_uf(x, uf) == root_uf(y, uf)){
		return 1;
	}
	else{
		return 0;
	}
}

//xが属する集合の要素数を返す
int rank_uf(int x, union_find *uf){
	return (uf->u_rank)[root_uf(x, uf)];
}

signed main(){
	int N, M, x, y, i;
	scanf("%lld%lld", &N, &M);
	int *A = (int *)malloc(sizeof(int) * N);
	minA = (int *)malloc(sizeof(int) * N);
	then_num = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
		minA[i] = A[i];
		then_num[i] = i;
	}
	union_find *uf = make_union_find(N);
	for(i = 0; i < M; i++){
		scanf("%lld%lld", &x, &y);
		combine_uf(x, y, uf);
	}
	int ans = 0, link_num = 0;
	for(i = 0; i < N; i++){
		if(i == root_uf(i, uf)){
			ans += minA[i];
			A[then_num[i]] = inf;
			link_num++;
		}
	}
	if(link_num == 1){
		printf("0\n");
		return 0;
	}
	sort(A, N);
	for(i = 0; i < link_num - 2; i++){
		if(A[i] == inf){
			printf("Impossible\n");
			return 0;
		}
		else{
			ans += A[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int x, y, z;
	
	cin >> x >> y;
	
	if (x < y) swap(x, y);
	
	while (y > 0){
		z = x % y;
		x = y;
		y = z;
	}
	
	cout << x << "\n";
	
	return (0);
}


Measured memory_bytes: 3108
from collections import Counter


class Combination:
    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.fact, self.inv = self._make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def _make_factorial_list(self, N):
        fact = [1] * (N + 1)
        inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            fact[i] = (fact[i - 1] * i) % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            inv[i - 1] = (inv[i] * i) % MOD
        return fact, inv


if __name__ == "__main__":
    N = int(input())
    A = tuple(map(int, input().split()))
    mod = 10 ** 9 + 7

    X = Counter(A).most_common()[0][0]
    left = A.index(X)
    right = A[::-1].index(X)
    LR = left + right

    comb = Combination(10 ** 5 + 10)

    ans = []
    for i in range(1, N + 2):
        val = comb(N+1, i)-comb(LR, i-1)
        val = (val + mod) % mod
        ans.append(val)

    print(*ans, sep="\n")


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

int main() {
  //定義一覧
  int N; //N個のボール
  int K; //最大ｘ座標K
  int X; //指定X座標にボールが1個ある
  int A; //Aロボットの移動数
  int B; //Bロボットの移動数
  int tmp = 0; //比較した最小移動数の累積変数
  
  //入力
  cin >> N >> K;
  //繰り返し
  for(int i = 0; i < N; i++){
  	//X座標の入力
    cin >> X;
    //Aロボットの動き
    A = (X - 0) * 2;
    //Bロボットの動き
    B = (K - X ) * 2;
    //最小移動数の比較
    if(A < B){
    	tmp += A;
    }else{
    	tmp += B;
    }
  }
  
  //最小移動数の合計の出力
  cout << tmp << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

string s;
int n;
const int mxn = 1e5+99;
ll dp[mxn][13];
const int modi = 1e9+7;

ll find(int idx, int rem){
	// cout << idx << " " << rem << endl;
	if(idx>=n){
		if(rem == 5)
			return 1ll;

		return 0ll;
	}

	ll &ans = dp[idx][rem];
	if(ans!=-1){
		return ans;
	}
	ans = 0;
	if(s[idx]=='?'){
		for(int i =0;i<=9;i++){
			ans = ans + find(idx+1,(rem*10+i)%13);
			ans%=modi;
		}
	}
	else{
		ans+=find(idx+1,(rem*10+(s[idx]-'0'))%13);
		ans%=modi;
	}
	return ans;

}


void solve(){
	cin >> s;
	n = s.length();
	memset(dp,-1,sizeof(dp));
	cout << find(0,0) << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 20168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k)
    cout<<s;
  else{
    for(int i=0;i<k;i++)
      cout<<s[i];
    cout<<"...";
  }
  return 0;
}

Measured memory_bytes: 3584
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(auto &i:a){cin>>i;}
    ll ans=a[0];
    for(int i=1;i<n;i++){
        if(a[i-1]<a[i]){ans+=a[i]-a[i-1];}
    }
    cout<<ans<<endl;
    
    
    return 0;
}


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

using namespace std;

const int N=1e6+3;

const double eps=1e-9;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;

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

const int mod=1e9+7;

int n,a[N],b[N],m,k,q,u,v,x,y,tc,l,r,c,ans;

char s[N],grid[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i = 0 ; ; i++){
		if (i&1)
			a-=d;
		else
			c-=b;
		if (a<=0)
			return !printf("No\n");
		if (c<=0)
			return !printf("Yes\n");
	}
}


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


int main(){
  int a, b;
  cin >> a >> b;
  if (0 < a && a < 10 && 0 < b && b < 10){
    cout << a*b << endl;
  }else{
    cout << -1 << endl;
  }
}


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

int main() {
  int K, S;
  int Z; 
  int num = 0; 

  cin >> K >> S;
  rep(X, K+1){
    rep(Y, K+1){
      Z = S - (X+Y);
      if(Z >= 0 and Z <=K) num += 1;
    }
  }  

  cout << num << endl;
}

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

int main() {
  int N, a, b, c, d;

  cin >> N;
  
  if (N < 1000 || N > 9999) {
    cout << "error" << endl;
  }
  else {
	a = N / 1000;
    b = (N - a * 1000) / 100;
    c = (N - (a * 1000 + b * 100) ) / 10;
    d = N - (a * 1000 + b * 100 + c * 10);
    
    if (a == b) {
      if (b == c) {
	    cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else if (b == c) {
      if (c == d) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int q;
ll a, b;
bool ok(ll x) {
    ll t = (x + 1) / 2;
    if (x < a) {
    for (ll i = t - 4; i <= t + 4; i++) {
        if (i <= 0) continue;
        if (i > x) continue;
        ll p = x + 1 - i;
        if (p >= b) p++;
        if (i * p >= a * b) return false;
    }
    }
    else {
        for (ll i = t - 4; i <= t + 4; i++) {
            if (i <= 0) continue;
            if (i > x + 1) continue;
            ll rpos = i;
            if (i >= a) rpos--;
            ll spos = x + 1 - i;
            if (spos >= b) spos++;
            if (i * spos >= a * b) return false;
        }
    }
    return true;
}
void solve() {
    cin >> a >> b;
    ll l = 0;
    ll r = min(a * b, 2 * (ll)1e9 + 10);
    //cout << r << endl;
    if (a < b) swap(a, b);
    //cout << r << endl;
    //if (a == 1) cout << ok(2) << "///" << endl;
    while (r - l > 1) {
        ll md = (l + r) / 2;
        //cout << md << endl;
        if (ok(md)) l = md;
        else r = md;
    }
    cout << l << '\n';
    //cout << ok((a * b) / 4);
}
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> q;
    for (int i = 1; i <= q; i++) solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxW = sc.nextInt();
		
		int[] w = new int[n + 1];
		int[] v = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		
		long[][] dp = new long[n + 1][maxW + 1];
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= maxW; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j - w[i] >= 0) 
					dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			}
		}
		
		System.out.println(dp[n][maxW]);
		
//		for (long[] arr : dp)
//			System.out.println(Arrays.toString(arr));
		
		sc.close();
	}
}



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

int main(){
    long long N, A, B, C;
    cin >> N >> A >> B;
    int i;
    C = N/(A+B) * A;
    if(N % (A+B) >= A)
        cout << C+A << endl;
    else
        cout << C+N%(A+B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios :: sync_with_stdio(false); cin.tie(NULL)
using namespace std;

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



Measured memory_bytes: 3476
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  lld n, m, k;
  cin >> n >> m >> k;
  vector<lld> a(n), b(m);
  lld s = 0;
  for (lld i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  for (lld i = 0; i < m; i++) {
    cin >> b[i];
  }
  lld x = 0;
  lld c = 0;
  lld t = 0;
  for (lld i = n; i >= 0; i--) {
    if (i != n) {
      s -= a[i];
    }

    while (c < m && s + t + b[c] <= k) {
      t += b[c];
      c++;
    }

    if (s + t <= k) {
      x = max(x, i + c);
    }
  }
  cout << x << "\n";
}

Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

const int N = 505;

int n, k, sum = 0;
int a[N];

int check(int x)
{
	int reqd = 0;
	vector<int> v;
	for(int i = 1; i <= n; i++)
	{
		int cur = a[i] % x;
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	int l = 0, r = v.size() - 1;
	int rem = 0;
	while(l <= r)
	{
		if(rem <= 0)
		{
			rem += v[l];
			reqd += v[l];
			l++;
		}
		else
		{
			rem -= (x - v[r]);
			reqd += (x - v[r]);
			r--;
		}
	}
	if(reqd > 2 * k)
		return 0;
	if(rem != 0)
		return 0;
	return 1;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int ans = 1;
	for(int i = 1; i * i <= sum; i++)
	{
		if(sum % i == 0)
		{
			if(check(i))
				ans = max(ans, i);
			if(check(sum / i))
				ans = max(ans, sum / i);
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  init();
  ll k;std::cin >> k;
  string s;std::cin >> s;
  ll ans = mpow(26, s.size() + k, P);//all
  ll m = s.size();
  ll sub = 0;
  for(int i=0;i<s.size();i++){
    sub = (sub + pp(mpow(25, m+k-i, P), comb(m+k, i)))%P;
  }

  std::cout << (ans-sub+P)%P << '\n';
  return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if ('a' <= s[0] && s[0] <= 'z') {
    cout << "a\n";
  } else {
    cout << "A\n";
  }
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n;
int main() {
    DAU
    cin >> n;
    cout << fixed << setprecision(10) << 1.0 - 1.0 * (n / 2) / n;
    PLEC
}


Measured memory_bytes: 3804
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (k (read))
         as)
    (dotimes (i n) (push (read) as))
    (let ((max (apply #'max as))
          (gcd (apply #'gcd as)))
      (write-line (if (and (<= k max)
                           (zerop (mod k gcd)))
                      "POSSIBLE"
                      "IMPOSSIBLE")))))

#-swank(main)


Measured memory_bytes: 59748
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define max_heap priority_queue<int>
#define min_heap priority_queue<int,vector<int>,greater<int>>
using ll = long long;
#define int long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define inp_arr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define out_arr(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";
#define deb(n) cerr << #n << " = " << n << "\n";
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
ll mypower(ll x,ll n,ll c){
    if(n == 0)
        return 1;
    ll temp = mypower(x,n/2,c)%c;
    if(n%2)
        return (n<0)? (1/x)*temp*temp%c: ((x*temp)%c)*temp%c;
    else
        return temp*temp%c;
}
bool codejam = 0;

ll f1(int x,int y){
	return x+y;
}
ll f2(int x,int y){
	return -x+y;
}
ll f3(int x,int y){
	return x-y;
}
ll f4(int x,int y){
	return -x-y;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	ll n;
	cin>>n;
	vector<pair<int,int>> a;
	vector<int> fmax(4,INT_MIN);
	vector<int> fmin(4,INT_MAX);
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		int f11 = f1(x,y);
		int f22 = f2(x,y);
		int f33 = f3(x,y);
		int f44 = f4(x,y);
		fmax[0] = max(fmax[0],f11);
		fmax[1] = max(fmax[1],f22);
		fmax[2] = max(fmax[2],f33);
		fmax[3] = max(fmax[3],f44);

		fmin[0] = min(fmin[0],f11);
		fmin[1] = min(fmin[1],f22);
		fmin[2] = min(fmin[2],f33);
		fmin[3] = min(fmin[3],f44);
	}
	int ans = INT_MIN;
	for(int i=0;i<4;i++)
		ans = max(ans,fmax[i]-fmin[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3660
n = input()
v = map(int, raw_input().split(' '))
v.sort()

def good(mid, v):
	sum = v[mid]
	for i in range(n):
		if i != mid:
			if v[i] > 2 * sum:
				return False

			sum += v[i]

	return True


l, r = 0, n - 1
best = n - 1

while l <= r:
	mid = (l + r) / 2

	if good(mid, v):
		best = mid
		r = mid - 1
	else:
		l = mid + 1

print n - best

Measured memory_bytes: 11340
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    ll N, D, A;
    in >> N >> D >> A;
    vector<pll> v(N);
    REP(i, N) {
        ll X, H;
        in >> X >> H;
        v[i] = {X, H};
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    ll damage = 0;
    queue<pll> q{};
    REP(i, N) {
        while (!q.empty()) {
            auto f = q.front();
            if (v[i].first > f.first) {
                damage -= f.second;
                q.pop();
            } else {
                break;
            }
        }
        v[i].second -= damage;
        POSITIVE(v[i].second);
        auto count = (v[i].second + A - 1) / A;
        damage += count * A;
        q.emplace(v[i].first+2*D, count*A);
        ans += count ;
    }

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

//typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		40010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//




//
int main(){
	int N ,K; cin>>N>>K;
	string S;cin>>S;

	int ans = 0;

	REP(i,N-1){
		if(S[i] == S[i+1])ans++;
	}

	cout << min(N-1,ans+K*2) << endl;

	return 0;
}




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

int a[5];
int ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	for(int i=0; i<5; ++i) cin >> a[i];
	sort(a, a+5, [](const int x, const int y){
		if(x % 10 == 0) return true;
		if(y % 10 == 0) return false;
		return x % 10 > y % 10;
	});
	for(int i=0; i<5; ++i){
		ans = (ans + 9) / 10 * 10;
		ans += a[i];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    double ans = 0;
    double a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        ans += 1 / a;
    }

    cout << setprecision(16) << ( 1.0 / ans ) << endl;

    return 0;
}

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

#define debug(x)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sq(x) ((x) * (x))
#define PRECISION 30

using namespace std;

template<class T> int check_mod(T a, T b) { return (a % b) ? 1 : 0; }
template<class T> void maxi(T &a, T b) { a = max(a, b); return; }
template<class T> void mini(T &a, T b) { a = min(a, b); return; }

bool is_prime(int a) { if (a == 2) return true; if (!(a & 1) || a == 1) return false; for (int i = 3; i * i <= a; i += 2) if (!(a % i)) return false; return true; }
bool is_prime(ll a) { if (a == 2) return true; if (!(a & 1) || a == 1) return false; for (ll i = 3; i * i <= a; i += 2) if (!(a % i)) return false; return true; }
bool is_palindrome(string s) { int len = (int)s.length(); int mid = len >> 1; for (int i = 0; i < mid; i++) if (s[i] != s[len - i - 1]) return false; return true; }
int gcd(int a, int b) { while (b) { int mod = a % b; a = b; b = mod; } return a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
int binpow(int a, int b, int MODULO) { int res = 1; while (b) { if (b & 1) { res *= a; res %= MODULO; } a *= a;  a %= MODULO; b >>= 1; } return res; }
ll gcd(ll a, ll b) { while (b) { ll mod = a % b; a = b; b = mod; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll MODULO) { ll res = 1; while (b) { if (b & 1) { res *= a; res %= MODULO; } a *= a;  a %= MODULO; b >>= 1; } return res; }
string binary(int N) { if (!N) return "0"; string bin = ""; while (N) { bin += '0' + (N & 1); N >>= 1; } reverse(all(bin)); return bin; }
string binary(ll N) { if (!N) return "0"; string bin = ""; while (N) { bin += '0' + (N & 1); N >>= 1; } reverse(all(bin)); return bin; }
           
const int INF = 2147483547;           // Max int value - 100 so it will not overflow
const int MODULO = 1000000007;
const int _MODULO = 998244353;
const ll INF64 = 9223372036854775707; // Max long long value - 100 so it will not overflow
const ll MODULO64 = 1000000007;
const ll _MODULO64 = 998244353;
const double epsilon = 10e-6;
const double PI = acos(-1);

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	auto t1 = chrono::high_resolution_clock::now();
    #define debug(x) cerr << #x << " = " << x << "\n";                        
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, n;
	cin >> h >> n;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		sum += x;
	}
	cout << (sum < h ? "No" : "Yes") << '\n';
#ifdef LOCAL
	auto t2 = chrono::high_resolution_clock::now();
	cerr << "Running time " << chrono::duration_cast<chrono::nanoseconds>(t2 - t1).count() << " nanoseconds" << endl;
#endif
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define l1 10000000
#define l2 25500000
#define mod 1000000007
using namespace std;
int s,f[l2+5];
long long quickpow(long long a,long long b){
	long long ret=1;
	for(; b; a=a*a%mod,b>>=1)
		(b&1)&&(ret=ret*a%mod);
	return ret;
}
int count1(){
	int ret=0,r=0,cnt=0;
	for(int i=0; ++i<l1; ){
		for(cnt-=f[i-1]; cnt+f[r+1]<=s&&r<l2; cnt+=f[++r]);
		cnt==s&&(++ret);
		if(r==l2)
			return ret;
	}
	return ret;
}
int count2(int n){
	int lim=n>>3,ret=lim;
	for(int t=0; ++t<=lim; !(n%t)&&(ret=(ret+quickpow(10,n/t-1)*9-t)%mod));
	return ret;
}
int main(){
	for(int i=1,r=10,cnt=1; i<l1; i=r,r*=10,++cnt)
		for(int j=i-1; ++j<r; f[j]=cnt);
	for(int i=l1-1; ++i<=l2; f[i]=8);
	scanf("%d",&s);
	printf("%d\n",((count1()+count2(s))%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 101324
from numpy import log
def f(k):
  c=0
  while k % 2 == 0:
    k //= 2
    c+=1
    if c==2:
      break
  return c
def g(k):
  return f(int(k))
n=int(input())
a=list(map(g,input().split()))
ct0=a.count(0)
ct1=a.count(1)
ct2=a.count(2)
if ct0 <= ct2 or (ct0 == ct2 + 1 and ct1==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 20248
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let k: i64 = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut l = 0;
    while 1 << l <= k {
        l += 1;
    }

    let mut x = 0;
    for i in (0..l).rev() {
        let mut cnt = 0;
        for &a in &a {
            if (a >> i) & 1 == 0 {
                cnt += 1;
            }
        }
        if cnt > n - cnt {
            if x | (1 << i) <= k {
                x |= 1 << i;
            }
        }
    }

    let ans: i64 = a.iter().map(|&a| a ^ x).sum();
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

T = list(input())

n = len(T)

for i in range(n):
    if T[i] == '?':
        T[i] = 'D'

print(''.join(T))

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

int main() {
  int N, K, Q; cin >> N >> K >> Q;
  int A[Q]; for (int i = 0; i < Q; i++) cin >> A[i];
  int C[N]; for (int i = 0; i < N; i++) C[i] = 0;
  for (int i = 0; i < Q; i++) {
    C[A[i]-1]++;
  }
  for (int i = 0; i < N; i++) {
    if (C[i] > Q - K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
gets
cnt = {}
gets.split.each do |x| 
	x = x.to_i
	
	cnt[x] += 1 if cnt[x]
	cnt[x] = 1 if !cnt[x]
	
	cnt[x - 1] += 1 if cnt[x - 1]
	cnt[x - 1] = 1 if !cnt[x - 1]
	
	cnt[x + 1] += 1 if cnt[x + 1]
	cnt[x + 1] = 1 if !cnt[x + 1]
end

p cnt.values.max

Measured memory_bytes: 14220
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    int orig = 0;
    for (int i = 0; i <= N; i++) {
        orig += abs(A[i] - A[i + 1]);
    }
    for (int i = 1; i <= N; i++) {
        const int adv = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]) - abs(A[i - 1] - A[i + 1]);
        cout << orig - adv << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <map>
    using namespace std;
    typedef long long ll;
    #define rep(i,n) for (int i=0;i < (int)(n);i++)

    int main(){
       int a,b,c;
      cin >> a >> b >> c;
      int ans;
      ans=a*100+10*b+c;
      if (ans%4 == 0) cout << "YES" << endl;
      else cout << "NO" << endl;

      
      return 0;
    }
      
      

Measured memory_bytes: 256
import math
import numpy as np
N = int(input())
m_list = []
max_p = math.floor(-1+math.sqrt(1+N))
for p in range(1, max_p+1):
   if N % p == 0:
       m = N//p -1
       m_list.append(m)
print(int(np.sum(m_list)))

Measured memory_bytes: 14456
import sys
def side(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0
 
for s in sys.stdin:
  x = map(float, s.split())
  p1 = x[0:2]
  p2 = x[2:4]
  p3 = x[4:6]
  p0 = x[6:]
  print ["NO","YES"][(side(p1, p2, p0)==side(p2, p3, p0)==side(p3, p1, p0))]

Measured memory_bytes: 4244
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int DP[110][5][5][5];

void add(long long & a, long long b){
  a = (a+b) % MOD;
}


// A 1 C 2 G 3 T 4

signed main() {
  int N; cin >> N;
  memset(DP, 0, sizeof(DP));
  DP[0][0][0][0] = 1;
  for (int n = 0; n < N; n++) {
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 5; k++) {
          for (int l = 1; l < 5; l++) {
            //AGC?
            if (i == 1 && j == 3 && k == 2) continue;
            //ACG?
            if (i == 1 && j == 2 && k == 3) continue;
            //GAC?
            if (i == 3 && j == 1 && k == 2) continue;
            //?AGC
            if (j == 1 && k == 3 && l == 2) continue;
            //?ACG
            if (j == 1 && k == 2 && l == 3) continue;
            //?GAC
            if (j == 3 && k == 1 && l == 2) continue;
            //AG?C
            if (i == 1 && j == 3 && l == 2) continue;
            //A?GC
            if (i == 1 && k == 3 && l == 2) continue;
            add(DP[n+1][j][k][l], DP[n][i][j][k]);
          }
        }
      }
    }
  }

  ll res = 0;
  for (int i = 1; i < 5; i++) {
    for (int j = 1; j < 5; j++) {
      for (int k = 1; k < 5; k++) {
        res += DP[N][i][j][k];
      }
    }
  }

  cout << res % MOD<< endl;
}


Measured memory_bytes: 384