akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  c
//
//  Created by 13B10694 on 2015/06/01.
//  Copyright (c) 2015????´ 13B10694. All rights reserved.
//

#include <iostream>
#include <vector>
#include<stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;

int now=1;

class team{
    
public:
    int id, pen, sol;
    int wrong[12];
    vector <int> solved;
    team(){
        memset(wrong, 0, sizeof(wrong));
        id=now++;
        pen=0;sol=0;
    }
    ~team(){
        solved.clear();
    }
    
    bool operator < (const team& b) const
    {
        return solved.size()==b.solved.size() ? pen== b.pen ? id<b.id : pen<b.pen : solved.size()>b.solved.size();
    }
};

int main() {
    int t,p,r;
    while(cin>>t>>p>>r,t){
        now=1;
        vector<team> tea(t);

        for(int i=0;i<r;i++){
            int ti, pi, tim;
            string mes;
            cin>>ti>>pi>>tim>>mes;
            ti-=1;
            if(mes=="WRONG"){
                tea[ti].wrong[pi]++;
                continue;
            }
            if(find(tea[ti].solved.begin(),tea[ti].solved.end(),pi)!=tea[ti].solved.end()){
                continue;
            }
            tea[ti].solved.push_back(pi);
            tea[ti].pen += tea[ti].wrong[pi]*1200+tim;
  
        }
        sort(tea.begin(),tea.end());
        for(int i=0;i<t;i++){
            cout<<tea[i].id<<" "<<tea[i].solved.size()<<" "<<tea[i].pen<<endl;
        }
       // tea.clear();
    }
    
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod


int n, m;
vector<vector<int>> g(100000 + 6);

int ord[100000 + 6], low[100000 + 6];
bool visited[100000 + 6];

vector<pair<int, int>> Bridges;
vector<int> Points;

void dfs(int now, int par, int &cnt) {
    visited[now] = true;
    ord[now] = cnt++;
    low[now] = ord[now];
    bool check = false;
    int outdeg = 0;
    for (auto nx : g[now]) {
        if (nx == par) continue;
        if (!visited[nx]) {
            outdeg++;
            dfs(nx, now, cnt);
            low[now] = min(low[now], low[nx]);
            //???????????????
            if (ord[now] < low[nx]) {
                Bridges.push_back({min(now, nx), max(now, nx)});
            }
            //??¢??????????????????
            if (par != -1 && !check && ord[now] <= low[nx]) {
                check = true;
                Points.push_back(now);
            }
        }
        else {
            low[now] = min(low[now], ord[nx]);
        }
    }
    //???????????????????????\?????¢????????¨???????????????
    if (par == -1 && outdeg >= 2) {
        Points.push_back(now);
    }
    return;
}

void lowlink (int n, vector<vector<int>>& g) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(i, -1, cnt);
        }
    }
    sort(all(Bridges));
    sort(all(Points));
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    lowlink(n, g);
    rep(i, Bridges.size()) {
        cout << Bridges[i].fi << " " << Bridges[i].se << endl;
    }
    /*
    rep(i, Points.size()) {
        cout << Points[i] << endl;
    }
    */
}

Measured memory_bytes: 6828
fun main(args: Array<String>) {

    // 標準入力覚える
    val firstLine = readLine()!!.split(" ")
    val n = firstLine[0].toInt()
    val x = firstLine[1].toInt()

    // atCoderで使えないかも
//    val list = List(n) {
//        readLine()!!.toInt()
//    }
    var list = mutableListOf<Int>()
    // range覚えて!! 3回ループだと1..3になるみたい i < 3ではなく i == 3なのか？
    for (i in 1..n) {
        list.add(readLine()!!.toInt())
    }
    val kindCount = list.size

    val summary = list.sum()
    // sumはOKだけどmin maxはInt?型になるみたい
    val min = list.min()!!.toInt()
    val remainder = x - summary

    println(kindCount + remainder / min)
}

