akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

int n,m,cnt1,cnt2;
char s[15][15],b[15][15],c[15][15];
bool used[15],use[15];
int row[15][30],col[15][30];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			row[i][s[i][j]-'a']++;
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			col[i][s[j][i]-'a']++;
		}
	}
	int diff1=0,diff2=0;
	for(int i=0;i<n;i++){
		if(used[i]) continue;
		bool Ok=0;
		for(int j=0;j<n;j++){
			if(used[j]||j==i) continue;
			bool ok=1;
			for(int k=0;k<26;k++){
				if(row[i][k]!=row[j][k]){
					ok=0;
					break;
				}
			}
			if(ok){
				used[i]=1;
				used[j]=1;
				for(int k=0;k<m;k++){
					b[cnt1][k]=s[i][k];
					b[n-1-cnt1][k]=s[j][k];
				}
				cnt1++;
				Ok=1;
				break;
			}
		}
		if(!Ok){
			diff1++;
		}
	}
	if(n%2&&diff1==1){
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			for(int j=0;j<m;j++){
				b[n/2][j]=s[i][j];
			}
		}
	}
//	for(int i=0;i<n;i++){
//		printf("%s\n",b[i]);
//	}
	if(n%2&&diff1>1){
		puts("NO");
		return 0;
	}else if((!(n%2))&&diff1>0){
		puts("NO");
		return 0;
	}
	for(int i=0;i<m;i++){
		if(use[i]) continue;
		bool Ok=0;
		for(int j=0;j<m;j++){
			if(use[j]||j==i) continue;
			bool ok=1;
			for(int k=0;k<26;k++){
				if(col[i][k]!=col[j][k]){
					ok=0;
					break;
				}
			}
			if(ok){
				for(int k=0;k<n;k++){
//					printf("%d %d %d %d\n",k,cnt2,k,i);
//					printf("%d %d %d %d\n",k,m-1-cnt2,k,j);
					c[k][cnt2]=b[k][i];
					c[k][m-1-cnt2]=b[k][j];
				}
				cnt2++;
				use[i]=1;
				use[j]=1;
				Ok=1;
				break;
			}
		}
		if(!Ok){
			diff2++;
		}
	}
	if(m%2&&diff2==1){
		for(int i=0;i<m;i++){
			if(use[i]) continue;
			for(int j=0;j<n;j++){
				c[j][m/2]=b[j][i];
			}
		}
	}
	if(m%2&&diff2>1){
		puts("NO");
		return 0;
	}else if((!(m%2))&&diff2>0){
		puts("NO");
		return 0;
	}
	bool ok=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(c[i][j]!=c[n-1-i][m-1-j]){
				ok=0;break;
			}
		}
	}
//	for(int i=0;i<n;i++){
//		for(int j=0;j<m;j++) printf("%c",c[i][j]);
//		puts("");
//	}
	if(!ok){
		puts("NO");
		return 0;
	}
//	printf("%d %d\n",diff1,diff2);
	puts("YES");
	return 0;
}


Measured memory_bytes: 384
def main():
    from bisect import bisect_right
    N = int(input())
    A = sorted(int(x) for x in input().split())
    B = sorted(int(x) for x in input().split())
    C = sorted(int(x) for x in input().split())

    b2c = [0] * (N+1)
    for i in range(N):
        b = B[i]
        j = bisect_right(C, b)
        b2c[i] = N - j
        #print("B[%d]=%5d"%(i,b), "C[%d]=%5d"%(j, C[j]), "bc=%d"%(N-j))

    for i in range(N-1)[::-1]:
        b2c[i] += b2c[i+1]
        pass
    #print(b2c)

    total = 0
    for i in range(N):
        a = A[i]
        a2b = bisect_right(B, a)
        t = b2c[a2b]
        #print("%d:t=%d"%(i, t),a2b)
        total+=t

    print(total)
        
main()


Measured memory_bytes: 24052
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const long double EPS = 1e-14;
const long double INF = 1e+20;
const long double PI = acos(-1);
const int mat_N=3;
const int mat_M=3;
// long long, including mod calculation
struct mat{
	long long a[mat_N][mat_M];
	mat(){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=0;}
	mat(int s){for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)a[i][j]=(i==j)*s;}
	mat operator+(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-(const mat &m)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]+m.a[i][j];
		return ret;
	}
	mat operator-()const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=-a[i][j];
		return ret;
	}
	mat operator*(const long long &k)const{
		mat ret;
		for(int i=0;i<mat_N;i++)for(int j=0;j<mat_M;j++)ret.a[i][j]=a[i][j]*k%mod;
		return ret;
	}
	// assuming mat_N = mat_M
	// by changing here, you can use for graph problems (ex. a[i][j]=min(a[i][k]+a[k][j]))
	mat operator*(const mat &m)const{
		mat ret;
		for(int k=0;k<mat_N;k++)for(int i=0;i<mat_N;i++)for(int j=0;j<mat_N;j++){
			ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j])%mod;
		}
		return ret;
	}
};
mat I=mat(1);
mat pw(mat a,long long t){
	mat ret=I;
	while(t){
		if(t&1){
			ret=ret*a;
		}
		t/=2;
		a=a*a;
	}
	return ret;
}
 
