akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0
c = 0
while len(a) > 0:
    m = max(a)
    i = a.index(m)
    a.pop(i)
    if c % 2 == 0:
        alice += m
    else:
        bob += m
    c += 1

print(alice - bob)


Measured memory_bytes: 3060
MAX =10000
isPrime = Array.new(MAX+1,true)
isPrime[0,2]=false,false
(2..100).each{|i|
  if isPrime[i]
    (i*2).step(MAX,i){|j|
      isPrime[j]=false
    }
  end
}
prime=[]
isPrime.each_index{|x|
  prime << x if isPrime[x]
}
 
loop do
  n = gets.to_i
  break if n==0
  c=0
  (0...prime.size).each{|i|
    break if prime[i] > n
    sum =0
    (i...prime.size).each{|j|
      break if sum>n
      sum+=prime[j]
      if sum==n
        c+=1
        break
      end
    }
  }
  puts c
end

Measured memory_bytes: 2796
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  string s;
  cin>>N;
  cin>>s;
  string t[4];
  t[0]="SS";
  t[1]="SW";
  t[2]="WS";
  t[3]="WW";
  FOR(i,1,N){
    REP(j,4){
      if((s[i]=='o')^(t[j][i]=='S')) t[j]+=(t[j][i-1]=='S'?'W':'S');
      else  t[j]+=(t[j][i-1]=='S'?'S':'W');
    }
  }
  // REP(i,4)cerr<<t[i]<<endl;
  REP(i,4){
    bool f=(t[i][0]==t[i][N])and(((s[0]=='o')^(t[i][0]=='S'))==(t[i][1]!=t[i][N-1]));
    if(!f)continue;
    cout<<t[i].substr(0,N)<<endl;
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;
}


Measured memory_bytes: 1152
n,l=int(input()),list(map(float,input().split()))
dp=[[0.0]*(n+1) for _ in range(n+1)]
dp[0][0]=1.0
for i in range(1,n+1):
    for j in range(i+1):
        if j==0:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])
        else:
            dp[i][j]=dp[i-1][j]*(1.0-l[i-1])+dp[i-1][j-1]*l[i-1]
