akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int; 

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAXN = 1e6;

int n, s;
LL dp[MAXN];
LL mod = 998244353;
int t[MAXN];

int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
  }

  LL res = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 3000; j >= 0; --j) {
      if (dp[j] != 0) {
        dp[j + t[i]] += dp[j] % mod;
      }
    }
    dp[t[i]] += i;
    dp[t[i]] % mod;
    res += dp[s] % mod;
  }
  cout << res % mod << endl;
}


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

typedef long long ll;

using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
      cin.tie(0);
      
    ll n,x;
    cin>>n>>x;
    ll arr[n];
    ll ans=0;
    for(ll i=0; i<n; i++)
    {
        cin>>arr[i];
        ll alpha = abs(x-arr[i]);
        ans = gcd(alpha,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		int k = 0;
		int tmp = -1;
		out: for(int i = 0; i <= N; i++) {
			for(int j = 0; i + j <= N; j++) {
				k = N - i - j;
				if(N == i + j + k && 10000*i + 5000*j + 1000*k == Y) {
					System.out.println(i + " " + j + " " + k);
					tmp++;
					break out;
				}
			}
		}
		if(tmp == -1) {
			System.out.println(tmp + " " + tmp + " " + tmp);
		}
	}

}


Measured memory_bytes: 23124
def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cl=list(c.items())
    cl.sort(key=lambda x:x[0],reverse=True)
    ans=[]
    for key,value in cl:
        if value>=4:
            ans.append(key)
            ans.append(key)
            break
        elif value>=2:
            ans.append(key)
            if len(ans)==2:
                break
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

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

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<int> col_sum(n + 1);
		for (int i = 0;i != n + 1;++i) {
			col_sum[i] = 0;
		}
		for (int i = 0;i != n;++i) {
			int row_sum = 0;
			for (int j = 0;j != n;++j) {
				int num;
				cin >> num;
				cout << setw(5) << num;
				col_sum[j] += num;
				row_sum += num;
			}
			cout << setw(5) << row_sum << endl;
			col_sum[n] += row_sum;
		}
		for (int i = 0;i != n + 1;++i) {
			cout << setw(5) << col_sum[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 2972
S = list(input())
cnt = 0
for i in range(len(S)) :
    if(i % 2 == 0) :
        if(S[i] == "L") :
            break
        else :
            cnt += 1
    else :
        if(S[i] == "R") :
            break
        else :
            cnt += 1
    
if(cnt == len(S)) :
    print("Yes")
else :
    print("No")
    

Measured memory_bytes: 3060
N = int(input())
S = input()
L = []
for i in range(1, N):
    a = set()
    b = set()
    for j in S[:i]:
        a.add(j)
    for k in S[i:]:
        b.add(k)
    count = len(a & b)
    L.append(count)

print(max(L))


Measured memory_bytes: 3064
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    a, b, x = MII()
    if x < a: print('NO')
    elif x <= a+b: print('YES')
    else: print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
ans = 0
def even(x):
    return x%2 == 0
 
def loop(ans, a):
    while(True):
        #print(a)
        for i in range(n):
            if even(a[i]):
                a[i] = a[i]//2
            else:
                return ans
        ans += 1
    return ans
 
ans = loop(ans, a)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a,b;
	cin>>a>>b;
	cout<<(a*b)<<endl;
	return 0;
}



Measured memory_bytes: 3640
n, q = map(int, input().split())
s = input()
ac = [0]
for i in range(len(s)-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac.append(ac[i]+1)
  else:
    ac.append(ac[i])
for i in range(q):
  l, r = map(int, input().split())
  print(ac[r-1]-ac[l-1])
  


Measured memory_bytes: 6100
N = int(input())
K = int(input())
x = list(int(i) for i in input().split())
sum = 0
for i in range(N):
    if K - x[i] <= x[i]:
        sum += (K-x[i])*2
    if K - x[i] > x[i]:
        sum += x[i]*2

print(sum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a+b,min(a+c,b+c));
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	if(nn % 1000 == 0)
	{
		cout << '0' << endl;
		return 0;
	}
	cout << (1000 - (nn % 1000)) << endl;
	return 0;
}

Measured memory_bytes: 3620
n,m = map(int,input().split())
ks = []
ans = 0
for i in range(m):
    k = list(map(int,input().split()))
    ks.append([k[0],set(k[1:])])
p = list(map(int,input().split()))

for i in range(2**n):
    now = set()
    for j in range(n):
        if (i>>j)&1:
            now.add(j+1)
    t  = True
    for j in range(m):
        if len(ks[j][1]&now)%2!=p[j]:
            t = False
            break
    if t:
        ans += 1

print(ans)




Measured memory_bytes: 42608
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]-(i+1)
ac=Counter(a)
if len(a)%2==0:
    dist=len(a)//2