long long calc(long long a){
	mat w;
	w.a[0][0]=1;
	w.a[0][1]=mod-1;
	w.a[0][2]=1;
	w.a[1][0]=1;
	w.a[2][0]=1;
	w.a[2][2]=1;
	mat v=pw(w,a);
	long long SM=v.a[2][0];
	long long TP=v.a[0][0];
	long long n=a%mod;
	return (n+1+(n)*(SM+TP+mod-1)%mod+SM*(n)%mod*(n))%mod;
}
int main(){
	long long a;scanf("%lld",&a);
	printf("%lld\n",calc(a-1));
}

Measured memory_bytes: 128
import sys
N, Y = map(int, input().split())

for i in range(N + 1):
    if 10000 * i > Y:
        break
    for j in range(N + 1 - i):
        if 10000 * i + 5000 * j > Y:
            break
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print('{0} {1} {2}'.format(i, j, k))
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long LL;
const double pi = acos(-1);
void solve1(double a,double b,double d){
    double y = a;
    double x = b - (d - b);
    //printf("d = %.10f,x = %.10f,y = %.10f\n",d,x,y);
    double angle = atan2(y,x) / pi * 180.0;
    printf("%.12f\n",90. - angle);
}
void solve2(double a,double b,double x){
    double d = (a*a*b-x)/(a*b) * 2;
    double xx = b;
    double yy = 2 * a - d;
    double angle = atan2(yy,xx) / pi * 180.0;
    printf("%.12f\n",90.-angle);
}
int main(){
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);    
    double d = x / a / a;d *= 2;
    if(d >= b)solve1(a,b,d);
    else solve2(a,b,x);
    return 0;
}

Measured memory_bytes: 2492
N,W=map(int,input().split())
v,w=[],[]
for i in range(N):
    t,m=map(int,input().split())
    v.append(t);w.append(m)
dp=[0]*(W+1)
for i in range(1,W+1):
    for k in range(N):
        if(i-w[k]>=0):
            dp[i]=max(dp[i],dp[i-w[k]]+v[k])
print(dp[W])


Measured memory_bytes: 5920
from collections import defaultdict
import heapq

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

data=defaultdict(int)
for i in range(0,N):
    data[A[i]]+=1

A=[-A[i] for i in range(0,N)]
heapq.heapify(A)
count=0
while A:
    x=-heapq.heappop(A)
    if data[x]!=0:
        data[x]-=1
        y=2**(len(bin(x))-2)-x
        if data[y]!=0:
            data[y]-=1
            count+=1

print(count)

Measured memory_bytes: 118732
X,Y = map(int,input().split())

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

m = (2*X - Y)//3
n = (-X + 2*Y)//3

if (X+Y) % 3 != 0 or m < 0 or n < 0:
    print(0)
else:
    comb = Combination(10**6)
    print(comb(n+m,n))

Measured memory_bytes: 121832
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	long long int num[26] = {};
	for (auto i : s) {
		num[i - 'a']++;
	}
	N = s.size()*(s.size()-1)/2;
	for (int i = 0; i < 26; i++) {
		N -= num[i] * (num[i]-1) / 2;
	}
	N++;
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 720
N = int(input())
A = list(map(int, input().split(' ')))
fusion = sum(A)
ans = 1
A.sort()

for i in range(N - 2, -1, -1):
    fusion -= A[i + 1]
    if fusion * 2 >= A[i + 1]:
        ans += 1
    else:
        break

print(ans)

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

