akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (lli i = 0; i < (lli)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, m, k, ans=0;
    cin >> n >> m >> k;
    vi a(n+1), b(m+1);
    a[0] = 0;
    b[0] = 0;
    rep(i,n){
        lli an;
        cin >> an;
        a[i + 1] = a[i] + an;
    }
    rep(i, m){
        lli bn;
        cin >> bn;
        b[i + 1] = b[i] + bn;
    }
    lli prev = m;
    rep(i,n+1){
        lli tmp = k - a[i];
        if(tmp<0){
            break;
        }
        for (lli j = prev; j >= 0;j--){
            if(b[j]<=tmp){
                prev = j;
                ans = max(ans, i + j);
                break;
            }
            else
                continue;
            
        }
    }
    out(ans);
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans[4];
    ans[0] = a * c;
    ans[1] = a * d;
    ans[2] = b * c;
    ans[3] = b * d;

    ll anss = ans[0];
    for(int i=1; i<4; i++) chmax(anss, ans[i]);


    cout << anss << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){

	int a,b,c,d;
	int i,n;
	int count=0;

	while(1){
		if(scanf("%d",&n) == EOF){
			break;
		}

		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d == n){
							count++;
						}
					}
				}
			}
		}
		printf("%d\n",count);
		count = 0;
	}

	return 0;
}

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

using namespace std;

const long long mod = 1e9 + 7;
vector <bool> B;
vector <long long> dp;

int main()
{
	int n,m;
	cin>>n>>m;
	
	B.resize(n+1,true);
	dp.resize(n+1);
	dp[0]=1;
	
	for (int i=0;i<m;i++){
		int a;
		cin>>a;
		B[a]=false;
	}
	dp[1]=B[1]*1;
	for (int i=2;i<=n;i++){
		dp[i]=(dp[i-1]+dp[i-2])*B[i];
		dp[i]%=mod;
	}
	cout<<dp[n]<<endl;
}

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

using namespace std;


vector<int> v(4);
int ans;

int solve() {
    int num; cin >> num;
    for (int i = 3; i >= 0; i--) {
        v[i] = num % 10;
        num /= 10;
    }

    for (int bit = 0; bit < (1<<3); bit++) {
        int tmp = v[0];
        for (int i = 1; i < 4; i++) {
            if (bit & (1<<(i-1))) tmp += v[i];
            else tmp -= v[i];      
        }
        if (tmp == 7) {
            ans = bit;
            return ans;
        }
    }
}


void print() {
    cout << v[0];
    for (int i = 1; i < 4; i++) {
        if (ans & (1<<(i-1))) cout << '+' << v[i];
        else cout << '-' << v[i];
    }
    cout << "=7" << endl;
}


