akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
    ll N,r=0;
    cin >> N;
    vector<ll> A(N),t(N);
    rep(i,N)
        cin >> A.at(i);
    sort(A.begin(), A.end());

    if(N%2) {
        ll r1=0,r2=0;
        rep(i,N/2)
            t.at((i+1)*2) = A.at(i);
        t.at(0) = A.at(N/2);
        rep(i,N/2)
            t.at(i*2+1) = A.at(i+N/2+1);
        rep(i,N-1)
            r1 += abs(t.at(i)-t.at(i+1));
        
        rep(i,N/2)
            t.at(i*2) = A.at(i+N/2+1);
        t.at(N-1) = A.at(N/2);
        rep(i,N/2)
            t.at(i*2+1) = A.at(i);
        rep(i,N-1)
            r2 += abs(t.at(i)-t.at(i+1));

        r = max(r1,r2);
    } else {
        rep(i,N/2)
            t.at(i*2) = A.at(i+N/2);
        rep(i,N/2)
            t.at(i*2+1) = A.at(i);
        rep(i,N-1)
            r += abs(t.at(i)-t.at(i+1));
    }

    cout << r << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define INF 0x3f3f3f3f
#define mul(x) x*x*(x-=1)


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,k,i;
    cin>>n>>k;

    vector<ll> a(n+1),b;
    for(i=1 ; i<=n ; i++)cin>>a[i];

    b.push_back(1);
    ll to = a[1];
    map<ll,ll> m;
    m[1]=1;

    while(m[to]==0)
    {
        b.push_back(to);
        m[to] = 1;
        to = a[to];
    }

    ll idx = (find(b.begin(),b.end(),to)-b.begin())+1;
    if(idx>=k)cout<<b[k];
    else
    {
        idx--;
        k-=idx;

        ll rem = b.size()-idx;
        cout<<b[idx + (k%rem)];
    }
    
    return 0;
}

Measured memory_bytes: 18480
#include <iostream>

using namespace std;

#define WH 110