int main() {
  int n, a, b;
  cin >> n;
  if (n == 1) {
    cout << "Hello World"
         << "\n";
  } else {
    cin >> a >> b;
    cout << a + b << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
  printf("%.5f\n",  sqrt( pow(x1-x2,2)+pow(y1-y2,2) ) );
}


Measured memory_bytes: 3284
#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 H, N;
  cin >> H >> N;
  int A[N];
  REP(i, N) cin >> A[i];
  int ans = 0;
  REP(i,N) ans += A[i];
  if (ans >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

const int MOD = 1e9 + 7;

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

ll pow_mod(ll x, ll n, int M) {
    ll ans = 1;
    for (; n; n>>=1) {
        if (n & 1) ans = ans * x % M;
        x = x * x % M;
    }
    return ans;
}

ll f(ll H, ll W) {
    ll ans = (pow_mod(2, W, MOD) + pow_mod(2, H, MOD)) % MOD;
    ll d = gcd(H, W);
    ans = (ans + pow_mod(2, d, MOD));
    ans = (ans + MOD - 3) % MOD;
    return ans;
}

int main() {
    ll H, W, T;
    cin >> H >> W >> T;
    ll d = gcd(H, T);
    ll e = gcd(W, T);
    ll x = f(H / d, W / e);
    ll ans = pow_mod(x, d * e, MOD);
    cout << ans << endl;
}


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

int main(){
    int arr[5];
    scanf("%d%d%d",&arr[0],&arr[1],&arr[2]);
    sort(arr,arr+3);
    int ans = 0;
    if(arr[0]==arr[1]){
        if(arr[1]==arr[2])
            ans =1;
        else ans = 2;
    }else if(arr[1]==arr[2]){
        ans = 2;
    }else ans = 3;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define FASTI0 ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int ceil(int a,int b)
{
    if(a%b==0)
    return a/b;
    else
        return a/b+1;
}
int32_t main()
{
    int n,x,t;
    cin>>n>>x>>t;
    cout<<ceil(n,x)*t;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
vector<int>ta;
bool is(int n){
	if(n==2)return true;
	for(int i=2;i*i<=n;i++)if(n%i==0)return false;
return true;
}
void init(){
int i=2;
while(ta.size()<=100000){
if(is(i))ta.push_back(i);	
i++;
}
}
int m,a,b,a1=0,a2=0;
int main(){
init();
//for(int i=0;i<10;i++)cout<<ta[i]<<" ";cout<<endl;
while(true){
cin>>m>>a>>b;
if(m+a+b==0)break;
a1=0,a2=0;
for(int i=0;ta[i]<=m;i++){
	for(int j=0;ta[j]<=m;j++){
	//if(i>j)continue;
	int p=ta[j],q=ta[i];
	double a_b=(double)a/(double)b,p_q=(double)p/(double)q;
	if(p*q<=m&&a_b<=p_q&&p_q<=1.0&&a1*a2<p*q){a1=min(q,p),a2=max(p,q);}
	if(p*q>m)break;
	}
}
cout<<a1<<" "<<a2<<endl;
}
return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include<vector>
#include <cmath>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == t.at(i)) {
			count = ++count;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

//mod(1e9+7)
const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

int main() {
    string s; cin >> s;
    int n = s.size();
    vint mo(n);
    mo[n-1] = 1;
    for (int i = n-2; i >= 0; i--) {
        mo[i] = (mo[i+1]*10)%13;
    }
    int sum = 0;
    int ct = 0;
    rep(i,n) {
        if (s[i] != '?') {
            sum += mo[i]*(s[i]-'0');
            sum %= 13;
            ct++;
        }
    }
    if (ct == n) {
        if (sum == 5) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    int x = 5-sum;
    if (x < 0) x += 13;
    vector<map<int,mint>> mp;
    rep(i,n) {
        if (s[i] == '?') {
            map<int,mint> tmp;
            rep(j,10) tmp[j*mo[i]%13] += 1;
            mp.push_back(tmp);
        }
    }
    map<int,mint> ans = mp[0];
    REP(i,mp.size()) {
        map<int,mint> tmp;
        rep(j,14)rep(k,14) {
            tmp[(j+k)%13] += ans[j] * mp[i][k];
        } 
        swap(ans,tmp); 
    }
    cout << ans[x].x << endl;
}

Measured memory_bytes: 94252
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

inline void add(int& a, int b){a = (a+b); if(a>=mod)a-=mod;}
inline void sub(int& a, int b){a = a-b; if(a<0)a+=mod;}
inline void mul(int& a, int b){a = (a*b)%mod;}

int n;
const int N = 3001;
int dp[N][N],pre[N][N];


void mymain(){
    cin >> n;
    string s;
    cin >> s;

    dp[1][1]=1;
    for(int i=2;i<=n;i++){


        for(int j=1;j<n;j++){
            pre[i-1][j] = (pre[i-1][j-1]+dp[i-1][j])%mod;
        }


        for(int j=1;j<=i;j++){
            int L,R;
            if(s[i-2] == '<'){
                L=1,R=j-1;
            }else{
                L=j,R=i-1;
            }

            if(L<=R){
                dp[i][j] = (dp[i][j] + (pre[i-1][R] - pre[i-1][L-1]+mod)%mod)%mod;
            }

            /*
            for(int z = L;z<=R;z++){
                add(dp[i][j],dp[i-1][z]);
            }




            for(int k=1;k<i;k++){
                int rk=k;
                if(j<=k){
                    rk++;
                }
                if(rk < j && s[i-2] == '<'){
                    add(dp[i][j] , dp[i-1][k]);
                }
                if(rk > j && s[i-2] == '>'){
                    add(dp[i][j] , dp[i-1][k]);
                }
            }*/
        }
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
        add(ans , dp[n][i]);

    cout << ans << endl;

}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}
/*

*/


Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int q;
  cin >> s >> q;
  
  int count = 0;
  int t_i;
  int f_i;
  char c_i;
  
  for(int i = 0; i < q; ++i){
    cin >> t_i;
    
    if(t_i == 1){
      // t_i = 1なら，countをincrement
      ++count;
    }else{
      // t_i = 2なら，count + f_iを2で割った余りが0なら先頭，1なら末尾にc_iを追加
      cin >> f_i >> c_i;
      if((count + f_i) % 2 == 1){
        s.insert(s.begin(), c_i);
      }else{
        s.insert(s.end(), c_i);
      }
    }
  }
 
  if(count % 2 == 1){
    reverse(s.begin(), s.end());
  }
  
  
  cout << s << endl;
  return 0;
  
}

Measured memory_bytes: 900
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define SPACEREP(lst,itr) for(auto itr=lst.begin(); itr!=lst.end();++itr){cout<<*itr<<(++itr!=anslist.end()?" ":"\n");itr--;}
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll pow(int x){
    ll ans=1;
    REP(i,0,x){
        ans*=3;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int ans=1;
    while(1){
        if(pow(ans-1)<n && n<=pow(ans))break;
        ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;


template <typename T> void show_vec(vector<T> v);





int main(){

    

    //solve();
    int n;
    cin >> n;
    vector<ll> A;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    ll ret = 1;
    ll before = 1;
    for (int i = 0; i < n; i++)
    {
        if(A[i] == 0){
            cout << 0 <<endl;
            return 0;
        }
    }
    
    for (int i = 0; i < n; i++)
    {   
        before = ret;
        ret *= A[i];
        if(A[i] == 0){
            ret = 0;
            break;
        }
        else if(ret > (ll)1e+18 || before > ret){
            ret = -1;
            break;
        }   
        
    }
   
    cout << ret << endl;

    return 0;

}

template <typename T> void show_vec(vector<T> v){
    cout << "[";
    for (int i = 0; i < (int)v.size(); i++)
    {
        cout << v[i] << ",";
    }
    cout << "]" << endl;
}

Measured memory_bytes: 4320
#include <bits/stdc++.h> 
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<long> L;
  for(int i=0; i<N; ++i){
  	int x;
    cin >> x;
    L.push_back(x);
  }
  sort(L.begin(),L.end());
  int triangles = 0;
  if(N>=3){
  for(int i=0; i<N-2; ++i){
    for(int j=i+1; j<N-1; ++j){
		if(L[i]==L[j]){continue;}
    	for(int k=j+1; k<N; k++){
	    	if(L[j]==L[k]){continue;}
      		if(L[i]+L[j]>L[k]){++triangles;}
        	else{break;}
      }
    }
  }
  }
  cout << triangles << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll, ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
//#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF -1e16

#define maxn 1000005
int spf[maxn];
vll primes;
void sieve()
{
	rep(i,2,maxn)
	{
		if (spf[i]==0)
		{
			spf[i]=i;
			for(int j=2*i;j<=maxn;j+=i)
			{
				if(spf[j]==0)
					spf[j]=i;
			}
		}
	}
}
// void SieveOfEratosthenes(int n) 
// { 
//     bool prime[n+1]; 
//     memset(prime, true, sizeof(prime)); 
  
//     for (int p=2; p*p<=n; p++) 
//     { 
//         if (prime[p] == true) 
//         { 
//             for (int i=p*2; i<=n; i += p) 
//                 prime[i] = false; 
//         } 
//     }
//     for (int p=2; p<=n; p++) 
//       if (prime[p]) 
//           primes.pb(p); 
// } 
// bool isPrime(ll n) 
// { 
//     if (n <= 1) 
//         return false; 
//     if (n <= 3) 
//         return true; 
//     if (n % 2 == 0 || n % 3 == 0) 
//         return false; 
//     for (int i = 5; i * i <= n; i = i + 6) 
//         if (n % i == 0 || n % (i + 2) == 0) 
//             return false; 
//     return true; 
// } 
// ll power(ll x,ll y)
// {
//     ll X=x;
//     //X=X%p;//if x is greater than p
//     if(X==0)
//     {
//         return 0;
//     }
//     ll res=1ll;
//     while(y>0)
//     {
//         if(y&1)
//         {
//             res=((res)*(X));
//             y--;
//         }
//         y=y>>1;
//         X=((X)*(X));
//     }
//     // res=(res>=0)?(res%p):(res+p)%p;
//     return(res);
// }
// void dfs(int u, int par){
//     cnt[u] = 1;
//     p[u] = par;
//     for(int i : g[u]){
//         if(i != par){
//             dfs(i,u);
//             cnt[u] += cnt[i];
//         }
//     }
// }
// int children(vll v[],int parent,int src,vll& chil)
// {
// 	int ans =0;
// 	for(auto it:v[src])
// 	{
// 		if(it!=parent)
// 		{
// 			ans+= 1+children(v,src,it,chil);
// 		}
// 	}
// 	chil[src] = ans;
// 	return ans;
 
// }
signed main() {
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand (static_cast <unsigned> (time(0)));
// 	SieveOfEratosthenes(300001); 
// 	sort(all(primes));
    //sieve();
	int t=1;
	//cin >> t;
	while (t--) 
	{
	    int n;
      cin >> n;
      vll a(n);
      rep(i,0,n)
        cin >> a[i];
      ll ma=a[0],ans=0;
      rep(i,1,n)
      {
        if (a[i]<ma)
        {
          ans+=ma-a[i];
        }
        ma=max(a[i],ma);
      }
      cout <<ans<<endl;
		
		
	}
	return 0;
}


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

int main() {
  int N,x=1,a;
  cin >> N;
  
  vector<int> S(N);

  for(int i=0 ; i < N ; i++) cin >> S.at(i);
 
  a=S.at(0);

  for(int j=0 ; j < N ; j++) {
     if(a!=2){
      	x++;
  		a=S.at(a-1);
    }

   
   else  break;


   
  }

    if(x>N) cout << "-1" << endl;
    else cout  << x  <<endl;
    
    
    
  
  
  
  
  
  
}



Measured memory_bytes: 640
#include <iostream>

using namespace std;
int a, b;
int main()
{
	cin >> a >> b;
	if(a % 3 == 0){
		cout << "Possible";
	}else if(b % 3 == 0){
		cout << "Possible";
	}else if((a + b) % 3 == 0){
		cout << "Possible";
	}else {
		cout << "Impossible";
	}

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;
#define dump(x) cout << (x) << '\n'
Int mod = 1e9+7;

Int gcd(Int n, Int m) {
    Int x = max(n, m);
    Int y = min(n, m);
    return x % y == 0 ? y : gcd(y, x % y);
}

int main() {
    Int n;
    cin >> n;
    vector<Int> c(n);
    for (Int i = 0; i < n; i++) cin >> c[i];
    vector<Int> d = c;
    for (Int i = 0; i < n - 1; i++) {
        c[i + 1] = gcd(c[i], c[i + 1]);
    }
    for (Int i = n - 1; i > 0; i--) {
        d[i - 1] = gcd(d[i], d[i - 1]);
    }
    //for (Int i =0; i < n; i++) cout << c[i] << " "; cout << endl;
    //for (Int i =0; i < n; i++) cout << d[i] << " "; cout << endl;
    Int res = 1;
    for (Int i = 0; i < n; i++) {
        if (i == 0) {
            res = max(res, d[i + 1]);
        }
        else if (i == n - 1) {
            res = max(res, c[i - 1]);
        }
        else {
            res = max(res, gcd(c[i - 1], d[i + 1]));
        }
    }
    dump(res);
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> h(n);
  vector<bool> v(n, true);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  vector<ll> dh(n);
  for(int i=1; i<n; i++){
  	dh[i] = h[i+1] - h[i]; 
  }
  
  ll lim = h[0];
  for(int i=0; i<n-1; i++){
  	if(dh[i] < -1){
      cout << "No" << endl;
      return 0; 
    }
    if(dh[i] == -1){
      if(lim - h[i] > 0){
        cout << "No" << endl;
      	return 0;
      }else{
      	lim = h[i];
      }
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		long N_min= 0;
		
			if (N<=K){
			N_min=Math.min(Math.abs(N-K),Math.abs(N));
			System.out.println(N_min);
			}
			else{
			N_min=Math.min(N%K,Math.abs((N%K)-K));
			System.out.println(N_min);
			}
		}
    }

Measured memory_bytes: 21844
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[warn(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        s: String
    };
    let mut res = vec!{
        vec!{0, 0},
        vec!{0, 1},
        vec!{1, 0},
        vec!{1, 1}
    };
    for (i, c) in s.chars().enumerate() {
        let no1 = c == 'o';
        for u in 0..4 {
            let mut k = res[u][i];
            if if res[u][i+1] == 1 { no1 } else { !no1 } {
                k = 1 - k;
            }
            res[u].push(k);
        }
    }
    for ref u in res {
        if u[n] == u[0] && u[n+1] == u[1] {
            for i in 1..n+1 {
                print!("{}", if u[i] == 0 {"S"} else {"W"});
            }
            println!("");
            return;
        }
    }
    println!("-1");
}

Measured memory_bytes: 6396
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents
main :: IO ()
main = do
    s <- getLine
    q <- getInt
    query <- map words <$> replicateM q getLine
    putStrLn $ ans $ foldl f (s, "") query

f :: (String, String) -> [String] -> (String, String)
f (l, r) [[c1]]
    | c1=='1' = (r, l)
f (l, r) [[c1],[c2],[c3]]
    | c2 == '1' = (c3:l, r)
    | c2 == '2' = (l, c3:r)
ans :: (String, String) -> String
ans (l, r) = l ++ reverse r

Measured memory_bytes: 78076
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll t1,t2,a,b,c,d; cin >> t1 >> t2 >> a >> b >> c >> d;
	if(a>c&&b>d){
		cout << 0 << endl;
		return 0;
	}
	if(c>a&&d>b){
		cout << 0 << endl;
		return 0;
	}
	if(a>c){
		if((a-c)*t1>(d-b)*t2){
			cout << 0 << endl;
			return 0;
		}
		else if((a-c)*t1==(d-b)*t2){
			cout << "infinity" << endl;
			return 0;
		}
		else{
			ll ans=0;
			ll p=(d-b)*t2-(a-c)*t1;
			if((a-c)*t1%p==0){
				ans++;
			}
			ans+=((a-c)*t1+p-1)/p*2;
			cout << ans-1 << endl;
		}
	}
	else{
		swap(a,c);
		swap(b,d);
		if((a-c)*t1>(d-b)*t2){
			cout << 0 << endl;
			return 0;
		}
		else if((a-c)*t1==(d-b)*t2){
			cout << "infinity" << endl;
			return 0;
		}
		else{
			ll ans=0;
			ll p=(d-b)*t2-(a-c)*t1;
			if((a-c)*t1%p==0){
				ans++;
			}
			ans+=((a-c)*t1+p-1)/p*2;
			cout << ans-1 << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
using namespace std;
int main(){
  int n,q,time=0;
  queue<pair<string,int> > qu;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    pair<string,int> p;
    cin>>p.first>>p.second;
    qu.push(p);
  }
  while(!qu.empty()){
    if(qu.front().second>q){
      qu.front().second-=q;
      qu.push(qu.front());
      qu.pop();
      time+=q;
    }else{
      time+=qu.front().second;
      cout<<qu.front().first<<" "<<time<<endl;
      qu.pop();
    }
  }
  return 0;
}

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

int main () {
  int N;
  cin >> N;
  int t = N;
  int c = 0;
  while (t > 0) {
    c += t%10;
    t /= 10;
  }
  if (N%c == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
string s[15];
vector<string> S;
string mar[15][15];
string dp[(1<<15)][15];

string marge(int a,int b){
  for(int i=0;i<(int)S[a].size();i++){
    bool f = true;
    for(int j=0;j<(int)S[b].size()&&i+j<(int)S[a].size();j++){
      if( S[b][j] != S[a][i+j] ) f = false;
      if(!f) break;
    }
    if( f ){
      if( i + S[b].size() <= S[a].size() ) return "";
      return S[b].substr((int)S[a].size()-i);
    }
  }
  return S[b];
}
bool contain(int a,int b){
  if( s[a].size() < s[b].size() ) return false;
  for(int i=0;i<(int)s[a].size()-(int)s[b].size()+1;i++){
    if( s[a].substr(i,(int)s[b].size()) == s[b] ) return true;
  }
  return false;
}
#define INF "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
int main(){
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      cin >> s[i];
    }
    bool used[15]={};
    for(int i=0;i<N;i++){
      if( used[i] ) continue;
      for(int j=0;j<N;j++)
	if( i!=j && contain(i,j) ) 
	  used[j] = true;
    }    
    S.clear();
    for(int i=0;i<N;i++) if( !used[i] ) S.push_back( s[i] );
    N = S.size();

    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	mar[i][j] = marge(i,j);
      }
    }
    for(int i=0;i<N;i++) mar[N][i] = S[i];
    string res = INF;
    fill(dp[0],dp[(1<<N)],INF);
    dp[0][N] = "";
    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<=N;j++){
	if( dp[i][j] == INF ) continue;
	if( i == (1<<N) -1  ) {
	  if( res.size() > dp[i][j].size() ) res = dp[i][j];
	  else if( res.size() == dp[i][j].size() ) res = min( res,dp[i][j] );
	}
	for(int k=0;k<N;k++){
	  if( i & (1<<k) ) continue;
	  int nt = i | (1<<k);
	  string ns = dp[i][j] + mar[j][k];
	  if( dp[nt][k].size() > ns.size() ) dp[nt][k] = ns;
	  else if( dp[nt][k].size() == ns.size() ) 
	    dp[nt][k] = min( dp[nt][k], ns );
	}
      }
    }
    cout << res << endl;
  }  
}

Measured memory_bytes: 9280
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        if (n >= m) {
            System.out.println(0);
            return;
        }

        int[] xs = new int[m];
        for (int i = 0; i < m; i++) {
            xs[i] = sc.nextInt();
        }
        Arrays.sort(xs);

        Integer[] ds = new Integer[m - 1];
        for (int i = 0; i < m - 1; i++) {
            ds[i] = Math.abs(xs[i + 1] - xs[i]);
        }
        Arrays.sort(ds, Collections.reverseOrder());

        int ans = 0;
        for (int i = n - 1; i < m - 1; i++) {
            ans += ds[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50720
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

vector<vector<vector<ll>>> dp(3030, vector<vector<ll>>(3030, vector<ll>(2,longinf)));
vector<ll> a(3030);
int n;

ld rec(int x, int y, int idx){
  if(dp[x][y][idx]!=longinf){ return dp[x][y][idx]; }
  if(x==y){ if(idx){return a[x];}else{ return -a[x];}}
  if(idx){ return dp[x][y][idx] = max(a[x]+rec(x+1,y,1-idx), a[y]+rec(x,y-1,1-idx)); }
    else { return dp[x][y][idx] = min(-a[x]+rec(x+1,y,1-idx), -a[y]+rec(x,y-1,1-idx)); }
}

int main(){  
  cin >> n;
  rep(i,n){ cin >> a[i]; }

  ll ans=rec(0,n-1,1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 504960
#include <bits/stdc++.h>
using namespace std;
int w,h;
vector<string> field;
int dist(pair<int,int> a,pair<int,int> b){
	queue<pair<pair<int,int>,int> > bfs;
	set<pair<int,int> > already;
	bfs.push(make_pair(a,0));
	while(!bfs.empty()){
		pair<int,int> pos;
		int cost;
		tie(pos,cost)=bfs.front();
		bfs.pop();
		int y,x;
		tie(y,x)=pos;
		if(y<0||h<=y||x<0||w<=x) continue;
		if(field[y][x]=='x') continue;
		if(!already.insert(pos).second) continue;
		if(pos==b) return cost;
		int dy[4]={0,0,-1,1},dx[4]={-1,1,0,0};
		for(int i=0;i<4;++i)
			bfs.push(make_pair(make_pair(y+dy[i],x+dx[i]),cost+1));
	}
	return 1048576;
}
int solve(){
	cin >> w >> h;
	if(!w&&!h) return 0;
	field.resize(h);
	for(int i=0;i<h;++i)
		cin >> field[i];
	pair<int,int> robot;
	vector<pair<int,int> > dirty;
	for(int i=0;i<h;++i)
		for(int j=0;j<w;++j){
			if(field[i][j]=='o') robot=make_pair(i,j);
			if(field[i][j]=='*') dirty.push_back(make_pair(i,j));
		}
	//init bitdp[state][lastpos]
	vector<vector<int> > bitdp;
	bitdp.assign(1<<dirty.size(),vector<int>());
	for(int i=0;i<(1<<dirty.size());++i)
		bitdp[i].assign(dirty.size(),1048576);
	for(int i=0;i<dirty.size();++i){
		bitdp[1<<i][i]=dist(robot,dirty[i]);
		if(bitdp[1<<i][i]>8192) return -1;
	}
	vector<vector<int> > ecost;
	ecost.assign(dirty.size(),vector<int>());
	for(int i=0;i<dirty.size();++i)
		ecost[i].assign(dirty.size(),1048576);
	for(int i=0;i<dirty.size();++i)
		for(int j=0;j<dirty.size();++j)
			ecost[i][j]=dist(dirty[i],dirty[j]);
	for(int i=0;i<(1<<dirty.size());++i)
		for(int j=0;j<dirty.size();++j){
			if(i&(1<<j)) continue;
			for(int k=0;k<dirty.size();++k)
				if(i&(1<<k)) bitdp[i|(1<<j)][j]=min(bitdp[i|(1<<j)][j],bitdp[i][k]+ecost[k][j]);
		}
	int answer=1048576;
	for(int i=0;i<dirty.size();++i)
		answer=min(answer,bitdp[(1<<dirty.size())-1][i]);
	if(answer>65536) answer=-1;
	return answer;
}
int main() {
	for(;;){
		int answer=solve();
		if(answer) cout << answer << endl;
		else break;
	}
	return 0;
}

Measured memory_bytes: 1284
s = list(input()) + [False]
a = ['A','T','G','C']
for i in range(len(s)):
    if s[i] not in a:
        s[i] = False
cnt = 0
ans = 0
for b in s:
    if b:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 0
print(ans)

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    bool od = s.size() % 2 == 0;
    bool mt = s.front() == s.back();
    bool ans = od ^mt;
    cout << (ans ? "Second" : "First") << endl;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll M, ll K) {
  bool flag = false;
  REP(i,N+1) REP(j,M+1) {
    if ((N - i) * j + i * (M - j) == K) flag = true;
  }
  cout << flag << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll K;
	ll M;
	scanf("%lld", &N);
	scanf("%lld", &M);
	scanf("%lld", &K);
	solve(N, M, K);
	return 0;
}


Measured memory_bytes: 256
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a, b, c;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> c;
    if(a == b && b == c)
    {
        if(a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
            cout << "-1\n";
        else
            cout << "0\n";
        return 0;
    }
    int ans = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
    {
        ll a1, b1, c1;
        a1 = (b + c) / 2;
        b1 = (a + c) / 2;
        c1 = (a + b) / 2;
        a = a1;
        b = b1;
        c = c1;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3604
w, h, n = map(int, input().split())
minx = miny = 0
maxx = w
maxy = h
for _ in range(n):
    x1, y1, a = map(int, input().split())
    if a == 1:
        minx = max(minx, x1)
    if a == 2:
        maxx = min(maxx, x1)
    if a == 3:
        miny = max(miny, y1)
    if a == 4:
        maxy = min(maxy, y1)

print(max(0, (maxx - minx)) * max(0, (maxy - miny)))

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()

typedef long long ll;

template <class T = int>
T in() { T x; cin >> x; return x; }
#define output(e) cout << e << '\n'

#ifdef LOCAL
#define dr(x) cout << "L" << __LINE__ << ": " << #x << " -> " << x << "\n"
#else
#define dr(x)
#endif

//
// Implementation
//

int t[200000];

int main() {
  int N = in();
  int T = in();
  rep(i, N) t[i] = in();

  ll keika = 0;
  ll saidai = T;
  ll sum = T;
  for (int i = 1; i < N; i++) {
    if (t[i] >= keika) {
      if (saidai > t[i]) {
        sum -= saidai - t[i];
      }
      sum += T;
      keika = t[i];
      saidai = t[i] + T;
    }
  }
  output(sum);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    string s,t;
    cin>>s>>t;
    int n=s.size();
    rep(i,n) {
        t.push_back(t[i]);
    }

    int ans=false;
    rep(i,n) {
        if(s[0]==t[i]) {
            for(int j=1;j<n;j++) {
                if(s[j]==t[i+j]) {
                    if(j==n-1)  ans=true;
                }
                else break;
            }
        }
    }

    if(ans) cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;
    

 return 0;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int k,x;cin>>k>>x;
  if(500*k >= x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
long long MIN(long long a,long long b){return a<b?a:b;}
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  long long n,i,j,m=1e14,d[100010],s=0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&j);
    hin(j);
  }
  for(i=0;i<n;i++)d[i]=N[hout()];
  for(i=0;i<n;i++){
    j=labs(d[i]-d[n/2]);
    s+=j*2;
    if(m>j&&i-n/2)m=j;
  }
  //if(n-1)s-=m;
  if(n%2==0)s-=labs(d[n/2]-d[n/2-1]);
  else s-=MIN(labs(d[n/2]-d[n/2-1]),labs(d[n/2]-d[n/2+1]));
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 5760
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    A = a[i]
    B = b[i]
    C = c[i]
    if A == B:
        if B != C:
            ans += 1
    elif B == C:
        if B != A:
            ans += 1
    elif C == A:
        if A != B:
            ans += 1
    elif A != B and B != C and C != A:
        ans += 2
print(ans)

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

int main() {
    int A , B;
    char op;
    int sum;

    cin >> A >> op >> B;

    if (op == '+') {
        sum = A + B;
    }

    if (op == '-') {
        sum = A - B;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n; cin>>n;
      int coun=0; 
      for(int i=0; i<n; i++)
    {
         int a,b;
          cin>>a>>b;
          if(a==b){
          coun++;
        }
      else {
        coun=0;
      }
      if(coun==3){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  cout<<"No"<<endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	double a, b, c, d, e, f;
	double x, y;
	while (cin >> a >> b >> c >> d >> e >> f) {
		x = (c*e - b*f) / (a*e - b*d);
		y = (c*d - a*f) / (b*d - a*e);
		if (x == -0) {
			x = 0;
		}
		if (y == -0) {
			y = 0;
		}
		printf("%.3lf ", x);
		printf("%.3lf\n", y);
	}
	return 0;
}

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

int main(){
  int n, m, x;
  cin >> n >> m;
  priority_queue<int> que;
  for(int i=0; i<n; ++i){
    cin >> x;
    que.push(x);
  }
  for(int i=0; i<m; ++i){
    x = que.top();
    que.pop();
    que.push(x/2);
  }
  long long ans = 0;
  for(int i=0; i<n; ++i){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
string a, b, c;

int main(void){
	
	cin >> a >> b >> c;
    cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]);
	
    return 0;
}

Measured memory_bytes: 256
# AOJ 1159: Next Mayor
# Python3 2018.7.14 bal4u

while True:
	n, p = map(int, input().split())
	if n == 0: break
	ans, m = 0, p
	x = [0]*53
	while True:
		m -= 1
		if m >= 0:
			x[ans] += 1
			if x[ans] == p: break
		else: m = x[ans]; x[ans] = 0
		ans += 1
		if ans == n: ans = 0
	print(ans)




Measured memory_bytes: 5592