akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdio.h>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    std::string s;
    std::cin >> s;

    int type[n];

    const int sheep = 0;

    for (type[0] = 0; type[0] <= 1; type[0]++) {
        for (type[1] = 0; type[1] <= 1; type[1]++) {

            int i = 1;
            for (int offset = 0; offset < n - 2; offset++) {
                int c = (i + offset) % n;
                int p = (i + offset - 1 + n) % n;
                int ne =(i + offset + 1) % n;

                if (s[c] == 'o') {
                    if (type[c] == sheep) {
                        type[ne] = type[p];
                    } else {
                        type[ne] = 1 - type[p];
                    }
                } else {
                    if (type[c] == sheep) {
                        type[ne] = 1 - type[p];
                    } else {
                        type[ne] = type[p];
                    }
                }
            }
            int c = 0;
            int p = n - 1;
            int ne = 1;

            bool ok = true;
            if (s[c] == 'o') {
                if (type[c] == sheep) {
                    if (type[ne] != type[p])
                        ok = false;
                } else {
                    if (type[ne] == type[p])
                        ok = false;
                }
            } else {
                if (type[c] == sheep) {
                    if (type[ne] == type[p])
                        ok = false;
                } else {
                    if (type[ne] != type[p])
                        ok = false;
                }
            }

            c = n - 1;
            p = n - 2;
            ne = 0;
            if (s[c] == 'o') {
                if (type[c] == sheep) {
                    if (type[ne] != type[p])
                        ok = false;
                } else {
                    if (type[ne] == type[p])
                        ok = false;
                }
            } else {
                if (type[c] == sheep) {
                    if (type[ne] == type[p])
                        ok = false;
                } else {
                    if (type[ne] != type[p])
                        ok = false;
                }
            }
            if (ok) {
                for (int i = 0; i < n; i++) {
                    if (type[i] == sheep)
                        std::cout << 'S';
                    else
                        std::cout << 'W';
                }
                std::cout << std::endl;
                return 0;
            }

        }
    }

    std::cout << -1 << std::endl;
    return 0;
}

Measured memory_bytes: 976
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))

ans=0
for i in range(n-1,-1,-1):
	val=min(arr2[i],arr1[i+1])
	ans+=val
	arr2[i]-=val
	arr1[i+1]-=val
	val=min(arr2[i],arr1[i])
	ans+=val
	arr2[i]-=val
	arr1[i]-=val
	#print(arr1,arr2)
print(ans)


Measured memory_bytes: 18624
n = int(input())
a = input().split()
b=a[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if a[j][1]<a[j-1][1]:
            a[j-1],a[j]=a[j],a[j-1]

print(*a)
print('Stable')

for i in range(n):
    min=i
    for j in range(i,n):
        if b[min][1]>b[j][1]:
            min=j
    b[i],b[min]=b[min],b[i]
print(*b)
if a==b:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
  int64_t x;
  mint(int64_t x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(int64_t t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  //for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int N = 1010;

//head

int h, w;
string s[N];
mint dp[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  rep(i, h) cin >> s[i];

  dp[0][0] = 1;
  rep(i, h) rep(j, w) {
    if(i != h-1 and s[i+1][j] != '#') {
      dp[i+1][j] += dp[i][j];
    }
    if(j != w-1 and s[i][j+1] != '#') {
      dp[i][j+1] += dp[i][j];
    }
  }

  cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 12620
from sys import stdin

read = stdin.readline

N = int(read())
data = [int(read()) for _ in range(N)]
min = data[0]
max_profit = data[1] - data[0]

for index in range(1,N):
    if max_profit < data[index] - min:
        max_profit = data[index] - min
    if data[index] < min:
        min = data[index]

print(max_profit)


Measured memory_bytes: 13616
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 n=sc.I;
		int[] s=sc.Ia;
		string t=sc.S;
		char[] c=t.ToCharArray();
		c[s[1]-1]=(char)(c[s[1]-1]+32);
		Console.WriteLine(String.Join("",c));
	}
}

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 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{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 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()).Split();}}
}