int main() {
    solve();
    print();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100000
#define MAX 2000000000

typedef struct {
    char suit;
    int val;
}Card;
Card L[N/2+2], R[N/2+2];

int n, A[N];


void merge(Card A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    
    for(int i=0; i<n1; i++){
        L[i] = A[left+i];
    }
    for(int i=0; i<n2; i++){
        R[i] = A[mid+i];
    }
    L[n1].val=MAX;
    R[n2].val=MAX;
    int i=0;
    int j=0;

    for(int k=left; k<right; k++){
        
        if(L[i].val <= R[j].val){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(Card A[],int n,  int left, int right){
    int mid;
    if(left+1 < right){
        mid = (left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(Card A[], int n, int p, int r){
    Card x=A[r];
    int i=p-1;
    for(int j=p; j<r; j++){
        if(A[j].val<=x.val){
            i++;
            Card temp;
            temp=A[i];
            A[i]=A[j];
            A[j]=temp;
        }
    }
    Card temp;
    temp=A[i+1];
    A[i+1]=A[r];
    A[r]=temp;

    return i+1;

}

void quicksort(Card A[], int n, int p, int r){
    if(p<r){
        int q=partition(A, n, p, r);
        quicksort(A, n, p, q-1);
        quicksort(A, n, q+1, r);
    }
}

int main(void){
    Card A[N], B[N];
    char S[10];
    int v;
    int check=1;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%s %d", S, &v);
        A[i].suit=B[i].suit=S[0];
        A[i].val=B[i].val=v;

    }

    mergeSort(A, n, 0, n);
    quicksort(B, n, 0, n-1);

    for(int i=0; i<n; i++){
        if(A[i].suit!=B[i].suit){
            check=0;
        }
    }

    if(check==1){
        printf("Stable\n");
    }
    else{
        printf("Not stable\n");
    }

    for(int i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].val);
    }
    
    return 0;
}






Measured memory_bytes: 4028
#include<iostream>
using namespace std;
int cnt[300005];
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    	if(s[i]==0)
    		cnt[i]=(s[i]=='W'?1:0);
    	else
    		cnt[i]=cnt[i-1]+(s[i]=='W'?1:0);
    int ans=1e9;
    for(int i=0;i<s.size();i++)
    {
    	if(i==0)
    	{
    		ans=min(ans,int(s.size()-(s[0]=='E'?1:0)-cnt[s.size()-1]));
		}
		else if(i==s.size()-1)
		{
			ans=min(ans,cnt[s.size()-1]-(s[s.size()-1]=='W'?1:0));
		}
		else
			ans=min(ans,int(cnt[i-1]+s.size()-i-1-(cnt[s.size()-1]-cnt[i])));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll X[100011];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,p;
	cin>>n>>p;
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		ll w,b; cin>>w>>b;
		sum+=-ll(p)*b;
		X[i]=ll(p)*b+ll(100-p)*w;
	}
	sort(X,X+n);
	reverse(X,X+n);
	for(int i=0;i<n;i++)
	{
		sum+=X[i];
		if(sum>=0)
		{
			cout<<i+1<<'\n';
			return 0;
		}
	}
}	

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {

        // read n
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        // read coords
        LinkedList<Coord> nzlist = new LinkedList<Coord>();
        LinkedList<Coord>  zlist = new LinkedList<Coord>();

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int h = sc.nextInt();
            if (h != 0){
                nzlist.add(new Coord(x,y,h));
            } else {
                 zlist.add(new Coord(x,y,h));
            }
        }

        LinkedList<Coord> alllist = (LinkedList<Coord>) nzlist.clone();
        alllist.addAll(zlist);

        // 1 <= N <= 100 なので nzlist は empty でない


        // search
        boolean okFlag = false;
        Coord center = new Coord(-1,-1,-1);
        for (int x=0; x<=100; x++) {
            for (int y = 0; y<=100; y++) {
                // h-coord: (x,y)
                Coord c = nzlist.get(0); // Warning: unchecked
                int h = c.h+Math.abs(c.x-x)+Math.abs(c.y-y);
                center = new Coord(x,y,h);

                okFlag = true;
                for (Coord e : alllist){
                    if (e.h != Math.max(h-Math.abs(x-e.x)-Math.abs(y-e.y), 0)){
                        okFlag = false;
                        break;
                    }
                }
                if(okFlag){break;}
            }
            if(okFlag){break;}
        }

        System.out.print(center.show()+"\n");
    }


}


class Coord{

    public int x;
    public int y;
    public int h;

    Coord(int x, int y, int h){
        this.x = x;
        this.y = y;
        this.h = h;
    }

    public String show(){
        return String.valueOf(x)+' '+String.valueOf(y)+' '+String.valueOf(h);
    }

}



Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define piii pair<int,pair<int,int> >
#define pii pair<int,int>
#define ll long long
int a[3];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]-a[0]<<'\n';
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
# include <cmath>
using namespace std;