print(sum(dp[n][((n+1)//2):]))

Measured memory_bytes: 111580
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000




int main(){
	
	string A,B;
	cin>>A>>B;
	
	bool f = false;
	for(int i=0;i<B.size();i++){
		if(B[i]=='1')f=true;
	}

	
	
	int ans = 1000000000;
	if(f){
		for(int K=0;K<2;K++){
			vector<bool> ok(A.size(),false);
			vector<int> right(A.size(),0);
			for(int i=0;i<A.size();i++){
				if(i==0||right[i-1]==0){
					int cnt = 0;
					int now = i;
					while(B[now]!='1'){
						now++;
						now%=A.size();
						cnt++;
					}
					right[i] = cnt;
				}
				else{
					right[i] = right[i-1]-1;
				}
			}
			
			for(int i=0;i<A.size();i++){
				for(int j=0;j<B.size();j++){
					if(B[j]=='1')ok[j]=true;
				}
				
				vector<int> left(A.size(),0);
				for(int j=0;j<A.size();j++){
					if(j==0||B[j]=='1'){
						int cnt = 0;
						int now = j;
						while(B[now]!='1'){
							now --;
							if(now<0)now+=A.size();
							cnt++;
						}
						left[j] = cnt;
					}
					else{
						left[j] = left[j-1] + 1;
					}
				}
				
				vector<pair<int,int>> P;
				for(int j=0;j<A.size();j++){
					if(ok[j])continue;
					if(A[j]==B[j])continue;
					P.emplace_back(left[j],right[j]);
				}
				int num = 100000000;
				sort(P.begin(),P.end());
				vector<int> maxi(P.size()+1,0);
				for(int j=P.size()-1;j>=0;j--){
					maxi[j] = max(maxi[j],P[j].second);
					maxi[j] = max(maxi[j],maxi[j+1]);
				}
				for(int j=0;j<P.size();j++){
					num = min(num,P[j].first + maxi[j+1]);
				}
				num = min(num,maxi.front());
				
				int X = i;
				for(int j=0;j<A.size();j++){
					if(A[j]!=B[j])X++;
				}
				X += num*2;
				
				ans = min(X,ans);
				char x = B.back();
				B.pop_back();
				B.insert(B.begin(),x);
				/*
				char x = B[0];
				B.erase(B.begin());
				B.push_back(x);
				*/
			}
			reverse(A.begin(),A.end());
			reverse(B.begin(),B.end());
		}
	}
	else{
		for(int i=0;i<A.size();i++){
			if(A[i]=='1'){
				cout<<-1<<endl;
				return 0;
			}
		}
		ans=0;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int a = 0, b = 0;
			for(int i=0;i<n;i++){
				int ta = stdIn.nextInt();
				int tb = stdIn.nextInt();
				if(ta>tb){
					a+=ta;
					a+=tb;
				}
				else if(ta<tb){
					b+=ta;
					b+=tb;
				}
				else{
					a+=ta;
					b+=tb;
				}
			}
			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		String S=in.next();
		String T=in.next();
		String X=T.substring(0, T.length()-1);
		if(S.equals(X)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26912
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	int k, s; cin >> k >> s;
	int ans = 0;
	if (k < s) {
		for (int i = 0; i <= k; i++) {
			ans += s - i + 1;
			int a = s - i - k;
			//cout <<'A'<< a << endl;
			if ((s - i) % 2 == 0) {
				if (a > 0 && k >= (s - i) / 2) {
					ans += -a * 2;
				}
				else if(a>0&&k<(s-i)/2) {
					ans += -(s - i + 1);
				}
			}
			else {
				if (a > 0 && k >= (s - i) / 2 ) {
					ans += -a * 2;
				}
				else if (a > 0 && k < (s - i) / 2) {
					ans += -(s - i + 1);
				}
			}
			//cout << ans << endl;

		}
	}
	else {
		for (int i = 0; i <= s; i++) {
			ans += s - i + 1;
		}
	}
	cout << ans << endl;
}


    

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

int main(){
    int n,m; cin>>n>>m;
    priority_queue<pair<int,int>> q;
    long long ans=0;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        q.push(make_pair(a,1));
    }
    for(int i=0;i<m;i++){
        int b,c; cin>>b>>c;
        q.push(make_pair(c,b));
    }
    for(int i=0;i<n;i++){
        auto p=q.top();
        q.pop();
        ans+=p.first;
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll s, w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}


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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
#define PI 3.14159265
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ull n; cin >> n;
    string s;
    while (n > 0) {
        char ch = 'a' + ((n - 1) % 26);
        s += ch;
        n = (n - 1) / 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int m;
string s, a, b, c, d;
typedef unordered_set<string> set_t;
int main()
{
	cin >> m;
	for(int i=0; i<m; i++)
	{
		cin >> s;
		set_t A{};
		for(int k=1; k<s.size(); k++)
		{
			a=s.substr(0, k);
			b=s.substr(k);
			c=a;
			d=b;
			reverse(c.begin(), c.end());
			reverse(d.begin(), d.end());
			A.insert(a+b);
			A.insert(b+a);
			A.insert(a+d);
			A.insert(d+a);
			A.insert(c+b);
			A.insert(b+c);
			A.insert(c+d);
			A.insert(d+c);
		}
		cout << A.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3240
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	ans = 1
	while True:
		N = int(N // K)
		if N == 0:
			break
		ans += 1
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
/// [Amberjack] CUT BEGIN
#include <bits/stdc++.h>
using namespace std;

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

typedef int _loop_int;
#define __GET_REP_MACRO(_1,_2,_3,NAME,...) NAME
#define __REP0(i,n) for(_loop_int i=0;i<(n);++i)
#define __REP1(i,a,b) for(_loop_int i=(a);i<(b);++i)
#define __REPR0(i,n) for(_loop_int i=(n)-1;i>=0;--i)
#define __REPR1(i,a,b) for(_loop_int i=(b)-1;i>=(a);--i)
#define REP(...) __GET_REP_MACRO(__VA_ARGS__,__REP1,__REP0)(__VA_ARGS__)
#define REPR(...) __GET_REP_MACRO(__VA_ARGS__,__REPR1,__REPR0)(__VA_ARGS__)

#ifdef BURI
#define __DEBUG0() "Hello"
#define __DEBUG1(x) #x"("<<(x)<<")"
#define __DEBUG2(x,...) #x"("<<(x)<<"), " __DEBUG1(__VA_ARGS__)
#define __DEBUG3(x,...) #x"("<<(x)<<"), " __DEBUG2(__VA_ARGS__)
#define __DEBUG4(x,...) #x"("<<(x)<<"), " __DEBUG3(__VA_ARGS__)
#define __DEBUG5(x,...) #x"("<<(x)<<"), " __DEBUG4(__VA_ARGS__)
#define __GET_DEBUG_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define __DEBUG(...) __GET_DEBUG_MACRO(__VA_ARGS__,__DEBUG5,__DEBUG4,__DEBUG3,__DEBUG2,__DEBUG1,__DEBUG0)(__VA_ARGS__)
#define DEBUG(...) cerr<<__DEBUG(__VA_ARGS__)<<endl
#else
#define DEBUG(...)
#endif

#define gc getchar_unlocked
inline void getll(ll &x){
  int sgn=1;x=0;
  char c=gc();
  while(c!='-'&&(c<'0'||c>'9'))c=gc();
  if(c=='-') sgn=-1; else x=c-'0';
  c=gc();
  while('0'<=c&&c<='9'){
    x*=10;
    x+=c-'0';
    c=gc();
  }
  x*=sgn;
}
inline void read(ll &x){getll(x);}
inline void read(int &x){ll y;getll(y);x=y;}
inline void read(float &x){scanf("%f",&x);}
inline void read(double &x){scanf("%lf",&x);}
inline void read(long double &x){scanf("%Lf",&x);}
inline void read(char *s){scanf("%s",s);}
inline void read(string &s){int len=s.size();char *buf=(char*)malloc(len*sizeof(char));scanf("%s",buf);s=string(buf);free(buf);}
inline void read(char &c){char *buf=(char*)malloc(5*sizeof(char));scanf("%s",buf);c=buf[0];free(buf);}
inline void read(){}
template<typename S,typename ...T>
inline void read(S& first, T&... rest){
  read(first);
  read(rest...);
}
/// [/Amberjack] CUT END

int n;
int main(){
  ll ans;
  read(n,ans);
  ans-=1;
  int ban = 2;
  int a;
  REP(i,1,n){
    read(a);
    if(a==ban)ban++;
    ans += (a-1)/ban;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long M=0;
  cin>>N;
  vector<long long>vec(N);
  vector<long long>v(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
    cin>>v.at(X);
  }
  for(int X=N-1;X>=0;X--){
    vec.at(X)+=M;
    if(vec.at(X)%v.at(X)!=0){
      M+=v.at(X)-vec.at(X)%v.at(X);
    }
  }
  cout<<M<<endl;
}

Measured memory_bytes: 4824
n,m = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(m)]
l = sum(l,[])

for i in range(1,n+1):
    x = 0
    for j in range(len(l)):
        if i == l[j]:
            x += 1
    print(x)


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

int main(){
  int N,i,j;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

  for(i=0;i<N;i++){
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }
  sort(B.begin(),B.end());
  int maxnum = B.at(N-1);
  int maxnum2 = B.at(N-2);
  for(i=0;i<N;i++){
    if(A.at(i)==maxnum)
    cout << maxnum2 << endl;
    else
    cout << maxnum << endl;
  }
}

Measured memory_bytes: 3200
class UnionFind():
# ***0-based index!!!***
    def __init__(self, n):
        self.n = n
        self.parent = [-1 for i in range(n)]
    
    def root(self, x):
        if self.parent[x] <0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    
    def same(self, x, y):
        return (self.root(x) == self.root(y))

    def union(self, x, y):
        p = self.root(x)
        q = self.root(y)
        
        if not p==q :
            if self.parent[p] > self.parent[q]:
                p,q = q,p
            self.parent[p] += self.parent[q]
            self.parent[q] = p
    
    def size(self, x):
        return -self.parent[self.root(x)]


N,M = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(M):
    A,B = list(map(int, input().split()))
    uf.union(A-1, B-1)

ans = 0
for i in range(N):
    if uf.root(i) == i:
        ans += 1
print(ans-1)


Measured memory_bytes: 10784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int result;
		int a, b;
		Scanner scanner = new Scanner(System.in);
		a = scanner.nextInt();
		b = scanner.nextInt();
		scanner.close();
		result = (a + b)%24;
		System.out.print(result);
	}

}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        int[] da = new int[n];
        int[] db = new int[m];
        for (int i = 0; i < n; i++) {
            da[i] = scanner.nextInt();
        }
        for (int i = 0; i < m; i++) {
            db[i] = scanner.nextInt();
        }
        long[] sa = new long[n + 1];
        long[] sb = new long[m + 1];
        for (int i = 1; i <= n; i++) {
            sa[i] = sa[i - 1] + da[i - 1];
        }
        for (int i = 1; i <= m; i++) {
            sb[i] = sb[i - 1] + db[i - 1];
        }
        int i = 0, j = m;
        int ans = 0;
        for (; i <= n; i++) {
            if (sa[i] > k) break;
            while (sb[j] > k - sa[i]) {
                j--;
            }
            ans = Math.max(ans, i + j);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61928
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf=1000000007;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int n, m, qx, qy, zx, zy, dx[4]= {1,-1,0,0}, dy[4]= {0,0,1,-1};
string s[1005];
int f[1005][1005];
struct w
{
    int x, y, ci;
} w, w2;

bool operator<(struct w a,struct w b)
{
    return a.ci>b.ci;
};

int bfs()
{
    w.x=qx;
    w.y=qy;
    w.ci=0;
    f[w.x][w.y]=0;
    priority_queue<struct w> q;
    q.push(w);
    while(!q.empty())
    {
        w=q.top();
        q.pop();
        //printf("%d %d\n",w.x,w.y);
        if(w.ci>f[w.x][w.y])
        {
            continue;
        }
        if(w.x==zx&&w.y==zy)
        {
            return w.ci;
        }
        for(int i=0; i<4; i++)
        {
            w2.x=w.x+dx[i];
            w2.y=w.y+dy[i];
            w2.ci=w.ci;
            if(w2.x>=0&&w2.x<n&&w2.y>=0&&w2.y<m&&f[w2.x][w2.y]>w2.ci&&s[w2.x][w2.y]=='.')
            {
                f[w2.x][w2.y]=w2.ci;
                q.push(w2);
            }
        }
        for(int i=-2; i<=2; i++)
        {
            for(int j=-2; j<=2; j++)
            {
                w2.x=w.x+i;
                w2.y=w.y+j;
                w2.ci=w.ci+1;
                if(w2.x>=0&&w2.x<n&&w2.y>=0&&w2.y<m&&f[w2.x][w2.y]>w2.ci&&s[w2.x][w2.y]=='.')
                {
                    f[w2.x][w2.y]=w2.ci;
                    q.push(w2);
                }
            }
        }
    }
    return -1;
}

int main()
{
    scanf("%d%d",&n,&m);
    scanf("%d%d",&qx,&qy);
    fill(f[0],f[0]+1005*1005,inf);
    qx--;
    qy--;
    scanf("%d%d",&zx,&zy);
    zx--;
    zy--;
    for(int i=0; i<n; i++)
    {
        cin >> s[i];
    }
    cout << bfs() << endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    if (N == 1) {
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << "1 1" << endl;
        cout << "1 1" << endl;
        return 0;
    }
    // 6
    // 12 = 4 * 3
    int M = -1;
    for (int i = 1; i <= N; ++i) {
        if (i * (i - 1) == 2 * N) {
            M = i;
            break;
        }
    }
    if (M == -1) {
        cout << "No" << endl;
        return 0;
    }
    vector<vector<int>> v(M, vector<int>(M-1, 0));
    int c = 1;
    for (int k = M - 1; k > 0; --k) {
        for (int l = 0; l < k; ++l) {
            int i0 = M - k - 1;
            int j0 = M - 1 - k + l;
            int i1 = M - k + l;
            int j1 = M - 1 - k;
            v[i0][j0] = c;
            v[i1][j1] = c;
            ++c;
        }
    }
    cout << "Yes" << endl;
    cout << v.size() << endl;
    for (const auto &row: v) {
        cout << row.size();
        for (const auto &e: row) {
            cout << " " << e;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll n; cin>>n ;
  vector<ll> A(n) ,B(n) ;
   rep(i,n) cin>> A[i] ;
   rep(i,n) cin>>B[i] ;
   ll suma = 0; ll sumb=0 ; ll needa = 0;ll needb=0 ;
   rep(i,n){
       suma+= A[i];
       sumb+= B[i] ;
       if(A[i]>B[i]) needb+= A[i]-B[i] ;
       if(A[i]<B[i]) needa+= (B[i]-A[i]+1)/2 ;
   }
   ll k= sumb-suma ;
   if(k>=0 && needa<=k&&needb<=k) cout<<"Yes"<<endl ;
   else cout<< "No"<<endl ;
 return 0 ; 
}



Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
これどんな木つくってもおなじ？
ただの範囲の和として確認か
*/
int main(){
  ll N,M; cin>>N>>M;
  vector<ll> A(N+1,0),B(N+1,0);
  for(ll i=0; i<M; i++){
    ll a,b; cin>>a>>b;
    if(a>b) swap(a,b);
    B[a]++;
    B[b]--;
  }
  for(ll i=1; i<N; i++) B[i+1]+=B[i];
  for(ll i=1; i<N; i++){
    if(B[i]%2>0){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<cctype>
using namespace std;
int main(){
    char ch;
    while(true){
        scanf("%c",&ch);
        if(isupper(ch)){
            printf("%c",tolower(ch));
        }
        else if(islower(ch)){
            printf("%c",toupper(ch));
        }else{
            printf("%c",ch);
        }
        if(ch=='\n')break;
    }return 0;
}



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    string str;
    cin >> str;

    int ans = sz(str);
    for (int i = 0; i + 1 < sz(str); i++) {
        if (str[i] != str[i+1])
            ans = min(ans, max(i+1, sz(str)-i-1));
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
s = input()
front = int(s[0:2])
back = int(s[2:4])


yymm = False
mmyy = False


if 1 <= front <= 12:
    if 0 <= back <= 99:
        mmyy = True

if 1 <= back <= 12:
    if 0 <= front <= 99:
        yymm = True

if mmyy and yymm:
    print('AMBIGUOUS')
elif mmyy:
    print('MMYY')
elif yymm:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s.substr(i, 3) == "ABC") ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int ll;
int main()
{
	int n;
	cin >> n;
  	vector<int> p(n);
  	for(int i=0; i<n; i++){
		cin >> p.at(i);
    }
  	sort(p.begin(), p.end());
  	int ans=0;
  	for(int i=0; i<n-1; i++){
		ans += p.at(i);
    }
  	ans += p.at(n-1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return a + b;
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}
 
	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}
 
	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}
 
	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};


vector<ll> enum_div(ll n){//yakusu
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i){
			if(n%i == 0){
				ret.push_back(i);
				if(i*i!=n)ret.push_back(n/i);
			}
	}
	return ret;
}

map<ll,ll> soinsubunkai(ll x){    // x = {first^second}*...
	map<ll,ll> ans;
	if(x==1){ans[1]++;return ans;}
	ll p=x;
	for(ll i=2;i*i<=x;i++){
		while(p%i==0){
			p /= i;
			ans[i]++;
		}
	}
	if(p!=1)ans[p]++;
	return ans;
}

int main(){


	ll N;

	cin >> N;

	ll ans = 0;

	FOR(a,1,N){
		ll b_max = N / a;
		if(b_max*a == N)b_max--;
		ans += b_max;
	}

	cout << ans << endl;

}


Measured memory_bytes: 3628
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;




int main()
{
  long n; //かっている数//最大100

  cin >> n;


  long k = 0;

  // vector<long> ssize(k);

  //完全グラフくさい
  bool isans = false;
  long p = 0;
  long nodenum = 0;
  for (int i = 1; i < 1000; ++i) {
    p = p + i;
    if (p == n) {
      nodenum = i;
      isans = true;
      break;
    }
  }


  cerr << "p:" << p << endl;

  vector<long> count(p + 1, 0);

  vector<long> sets(nodenum);



  // for (int i = 0; i < nodenum; ++i){//
  //   for (int i = 0; i < p; ++i)
  //   {
  //     /* code */
  //   }
  // }





  // stack<long> addList(nodenum+1);

  vector< vector<long> > addlist(nodenum+1);

  // stack<int> st;

  if (isans == false) {
    cout << "No";
  } else {
    cout << "Yes" << endl;
    cout << nodenum + 1 << endl;



    long pointer = 1;
    long pointer2 = 1;
    for (int i = 0; i < nodenum + 1; ++i) {
      cout << nodenum << " ";


      for (int k = pointer; k <= n ; ++k) {//最初にまだ追加してない数を追加していく
        if (k - pointer == nodenum - i) {
          pointer = k;
          break;
        }
        cout << k << " ";
        addlist[i].push_back(k);
      }

      long countx = 0;
      for (int k = pointer2; k <= n; ++k) {
        if (k - pointer2 == i) {
          pointer2 = k;
          break;
        }

        // cout << k <<" ";
        cout << addlist[countx].back() << " ";
        addlist[countx].pop_back();
        countx++;
      }

      cout << endl;
    }
  }




  return 0;
}



























Measured memory_bytes: 4096
a = Array.new(4,0)

10.times do
  a[3] = gets.chomp.to_i 
  3.times do |i|
    if a[2-i]<a[3-i]
      a[2-i], a[3-i] = a[3-i], a[2-i]
    else
      break
    end
  end
end
puts a[0]
puts a[1]
puts a[2]

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

int main(){
    int n;
    cin >> n;
    long long a[n+1];
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    long long ans[n+1];    
    long long t = 0;
    for(int j = 0; j < n/2; j++){
        long long index = (2 + 2*j);
        if(index > n){
            index %= n;
        }
        t += 2*a[index];
    }
    ans[1] = sum - t;
    for(int i = 2; i <= n; i++){
        ans[i] = 2*a[i-1] - ans[i-1];
    }

    for(int i = 1; i <= n-1; i++){
        cout << ans[i] << " ";
    }
    cout << ans[n] << endl;
    return 0;
}

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

int main() {
string S;
cin >> S;
int L = S.size();
string left = S.substr(0, (L-1)/2), right = S.substr((L+3)/2-1, (L-1)/2);
string Sinv=S, linv =left, rinv =right;
reverse(Sinv.begin(), Sinv.end());
reverse(linv.begin(), linv.end());
reverse(rinv.begin(), rinv.end());
if(S==Sinv && left ==linv && right==rinv) cout << "Yes" << endl;
else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
 
class Main
{
  public static void main(String args[])
  {
    int num;
    String buf;
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      buf = br.readLine();
      num = Integer.parseInt(buf);
      System.out.println(num * num * num);
    } catch(Exception e) {}
  }
}


Measured memory_bytes: 24204
n = int(input())

aa = list(map(int, input().split()))

ps = [p for p in aa if p >= 0]
ns = [p for p in aa if p < 0]

ps = sorted(ps)
ns = sorted(ns)

acts = []
if len(ps) == 0:
  m = ns.pop()
  for nn in ns:
    acts.append((m, nn))
    m -= nn
elif len(ns) == 0:
  m = ps[0]
  for i in range(1, len(ps)-1):
    acts.append((m, ps[i]))
    m -= ps[i]
  acts.append((ps[-1], m))
  m = ps[-1] - m
else:
  m = ns[0]
  for i in range(len(ps)-1):
    acts.append((m, ps[i]))
    m -= ps[i]
  ns[0] = m
  m = ps[-1]
  for i in range(len(ns)):
    acts.append((m, ns[i]))
    m -= ns[i]
  
print(m)
for x, y in acts:
  print(x, y)


Measured memory_bytes: 20364
n=int(input())
s=[]
from collections import Counter
for i in [0]*n:
    s.append(Counter(input()))
ans=""
for i in "abcdefghijklmnopqrstuvwxyz":
    tmp=[]
    for j in s:
        tmp.append(j[i])
    ans+=i*min(tmp)
print(ans)

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
const int N=200010,INF=0x3f3f3f3f;
const double PI=acos(-1);
int g[N],d[N];
int x[N],y[N],x2[N],y2[N];
struct data{
	int x,y;
}q[N],t[N];
int mnx,mxy;
void rot(int &x,int &y){
	int t=x;
	x=mxy-y;
	y=t-mnx;
}

bool cmp(data&x,data&y){
	return x.x<y.x;
}

int main(){
	//freopen("in","r",stdin);
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	if(tx<sx) swap(sx,tx),swap(sy,ty);
	int n;
	scanf("%d",&n);
	mnx=sx,mxy=sy;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		mnx=min(mnx,x[i]),mxy=max(mxy,y[i]);
	}	
	if(ty<sy){
		for(int i=1;i<=n;i++){
			rot(x[i],y[i]);	
		}
		rot(sx,sy),rot(tx,ty);
	}	
	//cout<<sx<<' '<<sy<<' '<<tx<<' '<<ty<<endl;
	//for(int i=1;i<=n;i++) cout<<x[i]<<' '<<y[i]<<endl;
	int n2=0;
	for(int i=1;i<=n;i++) if(x[i]>=sx&&x[i]<=tx&&y[i]>=sy&&y[i]<=ty){
		n2++;
		q[n2].x=x[i],q[n2].y=y[i];
		x2[i]=x[i],y2[i]=y[i];
	}
	double tmp;
	const int D=20;
	/*sort(t+1,t+1+n,cmp);
	int tot=0;q[t[1].x]=++tot;
	for(int i=2;i<=n2;i++) if(t[i].y!=t[i-1].y){
		q[t[i].x]=++tot;
	}else q[t[i].x]=tot;*/
	sort(q+1,q+1+n2,cmp);
	//for(int i=1;i<=n2;i++) cout<<q[i].x<<' '<<q[i].y<<endl;
	for(int i=1;i<=n2;i++) g[i]=INF;
	g[0]=-1,q[0].y=0;
	for(int i=1;i<=n2;i++){
		int k=lower_bound(g,g+n2+1,q[i].y)-g;
		d[i]=k;
		g[k]=q[i].y;
	}
	int mxc=0;
	for(int i=1;i<=n2;i++) mxc=max(mxc,d[i]);
	if(mxc==tx-sx+1||mxc==ty-sy+1) tmp=-(1-0.5*PI)*D+(1-0.25*PI)*D;
	else tmp=0;
	printf("%.13f\n",1.0*(ty-sy)*100+1.0*(tx-sx)*100-(1-0.25*PI)*mxc*D+tmp);
	return 0;
}


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

int main(){
  while(true){
    int n,m,h,k,s[1000],x[1000];
    pair<int,int> a[100000];
    scanf("%d %d %d %d",&n,&m,&h,&k);
    if(n==0&&m==0&&h==0&&k==0) return 0;
    for(int i=0;i<n;i++){
      if(i<k) x[i] = 1;
      else x[i] = 0;
      scanf("%d",s+i);
    }
    for(int i=0;i<m;i++) scanf("%d %d",&a[i].second,&a[i].first);
    sort(a,a+m);
    for(int i=0;i<m;i++) swap(x[a[i].second-1],x[a[i].second]);
    int sum = 0,ans;
    for(int i=0;i<n;i++) if(x[i]) sum += s[i];
    ans = sum;
    for(int i=m-1;i>=0;i--){
      int p = a[i].second - 1, q = a[i].second;
      ans = min(ans, sum - s[p] * x[p] - s[q] * x[q] + s[p] * x[q] + s[q] * x[p]);
      swap(x[p],x[q]);
      swap(s[p],s[q]);
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
static const int NIL=-1;
static const int MAX=100010;
int n;
vector<int> G[MAX];
int color[MAX];

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>h(n);
    rep(i,n)cin>>h[i];

    vector<int>a(m);
    vector<int>b(m);
    rep(i,m)cin>>a[i]>>b[i];
    vector<bool>g(n,true);

    rep(i,m){
        if(h[a[i]-1]<=h[b[i]-1])g[a[i]-1]=false;
        if(h[b[i]-1]<=h[a[i]-1])g[b[i]-1]=false;
    }
    int ans=0;
    rep(i,n)if(g[i]==true)ans++;
    cout<<ans<<endl;

}


Measured memory_bytes: 6696
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int mod=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

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

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k])%mod;
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}
const double PI = 3.1415926535897932384626433;

int main() {
	int n,m,a[10001];
	cin>>n>>m;
	rep(i,0,m)cin>>a[i];
	int cnt=0;
	rep(i,0,m)cnt+=a[i];
	if(cnt>n)print(-1);
	else print(n-cnt);

}


Measured memory_bytes: 3644
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B, C] = input[0].map(Number);
  const K = Number(input[1][0]);

  const max = Math.max(A, B, C);

  return max * 2 ** K + A + B + C - max;
};

console.log(main(read()));


Measured memory_bytes: 29600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N; cin >> N;
  vector<ll> a(3 * N);
  rep(i, 3 * N) {
    cin >> a[i];
  }
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  for(int i=1; i < 2 * N; i+=2) {
    ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int min = 1000;
        
        for (int i = 0; i+2 < line.length(); i++) {
            String s = line.substring(i, i+3);
            if (min > Math.abs(753-Integer.parseInt(s))) {
                min = Math.abs(753-Integer.parseInt(s));
            }
        }
        
        System.out.println(min);
    }
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
 
int n,a[10011],x,ans[200001],ansn,A[10011];
bool bo[100001];
 
int getval(int x,int nw)
{
	int ans=0;
	for (int i=n; i>=0; i--)
		ans=(1ll*ans*x+a[i])%nw;
	return ans;
}
 
int ran() {return rand()%1000*1000000+rand()%1000*1000+rand()%1000;}
 
void check(int nw)
{
	if (getval(0,nw)) return;
 	if (nw<=120)
	{
		for (int j=1; j<nw; j++)
			if (getval(j,nw)) return;
		ans[++ansn]=nw;
		return;
	}
	for (int j=1; j<=120; j++)
		if (getval(ran()%nw,nw)) return;
	ans[++ansn]=nw;
}
 
int main()
{
	memset(bo,1,sizeof(bo));
	for (int j=2; j<=100000; j++) if (bo[j])
		for (int i=(j<<1); i<=100000; i+=j) bo[i]=0;
	srand(20021221);
	scanf("%d",&n);
	for (int i=n; i>=0; i--) scanf("%d",&a[i]);
	for (int i=2; i<=40000; i++) if (bo[i]) check(i);
	int An=0;
	for (int i=0; i<=n; i++) if (a[i]) A[++An]=abs(a[i]);
	for (int T=1; T<=An&&T<=3; T++)
	{
		x=A[T];
		for (int i=2; i<=40000; i++) while (x%i==0) x/=i;
		if (x!=1) check(x);
	}
	sort(ans+1,ans+1+ansn);
	for (int i=1; i<=ansn; i++)
		if (ans[i]!=ans[i-1]) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 512
def rozwiaz(lista, k):
    wynik = [None] * len(lista)
    wynik[0] = 0
    for i in range(1, len(lista)):
        minimum = 1000000000000000
        for skok in range(1, k + 1):
            if skok <= i:
                proba = wynik[i - skok] + abs(lista[i] - lista[i - skok])
                if proba < minimum:
                    minimum = proba
        wynik[i] = minimum

    return wynik[len(lista) - 1]

def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def frog_2():
    N, K = wczytaj_liste()
    wysokosci = wczytaj_liste()
    print(rozwiaz(wysokosci, K))
    
frog_2()

Measured memory_bytes: 52448
#include<stdio.h>
int main()
{
	int k,x,i;
	scanf("%d %d",&k,&x);
	int s=x-(k-1);
	int p=x+(k-1);
	for(i=s;i<=p;i++)
	{
		printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
using namespace std;
ll n,d=0,ans=0;
string s;
int32_t main(){
cin>>s;
n=s.size();
for(ll i=0;i<n;i++)
if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
    d++;
}else {
ans=max(ans,d);
d=0;
}
ans=max(ans,d);
cout<<ans;
return 0;}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int INF = 1e9;
const int MOD = 1e9+7;
const int MAXW = 10010;

ll dp[MAXW];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    vector<int> w(N+1);
    for (int i = 0; i < N; i++)
        cin >> w[i];
    w[N] = INF;
    sort(w.begin(), w.end());
    ll ans = 0;
    // [0, i) ????????¨?????? i ????????¨????????????????????´????????°
    for (int i = 0; i <= N; i++) {
        memset(dp, 0, sizeof(dp));
        int sum = 0;
        for (int j = 0; j < i; j++)
            sum += w[j];
        dp[0] = 1;
        for (int j = i+1; j < N; j++) {
            for (int k = MAXW-1; k >= 0; k--) if (dp[k]) {
                if (k+w[j] <= W-sum) (dp[k+w[j]] += dp[k]) %= MOD;
            }
        }
        for (int j = max(0, W-sum-w[i]+1); j <= W-sum; j++) if (dp[j]) {
            (ans += dp[j]) %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3228
#include <iostream>

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;

  int ans;
  if (A >= 13) {
    ans = B;
  } else if (A >= 6) {
    ans = B / 2;
  } else {
    ans = 0;
  }

  cout << ans << endl;
}


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

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

int main()
{
  cout << fixed << setprecision(10);
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll E = (A-1)/C;
  ll F = (A-1)/D;
  ll G = lcm(C,D);
  ll H = (A-1)/G;
  ll I = B/C;
  ll J = B/D;
  ll K = B/G;
  ll L = B - I - J + K;
  ll M = A - E - F + H - 1;
  cout << L - M << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int a[10002];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==a[i+1])
		{
			i++; ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
   int n;
   int count = 0;
   scanf("%d", &n);
   char s[100];
   scanf("%s", s);
   for(int i = 0; i < n; i++){
      if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
         count++;
      }
   }
   
   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if(A >= 13) System.out.println(B);
		else if(A >= 6 && A <= 12) System.out.println(B/2);
		else System.out.println(0);
	}
}

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

int main(){

    vector<string> day =   {
        "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"
    };

    string s;
    cin >> s;

    for(int i = 0; i < 7; ++i){
        if(s == day[i])cout << i+1 << endl;
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

static const string numbers[] = {"1111110","0110000","1101101","1111001","0110011",
	"1011011","1011111","1110010","1111111","1111011"};
static const int order[] = {'g'-'a','f'-'a','e'-'a','d'-'a','c'-'a','b'-'a','a'-'a'};

string changeOrder(string numbers){
	reverse(numbers.begin(),numbers.end());
	return numbers;
}

void setStage(bitset<7>& stage,bitset<7>& next){
	for(int i=0;i<7;i++){
		if(next[i] & 1){
			stage[i] = ~stage[i];
		}
	}
}

int main(){

	int n;	
	while(~scanf("%d",&n)){
		if(n==-1) break;
		bitset<7> next;
		bitset<7> stage;
		for(int i=0;i<n;i++){
			int light;
			scanf("%d",&light);
			bitset<7> num(changeOrder(numbers[light]));
			next = stage ^ num;	
			setStage(stage,next);
			printf("%s\n",next.to_string().c_str());
			
		}
	}
}

Measured memory_bytes: 3080
#include<stdio.h>
#include<math.h>

int main(){
	int i,j,n;
	int kane = 100000;
	double money;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		kane += kane * 0.05;

		money = ceil((double)kane / 1000);
		
		kane = money * 1000;
	}
	
	printf("%d\n",kane);
	return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[] a=new int[s[1]];
		for(int i = 0;i<s[1];i++) {
			int[] e=sc.Ia;
			for(int j = 1;j<e.Length;j++) {
				a[i]|=1<<(e[j]-1);
			}
		}
		int[] p=sc.Ia;
		int ans=0;
		for(int i = 0;i<(1<<s[0]);i++) {
			int q=0;
			for(int j = 0;j<s[1];j++) {
				if(bits(a[j]&i)%2==p[j]){q++;}
				else{break;}
			}
			if(q==s[1]){ans++;}
		}
		Console.WriteLine("{0}",ans);
	}
	static int bits(long bits){
		bits=(bits&0x55555555)+(bits>>1&0x55555555);
		bits=(bits&0x33333333)+(bits>>2&0x33333333);
		bits=(bits&0x0f0f0f0f)+(bits>>4&0x0f0f0f0f);
		bits=(bits&0x00ff00ff)+(bits>>8&0x00ff00ff);
		return (int)((bits&0x0000ffff)+(bits>>16&0x0000ffff));
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return (Console.ReadLine()+" 0").Split();}}
}


Measured memory_bytes: 13268
import math


def comb(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))

    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t

    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)

    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// 解き直し.
// https://img.atcoder.jp/abc162/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[202020], dp[5][202020];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &a[i]);
    
    // 2. 解説通り(dp更新).
    dp[1][1] = a[0];
    dp[2][1] = max(a[0], a[1]);
    if(N >= 3){
        dp[3][1] = max({a[0], a[1], a[2]});
        dp[3][2] = a[0] + a[2];
    }
    repx(i, 4, N + 1){
        // i に ついて, s個以上, e個以下 を 選択.
        int s = i / 2 - 1, e = (i + 1) / 2;
        if(i % 3 == 0){
            dp[3][s]     = max(dp[1][s - 1] + a[i - 1], dp[2][s]);
            dp[3][s + 1] = max(dp[1][s] + a[i - 1],     dp[2][s + 1]);
            if(s + 2 == e) dp[3][s + 2] = dp[1][s + 1] + a[i - 1];
        }
        if(i % 3 == 1){
            dp[1][s]     = max(dp[2][s - 1] + a[i - 1], dp[3][s]);
            dp[1][s + 1] = max(dp[2][s] + a[i - 1],     dp[3][s + 1]);
            if(s + 2 == e) dp[1][s + 2] = dp[2][s + 1] + a[i - 1];
        }
        if(i % 3 == 2){
            dp[2][s]     = max(dp[3][s - 1] + a[i - 1], dp[1][s]);
            dp[2][s + 1] = max(dp[3][s] + a[i - 1],     dp[1][s + 1]);
            if(s + 2 == e) dp[2][s + 2] = dp[3][s + 1] + a[i - 1];
        }
    }
    // rep(i, 5){
    //     rep(j, N + 1) printf("%lld ", dp[i][j]);
    //     puts("");
    // }
    
    // 3. 出力.
    int index = (N % 3 == 0) ? 3 : (N % 3);
    printf("%lld\n", dp[index][N / 2]);
    return 0;
    
}

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

int main(){
    int n;string s,t;
    cin >> n >> s >> t;
    rep(i,n){
        cout << s.at(i) << t.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 3604