Measured memory_bytes: 13268
n=int(input())
AC=0
WA=0
TLE=0
RE=0
for i in range(n):
    s=input()
    if s=="AC":
        AC+=1
    elif s=="WA":
        WA+=1
    elif s=="TLE":
        TLE+=1
    else:
        RE+=1
print("AC","x", AC)
print("WA","x", WA)
print("TLE","x", TLE)
print("RE","x", RE)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, i;
	cin >> n;
	ll a[n];
	ll cnt = 0;
	fr(i,0,n)
	{
		cin >> a[i];
		if(a[i] != i+1)
			cnt++;
	}
	if(cnt > 2)
		cout << "NO";
	else
		cout << "YES";
}


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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << s1.at(0) << s2.at(1) << s3.at(2) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
 
 
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
const int INF = 1e9 + 5;
signed main() {
    FAST_IO;
 
    int n,k;
    cin>>n;
    int a[n], b[n], c[n];
    int dp[n][3] = {0};
    for (int i = 0; i < n; i++) cin>>a[i]>>b[i]>>c[i];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++){
        dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}

Measured memory_bytes: 5872
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){

  int x,y;
  cin >> x >> y;
  bool flag = false;

  for(int i = 0;i <= x;i++){
    if( i*2 + (x-i)*4 == y){
      flag = true;
      break;
    }
  }

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

}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(void){
  int H, W;
  int h, w;
  cin >> H; cin >> W;
  cin >> h; cin >> w;

  int h_num, w_num, answer;
  if(H == h || W == w)
    cout << "0" << endl;
  else{
    h_num = H*w;
    w_num = W*h;
    answer = H*W - (h_num+w_num) + h*w;
    cout << answer << endl;
  }



  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int MOD = 1000000007;

int main(){
    ll H,W;
    cin>>H>>W;
    ll N;
    cin>>N;
    vector<ll> a(N);
    for(ll i=0;i<N;i++){
        cin>>a[i];
    } 
    ll res[H][W];
    ll x=0,y=0;
    bool back=false;
    for(ll i=0;i<N;i++){
        for(ll j=0;j<a[i];j++){
            res[x][y] = i+1;
            if((y==0&&back)||(y==W-1&&!back)){
                x++;
                back = !back;
            }else{
                if(back){
                    y--;
                }else{
                    y++;
                }
            }
        }
    }
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++){
            cout<<res[i][j]<<" ";
        }
        cout<<endl;
    }

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    vi v(n);
    unsigned ll sum = 0;
    map<unsigned ll, unsigned ll> m;
    forn(n) { cin >> v[i]; sum += v[i]; m[v[i]]++; };
    int t; cin >> t;
    while(t--) {
        int b, c; cin >> b >> c;
        if(m[b] != 0) {
            int k = m[b];
            sum += (c - b) * k;
            m[b] = 0;
            m[c] += k;
        }
        cout << sum << endl;
    }   
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  set<char> st;
  for(int i = 0; i < S.size(); i++) {
    st.insert(S[i]);
  }

  if(st.size() == S.size()) cout << "yes";
  else cout << "no";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int d[100000],n,L,q,a,o;