Measured memory_bytes: 37864
#include <iostream>
#include <vector>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll solve(ll ai, ll aj, ll bi, ll bj) {
    if (aj > bj) {
        swap(ai, bi);
        swap(aj, bj);
    }

    ll s = 1;
    rep(i,30) s *= 3;
    ll dist = abs(ai-bi) + abs(aj-bj);
    ll res = dist;
    while(1) {
        s /= 3;
        if (s <= 0) break;

        ll nai = ai / s, nbi = bi / s;
        if (nai != nbi) break;

        ll naj = aj / s, nbj = bj / s;
        if (nai % 3 == 1 && abs(naj-nbj) > 1) {
            ll up = s*nai-1;
            ll bot = s*(nai+1);
            ll loss = min(ai,bi) - up;
            loss = min(loss, bot - max(ai, bi));
            res = dist + loss * 2;
            break;
        }
    }
    return res;
}

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

    rep(qi, q) {
        ll ai, aj, bi, bj;
        cin >> ai >> aj >> bi >> bj;
        ai--; aj--; bi--; bj--;

        ll ans = 0;
        ans = max(ans, solve(ai,aj,bi,bj));
        ans = max(ans, solve(aj,ai,bj,bi));
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 1<<19;
const int MM = 998244353;

int main()
{
	int H, W;
	scanf("%d%d", &H, &W);
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			char buf[100];
			scanf("%s", buf);
			if(strcmp(buf, "snuke") == 0) return !printf("%c%d\n", 'A'+j-1, i);
		}
	}
}


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

using namespace std;
using ll = long long;


int main()
{
	int n;
	cin >> n;
	map<int, int> x, y;
	for(int i = 0; i < n; i++) {
		int a; cin >> a;
		x[i - a]++;
		y[i + a]++;
	}

	ll sum = 0;

	for(int cur = 0; cur <= 200000; cur++) {
		sum += (ll)x[cur] * y[cur]; 
	}

	cout <<sum << endl;

}

