akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){
    string AtoZ;
    char atoz[26] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int a[26]={0};
    while(cin>>AtoZ){
        for(int i=0;i<AtoZ.size();i++){
            if(isupper(AtoZ[i])){
                AtoZ[i]=tolower(AtoZ[i]);
            }
            for(int j=0;j<26;j++){
                if(AtoZ[i]==atoz[j]){
                    a[j]++;
                    break;
                }
            }
        }
    }
    for(int k=0;k<26;k++){
        cout<<atoz[k]<<" : "<<a[k]<<endl;
    }
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int k;
vector<lint> a;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

template<typename T>
bool chmin(T &_a, T _b){
    if(_a > _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

bool solve(lint &mini, lint &maxi){
    mini = 2;
    maxi = 2;
    rrep(i, k){
        if((mini - 1LL) / a[i] == maxi / a[i]){
            return false;
        }
        mini = ((mini - 1LL) / a[i] + 1LL) * a[i];
        maxi = maxi / a[i] * a[i] + a[i] - 1LL;
    }

    return true;
}

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

    cin >> k;

    a.resize(k);
    rep(i, k){
        cin >> a[i];
    }

    lint ans1 = 2, ans2 = 2;
    if(solve(ans1, ans2)){
        cout << ans1 << " " << ans2 << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    ll N,K;
    cin >> N >> K;

    ll ans = 0;

    ll M = K;

    while(N >= M){
        M *= K;
        ans++;
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
import math
from sys import stdin
input = stdin.readline

n = int(input())
ans=[1145141919]
for i in range(1,round(math.sqrt(n))+1):
    if n%i==0:
        tmp=max(len(str(i)), len(str(n//i)))
        ans.append(tmp)
print(min(ans))


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main(void) {
	char name1[200], name2[100];
	scanf("%s%s", name1,name2);
	//つなげて検索
	sprintf(name1,"%s%s", name1, name1);
	if (strstr(name1, name2) == NULL) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 2140
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int x,y,h1,m1,h2,m2,t1,t2;
int table[7][7]={
{0,6,10,12,14,27,33},
{6,0,7,9,12,23,30},
{13,7,0,5,8,20,27},
{18,12,5,0,5,17,26},
{23,17,10,5,0,12,23},
{43,37,30,25,20,0,10},
{58,52,45,40,35,15,0}};

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int main(){
	while(scanf("%d",&x)*x){
		scanf("%d %d %d %d %d",&h1,&m1,&y,&h2,&m2);
		if(x>y)swap(&x,&y);
		x--;y--;
		t1=h1*60+m1;
		t2=h2*60+m2;
		if(table[y][x]<=40 && ( (17*60+30<=t1 && t1<=19*60+30) || (17*60+30<=t2 && t2<=19*60+30) ))printf("%d\n",(table[x][y]/2+table[x][y]%2)*50);
		else printf("%d\n",table[x][y]*50);
	}
	return 0;
}

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

using namespace std;


int N, M, f[110][110];

char s[110][110];


int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) scanf("%s", s[i]);
	f[0][0] = (s[0][0] == '#' ? 1 : 0);
	for (int i = 1; i < N; i++) {
		if (s[i][0] == '#') f[i][0] = f[i - 1][0] + (s[i - 1][0] == '#' ? 0 : 1);
		else f[i][0] = f[i - 1][0];
	}
	for (int j = 1; j < M; j++) {
		if (s[0][j] == '#') f[0][j] = f[0][j - 1] + (s[0][j - 1] == '#' ? 0 : 1);
		else f[0][j] = f[0][j - 1];
	}
	for (int i = 1; i < N; i++) {
		for (int j = 1; j < M; j++) {
			if (s[i][j] == '#') f[i][j] = min(f[i - 1][j] + (s[i - 1][j] == '#' ? 0 : 1), f[i][j - 1] + (s[i][j - 1] == '#' ? 0 : 1));
			else f[i][j] = min(f[i - 1][j], f[i][j - 1]);
		}
	}
	cout << f[N - 1][M - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define ll long long
#define double long double
#define MAX (int)(2*pow(10,5) + 10)
#define N 100000
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,9);
ll modulo = inf;
double eps = 1e-10;
ifstream in;
ofstream out;

void deal(){
	ll k,n;
	cin>>n>>k;
	if(k==1)
		cout<<0;
	else
		cout<<(n-k);
	
}


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


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

using namespace std;

int main() {
    int a,count=0;
    cin>>a;
    string s;
    cin>>s;
    for (int i = 0; i <a ; i++) {
        if (s[i]=='A' && s[i+1]=='B'&&s[i+2]=='C')
            count++;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int H, W, K; cin >> H >> W >> K;
    string c[H];
    int s[H][W];
    int cnt = 1;
    rep(i, H) {
        cin >> c[i];
    }
    rep(i, H) {
        rep(j, W) {
            if(c[i][j] == '#') {
                s[i][j] = cnt;
                ++cnt;
            }else {
                s[i][j] = 0;
            }
        }
    }
    rep(i, H) {
        int tmp = 0;
        rep(j, W) {
            if(s[i][j] == 0) {
                s[i][j] = tmp;
            }else {
                tmp = s[i][j];
            }
        }
        tmp = 0;
        rep(j, W) {
            if(s[i][W - 1 - j] == 0) {
                s[i][W - 1 - j] = tmp;
            }else {
                tmp = s[i][W - 1 - j];
            }
        }
    }
    rep(j, W) {
        int tmp = 0;
        rep(i, H) {
            if(s[i][j] == 0) {
                s[i][j] = tmp;
            }else {
                tmp = s[i][j];
            }
        }
        tmp = 0;
        rep(i, H) {
            if(s[H - 1 - i][j] == 0) {
                s[H - 1 - i][j] = tmp;
            }else {
                tmp = s[H - 1 - i][j];
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << s[i][j] << ' ';
        }
        cout << endl;
    }
}


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

int main(){
  int k,n;
  cin>>k>>n;
  int arr[1000005];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }int a[1000005];int max1=INT_MIN;
  for(int i=0;i<n-1;i++)
  {
    a[i]=abs(arr[i]-arr[i+1]);
    max1=max(max1,a[i]);
  }int sum=0;
  for(int i=0;i<n-1;i++)
  {
    sum+=a[i];
  }

int x = (k-arr[n-1]) + (arr[0]);
max1=max(max1,x);
  cout<<abs(sum+x-max1)<<endl;
  return 0;
}

Measured memory_bytes: 6656
/** Bismillahir Rahmanir Raheem **/
/**
********************************************************************
******************* Author:Ashik Iqbal****************************
********************************************************************
**/
/**
Name : Ashik Iqbal.
Email: ashiqueiqbal998@gmail.com.
Computer Science and Engineering.
North South University.
Dhaka, Bangladesh.
**/

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


/** templates starts here **/
#define ll long long int
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define stll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define mpii map<int,int>
#define mpll map<ll,ll>
#define mpss map<string,string>
#define mpsi map<string,int>
#define mpis map<int,string>
#define mpsll map<string,ll>
#define mplls map<ll,string>
#define sit set<int>::iterator
#define slit set<ll>::iterator
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define asrt(a) sort(a, a+n)
#define grtasrt(a) sort(a, a+n,greater<int>())
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define REV(i,j,k) for(int i=j;i>k;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(a,x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
#define mx 1000005
const int mod=1e9+7;
const int N = (int) 1e5 + 5;
/** templates ends here **/


int main ()
{

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



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
#define Graph vector<vector<int>>
using namespace std;

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

        map<string,int> m;
        long ans=0;

        rep(i,n)
        {
                string s; cin>>s;
                sort(All(s));
                if(m.count(s))
                {
                        ans+=m[s];
                }
                m[s]++;
        }
        cout<<ans<<endl;
}

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

using namespace std;

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	vector<vector<int>> g(n,vector<int>(m+1));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m + 1; j++){
			cin >> g[i][j];
		}
	}  
	auto calc_cost = [&](int mask){
		vector<int> und(m+1,0);
		for(int i = 0; i < n; i++){
			if(mask & (1 << i)){
				for(int j = 0; j < m + 1; j++){
					und[j]+=g[i][j];
				}
			}
		}
		bool ok = true;
		for(int i = 1; i < m + 1; i++){
			ok &= (und[i] >= x);
		}
		if(ok) return und[0];
			   return -1;	
	};
	int best = INT_MAX;
	for(int i = 0; i < (1 << n); i++){
		int val = calc_cost(i);
		if(val!=-1){
			best = min(best,val);
		}			
	}
	if(best == INT_MAX) best = -1;
	cout << best << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;

int main() {
	string s; cin >> s;
	ll k; cin >> k;
	for (int i = 0; i < min((ll)s.size(), k); i++) {
		if (s[i] >= '2') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << '1' << endl;
	return 0;
}


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

int main()    {
int a ;
int b;
int c;
int d;
int e;
int f;
int g;
cin >> a >> b >> c >> d  ;
if(a<b){ e = a;
}
else{e = b;
}
if(c<d){f=c;
}
else{f=d;
}
g = e +f ;

cout <<  g << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    char c[310][310];
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }
    int dp[310][310],cost[310][310],ans=0;
    rep(k,w-1){
        rep(i,h+1){
            rep(j,h+1){
                cost[i][j]=0;
                dp[i][j]=INF;
            }
        }
        rep(i,h+1){
            cost[i][0]=0;
            rep(j,h-i){
                if(c[i+j][k]==c[j][k+1])cost[i+j+1][j+1]=cost[i+j][j]+1;
                else cost[i+j+1][j+1]=cost[i+j][j];
            }
            cost[0][i]=0;
            rep(j,h-i){
                if(c[j][k]==c[i+j][k+1])cost[j+1][i+j+1]=cost[j][i+j]+1;
                else cost[j+1][i+j+1]=cost[j][i+j];
            }
        }
        dp[0][0]=0;
        rep(i,h+1){
            rep(j,h+1){
                if(i)chmin(dp[i][j],dp[i-1][j]+cost[i][j]);
                if(j)chmin(dp[i][j],dp[i][j-1]+cost[i][j]);
            }
        }
        ans+=dp[h][h];
    }
    cout<<ans<<endl;
    return 0;
}

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

int n;
long long a[300005];
long long sumesBlyat[200005];
long long sumesBlyat2[200005];
long long sumS = 0, sumE = 0;
multiset<long long> setS, setE;
long long pot = 0;

void ShowSet() {
	multiset<long long>::iterator it;
	for (it = setS.begin(); it != setS.end(); it++)
		cout << *it << " ";
	cout << endl;
}

int main() {
	/*
	setS.insert(1);
	setS.insert(1);
	setS.insert(2);
	ShowSet();
	setS.erase(setS.begin());
	ShowSet();
	*/

	
	cin >> n;
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		setS.insert(a[i]);
		setE.insert(a[3 * n - 1 - i]);
		sumS += a[i];
		sumE += a[3 * n - 1 - i];
	}

	long long ans = sumS - sumE;

	sumesBlyat[n - 1] = sumS;
	for (int l = n; l < 2 * n; l++) {
		if (a[l] - *setS.begin() > 0) {
			sumS += a[l] - *setS.begin();
			setS.erase(setS.begin());
			setS.insert(a[l]);
		}
		sumesBlyat[l] = sumS;
	}

	sumesBlyat2[2 * n] = sumE;
	for (int r = 2 * n - 1; r >= n; r--) {
		if (*(--setE.end()) - a[r] > 0) {
			sumE -= *(--setE.end()) - a[r];
			setE.erase(--setE.end());
			setE.insert(a[r]);
		}
		sumesBlyat2[r] = sumE;
	}

	for (int i = n - 1; i < 2 * n; i++) {
		if (ans < sumesBlyat[i] - sumesBlyat2[i + 1])
			ans = sumesBlyat[i] - sumesBlyat2[i + 1];
	}

	cout << ans << endl;


	/*
	int l = n;
	int r = 2 * n - 1;
	while (l <= r) {
		if (a[l] - *setS.begin() > 0 && pot - *setS.begin() >= *(--setE.end()) - pot) {
			sumS += a[l] - *setS.begin();
			setS.erase(setS.begin());
			setS.insert(a[l]);
			pot -= a[l];
			l++;
		}
		else if (*(--setE.end()) - a[r] >  0 && pot - *setS.begin() <= *(--setE.end()) - pot) {
			sumE -= *(--setE.end()) - a[r];
			setE.erase(--setE.end());
			setE.insert(a[r]);
			pot -= a[r];
			r--;
		}
		else {
			if (pot - *setS.begin() > *(--setE.end()) - pot) {
				pot -= a[l];
				l++;
			}
			else {
				pot -= a[r];
				r--;
			}
		}
	}
	
	//multiset<long long>::iterator it;
	//for (it = setS.begin(); it != setS.end(); it++)
	//	sumS +=*it;
	//for (it = setE.begin(); it != setE.end(); it++)
	//	sumE += *it;
	cout << sumS - sumE <<endl;

	*/
	return 0;
}

Measured memory_bytes: 13824
#include <iostream>

using namespace std;

int a, b;

int main()
{
	cin >> a >> b;
	
	if(a == 1) a+=13;
	if(b == 1) b+=13;
	
	if(a > b)
		cout << "Alice";
	else if(a < b)
		cout << "Bob";
	else
		cout << "Draw";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
long long  int n,m;
  cin >> n >> m;
  if(n>m) swap(n,m);
  if(n==1&&m==1) cout << 1<< endl;
  else if(n==1) cout << m-2 << endl;
  else{
    cout <<(m-2)*(n-2) << endl;
  }
}


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

int main() {
  for(int i = 0; i < 55; i++){
    int a = 0, b = 0, gcd, lcm;
    cin >> a >> b;

    if(a == 0 && b == 0){
      break;
    }
    else{
      int A = max(a, b), B = min(a, b);
      int r = A % B;
      while(r != 0){
        A = B;
        B = r;
        r = A % B;
      }
       gcd = B;

       lcm = gcd * (a / gcd) * (b / gcd);
    }
    cout << gcd << " " << lcm << endl;
  }
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M, Q;

// 19c10 = 92378

int main() {
    cin >> N >> M >> Q;
    vvi a(Q, vi(4));

    for (int i = 0; i < Q; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
        a[i][0]--;
        a[i][1]--;
    }

    int ans = 0;

    for (int mask = 0; mask < (1 << (M+N)); mask++) {
        int n_ = 0;
        vi x(0);
        int last = 0;
        for (int i = 0; i < M + N; i++) {
            if ((mask >> i) & 1) {
                n_++;
                for (int j = 0; j < i-last; j++)
                {
                    x.push_back(n_);
                }
                last = i+1;
            }
        }
        // n_++;
        // for (int j = 0; j < M + N - 3 - last; j++) {
        //     x.push_back(n_);
        // }

        if (x.size() != N) continue;

        // cout << endl;
        // for (int j = 0; j < x.size(); j++) {
        //     cout << x[j] << " ";
        // }

        int ans_ = 0;
        for (int i = 0; i < Q; i++) {
            if(x[a[i][1]] - x[a[i][0]] == a[i][2]){
                ans_ += a[i][3];
            }
        }

        ans = max(ans, ans_);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

//コンビネーションをmodで割った余りを産出
int64_t nCk( int64_t n, int64_t k  )
{
    int64_t ans_x = 1;
    int64_t ans_y = 1;

    for( int i = n; i > n - k; i-- )
    {
        ans_x *= i;
    }

    for( int i = 1; i <= k; i++ )
    {
        ans_y *= i;
    }

    return ans_x / ans_y;
}

int main()
{
    std::string word = "aa";
    std::string w = "Yes";
    int64_t a,b,c,d,e,f;
    std::cin>> word;

a = ( word.size() + 3 ) / 2 - 1;

for( int i = 0; i < ( word.size() - 1 ) / 2; i++ )
    {
        if( word[i] != word[a + i] )
        {
            w = "No";
            break;
        }
    }

std::cout<< w;
}


Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          fozubaoyou    no BUGs alive
*/
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = b; i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define SZ(x) ((int)(x).size())
using namespace std;
typedef vector<int> vi;

int selSort(vi &A) {
    int n = 0;
    REP(i, SZ(A)) {
        int minj = i;
        FOR(j, i, SZ(A)) if (A[j] < A[minj]) minj = j;
        if (i != minj) {
            n++;
            int tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;}}
    return n;
}

int main(){
    int n; cin >> n;
    vi A(n); REP(i,n) cin >> A[i];
    int nu = selSort(A);
    REP(i,n) {
        cout << A[i];
        i == n-1 ? cout << endl : cout << " ";}
    cout << nu << endl;
}

Measured memory_bytes: 3096
//ABC 132 A Fifty-Fifty

#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    bool flag;
    cin >> s;
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) flag=1;
    else if(s[0]==s[2] && s[2]!=s[1] && s[1]==s[3]) flag=1;
    else if(s[0]==s[3] && s[3]!=s[1] && s[1]==s[2]) flag=1;
    else flag=0;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
g1=[1,3,5,7,8,10,12]
g2=[4,6,9,11]
g3=[2]
if x in g1 and y in g1 or x in g2 and y in g2 or x in g3 and y in g3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n, a, b, c, d;
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    int x = (n + a - 1) / a * b;
    int y = (n + c - 1) / c * d;
    printf("%d\n", x < y ? x : y);
}


Measured memory_bytes: 2144
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
class mat2D {
private:
	vector<vector<T>> data;
public:
	mat2D(int rows, int cols) : data(vector<vector<T>>(rows, vector<T>(cols))) {}
	T operator () (int row, int col) { return data[row][col]; }

	friend istream& operator >> (istream& is, mat2D<T>& m) { return is >> m.data; }
	friend ostream& operator << (ostream& os, const mat2D<T>& m) {
		for (const vector<T>& row : m.data) os << row << endl;
		return os;
	}
};

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


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

	if (S.length() == 3)
		reverse(all(S));

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
while true
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?
 
  h.times do |n|
    if n % 2 == 0
      puts ('#.'*w)[0,w]
    else
      puts ('.#'*w)[0,w]
    end
  end
  puts
end

Measured memory_bytes: 8804
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<ctime>

using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int a[1005], b[1005];

int main(){
	int n, m, i, j, t, k, p, q, cost, flag;
	while(~scanf("%d %d", &n, &k)){
		if(n % 2) flag = n / 2 + 1; 
		else  flag = n / 2;
		if(flag < k) cout << "NO" << endl;
		else cout << "YES" << endl;
	 }
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Deque<Integer> stack = new ArrayDeque<>();
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                System.out.println(stack.pop());
            } else {
                stack.push(n);
            }
        }
    }
}


Measured memory_bytes: 25988
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,P = imn()
A = iln()

contains_odd_number = False
for a in A:
    if a % 2 == 1:
        contains_odd_number = True
if contains_odd_number:
    print(2**(N-1))
else:
    if P == 0:
        print(2**N)
    else:
        print(0)

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

int main()
{
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') s[i] = '9';
        else if (s[i] == '9') s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(input()) for _ in range(H)]
h=0
w=0
ans="Possible"
for i in range(H):
  for j in range(W):
    if A[i][j]=="#":
      if (i==h and j-w<2) or (i-h<2 and j==w):
        h=i
        w=j
      else:
        ans="Impossible"
print(ans)


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

int main() {
	int a,b,c,d,p;
	cin >> a >> b >> c >> d >> p;
	if(p<c){
		if(a*p<b){
			cout << a*p << endl;; 
		}else{
			cout << b << endl;
		}
	}else{
		if(a*p<b+(p-c)*d){
			cout << a*p << endl;
		}else{
			cout << b+(p-c)*d << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    ll x;cin>>x;
    for(ll i=-1000;i<=1000;i++){
        ll n=x+i*i*i*i*i;
        bool f=0;
        ll val;
        for(ll j=i+1;j<=1000;j++){
            if(j*j*j*j*j==n){
                f=1;
                val=j;
                break;
            }
        }
        if(f){
            cout<<val<<" "<<i<<"\n";
            return;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3616
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const n = nextInt()
    let x = nextIntArray()
    let min = Number.POSITIVE_INFINITY

    for(let p = 1; p<=100; p++){
        let curr = 0
        for(let i = 0; i<n; i++){
            curr += (x[i]-p)*(x[i]-p)
        }
        min = Math.min(min, curr)
    }
    console.log(min)
}
Main()


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

#define endl '\n'
#define int long long

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

	int n; cin >> n;
	vector<int> vec(n);
	for(int &i : vec) cin >> i;
	int last = vec[0];
	int ans = 0;
	for(int i = 1; i < n; i ++) {
		if(last > vec[i]) ans += last - vec[i];
		last = max(last, vec[i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4776
import java.util.Scanner;
 
public class Main{
 
 public static void main(String[] args){
  
   Scanner sc = new Scanner(System.in);
   
   int n = sc.nextInt();
   
   int m = sc.nextInt();
   
   int count = 0;
   
   int all = 0;
   
   String yon = "";
   
   double d = 0.0;
   
   int[] array = new int[n];
   
   for (int i = 0; i<array.length; i++){
    
     array[i] = sc.nextInt();
     
     all += array[i];
     
   }
   
   d = all/(4.0*(double)m);
   
   for(int i:array){
    
    if((double)i >= d){
      
      count += 1;
  	
    }
     
   }
   
   if(count >= m){
     
     yon = "Yes";
   
   }else{
     
     yon = "No";
     
   }
   
   System.out.println(yon);
   
 }
  
  
  
  
}  

Measured memory_bytes: 21972
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>

int main() {
	std::cout << std::setprecision(std::numeric_limits<double>::max_digits10);

	int N;
	std::cin >> N;

	std::vector<int> v(N);
	for(auto &vv : v) {
		std::cin >> vv;
	}

	std::sort(v.begin(), v.end());

	// 元々の具材の小さい順に入れる
	double result = (v[0] + v[1]) / 2.0;
	for(int i = 2; i < v.size(); i++) {
		result = (result + v[i]) / 2.0;
	}
	
	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define MAX 1000
#define VMAX 10000

int n,A[MAX],s;
int B[MAX],T[VMAX+1];


void sort(int A[]){
	int flag = 1;
	int tmp;
	while(flag == 1){
		flag = 0;
		for(int j = n-1; j >= 1; j--){
			if(A[j] < A[j-1]){
				tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				flag = 1;
			}
		}
	}
}

int min(int a, int b){
	if(a < b)return a;
	else return b;
}

int solve(){
	int ans=0;

	
	bool V[MAX];
	for(int i = 0;i < n;i++){
	B[i] = A[i];
	V[i] = false;
	}

	sort(B);
	for(int i = 0; i< n; i++){
		T[B[i]] = i;
	}
	
	for(int i = 0; i < n; i++){
		if(V[i]){continue;}
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an=0;
		while(1){
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if(V[cur]){
				break;
			}
		}
		ans += min(S + (an - 2) * m, m + S + (an + 1) * s);

}
	return ans;
}

int main(){
	scanf("%d", &n);
	s = VMAX;
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
		s = min(s, A[i]);
	}
	int ans = solve();
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 1<<20;

const int B = 40;
ll ct[B][2]={};

int n;
ll k;

ll f(int d){
    return 1LL<<d;
}

ll dp[B][2];
ll dfs(int d, int s){
    if(d==-1) return 0;
    if(dp[d][s]>=0) return dp[d][s];

    ll ret = 0;
    if(s==0){
        if(k>>d&1){
            // 0
            ret = max(ret, dfs(d-1,1)+f(d)*ct[d][1]);
            // 1
            ret = max(ret, dfs(d-1,0)+f(d)*ct[d][0]);
        }
        else{
            // 0
            ret = max(ret, dfs(d-1,0)+f(d)*ct[d][1]);
        }
    }
    else{
        // 0
        ret = max(ret, dfs(d-1,1)+f(d)*ct[d][1]);
        // 1
        ret = max(ret, dfs(d-1,1)+f(d)*ct[d][0]);
    }

    return dp[d][s] = ret;
}

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

    rep(i,n){
        ll a;
        cin >>a;

        rep(j,40){
            int b = a>>j&1;
            ++ct[j][b];
        }
    }

    memset(dp,-1,sizeof(dp));
    cout << dfs(39,0) << endl;
    return 0;
}


Measured memory_bytes: 256
def beki(n)
  # n より大きい、最小の2べき数を見つける
  # 1 -> 2     0001 ->  0010
  # 2 -> 4     0010 ->  0100
  # 3 -> 4     0011
  # 4 -> 8     0100 ->  1000
  # 5 -> 8     0101
  # 6 -> 8     0110
  # 7 -> 8     0111
  # 8 -> 16    1000 -> 10000
  # 15 -> 16   1111 -> 10000
  # 16 -> 32  10000 ->100000

  # 最上位ビットの位置
  pos = n.bit_length

  1 << pos
end

def pop_max_num(nums)
  n, cnt = nums.first
  return nil if n.nil?

  if 2 <= cnt
    nums[n] = cnt-1
  else
    nums.delete(n)
  end
  n
end

def find_and_pop_num(nums, n)
  cnt = nums[n]
  return nil if cnt == 0

  if 2 <= cnt
    nums[n] -= 1
  else
    nums.delete(n)
  end
  n
end

def main
  n = gets.chomp.to_i

  nums_ary = gets.split.map(&:to_i)
  nums_ary.sort!
  nums_ary.reverse!
  # puts nums_ary

  nums = nums_ary.each_with_object(Hash.new(0)) do |i, h|
    h[i] += 1
  end
  # puts nums

  ans = 0
  while true
    # 大きい方からxを取り出す
    x = pop_max_num(nums)
    break if x.nil?

    # x に対する相方yを探す
    # y <= x なので、
    #   x < x + y <= 2x
    # を満たす2べきは1つしかない
    b = beki(x)
    y = b - x

    # 相方 y を取り出す
    y = find_and_pop_num(nums, y)
    if y
      # 見つかった！
      ans += 1
    end
  end
  puts ans
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 31844
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    int x = i;
    if(x % 3 == 0){
      printf(" %d", i);
      continue;
    }
    do{
      if(x % 10 == 3){
        printf(" %d", i);
        break;
      }
      x /= 10;
    }while(x);
  }
  printf("\n");
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define st first
#define sc second
#define arr array
#define yes cout << "Yes" <<"\n"
#define no cout << "No" <<"\n"
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false)
#define out cin.tie(nullptr)
#define task "A"
#define open(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout);}
#define open_to_check(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin);}

using namespace std;

const int maxn = 2e6 + 1;
const ll mod = 1e9 + 7;
const ll lim = 1e18;


int main()
{
    //open_to_check(task);
    ll n, d;
    cin >> n >> d;
    ll dem = 0;
    for(int i=1; i<=n; i++){
        ll x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d){
            dem ++;
        }
    }
    cout << dem;
}
/*
6 8
1 2
1 3
2 3
2 4
2 6
3 5
3 6
4 5

*/


Measured memory_bytes: 3612
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

ans = [[0 for w in range(W)] for h in range(H)]

for h in range(H):
    if h%2 == 0:
        for w in range(W):
            ans[h][w] = N
            A[-1] -= 1
            if A[-1] == 0:
                A.pop(-1)
                N -= 1
    else:
        for w in range(1,W+1):
            ans[h][(-1)*w] = N
            A[-1] -= 1
            if A[-1] == 0:
                A.pop(-1)
                N -= 1

for h in range(H):
    ans[h] = map(str,ans[h])
    print(' '.join(ans[h]))

Measured memory_bytes: 3568
# https://atcoder.jp/contests/abc118/tasks/abc118_c


def get_input():
    n = int(input())
    a = [int(i) for i in input().split()]
    return n, a

def gcd(x, y):
        return y if not x%y else gcd(y, x%y)
    

if __name__ == "__main__":
    n, a = get_input()
    
    GCD = a[0]
    for idx in range(1, n):
        GCD = gcd(GCD, a[idx])
        if GCD <= 1: break
        
    print(GCD)

Measured memory_bytes: 62832
import sys
input = sys.stdin.readline

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

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}

SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

for i in range(N-1):
    if SB[i]>=SA[i+1]:
        print("Yes")
        sys.exit()

AB=[(B[i],A[i]) for i in range(N)]
AB.sort()

DICT={a:ind for ind,a  in enumerate(SA)}

Group=[i for i in range(N)]# グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):# find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

for i in range(N):
    _,a=AB[i]

    Union(DICT[a],i)

if len(set([find(i) for i in range(N)]))==1:
    print("No")
else:
    print("Yes")


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));

 for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int N;
  cin >> N;
  
  vector<int> B(N);
  for(int i = 0; i < N; i++) cin >> B.at(i);
    
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
 	   for (int k = 0; k < N; k++){
      if (A.at(i).at(j) == B.at(k)) {
        A.at(i).at(j) = 101;
      }
     }
    }
   }
  
  
  if(A.at(0).at(0) == 101 && A.at(0).at(1) == 101 && A.at(0).at(2) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(1).at(0) == 101 && A.at(1).at(1) == 101 && A.at(1).at(2) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(2).at(0) == 101 && A.at(2).at(1) == 101 && A.at(2).at(2) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(0).at(0) == 101 && A.at(1).at(0) == 101 && A.at(2).at(0) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(0).at(1) == 101 && A.at(1).at(1) == 101 && A.at(2).at(1) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(0).at(2) == 101 && A.at(1).at(2) == 101 && A.at(2).at(2) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(0).at(0) == 101 && A.at(1).at(1) == 101 && A.at(2).at(2) == 101){
    cout << "Yes" << endl;
  }
  else if(A.at(0).at(2) == 101 && A.at(1).at(1) == 101 && A.at(2).at(0) == 101){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

//関数

//main関数
int main() {
    //入力
    string S;
    cin>>S;
    long N=S.size();
    //計算
    long red=0,blue=0;
    for(int i=0;i<N;i++){
        if(S.at(i)=='0'){
            red++;
        }else{
            blue++;
        }
    }
    //出力
    cout<<2*min(red,blue)<<endl;
}


Measured memory_bytes: 512
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define MAX ((ll)1<<(ll)31)-1

bool sosu(ll x) {
	for (int i = 2; i*i < x; i++) {
		if (x%i == 0) {
			return false;
		}
	}
	return true;
}
int main(void) {
	ll x; cin >> x;
	for (ll i = x;; i++) {
		
		if (sosu(i)) {
			cout << i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
int main()
{
  int n;
  int h,i,j,k;
  int p[MAX][MAX];
  int num[MAX];
  int l[MAX];
  int flag,count;
  int result;
  while(1)
    {
      scanf("%d",&n);
      if(!n) break;
      for(i=0;i<n;i++)
	{
	  scanf("%d",&num[i]);
	  for(j=0;j<num[i];j++) scanf("%d",&p[i][j]);
	}
      scanf("%d",&k);
      for(i=0;i<k;i++) scanf("%d",&l[i]);
      flag=0;
      for(i=0;i<n;i++)
	{
	  for(j=0;j<k;j++)
	    {
	      for(h=0;h<num[i];h++)
		{
		  if(p[i][h]==l[j]) break;
		}
	      if(h==num[i]) break;
	    }
	  if(j==k)
	    {
	      if(flag)
		{
		  flag=2;
		  break;
		}
	      else
		{
		  result=i+1;
		  flag=1;
		}
	    }
	}
      if(flag==1) printf("%d\n",result);
      else printf("-1\n");
    }
  return 0;
}

Measured memory_bytes: 1828
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, a, N) for(int i = a; i < N; i++)

int main() {
    bool f1 = false;
    bool f9 = false;
    bool f7 = false;
    bool f4 = false;

    rep(i, 0, 4) {
        int a;
        cin >> a;
        if (a == 1) f1 = true;
        if (a == 9) f9 = true;
        if (a == 7) f7 = true;
        if (a == 4) f4 = true;
    }
    if (f1 && f9 && f7 && f4) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int maxi(int a, int b, int c){
    return max(a, max(b, c));
}
int mini(int a, int b, int c){
    return min(a, min(b, c));
}

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

    if (maxi(a, b, c) == 7 and mini(a, b, c) == 5 and a+b+c - maxi(a, b, c) - mini(a, b, c) == 5){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#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, k;
  cin >> n >> k;
  vector<lld> p(n);
  for (lld i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  lld s = 0;
  for (lld i = 0; i < k; i++) {
    s += p[i];
  }
  cout << s << "\n";
}

Measured memory_bytes: 3636