else:
    dist=len(a)//2+1
temp=0
for i,j in sorted(ac.items()):
    temp+=j
    if temp>=dist:
        ans=0
        for k in range(n):
            ans+=abs(a[k]-i)
        print(ans)
        
        exit()

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

int main() {
    int h,w;
    cin>>h>>w;
    char c[1001][1001];
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) cin>>c[i][j];
    }
    for(int i=0;i<w+2;i++) cout<<"#";
    cout<<endl;
    for(int i=0;i<h;i++) {
        cout<<"#";
        for(int j=0;j<w;j++) {
            cout<<c[i][j];
        }
        cout<<"#"<<endl;
    }
    for(int i=0;i<w+2;i++) cout<<"#";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 384
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/
void swap(int *a,int *b){
	int w;
	w = *b;
	*b = *a;
	*a = w;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int integer[3];
	int n;
	cin >> n;
	while(n>0){
		cin >> integer[0] >> integer[1] >> integer[2];
		if(integer[0] > integer[2])			swap(&integer[0],&integer[2]);
		if(integer[1] > integer[2])			swap(&integer[1],&integer[2]);
		else if(integer[1] < integer[0])	swap(&integer[0],&integer[1]);
		if(integer[2] * integer[2] == integer[0] * integer[0] + integer[1] * integer[1])
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		n--;
	}
	/*****処理部*****/
	
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

const int N_max=86;

uint64_t luca(int &n){
    vector<uint64_t> l(N_max+1);
    l.at(0) = 2;
    l.at(1) = 1;
    if (n > 1){
        for(int i=2; i<n+1; i++) {
            l.at(i) = l.at(i-1) + l.at(i-2);
        }
    }
    return l.at(n);
}
    

int main(){
    int n;
    cin >> n;
    uint64_t ans = luca(n);

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int n, vis[11]; long long z, p; string s;
long long rec(long long x, int d) {
	if (d == n) return x;
	long long ret = -1, sa = -1;
	for (int i = 0; i <= 9; i++) {
		if (!vis[i]) {
			vis[i] = 1;
			long long res = rec(x * 10 + i, d + 1);
			long long d1 = abs(res - z);
			long long d2 = min(d1, p - d1);
			if (sa < d2) {
				ret = res;
				sa = d2;
			}
			vis[i] = 0;
		}
	}
	return ret;
}
int main() {
	cin >> s;
	n = s.size(); p = 1;
	for (int i = 0; i < n; i++) {
		z = z * 10 + s[i] - 48;
		p *= 10;
	}
	long long ret = rec(0, 0);
	for (int i = 0; i < n; i++) {
		p /= 10;
		cout << (ret / p) % 10;
	}
	cout << endl;
	return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;rep(tcs,1,tt+1)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble
    ll k;
    cin>>k;
    ll f=0;
    ll mod=0;
    for(int i=0;i<k;i++){
        mod=mod*10+7;
        if(mod%k==0){
            f=i+1;
            break;
        }
        mod%=k;
    }
    if(f==0)cout<<-1;
    else cout<<f;
    return 0;
}


Measured memory_bytes: 3636
from bisect import bisect_left

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    def check(x):
        index = bisect_left(A,x)
        ans = 0
        for i in range(index,N):
            tmp = -(-A[i] // x) - 1
            ans += tmp
        if ans <= K:
            return True
        else:
            return False
    ok = max(A)
    ng = 0
    while abs(ok- ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    main()

Measured memory_bytes: 104664
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N,M; cin >> N >> M;
    vector<pair<int, int>> ab(M);
    REP(i,M) cin >> ab[i].first >> ab[i].second;
    int res[N]={0};

    REP(i,M){
        res[ab[i].first]++;
        res[ab[i].second]++;
    }

    REP(i,N){
        if(res[i]%2!=0){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<time.h>
#include<typeinfo>
#include <cstdlib>
#include<stdio.h>

using namespace std;

#define ll long long
#define MOD 1000000007

int n,m,k;
int pow2n;

int v[1000000];
int amount[1000000];
bool fin = false;
void dfs(int at){
	if(fin)return;
	if(at == n){
		for(int i = 0;i < n;i++){
			int value = v[i];
			for(int j = i+1;j < n;j++){
				value^=v[j];
				if(v[i]==v[j]){
					if(value!=k)return;
				}
			}
		}
		for(int i = 0;i < n;i++){
			cout << v[i] << " ";
		}
		cout << endl;
		fin = true;
		return;
	}
	for(int i = 0;i < pow2n;i++){
		if(amount[i]==2)continue;
		v[at] = i;
		amount[i]++;
		dfs(at+1);
		amount[i]--;
	}
	return;
}

int main(){
	cin >> m >> k;
	pow2n = 1<<m;
	n = 1<<(m+1);
	// fill_n(amount,1000000,0);
	// dfs(0);
	if(pow2n <= k){
		cout << -1 << endl;
		return 0;
	}
	if(m <= 2){
		fill_n(amount,1000000,0);
		dfs(0);
		if(!fin)cout << -1 << endl;
		return 0;
	}
	vector<int> ans;
	for(int i = 0;i < pow2n;i++){
		if(i==k)continue;
		ans.push_back(i);
	}
	ans.push_back(k);
	for(int i = pow2n-1;i != -1;i--){
		if(i==k)continue;
		ans.push_back(i);
	}
	ans.push_back(k);
	for(int i = 0;i < ans.size();i++){
		if(i!=0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}

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

int v[2010];
int nr[2010], id;
int n, k, q;

void solve(int st, int dr)
{
    int max_taken = dr - st - k + 2;
    if (max_taken <= 0)
        return;
    int start = id;
    while (st <= dr)
        nr[id++] = v[st++];

    sort(nr + start, nr + id);
    id = start + max_taken;
}

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

    for (int i = 1; i <= n; i++)
        cin >> v[i];

    int ans = 2e9;

    for (int idv = 1; idv <= n; idv++) {
        int val = v[idv];
        id = 0;
        for (int i = 1, prev = 1; i <= n; i++) {
            if (v[i] >= val) {
                if (i == n)
                    solve(prev, i);
            }
            else {
                if (prev <= i - 1)
                    solve(prev, i - 1);
                prev = i + 1;
            }
        }
        sort(nr, nr + id);
        if (id >= q)
            ans = min(ans, nr[q - 1] - nr[0]);
    }

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


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

using namespace std;

typedef long long ll;

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

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

#define abs(x) ((x) > 0 ? (x) : -(x))

int main(void) {
    int N;
    cin >> N;

    vector<double> a(N);
    double sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    double avg = sum / ((double) N);

    int ans = 0;
    for (int i = 1; i < N; i++) {
        if (abs(avg - a[i]) < abs(avg - a[ans])) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(int argc, char** argv){
    int N;
    cin >> N;
    vector<vector<int>> c(N, vector<int>(26, 0));
    for (int i=0; i<N; i++){
        string s;
        cin >> s;
        for (int j=0; j<10; j++) ++c[i][s[j]-97];
    }

    sort(c.begin(), c.end());

    vector<bool> match(N, false);
    for (int i=1; i<N; i++){
        bool flag = true;
        for (int j=0; j<26; j++)
            if (c[i-1][j] != c[i][j]) flag = false;
        if (flag) match[i] = true;
    }

    long long int ans = 0;
    long long int acc = 0;
    for (int i=0; i<N; i++){
        if (match[i]){
            ++acc;
            if (i==N-1)
                ans += acc*(acc+1)/2;
        }
        else {
            ans += acc*(acc+1)/2;
            acc = 0;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int m = Integer.parseInt(str.substring(5, 7));
		int d = Integer.parseInt(str.substring(8, 10));
		if (m >= 5 || (m >= 4 && d > 30)) {
			System.out.println("TBD");
		} else {
			System.out.println("Heisei");
		}
	}
}


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

using namespace std;

int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0) cout << 1 << endl;
  if(b == 0) cout << 2 << endl;
  if(c == 0) cout << 3 << endl;
  if(d == 0) cout << 4 << endl;
  if(e == 0) cout << 5 << endl;
}



Measured memory_bytes: 3648
n=int(input())
march=["M","A","R","C","H"]
cnt=[0]*5
for i in range(n):
  inp=input()
  for j in march:
    if inp[0]==j:
      cnt[march.index(j)]+=1
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
      
print(ans)

Measured memory_bytes: 9088
a, b, c = map(int, input().split())
k = int(input())

bk, ck = 0, 0

while a >= b:
    b *= 2
    bk += 1

while b >= c:
    c *= 2
    ck += 1

if bk + ck <= k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int head = 0, tail = 0;

struct Process
{
    string name;
    int time;
};

vector<Process> QUEUE;

Process dequeue()
{
    Process p = QUEUE[head];
    head++;
    return p;
}

void enqueue(struct Process p)
{
    QUEUE.push_back(p);
    tail++;
}

int main()
{
    // 入力の受け取り
    int n, q;
    Process p, current;

    cin >> n;
    cin >> q;
    for (int i = 0; i < n; i++)
    {
        cin >> p.name >> p.time;
        enqueue(p);
    }

    int total_time = 0;
    // timeからqを引く
    for (int j = 0; j < tail; j++)
    {
        current = dequeue();

        if (current.time - q > 0)
        {
            total_time += q;
            current.time -= q;
            enqueue(current);
        }
        else
        {
            total_time += current.time;
            cout << current.name << " " << total_time << endl;
        }
    }
}


Measured memory_bytes: 9312
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	int k,x,y;
	cin>>k>>x>>y;
	if(x%k == 0 || y%k == 0){
		cout<<"OK";
	}else
	if(y/k > x/k){
		cout<<"OK";
	}else{
		cout<<"NG";
	}
	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
int solve(int, int);
int n,q,A[2000];
int main()
{
  int i,mi;

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

    scanf("%d",&q);
    for(i=0; i<q; i++){
      scanf("%d",&mi);

      if(solve(0, mi)==1)
        printf("yes\n");
      else
        printf("no\n");
    }
    return 0;
}

int solve(int i, int m)
{
  if(m==0) return 1;

  if(i>=n) return 0;

  if(solve(i+1,m)) return 1;

  if(solve(i+1,m-A[i])) return 1;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int n;
vector<int> h(100);
vector<int> now(100);

int sol(int l, int r) {
    if (l == r) return 0;
    int Min = 100; // l~r区間中の最小の高さ
    int ind = 0;
    for (int i = l; i < r; i++)
    {
        if (h[i] <= Min) {
            Min = h[i];
            ind = i;
        }
    }
    // 最小分だけ水やり
    for (int i = l; i < r; i++)
    {
        h[i] -= Min;
    }
    // 最小の花より左の区間と右の区間に分ける
    return Min + sol(l,ind) + sol(ind+1,r);
}

int main() {
    cin >> n;
    rep(i,n) cin >> h[i];
    cout << sol(0,n) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> C(N - 1);
	vector<Int> S(N - 1);
	vector<Int> F(N - 1);
	vector<Int> time(N);//N番目の駅は0

	for (Int i = 0; i < N-1; i++) {
		cin >> C[i] >> S[i] >> F[i];
	}

	Int temp;
	for (Int i = 0; i < N-1; i++) {
		for (Int j = i; j < N-1; j++) {
			if (time[i] <= S[j]) {
				time[i] = S[j];
				time[i] += C[j];
				continue;
			}
			temp = ((time[i] - S[j]) + (F[j] - 1)) / F[j];
			time[i] = S[j] + temp * F[j];
			time[i] += C[j];
		}
	}

	for (Int i = 0; i < N; i++) {
		printf("%lld\n", time[i]);
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        char[] ynArr = {'y','y','y','y','y','y','y','y','y','y'};
        for (int i = 0; i < k; i++) {
            ynArr[sc.nextInt()] = 'n';
        }

        int[] allowArr = new int[10 - k];
        int arrIdx = -1;
        for (int i = 0; i < 10; i++) {
            if (ynArr[i] == 'y') {
                allowArr[++arrIdx] = i;
            }
        }

        int[] values = {1, 10, 100, 1000, 10000};
        int[] degIndex = {0, -1, -1, -1, -1};

        while (true) {
            int cv = 0;
            for (int i = 0; i < 5; i++) {
                if (degIndex[i] == -1) break;
                cv += values[i] * allowArr[degIndex[i]];
            }
            if (n <= cv) {
                System.out.println(cv);
                break;
            }
            degIndex[0] += 1;
            for (int j = 0; j < 5; j++) {
                if (arrIdx < degIndex[j]) {
                    degIndex[j] = 0;
                    degIndex[j+1] += 1;
                } else {
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 21716
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc= new Scanner(System.in);
    String str = sc.next();
    int len=str.length();
    if(str.charAt(len-1)=='s')
      System.out.print(str+"es");
    else
      System.out.print(str+"s");
  }
}

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

int n;
vector<ll>a;

int main(){
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	if(a[0]==0){
		cout<<0;
		return 0;
	}
	
	ll p=1,q=1e18;
	for(int i=0;i<n;i++){
		if(a[i]>q/p){
			cout<<-1;
			return 0;
		}
		p*=a[i];
	}
	cout<<p;
	return 0;
}


Measured memory_bytes: 4000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  ll n,k;
  cin >> n >> k;
  
  n %= k; 
  while(1){
    if(n > abs(n-k)){
    n = abs(n-k);
    }
    else break;
  }
  
  cout << n << endl;
    
  
}

Measured memory_bytes: 3624
N=int(input())
arr = [int(a) for a in input().split()]
dp = [[arr[0],arr[1],arr[2]],[0,0,0]]
l=1
p=0
for i in range(1, N):
    arr = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j == k: continue
            dp[l][k] = max(dp[l][k], dp[p][j] + arr[k])
    l=l^1
    p=p^1
            
print(max([dp[p][j] for j in range(3)]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++){
		if (s[i]==s[i+1]){
			printf("%d %d\n",i,i+1);
			return 0;
		}
		if (s[i]==s[i+2]){
			printf("%d %d\n",i,i+2);
			return 0;
		}
	}
	puts("-1 -1");
}

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

namespace Atc_0020
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            var nums = str.Split(' ');

            List<ulong> numList = new List<ulong>();

            for (int i = 0; i < nums.Length; i++)
            {
                numList.Add(ulong.Parse(nums[i]));
            }

            ulong tmp = numList[0];
            numList[0] = numList[1];
            numList[1] = tmp;

            tmp = numList[0];
            numList[0] = numList[2];
            numList[2] = tmp;

            for (int i = 0; i < numList.Count - 1; i++)
            {
                Console.Write(numList[i] + " ");
            }

            Console.WriteLine(numList[numList.Count - 1]);

        }
    }
}


Measured memory_bytes: 27952
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		//キーがStringで中身がintのHashMapを作る
		HashMap<String, Integer> count = new HashMap<String, Integer>();
		
		for (int s=0; s<N; s++) {
			String S = keyboard.next();
			int now = count.get(S) == null ? 0 : count.get(S);
			count.put(S, now + 1);
		}
		
		int M = keyboard.nextInt();
		for (int t=0; t<M; t++) {
			String T = keyboard.next();
			int now = count.get(T) == null ? 0 : count.get(T);
			count.put(T, now - 1);
		}
		
		int ans = 0;
		//拡張for分（左が確認する1個の名前、右が確認するものの集合）
		//HashMapでキーが登録されている部分のintの集合を、valとして1個ずつ順番に全部確認する
		//右にcount.keysと書くと、全てのキーの集合が取れるし、count.entrySetなら全てのキーと中身のセットの集合が取れる
		for (int val: count.values()) { 
			if (ans < val) {
				ans = val;
			}
		}
				
		System.out.println(ans);
		keyboard.close();
	}
	
}


Measured memory_bytes: 35644
#include <cstdio>
#include <vector>

const int MN = 100005, ME = 300005;

int N, A[MN], B[MN], R1, R2;

int deg1[MN], deg2[MN];
int E, eu[ME], ev[ME], dir[ME];
std::vector<int> G[MN * 2];

void DFS(int u) {
	while (!G[u].empty()) {
		int e = G[u].back();
		G[u].pop_back();
		if (!dir[e]) {
			int v = eu[e] ^ ev[e] ^ u;
			dir[e] = u == eu[e] ? 1 : 2;
			DFS(v);
		}
	}
}

int Ans[MN];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	for (int i = 1; i <= N; ++i) scanf("%d", &B[i]);
	for (int i = 1; i <= N; ++i) {
		if (A[i] != -1) {
			++deg1[A[i]], ++deg1[i];
			++E, eu[E] = A[i], ev[E] = i;
			G[A[i]].push_back(E);
			G[i].push_back(E);
		} else R1 = i;
		if (B[i] != -1) {
			++deg2[B[i]], ++deg2[i];
			++E, eu[E] = N + B[i], ev[E] = N + i;
			G[N + B[i]].push_back(E);
			G[N + i].push_back(E);
		} else R2 = i;
	}
	++deg1[R1], ++deg2[R2];
	++E, eu[E] = N + N + 1, ev[E] = R1;
	G[N + N + 1].push_back(E), G[R1].push_back(E);
	++E, eu[E] = N + N + 1, ev[E] = N + R2;
	G[N + N + 1].push_back(E), G[N + R2].push_back(E);
	for (int i = 1; i <= N; ++i) if ((deg1[i] ^ deg2[i]) & 1) return puts("IMPOSSIBLE"), 0;
	puts("POSSIBLE");
	for (int i = 1; i <= N; ++i) if (deg1[i] & 1) {
		++E, eu[E] = i, ev[E] = N + i;
		G[i].push_back(E), G[N + i].push_back(E);
	}
	DFS(N + N + 1);
	for (int i = E; i > 2 * N; --i)
		Ans[eu[i]] = dir[i] == 1 ? 1 : -1;
	for (int i = 1; i <= N; ++i) printf("%d%c", Ans[i], " \n"[i == N]);
	return 0;
}

Measured memory_bytes: 33952
package main

import (
	"fmt"
	"sort"
)

type choice struct {
	can int
	val int
}

type choices []choice

func (p choices) Len() int           { return len(p) }
func (p choices) Less(i, j int) bool { return p[i].val > p[j].val }
func (p choices) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	as := make(sort.IntSlice, 0, n)
	for index := 0; index < n; index++ {
		var n int
		fmt.Scan(&n)
		as = append(as, n)
	}

	as.Sort()
	chs := make(choices, 0, m)
	for index := 0; index < m; index++ {
		var b, c int
		fmt.Scan(&b)
		fmt.Scan(&c)

		chs = append(chs, choice{can: b, val: c})
	}
	sort.Sort(chs)

	var idx int

	for _, item := range chs {
		keep := true
		for {
			if item.can == 0 {
				break
			}
			if as[idx] < item.val {
				as[idx] = item.val
				idx++
				item.can--
			} else {
				keep = false
				break
			}
			if idx >= n {
				keep = false
				break
			}
		}
		if !keep {
			break
		}
	}

	var re int64
	for _, item := range as {
		re += int64(item)
	}
	fmt.Println(re)
}


Measured memory_bytes: 7424
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int[] hwn=Readint();
    int h=hwn[0];
    int w=hwn[1];
    int n=hwn[2];
    int[] src=Readint();
    string s=ReadLine();
    string t=ReadLine();
    int l=src[1],r=src[1],u=src[0],d=src[0];
    for (int i=0;i<n;i++){
      switch(s.Substring(i,1)){
        case "L":
          l--;
          if(l<1){
            WriteLine("NO");
            return;
          }
          break;
        case "R":
          r++;
          if(r>w){
            WriteLine("NO");
            return;
          }
          break;
        case "U":
          u--;
          if(u<1){
            WriteLine("NO");
            return;
          }
          break;
        case "D":
          d++;
          if(d>h){
            WriteLine("NO");
            return;
          }
          break;
      }
      switch(t[i]){
        case 'L':
          r = Max(1,r-1);
          break;
        case 'R':
          l = Min(w,l+1);
          break;
        case 'U':
          d = Max(1,d-1);
          break;
        case 'D':
          u = Min(h,u+1);
          break;
      }
    }
    WriteLine("YES");
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

Measured memory_bytes: 18268
#include <stdio.h>

int main(){
	int num, i;
	char number[1001];
	while(1){
		scanf("%s", number);
		if(number[0] == '0')break;
		i = 0;
		num = 0;
		while(1){
			if(number[i] == '\0')break;
			num += number[i] - '0';
			i++;
		}
		printf("%d\n", num);
	}
			return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int ac[3]={0};
	ac[0]=a-b;
	ac[1]=a+b;
	ac[2]=a*b;
	sort(ac,ac+3);
	cout<<ac[2];
}

Measured memory_bytes: 256
N = 10**6
mod = 10**9 + 7
fact = [1]
for i in range(1, N+1):
     fact.append(fact[-1]*i%mod)

n,m = map(int, input().split())

if n-m  > 1 or m-n >1:
     ans=0
elif n-m == 0:
     ans = 2*fact[n]*fact[m]%mod
else:
     ans = fact[n] * fact[m] % mod
print(ans)


Measured memory_bytes: 42644
import Foundation

var input = readLine()
var inputs = input!.components(separatedBy: " ")

var N = Int(inputs[0])!
var L = Int(inputs[1])!

var strs : [String] = [String]()

for _ in 0 ..< N{
    strs.append(readLine()!)
}

strs.sort()

var ans : String = ""

for i in 0 ..< N{
    ans += strs[i]
}

print(ans)

Measured memory_bytes: 14196
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=6e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> x(N),y(N);
    REP(i,N) cin >> x[i]>>y[i];
    ll x_max,x_min;
    ll y_max,y_min;
    ll ans=INF;
    int cnt=0;
    if(K==2){
        REP(i,N-1){
            REP2(j,i+1,N){
                x_max=max(x[i],x[j]);
                y_max=max(y[i],y[j]);
                x_min=min(x[i],x[j]);
                y_min=min(y[i],y[j]);
                cnt=4;
                REP(k,N){
                    if(k==i||k==j) continue;
                    if(x[k]<=x_max&&y[k]<=y_max&&x[k]>=x_min&&y[k]>=y_min) cnt++;
                }
                if(cnt>=K){
                    ans=min(ans,(x_max-x_min)*(y_max-y_min));

                }
            }
        }
    }

    if(K==3){
        REP(i,N-2){
            REP2(j,i+1,N-1){
                REP2(l,j+1,N){
                    x_max=max(max(x[i],x[j]),x[l]);
                    y_max=max(max(y[i],y[j]),y[l]);
                    x_min=min(min(x[i],x[j]),x[l]);
                    y_min=min(min(y[i],y[j]),y[l]);
                    cnt=4;
                    REP(k,N){
                        if(k==i||k==j||k==l) continue;
                        if(x[k]<=x_max&&y[k]<=y_max&&x[k]>=x_min&&y[k]>=y_min) cnt++;
                    }
                    if(cnt>=K){
                        ans=min(ans,(x_max-x_min)*(y_max-y_min));

                    }
                    
                }
            }
        }
    }
    if(K>=4){
        REP(i,N-3){
            REP2(j,i+1,N-2){
                REP2(l,j+1,N-1){
                    REP2(m,l+1,N){
                        x_max=max(max(x[i],x[j]),max(x[l],x[m]));
                        y_max=max(max(y[i],y[j]),max(y[l],y[m]));
                        x_min=min(min(x[i],x[j]),min(x[l],x[m]));
                        y_min=min(min(y[i],y[j]),min(y[l],y[m]));
                        cnt=4;
                        REP(k,N){
                            if(k==i||k==j||k==l||k==m) continue;
                            if(x[k]<=x_max&&y[k]<=y_max&&x[k]>=x_min&&y[k]>=y_min) cnt++;
                        }
                        if(cnt>=K){
                            ans=min(ans,(x_max-x_min)*(y_max-y_min));

                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] w = new int[n];
        int s1 = 0;
        int s2 = 0;
        int sub;
        int min = 10000000;
        for (int i = 0; i < n; i++) {
            w[i] = stdIn.nextInt();
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(j <= i) {
                    s1 += w[j];
                } else {
                    s2 += w[j];
                }
            }
            sub = Math.abs(s2 - s1);
            if(sub < min) {
                min = sub;
            }
            s1 = 0;
            s2 = 0;
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 23636
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3

int sign(li x) { return x < 0 ? -1 : x > 0; }

//          a / b
li floor(li a, li b) {
  if (sign(a) != sign(b) && a % b)
    return a / b - 1;
  else
    return a / b;
}

//         a / b
li ceil(li a, li b) {
  if (sign(a) == sign(b) && a % b)
    return a / b + 1;
  else
    return a / b;
}

void _main(int tc) {
  li a, b, x;
  cin >> a >> b >> x;
  li leftLimit = x * ceil(a, x);
  li rightLimit = x * floor(b, x);
  cout << 1 + (rightLimit - leftLimit) / x << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  ll N;
  cin >> N;

  ll b[200010];
  vector<ll> a(N);
  REP(i, N){
    cin >> a[i];
    b[a.at(i)]++;
  }
  
  ll c[200010];

  ll sum = 0;
  REP(i,200010){
    sum+=b[i]*(b[i]-1)/2;
    c[i] = b[i]*(b[i]-1)/2-(b[i]-1)*(b[i]-2)/2;
  }
  REP(i,N){
    cout << sum - c[a.at(i)] << endl;
  }
}

Measured memory_bytes: 7168
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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


int main(){
    int w,n,a,b,t;
    int arr[30];
    scanf("%d", &w);
    scanf("%d", &n);
    rep(i,w) arr[i] = i+1;
    while(n--) {
        scanf("%d,%d", &a, &b);
        t = arr[a-1];
        arr[a-1] = arr[b-1];
        arr[b-1] = t;
    }
    rep(i,w) printf("%d\n", arr[i]);
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define pw(x) (1LL << (x))
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl

using namespace std;
typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n, x;
    while (cin >> n >> x) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        sort(a.begin(), a.end());

        int ans = 0;
        for (int y : a) {
            if (y <= x) {
                x -= y;
                ans++;
            }
        }
        if (x > 0 && ans == n) ans--;
        cout << ans << endl;
    }

#ifdef HOME
    cerr << "time = " << (clock() * 1. / CLOCKS_PER_SEC) << "\n";
#endif
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long llong;

int N;
llong v_list[100001];
double tripartition;
	
llong BaumukuchenGetAnswer();
inline llong searchOne(int n0, int n1_left, int n2_left);
inline llong getMinV(int n0, int n1_left, int n2_left);
inline int findIndexBinary(int from_n, int to_n, double target);
inline int findIndexSequential(int from_n, double target);


int main(){
	/*
	FILE* fp = fopen("input.txt", "r");
	fscanf(fp, "%lld", &N);
	v_list[0] = 0;
	for(int n=1; n<N+1; n++){
		llong A;
		fscanf(fp, "%lld", &A);
		v_list[n] = v_list[n-1] + A;
	}
	fclose(fp);

	/*/
	scanf("%lld", &N);
	v_list[0] = 0;
	for(int n=1; n<N+1; n++){
		llong A;
		scanf("%lld", &A);
		v_list[n] = v_list[n-1] + A;
	}
	//*/
	printf("%lld\n", BaumukuchenGetAnswer());
}

llong BaumukuchenGetAnswer(){
	tripartition = v_list[N] / 3.0;
	int n0_max = findIndexBinary(0, N, tripartition);

	int n1_left = n0_max;
	int	n2_left = findIndexBinary(n1_left, N,  2*tripartition);
	llong interm_maxV = searchOne(0, n1_left, n2_left);
	for (int n0 = 1; n0 <= n0_max; n0++){
		n1_left = findIndexSequential(n1_left,   tripartition + v_list[n0]);
		n2_left = findIndexSequential(n2_left, 2*tripartition + v_list[n0]);
		
		llong tmp = searchOne(n0, n1_left, n2_left);
		if (tmp > interm_maxV) interm_maxV = tmp;
	}
	return interm_maxV;
}

llong searchOne(int n0, int n1_left, int n2_left){
	llong V_ll = getMinV(n0, n1_left  , n2_left  );
	llong V_lr = getMinV(n0, n1_left  , n2_left+1);
	llong V_rl = getMinV(n0, n1_left+1, n2_left  );
	llong V_rr = getMinV(n0, n1_left+1, n2_left+1);
	return max( max(V_ll,V_lr), max(V_rl, V_rr));
}

llong getMinV(int n0, int n1, int n2){
	llong V0 = v_list[n1] - v_list[n0];
	llong V1 = v_list[n2] - v_list[n1];
	llong V2 = v_list[n0] - v_list[n2] + v_list[N];
	return min(min(V0,V1),V2);
}

int findIndexBinary(int from_n, int to_n, double target){
	while (to_n - from_n != 1) {
		int n_mid = (to_n + from_n) / 2;
		if (v_list[n_mid] > target) to_n = n_mid;
		else from_n = n_mid;
	}
	return from_n;
}

int findIndexSequential(int from_n, double target){
	for(int n=from_n; n<= N; n++)if(v_list[n] > target) return n-1;
	return N-1;
}

Measured memory_bytes: 1804
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=150;
//ここまでテンプレ
int main(){
	int A,B;
	cin>>A>>B;
	string S;
	cin>>S;
	for(int i=0;i<A;i++){
		if(S[i]<'0' || '9'<S[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(S[A]!='-'){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=A+1;i<A+B+1;i++){
		if(S[i]<'0' || '9'<S[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
/* ****revpro**** */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		ll a[n];
		vector <pii> t[n];
		rep(i,0,n){
			cin>>a[i];
			rep(j,0,a[i]){
				pii x;
				cin>>x.F>>x.S;
				x.F--;
				t[i].pb(x);
			}
		}
		ll ans=0;
		rep(i,0,1<<n){
			ll f=1;
			ll cnt=0;
			rep(j,0,n){
				if(i&(1<<j)){
					cnt++;
					for(auto k:t[j]){
						if(((i&(1<<k.F))&&k.S)||(!(i&(1<<k.F))&&(k.S==0)))
							continue;
						else f=0;
					}
				}
			}
			if(f) ans=max(ans,cnt);
		}
		cout<<ans<<endl;

	}
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	string s,t,u;
	ll a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) {
		a--;
	}
	else {
		b--;
	}
	cout << a << " " << b;
	return(0);
}

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

int main(){
    int n, c; cin >> n >> c;
    vector<vector<int> > lis(c, vector<int>(200002, 0));
    for(int i = 0; i < n; i++){
        int a, b, c; cin >> a >> b >> c;
        for(int i = a*2-1; i <= b*2; i++){
            lis[c-1][i] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < 200002; i++){
        int k = 0;
        for(int l = 0; l < c ;l++){
            k += lis[l][i];
       }
       ans = max(ans, k);
   }
   cout << ans << endl;
}

Measured memory_bytes: 24576
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


N,K = map(int,input().split())
ans = K * (K-1)**(N-1)
print(ans)


Measured memory_bytes: 6344
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    vector<pair<ll, ll>> v;
    for(int i=0; i<N; ++i){
        ll x, y;
        cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    sort(v.begin(), v.end());
    ll ans=5e18;
    for(int i=0; i+K<=N; ++i){
        vector<ll> u;
        for(int j=0; j+1<K; ++j) u.push_back(v[i+j].second);
        for(int j=i+K-1; j<N; ++j){
            u.push_back(v[j].second);
            sort(u.begin(), u.end());
            ll mn=3e9;
            for(int t=0; t+K-1<=j-i; ++t) mn=min(mn, u[t+K-1]-u[t]);
            ans=min(ans, mn*(v[j].first-v[i].first));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n=int(input())
numlista=list(map(int,input().split()))
import collections
numkosuu=collections.Counter(numlista)
suma=0
for i in numlista:
  suma+=i
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
#変化したところのみ計算する
  suma+=(c-b)*numkosuu[b]
#個数を更新する
  numkosuu[c]+=numkosuu[b]
  numkosuu[b]=0
  print(suma)

Measured memory_bytes: 23784