Measured memory_bytes: 35536
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (A, B, C) = (ABC[0], ABC[1], ABC[2]);
            var answer = false;
            answer |= A + B == C;
            answer |= A + C == B;
            answer |= B + C == A;
            Console.WriteLine(answer ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28268
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>

using namespace std;
using ll = long long int;

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

ll N, M, Q;
ll mx = 0;

ll d[10];

vector<ll> A(50), B(50), C(50), D(50);

void search(ll i, ll a) {
  if (i >= N) {
    ll sum = 0;
    rep(j, Q) {
      if (d[B[j] - 1] - d[A[j] - 1] == C[j]) {
        sum += D[j];
      }
    }

    if (mx < sum) {
      mx = sum;
    }

    return;
  }

  for (ll x = a; x <= M; x++) {
    d[i] = x;
    search(i + 1, x);
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cin >> N >> M >> Q;

  rep(i, Q) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
  }

  search(0, 1);

  cout << mx << endl;

  return 0;
}

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

using namespace std;

string S;
bool isUsed[27] = {0}, flag = true;

int main(){
    cin >> S;

    for(int i = 0; i < S.size(); i++){
        char buff = S[i];

        if(isUsed[buff - 'a']){
            flag = false;
            break;
        }
        isUsed[buff - 'a'] = true;
    }

    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
}


Measured memory_bytes: 256
from itertools import accumulate

N, K = map(int, input().split())
mod = 10**9 + 7

xs = []
x = 1
while x * x <= N:
    xs.append(N // x)
    x += 1
s = x - 1
y = 1
while y < N // y:
    xs.append(y)
    y += 1
xs = list(set(xs))
xs.sort()
compress = {x : i for i, x in enumerate(xs)}

dp = [[0] * len(compress) for _ in range(K)]
for x, i in compress.items():
    dp[-1][i] = x

for k in range(K-1)[::-1]:
    cum = list(accumulate([0] + dp[k+1]))
    for x, i in compress.items():
        a = max(compress[N // x], compress[N // s])
        dp[k][i] = (cum[-1] - cum[a]) % mod

    b = 1
    cum = [0] * len(compress)
    while b < N // b:
        cnt = N // b - N // (b + 1)
        cum[compress[b]] = (cum[compress[b]] + cnt * dp[k+1][compress[b]]) % mod
        b += 1
    cum = list(accumulate([0] + cum))
    for x, i in compress.items():
        b = N // x
        if x <= b:
            continue
        dp[k][i] += cum[-1] - cum[compress[b]+1]
        dp[k][i] += (x - N // (b + 1)) * dp[k+1][compress[b]]
        dp[k][i] %= mod
print(dp[0][-1])

Measured memory_bytes: 146272
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    L = len(S)
    if S[0] == 'A':
        CNT = 0
        CAP = 0
        for c in range(2,L-1):
            if S[c] == 'C':
                CNT += 1
        for c in S:
            if ord(c) >= 97:
                CAP += 1
        if CNT == 1 and CAP == L-2:
            print('AC')
        else:
            print('WA')
    else:
        print('WA')

if __name__ == '__main__':
    main()

Measured memory_bytes: 8968
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int n,m;
  
  cin>>n>>m;
  
  if(n==m)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   ll k;
           cin>>k;
           vll a(k);
           rep(i,0,k)cin>>a[i];
           if(a[k-1]!=2){
            cout<<-1<<endl;
             return 0;
           }
           ll mn=2,mx=3;
           reverse(all(a));
           rep(i,1,k){
             ll r=a[i];
            if(r>mx){
             cout<<-1<<endl;return 0; 
            }
            if(a[i]>=mn){
             mn=a[i]; 
            }
            else{
               ll g=(mn+a[i]-1)/a[i];
               a[i]=g*a[i];
               mn=a[i];
               if(a[i]>mx){
                cout<<-1<<endl;
                 return 0;
               }
             }
             a[i]=r;
             //mn
             /*while(a[i]+r<=mx)a[i]+=r;
             mx=a[i]+r-1;*/
             ll kk=(mx-a[i])/r;
             a[i]+=kk*r;
             mx=a[i]+r-1;
            //cout<<mx<<endl;
           }
           cout<<mn<<" "<<mx<<endl;
}

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

int main(){

    while(1){
        int n,l,r;
        cin >> n >> l >> r;
        if(n==0)break;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        int ans=0;
        for(int i=l;i<=r;i++){
            for(int j=0;j<=n;j++){
                if(j==n){
                    if(n%2==0)ans++;
                    break;
                }
                if(i%a[j]==0){
                    if(j%2==0){
                        ans++;
                    }
                    break;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

vector<long> h;
vector<long> dp;
int main(void){
    long N,K;
    cin >> N >> K;
    h = vector<long>(N);
    dp = vector<long>(N+2,1000000000);
    for(long i = 0;i < N;i++){
        cin >> h[i];
    }

    dp[0] = 0;

    for(long i=1;i<N;i++){
        for(long k=1;k<=K;k++){
            if(i >= k){
                dp[i] = min(dp[i],dp[i-k] + abs(h[i-k]-h[i]));
            }
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int a,b;
	cin>>a>>b;
  	if(a>b){
      REP(i,1,a){
        cout<<b;
      }
    }
     else{
       REP(i,1,b){
        cout<<a;
      }
     }
       
	return 0;

//   TimeTaken();
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 998244353
#define ep 0.000000001
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
//#define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    string s;
    cin>>s; char ch='s';
    if(s[s.sz-1]!='s')s.pb(ch);
    else{
        s.pb('e'); s.pb(ch);
    }
    cout<<s<<endl;
    return 0;
}
//https://thebestoffersintheweb.com/redirect/57a764d042bf8/

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   string s;cin >>s;
   if(s.size()==3)reverse(all(s));
   cout << s<< endl;
    return 0;
}


Measured memory_bytes: 256
import math
import copy
import sys


inputa = input().split()
# inputb = input().split()
# inputc = input().split()

# a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

a = str(inputa[0])
inputaList = list(a)

s = 0
for i in range(len(inputaList)):
    s += int(inputaList[i])

if int(a) % s == 0:
    print("Yes")
else:
    print("No")

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

using namespace std;

string x,y,z;
int ans=0,a,b;

int main()
{
	cin>>x>>y;
	cin>>a>>b;
	cin>>z;
	if(z==x)	cout<<a-1<<" "<<b;
	else	cout<<a<<" "<<b-1; 
	return 0;
 } 

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int cnt=0;
    for (int i=max(A,B); i>0; i--) {
        if (A%i==0 && B%i==0) {
            cnt++;
        }
        if (cnt==K) {
            cout << i;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <map>
#include <cstdio>
using namespace std;
void solve(int T){
	map<pair<int,int>,int>m;
	char cmd[2];
	int n;
	for(;T--;){
		scanf("%s%d",cmd,&n);
		if(*cmd=='D'){
			for(typeof(m.begin()) it=m.begin();it!=m.end();){
				if(it->second==n){
					typeof(m.begin()) it2=it;
					++it;
					m.erase(it2);
				}else{
					++it;
				}
			}
		}else if(*cmd=='R'){
			pair<int,int> f=make_pair(n,2000000000);
			typeof(m.begin()) it=m.lower_bound(f);
			if(it==m.begin()){
				puts("-1");
			}else{
				--it;
				printf("%d\n",it->first.first<=n&&n<=it->first.second ? it->second : -1);
			}
		}else if(*cmd=='W'){
			int z;
			scanf("%d",&z);
			int cur=0;
			for(typeof(m.begin()) it=m.begin();it!=m.end();++it){
				int d=it->first.first-cur;
				if(d>z)d=z;
				if(d)m[make_pair(cur,cur+d-1)]=n;
				z-=d;
				if(z==0)break;
				cur=it->first.second+1;
			}
			if(z)m[make_pair(cur,cur+z-1)]=n;
		}
	}
}
int main(){for(int T;~scanf("%d",&T)&&T;puts(""))solve(T);}

Measured memory_bytes: 1256
#include <stdio.h>
struct era{
	char name[20];
	int base;
	int west;
	int begin;
};
int main(void){
	struct era data[1000];
	int n,q,i,j,y;
	while(1){
		scanf("%d %d",&n,&q);
		if(!n){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%s %d %d",data[i].name,&data[i].base,&data[i].west);
			data[i].begin=data[i].west-data[i].base+1;
		}
		for(i=0;i<q;i++){
			scanf("%d",&y);
			for(j=0;j<n;j++){
				if(data[j].begin<=y&&y<=data[j].west){
					printf("%s %d\n",data[j].name,y-data[j].begin+1);
					break;
				}
			}
			if(j==n){
				puts("Unknown");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;


public class Main {
	static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int start = Character.getNumericValue(s.charAt(0));
		Main main = new Main();
		main.DC_op(s,1,start,s.substring(0, 1));
		sb.append("=7");
		System.out.println(sb.toString());

	}

	public void DC_op(String s,int steps,int results,String form) {
		if (steps == s.length()) {
			if (results == 7) {
				sb.delete(0, sb.length());
				sb.append(form);
			}
		}else {
			int target = Character.getNumericValue(s.charAt(steps));
			//+
			DC_op(s, steps + 1, results + target, form = form + "+" + target);
			form = form.substring(0, form.length() - 2);
			//-
			DC_op(s, steps + 1, results - target, form = form + "-" + target);
			form = form.substring(0, form.length() - 2);
		}

		return;
	}
}


Measured memory_bytes: 38824
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
 
using namespace std;
 
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)
 
int64_t gcd(int64_t a, int64_t b)
{
    if (a == 0) {
        return b;
    }
    return gcd(b % a, a);
}
 
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
 
    vector<int> b(n), c(n);
    rep(i, n)
    {
        if (i == 0) {
            b[i] = c[i] = 0;
        } else {
            b[i] = gcd(b[i - 1], a[i - 1]);
            c[i] = gcd(c[i - 1], a[n - i]);
        }
    }
 
    int64_t m = 1;
    rep(i, n)
    {
        m = max(m, gcd(b[i], c[n - 1 - i]));
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans = INT_MAX;
    int diff;
    for (int i = 0; i < N - K + 1; ++i) {
        diff = h[i + K - 1] - h[i];
        if (diff < ans) {
            ans = diff;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long int li;
typedef long long ll;
typedef long double ld;

int main()
{
	int n, ans = 0;
	cin >> n;
	ll a[n], x, y, z;
	vector<tuple<ll, ll, ll>> v;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 2; i++)
		for (int j = i + 1; j < n - 1; j++)
			for (int k = j + 1; k < n; k++)
			{
				x = a[i];
				y = a[j];
				z = a[k];
				if (x + y > z && x + z > y && y + z > x	&& x != y && y != z && x != z)
					v.push_back(make_tuple(x, y, z));
			}
	cout << v.size() << "\n";
}


Measured memory_bytes: 9560
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
height2=height.copy()
ans = 10 ** 100
# if N==K:
#     cost=0
#     for i in range(1,N):
#         tarou=max(height2[:i])
#         if tarou>=height2[i]:
#             cost+=tarou-height2[i]+1
#             height2[i]=tarou+1
#     print(cost)
#     exit()
for i in range(2 ** N):
    cost = 0
    height2 = height.copy()
    if bin(i).count("1")==K:
        for j in range(1,N):
            if i >> j & 1:
                    tarou=max(height2[:j])
                    if height2[j]<=tarou:
                        cost+=tarou-height2[j]+1
                        height2[j]=tarou+1
        # if N==K:
        #     print(cost)
        #     exit()
        if ans > cost:
            ans = cost

print(ans)

Measured memory_bytes: 3064
module Main where

import Data.Functor
import Data.List

main :: IO ()
main = do
  { [ss] <- getInts
  ; let (mm,s) = divMod ss 60
  ; let (h,m) = divMod mm 60
  ; putStrLn (intercalate ":" (map show [h, m, s]))
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3616
// AOJ GRL_6_A: Network Flow - Maximum Flow
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

// Ford-Fulkerson algorithm: maximum flow
struct edge
{
  int to, capacity, rev;
  edge(){}
  edge(int to, int capacity, int rev):to(to), capacity(capacity), rev(rev){}
};

struct FordFulkerson
{
  vector< vector<edge> > graph;
  vector<bool> used;
  FordFulkerson(int V):graph(V), used(V, false){}
  void add_edge(int from, int to, int capacity)
  {
    graph[from].push_back(edge(to, capacity, (int)graph[to].size()));
    graph[to].push_back(edge(from, 0, (int)graph[from].size()-1));
  }
  int dfs(int v, int sink, int f)
  {
    if(v == sink) return f;
    used[v] = true;
    for(int i = 0; i < graph[v].size(); i++) {
      edge& e = graph[v][i];
      if(!used[e.to] && e.capacity > 0) {
	int d = dfs(e.to, sink, min(f, e.capacity));
	if(d > 0) {
	  e.capacity -= d;
	  graph[e.to][e.rev].capacity += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int source, int sink)
  {
    int flow = 0;
    while(1) {
      fill(used.begin(), used.end(), false);
      int f = dfs(source, sink, inf);
      if(f == 0) return flow;
      flow += f;
    }
  }
};



int main()
{
  int V, E; cin >> V >> E;
  FordFulkerson mxf(V);
  while(E--) {
    int u, v, c;
    cin >> u >> v >> c;
    mxf.add_edge(u, v, c);
  }
  cout << mxf.max_flow(0, V-1) << endl;
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define fi first
#define se second
#define ll long long
#define ii pair<int, int>

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("Test.inp", "r", stdin);
	//freopen("RATING.out", "w", stdout);
	int h, n;
	cin >> h >> n;
	int t = 0;
	rep(i, 1, n) {
		int x;
		cin >> x;
		t += x;
	}
	if (t >= h) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
a,b, c,d = map(int, input().split())
num_list = [1,7,9,4]
if (a in num_list)==True:
    num_list.remove(a)
    if (b in num_list)==True:
        num_list.remove(b)
        if (c in num_list)==True:
            num_list.remove(c)
            if (d in num_list)==True:
                print("YES")
            else:
                print("NO")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")


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

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

#define MAXN 30000
int main(){
    int N;
    string G;
    cin >> N >> G;
    int S[MAXN];
    rep(i,N)S[i] = int(G[i])-'0';
    int ans = 0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                int oki = 0;
                int okj = 0;
                int okk = 0;
                int check = 1;
                for(int l=0;l<N;l++){
                    if(oki==0&&i==S[l]){
                        oki=1;
                    }else if(okj==0&&oki==1&&S[l]==j){
                        okj=1;
                    }else if(okk==0&&okj==1&&S[l]==k){
                        okk = 1;
                    }
                    if(oki==1&&okj==1&&okk==1&&check == 1){
                        ans++;
                        check  = 0;
                    }
                }
            }
        }
    }
    
    cout <<ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/***template***/
#define ll                   long long
#define LL                   long long
#define dd                   double
#define scl(n)               scanf("%lld",&n)
#define sl(n)                scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define pi                   pair<ll,ll>
#define pll                  pair<ll,ll>
#define pb                   push_back
#define mp                   make_pair
#define uu                   first
#define vv                   second
#define fr                   first
#define sc                   second
#define FOR(i,n)             for(ll i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define FOOR(i,a,b)          for(ll i=a;i<=b;i++)
#define LOP(i,a,b)           for(ll i=a;i<b;i++)
#define sorted(s)            sort(s.begin(),s.end())
#define sortedd(s)           sort(s.begin(),s.end(),cmp)
#define reversed(s)          reverse(s.begin(),s.end())
#define contains(a,b)        (find((a).begin(), (a).end(), (b)) != (a).end())
#define MAXN                 100005
#define pii                  3.1415926536
#define mod                  1000000007
#define eps                  0.0000000001
#define inf                  9000000000000000
#define INF                  (1LL<<62)
#define mstt(a,b)            memset((a),(b),sizeof (a))
#define sz(x)                (ll)x.size()
#define mx                    92681+10
struct node
{
    ll nod,d;
    node(ll a,ll b)
    {
        nod=a;
        d=b;
    }
    bool operator<(const node &p)const
    {
        return p.d<d;
    }
};
ll Set(ll n,ll pos)
{
    return n=n|(1LL<<pos);
}
ll reset(ll n,ll pos)
{
    return n=n&~(1LL<<pos);
}
bool check(ll n,ll pos)
{
    return (bool)(n&(1LL<<pos));
}
ll power(ll x,ll y)
{
    ll res = 1;
    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
/***template***/

int main()
{
    ll k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
    {
        cout<<s<<endl;
    }
    else
    {
        string s2;
        for(int i=0;i<k;i++)
        {
            s2.push_back(s[i]);
        }
        s2+="...";
        cout<<s2<<endl;
    }
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  int odd = 0;
  int two = 0;
  int four = 0;
  REP(i,n) {
    int a;
    cin>>a;
    if (a%2 == 1) {
      ++odd;
    } else if (a%4 == 2) {
      ++two;
    } else {
      ++four;
    }
  }
  int half_lo = n / 2;
  int half_hi = (n+1) / 2;
  if (odd == half_hi && four == half_lo) {
    cout<<"Yes\n";
  } else if (odd > four) {
    cout<<"No\n";
  } else {
    cout<<"Yes\n";
  }
  return 0;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
a = []
b = []
for i in range(n):
  if i % 2 == 0:
    a.append(l[i])
  else:
    b.append(l[i])

if n % 2 == 0:
  ans = b[::-1] + a
  print(' '.join(map(str, ans)))
else:
  ans = a[::-1] + b
  print(' '.join(map(str, ans)))

Measured memory_bytes: 32196
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int r, n;

double calc(int a, int height){
    double x = sqrt((double)(r * r - a * a));
    return (double)height - x;
}

int main() {
    while (1) {
        cin >> r >> n;
        if(r + n == 0) break;
        double ans = 20.0;
        int height[41] = {};
        rep(i, 0, n){
            int xl, xr, h;
            cin >> xl >> xr >> h;
            xl += 20;
            xr += 20;
            rep(j, xl, xr){
                height[j] = max(height[j], h);
            }
        }
        rep(i, 20 - r, 20 + r){
            int a = abs(i - 20);
            double limit = calc(a, height[i]);
            ans = min(ans, limit);
            
            // cout << i << ' ' << height[i] << ' ' << a << ' ' << limit << endl;

            int a2 = abs(i + 1 - 20);
            double limit2 = calc(a2, height[i]);
            ans = min(ans, limit2);
        }
        printf("%.10f\n", ans + r);
    }
}


Measured memory_bytes: 3068
n=int(input())
P=[float(i) for i in input().split()]
Ans=[[0]*(n+1) for _ in range(n+1)]
Ans[0][0]=1
for i in range(1,n+1):
  for j in range(i+1):
    if j==0:
      Ans[i][j]=Ans[i-1][j]*(1-P[i-1])
    else:
      Ans[i][j]=Ans[i-1][j]*(1-P[i-1])+Ans[i-1][j-1]*P[i-1]
ans=0
for i in range(n//2+1):
  ans+=Ans[n][i]
print(1-ans)

Measured memory_bytes: 262664
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}

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


//////////////////////////////////////////////////


int main() {
    int n, k, s; cin >> n >> k >> s;
    int a = s+1;
    if (s == 1e9) a = 1;
    rep(i,n) {
        if (i!=0) cout << " ";
        if (k) {
            cout << s;
            k--;
        }
        else cout << a;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
k = int(input())
sum = 0

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    
    
    return a

def gcd2(a, c):
    while c != 0:
        a, c = c, a % c
        
    return a


for i in range(1, k +1):
    for j in range(1, k +1):
        for k in range(1, k +1):
            sum += gcd2(gcd(i, j), k)
print(sum)

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

Vi yakusuu(int n){
    Vi ret;
    for(int i=1 ; i*i<=n ; ++i)
    {
        if(n%i == 0)
        {
            ret.push_back(i);
            if(i*i!=n)
            {
                ret.push_back(n/i);
            }
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    Vi a(n+1),memo(n+1);
    set<int> ans;
    REP(i,1,n+1){
        cin>>a[i];
    }

    REPR(i,n,0){
        if((memo[i]+a[i])%2==1){
            Vi yaku=yakusuu(i);
            REP(j,0,yaku.size()){
                memo[yaku[j]]++;
            }
            ans.insert(i);
        }
//        cout<<"i="<<i<<" "<<memo[i]<<endl;
//        if(memo[i]%2==1) ans.insert(i);
    }
    
    
//    Vi ans2;
//    REP(i,1,n+1) if(ans[i]%2==1) ans2.pb(i);
//    cout<<ans2.size()<<endl;
//    REP(i,0,ans2.size()) cout<<ans2[i]<<" ";
//    cout<<endl;
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x<<" ";
    cout<<endl;
    return 0;
}

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

ll m[100], a[100], b[100];
int main() {
	ll n;
	while (scanf("%lld", &n), n) {
		vector<ll>v;
		rep(i, n) {
			scanf("%lld%lld%lld", &m[i], &a[i], &b[i]);
			v.push_back(a[i]);
		}
		for (ll i : v) {
			ll cnt = 0;
			rep(j, n) {
				if (a[j] <= i&&i < b[j])cnt += m[j];
			}
			if (cnt > 150) {
				puts("NG");
				goto p;
			}
		}
		puts("OK");
	p:;
	}
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define ll long long

using namespace std;



int main()
{
    ios::sync_with_stdio(0);
    ll x,k;
    cin >> k >> x;
    for (int i=max(-1000000LL,x - k + 1);i < min(1000001LL,x + k);i++)
        cout << i << " ";
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
es = []
for i in range(M):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    es.append((a,b))
 
parent = None
def root(a):
    if parent[a] == a:
        return a
    else:
        parent[a] = root(parent[a])
        return parent[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    ra = root(a)
    rb = root(b)
    if ra == rb: return
    parent[ra] = rb;
 
ans = 0
for i in range(M):
    parent = [k for k in range(N)]
    for j,e in enumerate(es):
        if j == i: continue
        a,b = e
        unite(a,b)
    a,b = es[i]
    if not is_same(a,b):
        ans += 1
print(ans)

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

int main() {
	string s, t;
	cin >> s >> t;
	bool isyes = true;
	if (s[0] != t[2]) isyes = false;
	if (s[1] != t[1]) isyes = false;
	if (s[2] != t[0]) isyes = false;
	if (isyes) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

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

int main() {
    int64_t N, K;
    cin >> N >> K;
    int A[N+1], B[N+1] = {};
    for (int i = 0; i < N; i++) cin >> A[i+1];
    
    int now = 1, step = 0;
    bool divided = false;
    for (int64_t i = K; i > 0; i--) {
        int next = A[now];
        if ((next == 1 || B[next] != 0) && !divided) {
            divided = true;
            i %= B[now] - B[next] + 1;
        }
        if (i != 0) now = next;
        B[now] = ++step;
    }
    cout << now << endl;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[100005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll sum = 0;
    for (ll i = 0, t; i < n; i++) {
        cin >> t;
        sum += t;
        cnt[t]++;
    }
    int q;
    cin >> q;
    for (ll i = 0, b, c; i < q; i++) {
        cin >> b >> c;
        cnt[c] += cnt[b];
        sum += (c - b) * cnt[b];
        cnt[b] = 0;
        cout << sum << '\n';
    }
    return 0; 
}

Measured memory_bytes: 4416
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Word
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());

            while (num > 100 || num < 0)
            {
                num = int.Parse(Console.ReadLine());
            }

            Console.WriteLine(32 * num);
        }
    }
}



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

A = []
b = []
for i in range(n):
    dataset = input().split(" ")
    for j in range(m):
        A.append(int(dataset[j]))

for i in range(m):
    b.append(int(input()))



answer = []

for i in range(n):
    row_sum = 0
    for j in range(m):
        row_sum += A[i*m+j] * b[j]

    answer.append(row_sum)

for i in range(n):
    print(answer[i])



Measured memory_bytes: 5948
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll ans;
int N, K;
ll H[200005];

int main(void) {
    scanf("%d %d", &N, &K);
    rep(i, 0, N) scanf("%lld", &H[i]);

    sort(H, H+N, greater<ll>());

    rep(i, K, N) ans += H[i];

  
    printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1792
// abc135a: Harmony
#include <bits/stdc++.h>
using namespace std;
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  int a,b;in(a);in(b);
  int k = (a+b)/2;
  if(a+b==k*2) oute(k); else oute("IMPOSSIBLE");
}

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

int main() {
  vector<int> a(3);
  int a5=0;
  int a7=0;
  rep(i,3) cin>>a[i];
  rep(i,3){
  if(a[i]==5) a5++;
   else if(a[i]==7) a7++;
  }
  
  if(a5==2&&a7==1){ cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}



}

Measured memory_bytes: 256
import numpy as np
a, v = list(map(int, input().split(' ')))
b, w = list(map(int, input().split(' ')))
t = int(input())

if w >= v:
    print('NO')
    exit()

catchup_speed = (v - w)
start_dis = np.abs(b - a)

max_dis = t*catchup_speed

if start_dis <= max_dis:
    print('YES')
    exit()

print('NO')

Measured memory_bytes: 27068
#include <stdio.h>
#define N 20000000
void maxHeap(int);
void buildHeap(void);
int left(int);
int right(int);

int A[N],B[N],n;

int main(){
  int i;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  buildHeap();
  
  for(i=1;i<=n;i++)
    printf(" %d",A[i]);
  printf("\n");
  return 0;
}

void buildHeap(){
  int i;

  for(i=n/2;i>=1;i--){
    maxHeap(i);
  }
}

void maxHeap(int i){
  int l,r,largest;

  l=left(i);
  r=right(i);

  if(l<=n&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=n&&A[r]>A[largest])
    largest=r;

  if(largest!=i){
    B[i]=A[i];
    A[i]=A[largest];
    A[largest]=B[i];
    maxHeap(largest);
  }

}


int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 5672
// Sum of Consecutive Prime Numbers
// ??¨????????????????????????????????????????????§?????????

#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <string>
#include <queue>
#include <math.h>
using namespace std;

vector<int> Prime_Num;

int makePrimeQ(){
  int N = 10010;
  bool prime[N];

  for(int i=0;i<N;i++) 
    prime[i]=true;
  for(int i=2;i<=sqrt(N);i++){
    if(prime[i]){
      for(int j=2;i*j<N;j++) 
        prime[i*j]=false;
    }
  }
  for (int i=2; i<N; i++) {
    if (prime[i])
      Prime_Num.push_back(i);
  }
}
int solve(int num) {
  int count=0,sum=0,temp=0,i=0;
  queue<int> Q;
  bool flag = true;
  while (Prime_Num[i] <= num){
    if (flag) {
      temp = Prime_Num[i];
      Q.push(temp);
      sum += temp;
    }
    if (sum == num) {
      count++;
      sum -= Q.front();
      Q.pop();
      flag = true;
      i++;
    } else if (sum < num) {
      flag = true;
      i++;
    } else { // sum > num
      sum -= Q.front();
      Q.pop();
      flag = false;
    }
  }
  return count;
}

int main(){
  int num;
  makePrimeQ();
  while (cin >> num) {
    if (num == 0)
      break;
    // cout << Prime_Num[num] << endl;
    cout << solve(num) << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>    
#define pb push_back

#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))

typedef long long ll;
const int inf = 2e9;
using namespace std;
ll MOD = 1000000007;
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;
typedef vector<int> vi;


void mosA(vector<int> a){
	for(int i=0; i<a.size(); i++) printf("%d ",a[i]);
	printf("\n");
}
void mosP(vector<ii> a){
	for(int i=0; i<a.size(); i++) printf("%d %d\n",a[i].first,a[i].second);
	printf("\n");
}
ll min_especial(ll a, ll b){
  if(a!=-1 && b!=-1) return min(a,b);
  else return max(a,b);
}

bool ord(int a, int b){
	return b < a;
}


int k,q,n,m,t,a,b,u,f,l,x,z,y,s,d,h,r;
char S[100005];
vector<ii> v;
int C[100005];


int main(){

	scanf("%d%d%s",&n,&k,S);

	int inicio = 0;

	FOR(i,n){
		if(S[i]=='0' && S[i+1]!=S[i]){
			v.pb({inicio,i});
			inicio = i+1;
		}
		if(S[i]=='1'){
			inicio = i+1;
		}
	}

	inicio = 0;

	FOR(i,n){
		if(S[i]=='1' && S[i+1]!=S[i]){
			for(int j = inicio; j<=i; j++)
				C[j] = i+1-inicio;
			inicio = i+1;
		}
		if(S[i]=='0'){
			inicio = i+1;
		}
	}


	int l = v.size();

	int maximo = 0;

	FOR(i,l){

		ii a = v[i];

		if(i+k-1>=l){
			maximo = max(maximo, C[a.first-1] + n-a.first);
		} else {
			ii b = v[i+k-1];
			//cout<<a.first<<" "<<b.second<<endl;
			maximo = max(maximo,C[a.first-1] + b.second-a.first+1 + C[b.second+1]);
		}

	}

	if(!v.size()) maximo = C[0];


	printf("%d\n", maximo);


	return 0;
}

Measured memory_bytes: 1272