int dst(int a,int b){
	return min(abs(a-b),L-abs(a-b));
}
int main(){
	while(true){
		cin>>L;if(L==0)break;o=0;
		cin>>n>>q;for(int i=1;i<n;i++)cin>>d[i];
		sort(d,d+n);
		for(int i=0;i<q;i++){
			cin>>a;
			int pos1=lower_bound(d,d+n,a)-d;
			int G=min(dst(a,d[pos1%n]),dst(a,d[(pos1-1)%n]));
			o+=G;
		}
		cout<<o<<endl;
	}
	return 0;
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n; cin >> n;
	repn(x,100000){
		int k = x*108/100;
		if(n == k){
			cout<<x<<endl; return 0;
		}
	}
	cout<<":("<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory>
#include<cmath>
#include<algorithm>
#include<vector>
double min_double(double a,double  b){
    if(a<b) return a;
    else return b;
}
void swap(long long *x,long long *y){
    long long tmp;
    tmp=*x;
    *x=*y;  
    *y=tmp;
}

long long gcd(long long a,long long b){
    if(a<b) swap(&a,&b);
    if(b<1) return -1;

    if(a%b==0) return b;
    return gcd(b,a%b);
}

long long lcm(long long a,long long b){
    return a * b / gcd(a,b);
}
int main(){
    long long A,B,C,D;
    std::cin>>A>>B>>C>>D;

    if(C == 1 || D == 1){
        std::cout<<0<<std::endl;
        return 0;
    }

    long long num = B - A + 1;
    long long districtC1,districtC2;
    districtC1 = A / C;
    districtC2 = B / C;
    if(A % C == 0) districtC2++;
    long long districtC = districtC2 - districtC1;

    long long districtD1,districtD2;
    districtD1 = A / D;
    districtD2 = B / D;
    if(A % D == 0) districtD2++;
    long long districtD = districtD2 - districtD1;

    long long E = lcm(C,D);
    long long districtE1,districtE2;
    districtE1 = A / E;
    districtE2 = B / E;
    if(A % E == 0) districtE2++;
    long long districtE = districtE2 - districtE1;

    long long ans = num -districtC - districtD + districtE;

    std::cout<<ans<<std::endl;


    /*
    long long c = C,d = D;

    long long num = B - A + 1;

    long long E = C * D;
    long long e = E;

    long long districtC = 0;
    long long I = 1;
    while(1){
        c = C;
        c *= I;
        if(A <= c && c <= B) districtC++;
        else if(B < c) break;
        I++;
    }

    long long districtD = 0;
    I = 1;
    while(1){
        d = D;
        d *= I;
        if(A <= d && d <= B) districtD++;
        else if(B < d) break;
        I++;
    }

    long long districtE = 0;
    I = 1;
    while(1){
        e = E;
        e *= I;
        if(A <= e && e <= B) districtE++;
        else if(B < e) break;
        I++;
    }

    long long ans = num - districtC - districtD + districtE;

    std::cout<<ans<<std::endl;
    */
    

    return 0;
}



Measured memory_bytes: 3588
#include <stdio.h>

//????????????.
void swap(int *x, int *y);

int selectionSort(int *a, int n);

int main(void) {
	int i = 0;
	int n = 0;
	int count = 0;
	int a[100] = {};

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	count = selectionSort(a, n);

	for (i = 0; i < n; i++) {
		if (i != n - 1)
			printf("%d ", a[i]);
		else
			printf("%d\n%d\n", a[i], count);
	}

	return 0;
}

void swap(int *x, int *y) {
	int tmp = 0;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

int selectionSort(int *a, int n) {
	int i = 0;
	int j = 0;
	int minj = 0;
	
	int count = 0;		//????????????????????°.

	for (i = 0; i < n; i++) {
		minj = i;
		
		for (j = i; j < n; j++) {
			if (a[j] < a[minj])
				minj = j;
		}
		if (minj != i) {
			swap(&a[i], &a[minj]);
			count++;
		}
	}

	return count;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    ll cur = 1;
    rep(i,n){
        ll x; cin >> x;
        ll g = gcd(cur,x);
        x /= g;
        cur *= x;
    }
    cout << cur << endl;
    return 0;
}


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

signed main(){
	int n,a,b,c,d;
	cin>>n;
	a=(n-n%1000)/1000,b=(n%1000-n%100)/100,c=(n%100-n%10)/10,d=n%10;
	if(a==b and b==c){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(b==c and c==d){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll fnc(bitset<15> bit,vi a,int n,int k){
    ll res = 0;
    rep(i,n) if(bit.test(i)){
        for(int j=0;j<i;j++){
            if(a[i]<=a[j]){
                res += a[j] - a[i] + 1;
                a[i] = a[j] + 1;
            }
        }
    }
    int pre = 0;
    int sum = 0;
    rep(i,n){
        if(pre < a[i]){
            pre = a[i];
            sum++;
        }
    }
    if(sum<k) res = LINF;
    return res;
}

int main(){
    int n,k;
    cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];
    ll ans = LINF;
    for(int i=0;i<(1<<n);i++){
        bitset<15> bit(i);
        ans = min(ans,fnc(bit,a,n,k));
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define INF 1000000000000
typedef long long ll;

char masu[6][6];
int masu2[6][6];

int colB = 0b000000;
int rowB = 0b000000;

int main() {
	int h, w, k, ans = 0, sumK = 0;

	cin >> h >> w >> k;
	int flagH = 1 << h, flagW = 1 << w;

	REP(i, h) {
		REP(j, w) {
			cin >> masu[i][j];
		}
	}

	REP(i, flagH) {
		REP(j, flagW) {
			REP(x, h) {
				REP(y, w) {
					if (((colB >> x) & 1) == 0 && ((rowB >> y) & 1) == 0 && masu[x][y]=='#') {
						sumK++;
					}
				}
			}
			if (sumK == k) {
				ans++;
			}
			sumK = 0;
			rowB++;
		}
		rowB = 0;
		colB++;
	}
	cout << ans;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int (i)=int(a);i<=int (b);i++)
#define ff(i,a,b) for(int (i)=int(a);i<int (b);i++)
#define F(i,a,b) for(int (i)=int (a);i>=int (b);i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define all(x) x.begin(),x.end()
#define lower(p,x) lower_bound(all(p),x)
#define upper(p,x) upper_bound(all(p),x)
#define ms(a,x) memset(a,x,sizeof a)
typedef pair<int,int> ii;
const double pi=acos(-1.0);
const double eps=1e-5;
const int INF=1<<30,mod=1e9,N=1e6+6;
/*int power(int a,int b,int p){
	int ans=1%p;
	for(;b;b>>1){
		if(b&1)  ans=(ll)ans*a%p;
		else a=(ll)a*a%p;
	}
	return ans;
}*/int n;
int main(){
	cin>>n;
	ll a=1,b=1;
	ff(i,0,n){
			ll x,y;
			cin>>x>>y;if(a*y==b*x) continue;
			ll z=max((a+x-1)/x,(b+y-1)/y);
			a=z*x,b=z*y;
	}
	cout<<a+b;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,t; cin >> a >> b >> t;
    cout << (b) * ((10 * t  + 5) / (10 * a) )<< endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
   
    vector<int>vec;
    map<int,int>m1;

    int n;
    cin>>n;

    int j;
    for(int i=0; i < n;i++){
        cin>>j;
        vec.push_back(j);
    }

    //for each element
    for(auto el : vec){
        //add to map and count
        ++(m1[el-1]);
        ++(m1[el]);
        ++(m1[el+1]);
    }

    //get the max
    int max= 0;
    for(auto el: m1){
        if(el.second > max){
            max = el.second;
        }
    }

    cout<<max;
    return 0;

}



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

int main() {
  int N, c;
  cin >> N;
  c = 0;
  for(int i = 1; i < 50000; i++) {
    if(floor(i * 1.08) == N) {
      cout << i << endl;
      c++;
      break;
    }
  }
  if(c == 0) cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int n;
int arr[100010];

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

    for(int i = 0; i < n; ++i)
        std::cin >> arr[i], --arr[i];

    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(arr[i] > i && i == arr[arr[i]])
            ++cnt;
    }

    std::cout << cnt << std::endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(n) rep(i, n)
//#define int long long
using namespace std;

int n, idx, x, arr[10000], c[10000];
set<int> si; 

signed main()
{
    while (cin >> n, n)
    {   
        idx = 0;
        si.clear();

        for (int i=1; i<=(n-1)/2; i++) c[i] = 0;

        for (int i=1; i<n; i++)
        {   
            x = (i * i) % n;
            if (si.find(x) == si.end())
            {   
                si.insert(x);
                arr[idx++] = x;
            }   
        }   

        rep(i, idx)
        {   
            rep(j, idx)
            {   
                if (i == j) continue;
                int sub = arr[i] - arr[j];
                if (sub < 0) sub += n;
                if (sub > (n - 1) / 2) sub = n - sub;
                c[sub]++;
            }   
        }   

        for (int i=1; i<=(n-1)/2; i++) cout << c[i] << endl;
    }   

    return 0;
}

Measured memory_bytes: 1472
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    S_arr = []
    for i in range(N):
        _ = _in[i+1]
        S_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    c_arr = [0] * 4
    for S in S_arr:
        if S == 'AC':
            c_arr[0] += 1
        elif S == 'WA':
            c_arr[1] += 1
        elif S == 'TLE':
            c_arr[2] += 1
        else:
            c_arr[3] += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(f'AC x {c_arr[0]}')
    print(f'WA x {c_arr[1]}')
    print(f'TLE x {c_arr[2]}')
    print(f'RE x {c_arr[3]}')


if __name__ == "__main__":
    main()


Measured memory_bytes: 98384
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXM = 5 + 200000;
const ll INF = 1LL << 60;

struct st {
    int tam;
    vector<ll> tree;
    vector<ll> lazy;
    st(int n) {
        tam = n;
        tree.assign(tam << 2, 0LL);
        lazy.assign(tam << 2, 0LL);
    }
    ll lazy_query(int low, int high, int pos, int& qlow, int& qhigh) {
        int mid = (low + high) >> 1;
        int left = (pos << 1) | 1;
        int right = left + 1;
        if(lazy[pos] != 0) {
            tree[pos] += lazy[pos];
            if(low != high) {
              lazy[left] += lazy[pos];
              lazy[right] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if (qhigh < low || qlow > high)
            return -INF;
        if (low >= qlow && high <= qhigh)
            return tree[pos];
        ll l = lazy_query(low, mid, left, qlow, qhigh);
        ll r = lazy_query(mid + 1, high, right, qlow, qhigh);
        return max(l, r);
    }
    ll query(int i, int j) {
        return lazy_query(0, tam - 1, 0, i, j);
    }
    void lazy_update(int low, int high, int pos, int& qlow, int& qhigh, ll& cant) {
        int mid = (low + high) >> 1;
        int left = (pos << 1) | 1;
        int right = left + 1;
        if(lazy[pos] != 0) {
            tree[pos] += lazy[pos];
            if(low != high) {
              lazy[left] += lazy[pos];
              lazy[right] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if(low > qhigh || high < qlow)    return;
        if(low >= qlow && high <= qhigh) {
            tree[pos] += cant;
            if(low != high) {
              lazy[left] += cant;
              lazy[right] += cant;
            }
            return;
        }
        lazy_update(low, mid, left, qlow, qhigh, cant);
        lazy_update(mid + 1, high, right, qlow, qhigh, cant);
        tree[pos] = max(tree[left], tree[right]);
    }
    void update(int i, int j, ll x) {
        lazy_update(0, tam - 1, 0, i, j, x);
    }};


struct Point {
    int l,r,a;
} p[MAXM];

ll memo[MAXM];
vector<int> sr[MAXM];
bool done[MAXM];
int N,M;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N >> M;
    foi(i,0,M) {
        cin >> p[i].l >> p[i].r >> p[i].a;
        sr[p[i].l].push_back(i);
        sr[1 + p[i].r].push_back(i);
    }
    memset(memo, -1, sizeof memo);
    memset(done, false, sizeof done);
    ll ans = 0LL;
    st s(5+MAXM);
    for(int i = 1; i <= N; ++i) {
        for(int x : sr[i]) {
            if(p[x].l == i) {
                s.update(0, p[x].l - 1, p[x].a);
            } else {
                s.update(0, p[x].l - 1, -p[x].a);
            }
        }
        ll q = s.query(0, i - 1);
        ans = max(ans, q);
        s.update(i,i,q);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 27776
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,P[100005];
	int pos[100005];
	scan(N);
	set<int> st;
	st.insert(-2);
	st.insert(-1);
	st.insert(N);
	st.insert(N+1);
	rep(i,N){
		scan(P[i]);
		pos[P[i]]=i;
	}
	ll ans=0;
	brep1(i,N){
		int le2,le1,ri1,ri2;
		st.insert(pos[i]);
		auto itr=st.find(pos[i]);
		itr--;
		le1=*itr;
		itr--;
		le2=*itr;
		itr++; itr++; itr++;
		ri1=*itr;
		itr++;
		ri2=*itr;
		ll sum=0;
		if(ri1<N) sum+=(ll)(ri2-ri1)*(pos[i]-le1);
		if(le1>-1) sum+=(ll)(le1-le2)*(ri1-pos[i]);
		sum*=i;
		ans+=sum;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 */

/**
 * @author cthanh
 *
 */
public class Main{

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\?????????
		    String str = br.readLine();
		    double r =  Double.parseDouble( str);
		    double men = (double) r *r *Math.PI;
		    double syu = (double) r*2* Math.PI;
		   // System.out.println(Math.PI);
		    System.out.printf( "%.6f %.6f",men , syu );


	}

}

Measured memory_bytes: 24540
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b, c, K = MAP()

if a >= K:
    print(K)
    exit()
K -= a
ans = a
if b >= K:
    print(ans)
    exit()
K -= b
ans -= K
print(ans)


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

using namespace std;

int main(){
	string s,t;
	
	cin >> s >> t;
	
	int ans = t.size();
	
	for (int start = 0; start <= s.size() - t.size();start++){
		int diff = 0;
		
		for (int i = 0;i < t.size();i++){
			if (t[i] != s[start+i]){
				diff++;
			}
		}
		ans = min(diff,ans);
	}
	cout << ans;
	
	return 0;
}
		


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
#include<cstring>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

ll inf = ll(1e9 + 7);

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    vector<ll> cnt(k + 1);
    for (int i = k; i >= 1; i--) {
        ll ki = ll(k / i);
        ll cnti = modpow(ki, ll(n), inf);
        int ii = 2 * i;
        while (ii <= k) {
            cnti -= cnt[ii];
            cnti=(cnti+inf)%inf;
            ii += i;
        }
        cnt[i] = cnti;
        ans += ll(i) * cnti % inf;
        ans %= inf;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   string n;
   cin>>n;
   for(int i=0;i<3;i++){
       if(n[i]=='1'){n[i]='9';}
       else if(n[i]=='9'){n[i]='1';}
   }
   cout<<n<<endl;
return 0;}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H + W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or j == 0 or i == H-1 or j == W-1:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')


Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100;

int N;
int val[111], cost[111];

int main()
{
	while(scanf("%d", &N) != EOF)
	{
		for(int i = 1; i <= N; i++) scanf("%d", &val[i]);
		for(int i = 1; i <= N; i++) scanf("%d", &cost[i]);
		int ans = 0;
		for(int i = 1; i <= N; i++)
			if(val[i] > cost[i])
				ans += (val[i] - cost[i]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int h = Integer.parseInt(br.readLine());
		
		String[] s = br.readLine().split(" ");
		int A[] = new int[h];
		for(int i = 0; i < h; i++) {
			A[i] = Integer.parseInt(s[i]);
		}
		buildMaxHeap(A);
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < h; ++i) {
			sb.append(" " + A[i]);
		}
		System.out.println(sb);
	}
	public static void maxHeapify(int[] A, int i){
		int l = 2 * i + 1;
		int r = 2 * i + 2;
		
		int largest;
		int h = A.length;
		if (l < h && A[l] > A[i]){
			largest = l;
		}else{
			largest = i;
		}
		if(r < h && A[r] > A[largest]){
			largest = r;
		}
		
		if(largest != i){
			int tmp = A[i];
			A[i] = A[largest];
			A[largest] = tmp;
			maxHeapify(A, largest);
		}
	}
	public static void buildMaxHeap(int[] A){
		for(int i = A.length/2 - 1; i >= 0; --i){
			maxHeapify(A, i);
		}
	}
}

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

int main() {
	int N, T,t,tmp;
	long long ans=0;
	cin >> N >> T;
	cin >> tmp;
	for (int i = 1; i < N; i++) {
		cin >> t;
		if (t - tmp <= T) ans += t - tmp;
		else ans += T;
		tmp = t;
	}
	cout << ans + T << endl;
}


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

using namespace std;

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < n; ++i)
	{
		int a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	ll ans = 0, i = 0;
	while (m >= 0)
	{
		if (v[i].second < m)
		{
			ans += v[i].first * v[i].second;
			m -= v[i].second;
		}
		else
		{
			ans += v[i].first * m;
			break;
		}
		i++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0  # 何もしないと0なので、ansの初期値は0


for pick in range(min(n+1,k+1)):
    #  pick->取り出す操作をする回数(listより多く取り出さないように注意)

    for right in range(pick+1):
        left= pick-right # 左から取り出す数
        pick_list=v[:right]+v[n-left:]
        pick_list=sorted(pick_list)
        temp_ans=sum(pick_list)
        rem=min(k-pick,pick)# 右から取り出す数
        for i in range(rem):
            if pick_list[i]<0:
                temp_ans-=pick_list[i]
            else:
                break
        ans=max(ans,temp_ans)
print(ans)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int k, s;
  cin >> k >> s;
  lol ans = 0;
  rep(x, k + 1){
    rep(y, k + 1){
      if(s - (x + y) <= k && s - (x + y) >= 0){
	//	cout << x << " " << y << '\n';
	ans ++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}



const ll INF = 1LL << 60;
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

// dist[v] に頂点 s から頂点 v への距離を入れる関数
void dijkstra(int s, Graph &G, vector<ll> &dist){
  fill(all(dist), INF);
  dist[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(dist[nv] > dist[v] + w){
        dist[nv] = dist[v] + w;
        pq.push(P(dist[nv], nv));
      }
    }
  }
}

int main(){
  int n; cin >> n;
  Graph G(n);
  rep(i, n-1){
    int a,b,w; cin >> a >> b >> w;
    a--; b--; //0-index に直す
    G[a].pb(Edge(b,w));
    G[b].pb(Edge(a,w));
  }

  int Q,K; cin >> Q >> K;
  vector<ll> dist(n);
  dijkstra(K-1, G, dist);

  vi x(Q), y(Q);
  rep(i, Q) cin >> x[i] >> y[i];
  rep(i, Q) std::cout << dist[x[i]-1] + dist[y[i]-1] << '\n';
}


Measured memory_bytes: 9460
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int M, T, P, R;

	void run() {
		for (;;) {
			M = sc.nextInt();
			T = sc.nextInt();
			P = sc.nextInt();
			R = sc.nextInt();
			if ((M | T | P | R) == 0) {
				return;
			}
			Team[] team = new Team[T];
			for (int i = 0; i < T; i++) {
				Team t = new Team(i + 1);
				team[i] = t;
			}
			for (int i = 0; i < R; i++) {
				int m = sc.nextInt();
				int t = sc.nextInt();
				int p = sc.nextInt();
				int j = sc.nextInt();

				if (j != 0) {
					team[t - 1].wrong[p] += 20;
				} else {
					team[t - 1].time += m;
					team[t - 1].time += team[t - 1].wrong[p];
					team[t - 1].solve++;
				}
			}
			Arrays.sort(team);
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < T; i++) {
				sb.append(team[i].num);
				if (i != T - 1) {
					sb.append(team[i].solve == team[i + 1].solve
							&& team[i].time == team[i + 1].time ? "=" : ",");
				}
			}
			System.out.println(sb);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	class Team implements Comparable<Team> {
		int num;
		int solve;
		int time;
		int[] wrong;

		Team(int num) {
			this.num = num;
			wrong = new int[P + 1];
		}

		@Override
		public int compareTo(Team arg0) {
			if (arg0.solve != this.solve) {
				return arg0.solve - this.solve;
			} else if (arg0.time != this.time) {
				return this.time - arg0.time;
			} else {
				return arg0.num - this.num;
			}
		}
	}
}

Measured memory_bytes: 60840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    string S;
    cin >>N>>K>>S;
    S[K-1]+='a'-'A';
    
    cout << S << endl;


    return 0;
    

}

Measured memory_bytes: 3576
#include <iostream>
#include <queue>
#define MAX 20
#define INF 10000000

using namespace std;

int w, h;
char c[MAX][MAX];
int d[MAX][MAX][1024];

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

void change(int a[10], int x){

	for(int i = 0 ; i < 10 ; ++i){
		a[i] = x % 2;
		x /= 2;
	}

}

int change(int a[10]){

	int res = 0;
	for(int i = 9 ; i >= 0 ; --i){
		res = res * 2 + a[i];
	}
	return res;
}

int bfs(int sy, int sx, int cnt){

	queue<int> qx, qy, qbit;
	qy.push(sy);
	qx.push(sx);
	qbit.push(0);

	d[sy][sx][0] = 0;


	while(qbit.empty() == false){

		int y = qy.front();
		qy.pop();

		int x = qx.front();
		qx.pop();

		int bit = qbit.front();
		qbit.pop();

		if( bit + 1 == (1 << cnt) ){				// ?????§?????¨??????????????????????????????
			return d[y][x][bit];
		}

		int a[10];
		for(int i = 0 ; i < 4 ; ++i){

			change(a, bit);
			int ny = dy[i] + y;
			int nx = dx[i] + x;

			if( ny < 0 || nx < 0 ) continue;		// ?????????
			if( h <= ny || w <= nx) continue;		// ?????????
			if( c[ny][nx] == 'x') continue;			// ?§??????§?????????

			if( c[ny][nx] != '.'){					// ?±??????????????????§????????´???
				int num = c[ny][nx] - '0';			// ?±???????????????????ID?????????
				a[num] = 1;
			}
			int nbit = change(a);
			int nCost = d[y][x][bit] + 1;

			if( nCost < d[ny][nx][nbit] ){			// ??????????????£??????????????´??? & ???????§£?????´??°
				d[ny][nx][nbit] = nCost;
				qy.push(ny);
				qx.push(nx);
				qbit.push(nbit);
			}

		}// end of for

	}// end of while

	return -1;
}// end of bfs

void init(){

	for (int i = 0 ; i < h ; ++i){
		for (int j = 0 ; j < w ; ++j){
			for(int k = 0 ; k < 1024 ; ++k){
				d[i][j][k] = INF;
			}
		}
	}


}

int main(void){


	int si, sj;
	while( cin >> w >> h ){

		if( w == h && h == 0 ){
			break;
		}
		init();
		int cnt = 0;

		for(int i = 0 ; i < h ; ++i){
			for(int j = 0 ; j < w ; ++j){
				cin >> c[i][j];
				if( c[i][j] == 'o'){
					sj = j;
					si = i;
					c[i][j] = '.';
				}else if( c[i][j] == '*'){
					c[i][j] = '0' + cnt++;
				}
			}
		}

		cout << bfs(si, sj, cnt) << endl;

		// for(int i = 0 ; i < h ; ++i){
		// 	for(int j = 0 ; j < w ; ++j ){
		// 		cout << c[i][j];
		// 	}
		// 	cout << endl;
		// }

	}// end of while

	return 0;
}// end of main

Measured memory_bytes: 2912
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string S = Console.ReadLine();
		
		int zero_one = 0;
		for(int i = 0; i < S.Length; i++)
		{
			if((i % 2 == 0) && (S[i] != '0')) zero_one++;
			if((i % 2 == 1) && (S[i] != '1')) zero_one++;			
		}
		
		int one_zero = 0;
		for(int i = 0; i < S.Length; i++)
		{
			if((i % 2 == 0) && (S[i] != '1')) one_zero++;
			if((i % 2 == 1) && (S[i] != '0')) one_zero++;	
		}
		
		Console.WriteLine(Math.Min(zero_one, one_zero));
	}	
}





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

using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  ll ABC[N+1][3];
  ll dp[N+1][3];
  for(int i=0; i<N; ++i){
    for(int j=0; j<3; ++j){
      cin >> ABC[i][j];
      dp[i][j] = 0;
    }
  }
  for(int j=0; j<3; ++j){
    dp[N][j] = 0;
  }

  for(int i=0; i<N; ++i){
    for(int j=0; j<3; ++j){
      for(int k=0; k<3; ++k){
        if(j==k) continue;
        if(dp[i+1][k] < dp[i][j] + ABC[i][k]){
          dp[i+1][k] = dp[i][j] + ABC[i][k];
        }
      }
    }
  }
  ll res = 0;
  for(int i=0; i<3; ++i){
    if(res < dp[N][i]){
      res = dp[N][i];
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
}


Measured memory_bytes: 32676