int main() {
	long long n;
	cin >> n;
	int ans = 100;
	for (long long i = 1; i <= sqrt(n); i++) {
		if (n%i == 0) {
			long long num = max(i, n / i);
			int a = 1;
			while (num >= 10) {
				num /= 10;
				a++;
			}
			if (ans > a) {
				ans = a;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      var inLines = lines[0].split(" ")
      var N = inLines[0];
      var M = inLines[1];
      var ans = 0;
      var P =[];
      var unitTime = (N -M ) * 100 + M * 1900;

//      P[0] = Math.pow((1./2),M )
//      ans = P[0] *unitTime;

//      for(var i = 1;i<1000;i++){
//        P[i] = ( P[i-1] ) * ( 1 - P[0])
//        ans += P[i] * unitTime * (i+1)
//        if (P[i] * unitTime < 0.01){
//            break;
//        }
//      }
        

    console.log(unitTime*Math.pow(2,M) )
      
//      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });


})();



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

int main(){
  char s[201] = {}, p[100] = {}, t[100] = {};
  cin >> s >> p;
  strcpy(t,s);
  strcat(s,t);
  if (strstr(s,p)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
set<int>s;
int main(void)
{
    int n;
    int bill;
    cin>>n>>bill;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n-i;++j)
        {
            if(10000*i+5000*j+1000*(n-i-j)==bill)
            {
                cout <<i <<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout <<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

int main(){
    int X;
    cin>>X;
    int x=0,i=0;
    while(x<X) x+=++i;
    cout<<i<<endl;

    return 0;
}

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

Measured memory_bytes: 3568
// AOJ 2162: Galaxy Wide Web Service
// 2017.12.13 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX1 55440
#define MAX2 96577

int a[MAX1+1], b[MAX2+1];
char chk[25], f[25];
int p1, p2;

typedef struct { int d, t, q[24]; } T;
T tbl[101];
char buf[205], *p;

int getint(void)
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int lcm(int a, int b)
{
	return a/gcd(a, b)*b;
}

int main()
{
	int n, i, j, jj, k, d, t, q, ans1, ans2;

	chk[13] = chk[17] = chk[19] = chk[23] = 1;

	while (fgets(p=buf, 10, stdin) && *p != '0') {
		n = getint();


		memset(f, 0, sizeof(f));
		p1 = p2 = 1;

		for (i = 0; i < n; i++) {
			fgets(p=buf, 205, stdin);
			d = getint(), t = getint();
			if (chk[d]) {
				if (!f[d]) f[d] = 1, p2 *= d;
			} else p1 = lcm(p1, d);
			
			tbl[i].d = d, tbl[i].t = t;
			for (j = 0; j < d; j++) tbl[i].q[j] = getint();
		}

		memset(a, 0, sizeof(int)*p1);
		memset(b, 0, sizeof(int)*p2);

		for (i = 0; i < n; i++) {
			d = tbl[i].d, t = tbl[i].t;
			if (chk[d]) {
				for (jj = t-1, j = 0; j < d; j++) {
					if (++jj == d) jj = 0;
					q = tbl[i].q[jj];
					for (k = j; k < p2; k += d) b[k] += q;
				}
			} else {
				for (jj = t-1, j = 0; j < d; j++) {
					if (++jj == d) jj = 0;
					q = tbl[i].q[jj];
					for (k = j; k < p1; k += d) a[k] += q;
				}
			}
		}

		ans1 = 0; for (i = 0; i < p1; i++) if (a[i] > ans1) ans1 = a[i];
		ans2 = 0; for (i = 0; i < p2; i++) if (b[i] > ans2) ans2 = b[i];
		printf("%d\n", ans1+ans2);
	}
	return 0;
}

Measured memory_bytes: 2340
# 085 C
N,Y = map(int, input().split())
x,y,z = -1,-1,-1
for i in range(N+1):
    for j in range(N+1):
        if ((10000*i + 5000*j + 1000*(N-i-j)) == Y)and(N-i-j>=0):
            x,y = i,j
            z = N - i - j
            break
    else:
        continue
    break
print(x,y,z)            

Measured memory_bytes: 65860
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;


int main()
{
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    
    vector<int> t_div[k];
    int hand[3] = {p, r, s};

    rep(i, n){
        if (t[i] == 'r'){
            t[i] = 0;
        } else if(t[i] == 's'){
            t[i] = 1;
        } else {
            t[i] = 2;
        }
        t_div[i%k].push_back(t[i]);
    }

    ll ans = 0;
    rep(i, k){
        int old = -1;
        rep(j, t_div[i].size()){
            if (t_div[i][j] != old){
                ans += hand[t_div[i][j]];
                old = t_div[i][j];
            } else {
                old = -1;
            }
        }
        //cout << ans << endl;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n;
    cin>>n;
    vector<int> v(n),v1(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
        v1[i]=v[i];
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(v1[i]!=v[n-1]) cout<<v[n-1]<<endl;
        else cout<<v[n-2]<<endl;
    }
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll N;
string S;
map<char, ll> dic;

int main() {
    cin >> N >> S;
    REP(i, N) { dic[S[i]]++; }
    ll ans = 1, tmp;
    FOREACH(d, dic) { (ans *= (d.second + 1)) %= MOD; }
    cout << ans - 1 << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

    sort(a.begin(), a.end());
    cout << (a[2]*10+a[1]+a[0]) << endl;
}

Measured memory_bytes: 3568
function main()
	N,A,B,C=map(x->parse(Int,x),split(readline()))
	L=map(x->parse(Int,x),readlines())
	ans=114514
	for i=0:(1<<2N)-1
		now=0
		a=b=c=0
		for j=1:N
			g=(i>>2(j-1))%4
			if g==0
				if a>0
					now+=10
				end
				a+=L[j]
			elseif g==1
				if b>0
					now+=10
				end
				b+=L[j]
			elseif g==2
				if c>0
					now+=10
				end
				c+=L[j]
			end
		end
		if a>0&&b>0&&c>0
			now+=abs(A-a)+abs(B-b)+abs(C-c)
			ans=min(ans,now)
		end
	end
	println(ans)
end
main()


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


bool prime[1000000];
int wei[1000000], sqrt_N = 1000;

int main()
{
  int N, i, j, k;

  for (i = 1; i <= 5; i += 4){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 2; i <= 4; i += 2){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000)break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 3; i <= sqrt_N; i += 6){
    for (j = 1; j <= 2; ++j){
      for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 5; i <= sqrt_N; ++i){
    if (prime[i]){
      for (j = i * i; j <= N; j += i * i){
        prime[j] = false;
      }
    }
  }
  prime[2] = prime[3] = true;

  for (i = 2; i < 1000000; ++i){
    wei[i] += wei[i - 1];
    if (prime[i]) wei[i]++;
  }

  while (~(scanf("%d", &N))) printf("%d\n", wei[N]);

  return 0;
}

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

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

    if((a == (b+c))||(b == (a+c))||(c==(a+b))){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s, t;
    std::cin >> s >> t;
    int ret = (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]);
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int W[200000];
int H[200000];

signed main(){
  int h,w;
  cin>>h>>w;
  int a[h][w];
  r(i,h)r(j,w)cin>>a[i][j];
  r(i,w)for(int j=i+1;j<w;j++){
    for(int k=i;k<=j;k++)W[k]++;
  }
r(i,w)W[i]++;
r(i,h)H[i]++;
  r(i,h)for(int j=i+1;j<h;j++){
    for(int k=i;k<=j;k++)H[k]++;
  }

int sum=0;
r(i,h)r(j,w){
  sum+=H[i]*W[j]*a[i][j];
}
cout<<sum<<endl;
}




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

using namespace std;

int main() {

	long sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;

	long px, py;
	px = sx;
	py = sy;

	while (py != ty) {
		cout << "U";
		py++;
	}
	while (px != tx) {
		cout << "R";
		px++;
	}

	while (py != sy) {
		cout << "D";
		py--;
	}
	while (px != sx) {
		cout << "L";
		px--;
	}

	cout << "L";
	px--;
	while (py != ty+1) {
		cout << "U";
		py++;
	}
	while (px != tx) {
		cout << "R";
		px++;
	}
	cout << "D";
	py--;
	cout << "R";
	px++;
	while (py != sy-1) {
		cout << "D";
		py--;
	}
	while (px != sx) {
		cout << "L";
		px--;
	}
	cout << "U";

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

bool solve();
static int n;
static vector<pair<int, int>> tasks;

bool solve() {
  bool ret = true;
  int sum = 0;
  for (auto v : tasks) {
    sum += v.second;
    if (sum > v.first) {
      ret = false;
      break;
    }
  }
  return ret;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  sort(tasks.begin(), tasks.end());
  if (solve()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include<string.h>
 
int main(){
	char a[20] = "AC";
	char b[20] = "WA";
	char c[20] = "TLE";
	char d[20] = "RE";
	int tc;
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	char s[100];
	scanf("%d", &tc);
	for(int i=0; i<tc; i++){
		scanf("%s", s);
		if(strcmp(s,a) == 0){
			ac++;
		}
		else if(strcmp(s,b) == 0){
			wa++;
		}
		else if(strcmp(s,c) == 0){
			tle++;
		}
		else if(strcmp(s,d) == 0){
			re++;
		}
	}	
		printf("AC x %d\n", ac);
		printf("WA x %d\n", wa);
		printf("TLE x %d\n", tle);
		printf("RE x %d\n", re);
	return 0;
}

Measured memory_bytes: 1720
public class Main {

	private int[] d;
	private int n;
	
	private Pair[] scan() {
		java.util.Set<Pair> lis = new java.util.TreeSet<Pair>();
		
		for (int p = 0; p + 1 < n; ++p) {
			if (Math.abs(d[p + 1] - d[p]) <= 1)
				lis.add(new Pair(p, p + 1));
		}
		for (int l = 4; l <= n; l += 2) {
			for (int s = 0; s + l <= n; ++s) {
				final int e = s + l - 1;
				if (lis.contains(new Pair(s + 1, e - 1)) && Math.abs(d[e] - d[s]) <= 1) {
					lis.add(new Pair(s, e));
					continue ;
				}
				for (int j = s + 1; j + 1 < e; j += 2) {
					if (lis.contains(new Pair(s, j)) && lis.contains(new Pair(j + 1, e))) {
						lis.add(new Pair(s, e));
						break ;
					}
				}
			}
		}
		
		return lis.toArray(new Pair[lis.size()]);
	}
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		try (java.util.Scanner sc = new java.util.Scanner(in)) {
			for (;;) {
				n = sc.nextInt();
				if (n == 0) break ;
				d = new int[n];
				for (int i = 0; i < n; ++i)
					d[i] = sc.nextInt();
				
				Pair[] seq = scan();
				java.util.Arrays.sort(seq);
				
				int[] fullSize = new int[n + 1];
				for (int i = 0; i < seq.length; ++i) {
					final Pair p = seq[i];
					final int score = (p.u - 1 < 0 ? 0 : fullSize[p.u - 1]) + p.length;
					for (int j = p.v; j <= n; ++j) {
						if (score <= fullSize[j]) break ;
						fullSize[j] = score;
					}
				}
				out.println(fullSize[n]);
			}
		}
	}
	
	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

	private static class Pair implements Comparable<Pair> {
		public final int u;
		public final int v;
		public final int length;
		
		public Pair(int u, int v) {
			this.u = Math.min(u, v);
			this.v = Math.max(u, v);
			this.length = v - u + 1;
		}
		
		@Override
		public int compareTo(Pair o) {
			if (this.u < o.u) return -1;
			if (o.u < this.u) return 1;
			if (this.v < o.v) return -1;
			if (o.v < this.v) return 1;
			return 0;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + u;
			result = prime * result + v;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (u != other.u)
				return false;
			if (v != other.v)
				return false;
			return true;
		}
		
		@Override
		public String toString() {
			return "(" + this.u + ", " + this.v + ")";
		}
	}
	
}

Measured memory_bytes: 71304
using System;

class calc {
    static void Main() {
        int i, j;

        for (i = 1; i < 10; i++) {
            for (j = 1; j < 10; j++)
            {
                Console.WriteLine("{0}x{1}={2}", i, j, i * j);
            }
        }
    }
}

Measured memory_bytes: 5580
n=int(input())
a=list(map(int, input().split()))
xor=[]
for i in range(n-1):
    xor.append(a[i]^a[i+1])
f=0
for i in range(0,len(xor),2):
    f^=xor[i]
first=f^a[0]
ans=[first]
k=first
print(first,end=' ')
for i in xor:
    print(k^i,end=' ')
    k=k^i


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

int main(){
    int N;
    cin >> N;
    int a[100000];
    a[0] = 0;
    for (int i = 1; i <= N; i++){
        cin >> a[i];
    }
    int i = 1;
    int count = 0;
    bool flag = false;
    while(1){
        if (count > N) break;
        count++;
        if (a[i] == 2 ) {
            flag = true;
            break;
        }
        i = a[i];
    }
    if (flag == true){
        cout << count << endl;
    }
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
	char s[200005];
	for (int i = 0; i < 200005; i++)s[i] = 'A';
	scanf("%s", s);
	int d;
	for (int i = 0; i < 200005; i++) {
		if (s[i] != 'A')d = i;
	}
	int e = 0;
	for (int i = 0; i < d; i++) {
		if (s[i] == 'B')e++;
	}
	long long a = 0, b = 0;
	for (long long i = 0; i < d; i++) {
		if (s[i] == 'B')a += i;
	}
	for (long long i = d - e; i < d; i++)b += i;
	printf("%lld\n", b-a);
	return 0;
}

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

int main() {
  
  vector<string> str(3);
  for(int i = 0; i < 3; i++) {
    cin >> str.at(i);
  }
  
  for(int j = 0; j < str.size(); j++) {
    cout << str.at(j).at(0);
  }
  cout << endl;
  
}

Measured memory_bytes: 256
N = int(input())
INF = 10**18
dp = [-1] * (100000 + 1)
dp[0] = 0

V = [1]
i = 1
while 9**i < 100000:
    dp[9**i] = 1
    V.append(9**i)
    i += 1
i = 1
while 6**i < 100000:
    dp[6**i] = 1
    V.append(6**i)
    i += 1
# print('V', V)
# print('dp', dp[:15])
for i in range(1, 100000 + 1):
    if dp[i] != -1:
        continue
    _min = INF
    for v in V:
        if i - v < 0:
            continue
        _min = min(_min, dp[i - v] + 1)
    dp[i] = _min

print(dp[N])


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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l.at(i);

	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());

	int len = 0;
	rep(i, k) len += l.at(i);

	cout << len << endl;
}


Measured memory_bytes: 256
from itertools import accumulate

n,k = map(int, input().split())
p = list(map(int, input().split()))
acc = list(accumulate([i for i in range(max(p)+1)]))
ap = [0] + list(accumulate(p))
mx = 0
pos = 0
for i in range(n-k+1):
    if mx < ap[i+k] - ap[i]:
        mx = ap[i+k] - ap[i]
        pos = i
ans = 0
for i in range(pos,pos+k):
    ans += acc[p[i]] / p[i]
print('{:.10f}'.format(ans))

Measured memory_bytes: 25148
{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as IM
import Data.List
import Debug.Trace

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

cum_max :: [Int] -> [Int]
cum_max = tail . scanl' max 0

nextZeta :: Int -> IM.IntMap (Int,Int) -> Int -> IM.IntMap (Int,Int)
nextZeta en im i = foldl' op im [0..en-1]
  where
    op !im !x | testBit x i = IM.adjust (f (im IM.! (clearBit x i))) x im
              | otherwise   = im
      where
{-
        f (q1,q2) (p1,p2) = (r1,r2)
          where r1:r2:_ = sortOn (\p -> -p) [p1,p2,q1,q2]
-}
        f !x !y = let (q1,q2) = x
                      (p1,p2) = y
                  in
                    if p1 >= q1 then
                      if p2 >= q1 then (p1,p2)
                      else (p1,q1)
                    else
                      if q2 >= p1 then (q1,q2)
                      else (q1,p1)

zeta :: Int -> [Int] -> IM.IntMap (Int, Int)
zeta n as = foldl' (nextZeta en) initmap [0..n-1] 
  where
    en = 2^n
    initmap = IM.fromList (zip [0..en-1] [(a,0) | a <- as])

solve :: Int -> [Int] -> [Int]
solve n as = cum_max $ tail $
                  map ((\(p,q)->p+q) . snd) $ IM.toAscList $ zeta n as

main :: IO ()
main = do
  conts <- B.getContents
  let n : as = bsReadInts conts
      answer = solve n as
  putStr (unlines (map show answer))


Measured memory_bytes: 121980
using System;
using System.Collections.Generic;

namespace Aizu {
    class OnlineJudge {
        static void Main() {
            var input = Console.ReadLine().Split();
            var conv = new Dictionary<string, int>(6);
            for (int i = 0; i < 6; ++i) {
                conv.Add(input[i], i);
            }
            var table = new string[6, 6] {
                { "", input[2], input[4], input[1], input[3], "" },
                { input[3], "", input[0], input[5], "", input[2] },
                { input[1], input[5], "", "", input[0], input[4] },
                { input[4], input[0], "", "", input[5], input[1] },
                { input[2], "", input[5], input[0], "", input[3] },
                { "", input[3], input[1], input[4], input[2], "" }
            };
            for (var i = int.Parse(Console.ReadLine()); i > 0; --i) {
                var filter = Console.ReadLine().Split();
                Console.WriteLine(table[conv[filter[0]], conv[filter[1]]]);
            }
        }
    }
}

Measured memory_bytes: 8948
s=input()
x,y=map(int,input().split())
ss=[len(i) for i in s.split("T")]
x-=ss[0]
a=[]
b=[]
for i in range(1,len(ss)):
  if ss[i]==0:continue
  if i%2==1:b.append(ss[i])
  else:a.append(ss[i])
x=abs(x)
y=abs(y)
if max(x,y)>8000:exit(print("No"))
def check(n,a):
  dp=[[0]*20001 for _ in range(len(a)+1)]
  n+=10000
  dp[0][10000]=1
  for i in range(1,len(a)+1):
    for j in range(20001):
      if j+a[i-1]<=20000:dp[i][j+a[i-1]]|=dp[i-1][j]
      if j-a[i-1]>=0:dp[i][j-a[i-1]]|=dp[i-1][j]
  if dp[len(a)][n]==1:return True
  return False
if check(x,a) and check(y,b):print("Yes")
else:print("No") 


Measured memory_bytes: 451848
input = raw_input().split(" ")
n = int(input[0])
m = int(input[1])

i = 0
vec_a = []
while i < n:
  line = map(int, raw_input().split(" "))
  vec_a.append(line)
  i += 1
i = 0
vec_b = []
while i < m:
  line = int(raw_input())
  vec_b.append(line)
  i += 1
# print vec_a
# print vec_b

vec_c = []
for i in vec_a:
  sum = 0
  for j in xrange(m):
    sum += i[j] * vec_b[j]
  vec_c.append(sum)

for i in vec_c:
  print i

Measured memory_bytes: 6500
using System;

class Program
{
    static void Main(string[] args)
    {

        var array = Console.ReadLine().Split(' ');
        
        var a = int.Parse(array[0]);
        var b = int.Parse(array[1]);

        if (a <= b)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	char arr[3];
	
	{
		scanf("%s", arr);

	}
	int flag;
	if(arr[0] == '7' || arr[1] == '7' || arr[2] == '7')
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
	
}

Measured memory_bytes: 3688
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
p_list = list(map(int, input().split()))
for i in range(0, n // 2 + 2):
    if x - i not in p_list:
        print(x - i)
        break
    if x + i not in p_list:
        print(x + i)
        break

Measured memory_bytes: 9176
n = gets.to_i
h1 = Hash.new(0)
gets.split.map(&:to_i).each { |e| h1[e] += 1 }
m = gets.to_i
h2 = Hash.new(0)
gets.split.map(&:to_i).each { |e| h2[e] += 1 }

puts h2.all? { |k, v| h1[k] >= v } ? :YES : :NO

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

using namespace std;

typedef long long ll;

vector < tuple <ll, ll, ll> > v;

int mask = 0;

bool compare(tuple <ll, ll, ll> x, tuple <ll, ll, ll> y) {
  ll s1 = 0;
  ll xx[] = {get <0>(x), get <1>(x), get <2>(x)};
  for(int i = 0; i < 3; i++) {
    ll sign = 0;
    if(mask & (1 << i)) sign = -1;
    else sign = 1;
    s1 += xx[i] * sign;
  }
  ll s2 = 0;
  ll yy[] = {get <0>(y), get <1>(y), get <2>(y)};
  for(int i = 0; i < 3; i++) {
    ll sign = 0;
    if(mask & (1 << i)) sign = -1;
    else sign = 1;
    s2 += yy[i] * sign;
  }
  return s1 > s2;
}

int main() {
  int n, m; cin >> n >> m;
  for(int i = 0; i < n; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    v.push_back(tuple <ll, ll, ll> (x, y, z));
  }
  ll best = -1e18;
  for(int i = 0; i < 8; i++) {
    mask = i;
    sort(v.begin(), v.end(), compare);
    ll x, y, z; x = y = z = 0;
    for(int i = 0; i < m; i++) {
      x += get<0> (v[i]); y += get <1> (v[i]), z += get<2> (v[i]);
    }
    ll cur = abs(x) + abs(y) + abs(z);
    best = max(best, cur);
  }
  cout << best << '\n';
}


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

int main(void)
{
    int a[3];
    for(int i=0;i<3;++i)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    cout <<a[0]+a[1]<<endl;
    return 0;
}


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

using namespace std;

int frog (int n, vector<int>& h) {
  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1],abs(h[i] - h[i-2]) + dp[i-2]);
  }
  return dp[n-1];
  
}

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  cout << frog(n, h);
}


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

const double g = 9.8;
const double EPS = 1.0e-6;
double K;
double v;

void kouhoth(int x, int y, vector<double> &TH)
{
	double K = 1.0*v*v/g;
	double d = K*K*x*x - x*x*(x*x+2*K*y);
	if(d<0) return;
	double kai1 = (K*x + sqrt(d)) / x / x;
	double kai2 = (K*x - sqrt(d)) / x / x;
	if(kai1+EPS>0) TH.push_back(atan(kai1+EPS));
	if(kai1-EPS>0) TH.push_back(atan(kai1-EPS));
	if(kai2+EPS>0) TH.push_back(atan(kai2+EPS));
	if(kai2-EPS>0) TH.push_back(atan(kai2-EPS));
}

double f(double th, int x)
{
	double K = 1.0*v*v/g;
	double si = sin(th);
	double co = cos(th);
	double ta = tan(th);
	double alpha = -0.5*(1.0+ta*ta)/K;
	double beta = 0.5*K*si*si;
	double naka = 1.0*x - K*si*co;
	return alpha * naka*naka + beta;
}

int main(){
	int n;
	int x, y;
	pair<double, double> buf;
	while(cin>>n>>v>>x>>y){
		vector<int> L, B, R, T;
		vector<double> TH;
		K = 1.0*v*v/g;
		for(int i=0; i<n; i++){
			int l, b, r, t;
			cin>>l>>b>>r>>t;
			if(x<l) continue;
			if(x<r) r = x;
			L.push_back(l);
			B.push_back(b);
			R.push_back(r);
			T.push_back(t);
			kouhoth(l,b,TH);
			kouhoth(r,b,TH);
			kouhoth(l,t,TH);
			kouhoth(r,t,TH);
		}
		kouhoth(x,y,TH);

		bool okflg = false;
		for(int i=0; i<TH.size(); i++){
			double th = TH[i];
			double mauey = f(th,x);
			if(mauey < y) continue;
			bool dameflg = false;

			// ツ津環嘉淞チツェツッツク
			for(int j=0; j<L.size(); j++){
				if(
					(f(th,L[j])<B[j]&&f(th,R[j])<B[j]) ||
					(f(th,L[j])>T[j]&&f(th,R[j])>T[j]) ){
						continue;
				} else {
					dameflg = true;
					break;
				}
			}

			// ツ猟篠可コツ湘。ツ害ツ閉ィツ確ツ認
			if(!dameflg){
				bool butukaruflg = false;
				for(int j=0; j<L.size(); j++){
					if(R[j]==x){
						if(y<T[j] && T[j]<mauey){
							butukaruflg = true;
							break;
						}
					}
				}
				if(!butukaruflg){
					okflg = true;
					break;
				}
			}
		}
		if(okflg) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 0
mylist=[]
mylist=input().split()
mylist_int=[]
mylist_int=[int(s) for s in mylist]
result=0

if mylist_int[0]>3:
    if mylist_int[1]==3:
        result+=100000
    elif mylist_int[1]==2:
        result+=200000
    elif mylist_int[1]==1:
        result+=300000
    

if mylist_int[0]==3:
    result+=100000
    if mylist_int[1]==3:
        result+=100000
    elif mylist_int[1]==2:
        result+=200000
    elif mylist_int[1]==1:
        result+=300000
        
elif mylist_int[0]==2:
    result+=200000
    if mylist_int[1]==3:
        result+=100000
    elif mylist_int[1]==2:
        result+=200000
    elif mylist_int[1]==1:
        result+=300000
        
elif mylist_int[0]==1:
    result+=300000
    if mylist_int[1]==3:
        result+=100000
    elif mylist_int[1]==2:
        result+=200000
    elif mylist_int[1]==1:
        result+=300000+400000
        
        
print(result)


Measured memory_bytes: 38384
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };


int main(void) {

	string s;
	cin >> s;

	int count = 1;
	int answer = s.size();
	int n = s.size();

	for (int i = 0; i < s.size()-1; i++) {
		if (s[i] != s[i + 1]) {
			answer = min(answer,max((i+1),n-(i+1)));
		}
	}

	std::cout << answer << endl;

	return 0;
}


Measured memory_bytes: 512
// A.

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, sum = 0, ans = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0; i < n; ++i) {
		if (abs(sum - a[i] * n) < abs(sum - a[ans] * n)) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int cnt[26];
char str[101];

int main()
{
	int i;
	
	scanf("%s", str);
	for(i=0;i<strlen(str);i++) cnt[str[i]-'a']++;
	
	for(i=0;i<26;i++){
		if(cnt[i]%2 == 1) break;
	}
	
	if(i < 26) printf("No");
	else printf("Yes");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int n,mi;
int r,w[1001];
int dp[1001][1001];

int rec(int i, int j){
	if(dp[i][j] >= 0) return dp[i][j];
	int res;
	if(i==n) res = 0;
	else if(j < w[i] || i==mi) res = rec(i+1, j);
	else res = max(rec(i+1, j), rec(i+1, j-w[i]) + w[i]);
	return dp[i][j] = res;
}

main(){
	int i,j;
	while(cin >> n, n){
		int sr=0,sw=0,mr=0;
		memset(dp, -1, sizeof(dp));
		for(i=0;i<n;i++){
			cin >> r >> w[i];
			sr += r;sw += w[i];
			if(mr<r){
				mr = max(mr, r);
				mi = i;
			}
		}
		if(sr-mr < mr){
			int blank = mr - (sr-mr);
			cout << mr*2 + sw - rec(0, blank) << endl;
		}else cout << sr + sw << endl;
	}
	return 0;
}

Measured memory_bytes: 5128
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    N,M = map(int,input().split())
    xyz = [list(map(int,input().split())) for i in range(N)]
    anslist = []
    for i in range(8):
        cand = []
        for j in range(N):
            p = 0
            for k in range(3):
                if ((i>>k)&1):
                    p -= xyz[j][k]
                else:
                    p += xyz[j][k]
            cand.append(p)
        cand.sort(reverse = True)
        anslist.append(sum(cand[:M]))

    print(max(anslist))

if __name__ == "__main__":
    main() #endline===============================================

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int k;
string s;

bool go(int i, int len, int last) {
    //watch(s);
    if (i==len) {
	if ((--k) == 0) {
	    cout<<s<<endl;
	    return true;
	}
	return false;
    }

    for (int d=(i? 0: 1); d < 10; d++) {
	if (i && abs(last-d)>1) continue;
	s += char('0'+d);
	if (go(i+1,len,d)) {
	    return true;
	}
	s.pop_back();
    }

    return false;
}



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

    cin>>k;
    for (int len=1 ; ; len++) {
	if (go(0,len,0)) return 0;
    }
    assert(0);
    return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

bool flg[100][100];
char a[100][100];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];

  rep(i, h) {
    bool f = true;
    rep(j, w) if (a[i][j] == '#') f = false;
    if (f) rep(j, w) flg[i][j] = true;
  }
  rep(j, w) {
    bool f = true;
    rep(i, h) if (a[i][j] == '#') f = false;
    if (f) rep(i, h) flg[i][j] = true;
  }

  rep(i, h) {
    bool f = true;
    rep(j, w) if (!flg[i][j]) f = false;
    if (!f) {
      rep(j, w) if (!flg[i][j]) cout << a[i][j];
      cout << endl;
    }
  }
}


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


int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>> n;
   	string a,b;
   	cin >> a>>b;
   	for(int i =0 ;i < n ;i++)
   	{
   		cout<< a[i]<<b[i];
   	}
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n, m; cin >> n >> m;
  if (n % 2 == 1) {
    for (int l = 1, r = n - 1; l <= m; l++, r--) {
      cout << l << " " << r << endl;
    }
  } else {
    for (int l = 1, r = n - 1; l <= m; l++, r--) {
      if (r - l <= n / 2) {
        cout << l << " " << r - 1 << endl;
      } else {
        cout << l << " " << r << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(((b-a) <=k) && ((c-a) <= k) && ((d-a) <= k) && ((e-a) <= k) && ((c-b) <= k) && ((d-b) <= k) && ((e-b) <= k) && ((d-c) <= k) && ((e-c) <=k) && ((e-d) <= k)) {
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256