int main(int argc, char const *argv[])
{
	int n;
	int w,h;
	int f[WH][WH];

	int x,y;
	int s,t;

	int cnt,max;

	while(1){
		cin>>n;
		if(n==0) break;

		cin>>w>>h;

		for(int i1=0;i1<WH;i1++){
			for(int i2=0;i2<WH;i2++){
				f[i1][i2]=0;
			}
		}

		for(int i1=0;i1<n;i1++){
			cin>>x>>y;
			f[y-1][x-1]=1;
		}

		cin>>s>>t;

		max=0;

		for(int i1=0;i1<h-t+1;i1++){
			for(int i2=0;i2<w-s+1;i2++){

				cnt=0;

				for(int i3=0;i3<t;i3++){
					for(int i4=0;i4<s;i4++){
						if(f[i1+i3][i2+i4]==1) cnt++;
					}
				}
				if(max<cnt) max=cnt;
			}
		}

		cout<<max<<endl;
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

const int MAXN = 1e5 + 5;

int a[MAXN];

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int n, x;
    scanf("%d %d", &n, &x);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] + a[i-1] > x) {
            ans += a[i] + a[i-1] - x;
            a[i] -= (a[i] + a[i-1] - x);
        }
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n,k;
  cin >> n >> k;
  cout << n-k+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const int MOD = 2019;

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    vector<int> A(N + 1, 0);
    map<int, int> m;
    m[0]++;
    int d = 1;
    for (int i = 0; i < N; i++) {
        int c = (int)(S[N - i - 1] - '0');
        A[i + 1] = (A[i] + c * d) % MOD;
        d *= 10;
        d %= MOD;
        m[A[i + 1]]++;
    }

    ll ans = 0;
    for (auto p : m) {
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4272
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから----------- 
int main(void){

    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> g(n);

    rep(i, m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> visited(n, 0);

    queue<pair<int,int>> q;
    vector<ll> ans(n, -1);
    q.push({0, -1});
    while(!q.empty()){
        pair<int,int> now = q.front();
        q.pop();
        ans[now.first] = now.second;
        rep(i, g[now.first].size()){
            pair<int,int> next;
            next.first = g[now.first][i];
            next.second = now.first;
            if(visited[next.first]) continue;
            visited[next.first] = 1;
            q.push(next);
        }
    }
    bool ok = true;
    for(int i = 1; i < n; i++){
        if(ans[i] == -1){
            ok = false;
        }
    }

    if(ok){
        cout << "Yes" << endl;
        for(int i = 1; i < n; i++){
            cout << ans[i] + 1 << endl;
        }
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 13300
#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli t,n,i,ans=0;
	cin>>n;
	map<string,lli>m;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		sort all(s[i]);
		m[s[i]]++;
	}
	map<string,lli>::iterator it;
	for(it=m.begin();it!=m.end();it++){
		t=it->second;
		if(t>1){
			t--;
			ans+=(t*(t+1))/2;
		}		
	}
	cout<<ans;	
	return 0;
}

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

const int maxb=18;
const int maxs=1<<maxb; 
const int mod=1e9+7;
int n,ans;
int inv[maxs],lg2[maxs];
int p[maxs],prod[maxs],iprod[maxs],sum[maxs];


int main(){
	scanf("%d",&n);
	inv[0]=inv[1]=1;
	prod[0]=iprod[0]=prod[1]=iprod[1]=1;
	for(int i=2;i<(1<<n);i++){
		inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
		lg2[i]=lg2[i>>1]+1;
		prod[i]=1LL*prod[i>>1]*i%mod;
		iprod[i]=1LL*iprod[i>>1]*inv[i]%mod;
	}
	for(int i=(1<<n-1);i<(1<<n);i++)
		scanf("%d",&p[i]),p[i]+=(1<<n-1)-1;
	for(int i=1;i<(1<<n-1);i++){
		int cur=0;
		for(int mask=0;mask<(1<<n-2-lg2[i]);mask++){
			int x=(i<<n-1-lg2[i])+mask,y=p[x],v=1LL*prod[x]*prod[y]%mod;
			while(y)sum[y]=(sum[y]+v)%mod,y>>=1;
		}
		for(int mask=0;mask<(1<<n-2-lg2[i]);mask++){
			int x=(i<<n-1-lg2[i])+(1<<n-2-lg2[i])+mask,y=p[x],v=1LL*prod[x]*prod[y]%mod;
			while(y>1){
				cur=(cur+1LL*sum[y^1]*v%mod*iprod[y>>1]%mod*iprod[y>>2])%mod;
				y>>=1;
			}
		}
		for(int mask=0;mask<(1<<n-2-lg2[i]);mask++){
			int x=(i<<n-1-lg2[i])+mask,y=p[x];
			while(y)sum[y]=0,y>>=1;
		}
		ans=(ans+1LL*cur*iprod[i]%mod*iprod[i>>1])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9452
import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if(S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n, m, q, k;
int main() {
	io
	string s, t;
	cin>>s>>t;
	n = s.size();
	int ans = 0;
	for(int i = 0; i<n; i++) {
		if(s[i] != t[i]) ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 3792
n = int(input())
l = list(map(int,input().split()))

ma = max(l)
mi = min(l)

ans = []

if abs(ma) >= abs(mi):
    ind = l.index(ma)
    if ind != 0:
        ans.append([ind+1,1])
        ans.append([ind+1,1])
    for i in range(1,n):
        
        ans.append([i,i+1])
        ans.append([i,i+1])
else:
    ind = l.index(mi)
    if ind != n-1:
        ans.append([ind+1,n])
        ans.append([ind+1,n])
    for i in range(n-2,-1,-1):
        
        ans.append([i+2,i+1])
        ans.append([i+2,i+1])
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

main(){
	int T;
	string s;
	while(cin >> n >> m >> s, n){
		int ans = 0;
		int cnt = s[0] == 'I';
		REP(i, s.size()-1){
			if(s[i+1] != s[i]) cnt ++;
			else cnt = s[i] == 'I';
			if((cnt & 1) && cnt/2 >= n) ans ++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mt make_tuple
#define eb emplace_back
using namespace std;
const int N=2e5+5;

void solve(){
    ll n,a,b,c,A,B,C;
    cin>>n>>a>>b>>c;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    string ans="";
    for(int i=0;i<n;i++){
        if(s[i]=="AB"){
            if(a==1 && b==1 && c==0 && i+1<n){
                if(s[i+1]=="AC"){
                    a++;
                    b--;
                    ans+="A";
                }
                else if(s[i+1]=="BC"){
                    b++;
                    a--;
                    ans+="B";
                }
                else{
                    a++;
                    b--;
                    ans+="A";
                }
            }
            else{
                if(a<b){a++;b--;ans+="A";}
                else {b++;a--;ans+="B";}
            }
        }
        if(s[i]=="AC"){
            if(a==1 && c==1 && b==0 && i+1<n){
                if(s[i+1]=="AB"){
                    a++;
                    c--;
                    ans+="A";
                }
                else if(s[i+1]=="BC"){
                    c++;
                    a--;
                    ans+="C";
                }
                else{
                    a++;
                    c--;
                    ans+="A";
                }
            }
            else{
                if(a<c){a++;c--;ans+="A";}
                else {c++;a--;ans+="C";}
            }
        }
        if(s[i]=="BC"){
            if(b==1 && c==1 && a==0 && i+1<n){
                if(s[i+1]=="AB"){
                    b++;
                    c--;
                    ans+="B";
                }
                else if(s[i+1]=="AC"){
                    c++;
                    b--;
                    ans+="C";
                }
                else{
                    b++;
                    c--;
                    ans+="B";
                }
            }
            else{
                if(b<c){b++;c--;ans+="B";}
                else {c++;b--;ans+="C";}
            }
        }
        if(a<0 || b<0 || c<0) {cout<<"No"<<endl;return;}
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 6920
a, b, c = map(int, input().split())
   
if a<b and a<c:
    if b<c :
        print(a, b, c)
    else :
        print(a, c, b)
elif b<a and b<c :
    if a<c :
        print(b, a, c)
    else :
        print(b, c, a)
else :
    if a<b :
        print(c, a, b)
    else :
        print(c, b, a)


Measured memory_bytes: 5596
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    scanf("%d%d", &a, &b);// don't forget &
    b *= 10;
    int ans = -1;
    for (int i = 0; i <= 9; i++) {
        int x = b + i;
        if (x * 8 / 100 == a) {
            ans = x;
            break;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

void solve() {
  int n,a;
  cin >> n >> a;
  if(n%500 <= a) cout<< "Yes" << endl;
  else cout << "No" << endl;
}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,i,j,temp,min,flag,count = 0;
  int A[100];
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  for(i = 0;i < n;i++){
    min = i;
    for(j = i+1;j < n;j++){
      if(A[j] < A[min])   min = j;
    }
    if(A[i] > A[min]){
      temp = A[i];
      A[i] = A[min];
      A[min] = temp;
      count++;
    }
  }
  for(i = 0 ;i < n;i++){
    printf("%d",A[i]);
    if(i != n-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;

int n,m,q,ans;
vector<int> a,b,c,d;

void dfs(vector<int> A){
  if(A.size() == n+1){
    int now = 0;
    rep(i,q){
      if(A[b[i]] - A[a[i]] == c[i]) now+= d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main(){
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];

  dfs(vector<int>(1,1));
  cout << ans << endl;
}
      


Measured memory_bytes: 3644
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string s;
	cin>>s;
	int i=0;
	while (s[i]!='\0'){
		if (i==4){
			cout<<" ";
		}
		cout<<s[i];
		i++;
	}
	cout<<endl;
	return 0;
}

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

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

    vector<string> m(h);
    for(auto &e: m) cin >> e;

    auto f = [&](long i) {
        return m[i/w][i%w] == '.';
    };

    vector<vector<long>> d(h*w, vector<long>(h*w, 1e9));
    for(long i=0; i<h*w; i++) {
        d[i][i] = 0;
        if(!f(i)) continue;
        if(i+w < h*w && f(i+w))
            d[i+w][i] = d[i][i+w] = 1;
        if(i-w >= 0 && f(i-w))
            d[i-w][i] = d[i][i-w] = 1;
        if((i+1)/w == i/w && f(i+1))
            d[i+1][i] = d[i][i+1] = 1;
        if(i-1 >= 0 && (i-1)/w == i/w && f(i-1))
            d[i-1][i] = d[i][i-1] = 1;
    }

    for(long k=0; k<h*w; k++)
        for(long i=0; i<h*w; i++)
            for(long j=0; j<h*w; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    long r = 0;
    for(long i=0; i<h*w; i++)
        for(long j=0; j<h*w; j++)
            if(d[i][j] < 1e9)
                r = max(r, d[i][j]);
    cout << r << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,ans;ans=0;
    int a[100005]={0};
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        if(a[i]!=a[i-1])
            ans=ans+1;
    }
    if(ans%2==0)
        ans=ans-1;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	K := readInt()
	V := make([]int, N)
	for i := range V {
		V[i] = readInt()
	}

	var ans int
	R := min(N, K)
	for a := 0; a <= R; a++ {
		for b := 0; b+a <= R; b++ {
			var sum int
			c := make([]int, 0, R)
			for i := 0; i < a; i++ {
				c = append(c, V[i])
				sum += V[i]
			}
			for i := 0; i < b; i++ {
				j := N - i - 1
				c = append(c, V[j])
				sum += V[j]
			}
			sort.Ints(c)

			k := K - (a + b)
			for i := 0; i < len(c) && i < k && c[i] < 0; i++ {
				sum += -c[i]
			}
			ans = max(ans, sum)
		}
	}
	println(ans)

}

// -----------------------------------------------------------------------------


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

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

	int c = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 2 == 1) {
			++c;
		}
	}

	cout << fixed;
	cout << setprecision(7) << (double)c / (double)n << endl;
	return 0;
}

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

int main()
{
    int n, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        string s;
        stringstream ss;
        ss << i;
        ss >> s;
        if(s.size()%2) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long lglg;

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

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

	if (n%2==1) cout << "No";
	else {
		bool success = true;
		for (int i=0;i<n/2; ++i) {
			if (s[i] != s[i+n/2]) {
				success = false;
				break;
			}
		}
		if (success) cout << "Yes";
		else cout << "No";
	}
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	int x;
	cin >> x;
	int f = x >= 30;
	cout << (f ? "Yes" : "No") << endl;

	return 0;
}


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



int main(){
	
	int i,j,N;
	char S[110];
	scanf("%s",S);
	int cnt=0;
	int max=0;
	int ex=0;
	for(i=0;i<3;i++){
		if(S[i]=='R')ex=1;
		
		if(i<2 && S[i]==S[i+1]&& S[i]=='R')cnt++;
	}
	if(cnt==2)max=3;
	else if(cnt==1)max=2;
	else if(ex==1)max=1;
	printf("%d\n",max);
		
	return 0;
}


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

int main()
{
    int n;
    double d;
    cin>>n>>d;
    double x,y;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        double res=sqrt(x*x+y*y);
        if(res<=d)
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3768
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int n, x;
	long long int min = 0;
    int	max = -1000000, sum = 1000000;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x;
		if (x < sum){
			sum = x;
		}
		if (x>max){
			max = x;
		}
		min = min + x;
	}
	cout << sum << " " << max << " ";
	printf("%ld\n", min);
	return 0;
}

Measured memory_bytes: 3228
// https://www.youtube.com/watch?v=C5_NnCp1CRI
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, m;
    cin >> n >> m;

    if (n % 2)
        for (int l = 1, r = n - 1; l <= m; l++, r--) {
            cout << l << " " << r << endl;
        }
    else {
        bool flag = false;
        for (int l = 1, r = n - 1; l <= m; l++, r--) {
            if (!flag && r - l <= n / 2) {
                r--;
                flag = true;
            }
            cout << l << " " << r << endl;
        }
    }
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;




int main(){
    int n;cin >> n;
    vector<int> S(1<<n);
    set<P> st;
    int mx=0;
    for (int i = 0; i < 1<<n; i++) {
        cin >> S[i];
        st.insert(mp(-S[i],i));
        mx = max(mx,S[i]);
    }
    vector<int> v;
    v.pb(mx);
    auto k = st.upper_bound(mp(-mx,-1));
    st.erase(k);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 1<<i; j++) {
            auto k = st.upper_bound(mp(-v[j],LINF));
            if(k==st.end()){
                puts("No");
                return 0;
            }
            v.pb(-k->fs);
            st.erase(k);
        }
    }
    puts("Yes");
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	ll x, y;
	//ll a, b, c;
	//ll k;
	string s;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	string sa, sb, sc;
	cin >> sa >> sb >> sc;

	s_ans = "a";
	while (1) {
		if (s_ans == "a") {
			if (sa.size() == 0) {
				s_ans = "A";
				break;
			}
			s_ans = sa[0];
			sa = sa.substr(1, sa.size() - 1);
		}
		else if (s_ans == "b") {
			if (sb.size() == 0) {
				s_ans = "B";
				break;
			}
			s_ans = sb[0];
			sb = sb.substr(1, sb.size() - 1);
		}
		else {
			if (sc.size() == 0) {
				s_ans = "C";
				break;
			}
			s_ans = sc[0];
			sc = sc.substr(1, sc.size() - 1);
		}
	}

	cout << s_ans << "\n";

}

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

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 3676
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
struct Gedge {
	int src, to;
	T cost;
	int id;
	Gedge(int s, int t, T c, int i = -1) :src(s), to(t), cost(c), id(i) {}
	Gedge(int t, T c) :src(-1), to(t), cost(c), id(-1) {}
};

template<class T>
using WeightedGraph = vector<vector<Gedge<T>>>;
using UnweightedGraph = vector<vector<LL>>;
template<class T>
using Gedges = vector<Gedge<T>>;

template<class T>
struct TNode {
	int parent;
	VI childs;
	T cost;
	int id;
	TNode() :parent(-1), cost(0), id(-1) {};
};
template<class T>
using Tree = vector<TNode<T>>;

//到達不可能->INF
template<class T>
void dijkstra(WeightedGraph<T>& G, int start, vector<T>& res) {
	res.resize(G.size(), INF);
	res[start] = 0;
	typedef pair<T, int> P;
	priority_queue<P, vector<P>, greater<P>> q;
	q.emplace(0, start);
	while (!q.empty()) {
		int cur;
		T cost;
		tie(cost, cur) = q.top();
		q.pop();
		if (res[cur] < cost)continue;
		for (Gedge<T>& e : G[cur]) {
			if (res[e.to] > cost + e.cost) {
				res[e.to] = cost + e.cost;
				q.emplace(res[e.to], e.to);
			}
		}
	}
	return;
}

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	WeightedGraph<LL> G(10);
	for (int s = 0; s <= 9; s++) {
		for (int t = 0; t <= 9; t++) {
			int c;
			cin >> c;
			G[t].push_back(Gedge<LL>(s, c));
		}
	}
	VLL res;
	dijkstra(G, 1, res);
	LL ans = 0;
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			int c;
			cin >> c;
			if (c != -1) {
				ans += res[c];
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
const int INF=1e9;
#define ll long long
int main(){
    int k;cin>>k;
    string s;cin>>s;
    if((int)s.size()<=k){
        cout<<s<<endl;
    }else{
        cout<<s.substr(0,k)<<"..."<<endl;
    }
} 

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>

#define rep(i,n) for (int i=0;i< (n);i++)

const int INF = 1e9;

using namespace std;

int m,n;
int c[21];

int dp[21][100005];

int dfs(int i,int sum){
	if(i==m){
		if(n==sum)
			return 0;
		else
			return INF;
	}
	
	if(dp[i][sum] != -1) return dp[i][sum];
	
	int ret;
	
	ret=dfs(i+1,sum);
	
	if(sum + c[i] <= n){
		ret = min(ret,dfs(i,sum+c[i])+1);
	}
	return dp[i][sum] = ret;
}	
int main() {
	rep(i,21) rep(j,100005) dp[i][j] = -1;
	cin >> n >> m;
	rep(i,m) cin >> c[i];
	cout << dfs(0,0) << endl;
	return 0;
}

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

int main(){
  long long s;
  cin>>s;
  const int v=1000000000;
  int x=(v-s%v)%v;
  int y=(s+x)/v;
  cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define local
#define forn(a,n) for(int i = a; i < n; i++)
#define mod 1000000007


using namespace std;

typedef long long int ll;
typedef vector<int> vec;
typedef vector<ll> vecl;
typedef unsigned long long int ull;
typedef vector<ull> vecu;


void print(const vecl &a)
{
    forn(0,a.size())
        cout << a[i] << " ";
    cout << "\n";
}
int small(int a)
{
    if(a % 2 == 0)
        return 2;
    for(int i = 3; i * i <= a; i +=2 )
    {
        if(a % i == 0)
        {
            return i;
        }
    }
    return a;
}
void solve()
{
  string s, t;
  cin >> s;
  cin >> t;
  int n = t.size();
  int mi = 1001;
  int k;
  for(int i = 0; i <= s.size() - n; i++)
  {
      k = 0;
      for(int j = 0; j < t.size(); j++)
      {
          if(s[i + j] != t[j])
            k++;
      }
      mi = min(k, mi);
  }
  cout << mi;
}



int main()
{
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif
            solve();
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#if 0
#define PRINT_TREE
#endif

int A(int sl, int sr) { return sl & sr; }
int O(int sl, int sr) { return sl | sr; }
int X(int sl, int sr) { return sl ^ sr; }

int (*keisan[3])(int, int) = {A, O, X};

char tree_data[100000];
int N;
int bubunnsyuugou[10];

int tree_pos;
int tree_ungetchar_pos = 0;
int tree_ungetchar_data[100000];
int tree_getchar(void) {
	return tree_ungetchar_pos > 0 ? tree_ungetchar_data[--tree_ungetchar_pos] : tree_data[tree_pos++];
}

void tree_ungetchar(int c) {
	tree_ungetchar_data[tree_ungetchar_pos++] = c;
}

typedef struct node_t_tag {
	int num;
	struct node_t_tag *left, *right;
} node_t;

int in_node_num;
node_t* in_node[16];

node_t* parse_tree(void) {
	int input;
	node_t* node = malloc(sizeof(node_t));
	if (node == NULL) exit(1);
	input = tree_getchar();
	if (input == '(') {
		node->num = -1;
		node->left = parse_tree();
		input = tree_getchar(); assert(input == ' ');
		node->right = parse_tree();
		input = tree_getchar(); assert(input == ')');
		in_node[in_node_num++] = node;
	} else {
		node->num = input - '1';
		node->left = node->right = NULL;
	}
	return node;
}

#ifdef PRINT_TREE
/* for testing */
void print_tree(const node_t* node) {
	if (node == NULL) {
		putchar('X');
	} else if (node->left == NULL && node->right == NULL) {
		printf("%d", node->num + 1);
	} else {
		putchar('(');
		print_tree(node->left);
		putchar(' ');
		print_tree(node->right);
		putchar(')');
	}
}
#endif

int evaluate_tree(const node_t* node) {
	if (node == NULL) {
		return 0;
	} else if (node->left == NULL || node->right == NULL) {
		return bubunnsyuugou[node->num];
	} else {
		return keisan[node->num](evaluate_tree(node->left), evaluate_tree(node->right));
	}
}

void free_tree(node_t* node) {
	if (node != NULL) {
		free_tree(node->left);
		free_tree(node->right);
		free(node);
	}
}

int main(void) {
	while (fgets(tree_data, sizeof(tree_data), stdin) != NULL && tree_data[0] != 'E') {
		char data_buffer[1024];
		int i;
		node_t* root;
#ifndef PRINT_TREE
		int search, search_max;
		int answer;
#endif
		if (fgets(data_buffer, sizeof(data_buffer), stdin) == NULL ||
			sscanf(data_buffer, "%d", &N) != 1) return 1;
		for (i = 0; i < N; i++) {
			int a, b, c, d;
			if (fgets(data_buffer, sizeof(data_buffer), stdin) == NULL ||
			sscanf(data_buffer, "%d%d%d%d", &a, &b, &c, &d) != 4) return 1;
			bubunnsyuugou[i] = (a << 3) | (b << 2) | (c << 1) | d;
		}
		tree_pos = 0;
		in_node_num = 0;
		root = parse_tree();
#ifdef PRINT_TREE
		print_tree(root);
		putchar('\n');
#else
		search_max = 1;
		for (i = 0; i < in_node_num; i++) search_max *= 3;
		answer = 0;
		for (search = 0; search < search_max; search++) {
			int cur = search;
			for (i = 0; i < in_node_num; i++) {
				in_node[i]->num = cur % 3;
				cur /= 3;
			}
			if (evaluate_tree(root) == (1 << 4) - 1) answer++;
		}
		printf("%d\n", answer);
#endif
		free_tree(root);
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <string>

using namespace std;

typedef long long int ll;

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

  string text;
  cin >> text;

  if (text == "SUN") {
    cout << 7 << endl;
  } else if (text == "MON") {
    cout << 6 << endl;
  } else if (text == "TUE") {
    cout << 5 << endl;
  } else if (text == "WED") {
    cout << 4 << endl;
  } else if (text == "THU") {
    cout << 3 << endl;
  } else if (text == "FRI") {
    cout << 2 << endl;
  } else if (text == "SAT") {
    cout << 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 public class Main { 
     public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
       while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
             } 
            for(int i = 0;i<H;i++){
                 for(int j = 0;j<W;j++) {
                      System.out.printf("#"); 
                    } System.out.printf("\n");
                 } System.out.printf("\n"); 
                }
             }
             }


Measured memory_bytes: 59772
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;




int main(){
    int n;
    while(cin>>n){
        string input;
        for(int roop=0; roop<n; roop++){
            cin>>input;
            bool go_end = true;
            int now=0;
            int len=0;
            string out_put;
            for(int i=0; i<input.length(); i++){
                if(input[i]=='-')continue;
                else if(input[i]=='<'){
                    now--;
                    go_end=false;
                }
                else if(input[i]=='>'){
                    go_end=true;
                    now++;

                }
                else{
                    if(go_end&&now==len){
                        out_put+=input[i];
                        len++;
                    }else if(!go_end&&now==-1){
                        out_put=input[i]+out_put;
                        len++;
                        now++;
                    }
                }
            }
            cout<<out_put<<endl;

        }
        
    }
}

Measured memory_bytes: 1216
c = [list(map(int, input().split())) for i in range(3)]
print("Yes" if c[1][0]-c[0][0]==c[1][1]-c[0][1]==c[1][2]-c[0][2] and c[2][0]-c[0][0]==c[2][1]-c[0][1]==c[2][2]-c[0][2]
     else "No")

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n, x;
	cin >> n >> x;
	int i;
	int a[110000];
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (i = 1; i < n; i++) {
		int tmp = a[i - 1] + a[i];
		int T = max(tmp - x, 0);
		ans += T;
		a[i] = max(a[i] - T, 0);
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 640
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int dy[]={-1,-1,-1,0,0,1,1,1};
        int dx[]={-1,0,1,-1,1,-1,0,1};
        while (true)
        {
            int w=sc.nextInt();
            int h=sc.nextInt();
            if (w==0 && h==0) {break;}
            int field[][]=new int[h+2][w+2];
            int searched[][]=new int[h+2][w+2];
            for (int y=0;y<h+2;++y)
            {
                for (int x=0;x<w+2;++x)
                {
                    if (1 <= y && y <= h && 1 <= x && x <= w) { field[y][x]=sc.nextInt(); }
                    else {field[y][x]=0;}
                    searched[y][x]=0;
                }
            }
            int count=0;
            for (int y=1;y<=h;++y)
            {
                for (int x=1;x<=w;++x)
                {
                    if (searched[y][x]==0 && field[y][x]==1)
                    {
                        Queue<Integer> queuey=new ArrayDeque<>();
                        Queue<Integer> queuex=new ArrayDeque<>();

                        searched[y][x]=1;
                        queuey.add(y);
                        queuex.add(x);

                        while (!queuey.isEmpty())
                        {
                            int q=queuey.remove();
                            int p=queuex.remove();
                            for (int k=0;k<dy.length;++k)
                            {
                                int t=q+dy[k];
                                int r=p+dx[k];
                                if (searched[t][r]==0)
                                {
                                    searched[t][r]=1;
                                    if (field[t][r]==1)
                                    {
                                        queuey.add(t);
                                        queuex.add(r);
                                    }
                                }
                            }
                        }
                        ++count;
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 46236
"""
A - Buttons
https://atcoder.jp/contests/abc124/tasks/abc124_a
"""
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    a = input_list[0]
    b = input_list[1]
    button_suspects = sorted([a, a-1, b, b-1], reverse=True)
    answer = button_suspects[0] + button_suspects[1]
    print(answer)

Measured memory_bytes: 3060
<?php

$score = array_fill_keys(array('h', 't'), 0);


fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    list($card['t'], $card['h']) = explode(' ', trim(fgets(STDIN)));

    foreach (getPoint($card) as $player => $point) {
        $score[$player] += $point;
    }
}

printf('%d %d%s', $score['t'], $score['h'], PHP_EOL);


function getPoint($card)
{
    if ($card['t'] == $card['h']) {
        return array('h' => 1,'t' => 1);
    }

    arsort($card);
    $winner = key(array_slice($card, 0, 1));

    return array($winner => 3);
}

Measured memory_bytes: 6656
N,M = map(int,input().split())
s = input()
t = input()
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
k = gcd(max(N,M),min(N,M))
lcm = N*M // gcd(max(N,M),min(N,M))
n = N//k
m = M//k
for i in range(k):
    if not s[n*i]==t[m*i]:
        print(-1)
        exit()
print(lcm)

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

int main() {
  int n,k;
  cin>>n>>k;
  int a[n];
  int b[n]={0};
  for(int i=0;i<n;i++) {
    cin>>a[i];
    b[a[i]-1]++;
  }
  sort(b,b+n,greater<int>());
  int res=0;
  int count=0;
  for(int i=0;i<n;i++){
    if(b[i]!=0){
      count++;
    }
    if(count>k){
      res+=b[i];
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
 
  int A,B;
  
  cin >> A >>B;
  if(A%3==0){
    cout << "Possible" << endl;
  }else if(B%3==0){
    cout << "Possible" << endl;
  }else if((A+B)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
        
  return 0;
}
 

Measured memory_bytes: 256
M = 999999
h, w = gets.chomp!.split(" ").map!(&:to_i)
a_hw = readlines
max_hw = Array.new(h) {|index| Array.new(w, M) }  

black = []
a_hw.each_with_index do |arr, h2|
    arr.each_char.with_index(0) do |ch, w2|
        if ch == "#"
            black.unshift([h2, w2, 0])
            max_hw[h2][w2] = 0
        end
    end
end
 
while black.empty?.!
    h2, w2, count = black.shift
    count += 1

    if h2 != 0 
        if max_hw[h2-1][w2] == M
            max_hw[h2-1][w2] = count
            black.push([h2 - 1, w2, count])
        end
    end
    if h2 != h - 1
        if max_hw[h2 + 1][w2] == M
            max_hw[h2+1][w2] = count
            black.push([h2 + 1, w2, count])
        end
    end
    if w2 != 0 
        if max_hw[h2][w2 - 1] == M
            max_hw[h2][w2 - 1] = count
            black.push([h2, w2 - 1, count])
        end
    end
    if w2 != w - 1
        if max_hw[h2][w2 + 1] == M
            max_hw[h2][w2 + 1] = count
            black.push([h2, w2 + 1, count])
        end
    end
end
 
#puts i
#puts max_hw.map {|x| x.join(",") }
puts count - 1
#puts max_hw.map{|x| x.max }.max


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

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

  REP(i, s.length()) s[i] = (char)('A' + (s[i] - 'A' + n) % ('Z' - 'A' + 1));
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256