akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define       inf                  1<<30
#define       p5                   100007
#define       p6                   1000007
#define       PI                   acos(-1)
#define       M                    1000000007
#define       sc                   scanf
#define       ss                   second
#define       ff                   first
#define       pf                   printf
#define       scin(x)              sc("%d",&(x))
#define       scin2(x,y)            sc("d",&(x),&(y))
#define       READ(f)              freopen(f, "r", stdin)
#define       WRITE(f)             freopen(f, "w", stdout)
#define       ll                   long long
#define       ull                  unsigned long long
#define       pii                  pair < int, int>
#define       pp                  pair < ll, ll>
#define       pq                   priority_queue
#define       pb                   push_back
#define       FastRead             ios_base::sync_with_stdio(0);cin.tie(0)
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
int ar[p5+2],dp[p5+2];
int main()
{
	ll n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
        cin>>ar[i];
	}
	dp[1]=0;
	dp[2]=abs(ar[1]-ar[2]);
	for(i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
	}
	cout<<dp[n]<<endl;
	return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    bool ok = true;
    REP(i, N){
    	if(A[i]%2==0){
    		if(A[i]%3!=0 && A[i]%5!=0) ok = false;
    	}
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

def lcm(a, b, g):
    return a * b / g
    

while True:
    try:
        a, b = map(int, raw_input().split())
    except EOFError:
        break

    g = gcd(a, b) 
    print "{} {}".format(g, lcm(a,b,g)) 

Measured memory_bytes: 4212
n = int(input())

wo = [input()]
st = 0
for i in range(1,n):
	inl = input()
	if ((inl in wo) or (wo[-1][-1] != inl[0])):
		st = 1
		break
	else:
		wo.append(inl)
	



ans = ["Yes","No"]
print(ans[st])

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int X, A;
	
	cin>>X>>A;
	
	if(X < A) cout<<0<<endl;
	if(X >= A) cout<<10<<endl;
	
	
	return 0;
}

Measured memory_bytes: 764
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        int retValue = b;

        if (a <= 5)
        {
            retValue = 0;
        }
        else if (a <= 12)
        {
            retValue = (b / 2);
        }

        //出力
        Console.WriteLine(retValue);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repri(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;
typedef vector<int> VI;
typedef vector<ll> VL;

auto mgcd=[](ll p, ll q) {return __gcd(p,q);};
auto mlcm=[](ll p, ll q) {return p*q/__gcd(p,q);};

int N;

void Main() {
	cin >> N;
	VI h(N);
	rep(i, N) cin >> h[i];

	int ans=0;
	while(1) {
		if (*max_element(h.begin(), h.end())==0) break;
		rep(i,N) {
			if (h[i]==0) continue;
			rep(j,i,N) {
				if(h[j]==0) break;
				h[j]--;
			}
			break;
		}
		ans++;
	}

	cout << ans << LF;

	return;
}

int main(){
	FAST;
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())


for a1 in range(0, 101):
    b1 = c11 - a1
    b2 = c12 - a1
    b3 = c13 - a1
    a2 = c21 - b1
    a3 = c31 - b1

    if all([c22 == a2 + b2,
           c23 == a2 + b3,
           c32 == a3 + b2,
           c33 == a3 + b3]):
        print("Yes")
        exit(0)
else:
    print("No")


Measured memory_bytes: 3064
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)
#define cio ios::sync_with_stdio(false);

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int x,y,A,B,C;
    scanf("%d %d %d %d %d",&x,&y,&A,&B,&C);
    
    int a[100010];
    int b[100010];
    int c[100010];
    for (int i = 0;i < A;i ++) scanf("%d",a + i);
    for (int i = 0;i < B;i ++) scanf("%d",b + i);
    for (int i = 0;i < C;i ++) scanf("%d",c + i);
    sort(a, a + A, greater<int>());
    sort(b, b + B, greater<int>());
    sort(c, c + C, greater<int>());
    int ea = x - 1;
    int eb = y - 1;
    for (int i = 0;i < C;i ++)
    {
        if (ea >= 0 && eb >= 0)
        {
            if (a[ea] <= b[eb])
            {
                if (a[ea] < c[i]) {
                    a[ea] = c[i];
                    ea --;
                }
            } else {
                if (b[eb] < c[i]) {
                    b[eb] = c[i];
                    eb --;
                }
            }
        } else {
            if (ea < 0 && eb < 0) break;
            if (ea < 0) {
                if (b[eb] < c[i]) {
                    b[eb] = c[i];
                    eb --;
                }
            }
            if (eb < 0) {
                if (a[ea] < c[i]) {
                    a[ea] = c[i];
                    ea --;
                }
            }
        }
        
    }
    ll sum = 0;
    for (int i = 0;i < x;i ++) sum += a[i];
    for (int i = 0;i < y;i ++) sum += b[i];
    printf("%lld\n",sum);
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N; cin >> N;
	string s; cin >> s;

	if(N % 2 == 1){
		cout << "No" << endl;
		return 0;
	}else{
		int j = N/2;
		REP(i,N/2){
			if(s[i] != s[j]){
				cout << "No" << endl;
				return 0;

			}


			j++;
		}

	}

	cout << "Yes" << endl;


	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
	if(a % b == 0)
	{
		return b;
	}
	else
	{
		return gcd(b, a % b);
	}
}

int main()
{
	int k, res=0, a,b,c;
	scanf("%d", &k);
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int l=1;l<=k;l++)
			{
				a = gcd(i,j);
				b = gcd(a,l);
				res += b;
			}
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3828
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();

		int a[] = new int[n];
		int c[] = new int[n - 1];

		for (int j = 0; j < n; j++) {
			a[j] = sc.nextInt();
		}

		int result = 0;
		for (int j = 0; j < n; j++) {
			result += sc.nextInt();
		}

		for (int j = 0; j < n - 1; j++) {
			c[j] = sc.nextInt();
		}


		for (int i = 0; i < n - 1; i++) {
			result += (a[i] + 1 == a[i + 1] ? c[a[i] - 1] : 0);
		}

		System.out.println(result);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
            return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
            }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
            }
        }

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
        }

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    int sum=0;
    for(int i=0;i<b;i++)
    {
        int c;
        cin >> c;
        sum+=c;
    }
    if(sum>=a)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let n = Int(readLine()!)!
    
    if n % 2 == 0 {
        print("0.5")
    } else {
        print(Double(n / 2 + 1) / Double(n))
    }
}

main()


Measured memory_bytes: 7724
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t; cin >> s >> t;
	int a, b; cin >> a >> b;
	string ss; cin >> ss;
	if (s == ss) a--;
	else b--;
	cout << a << " " << b << endl;

	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int M, N;
vector<int> A;
int sum;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		A.push_back(a);
		sum += a;
	}
	sort(A.rbegin(), A.rend());
	cout << (A[M - 1] * 4 * M >= sum ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int hight = sc.nextInt();
		sc.nextLine();
		String output;
		for (int i = 0; i < hight; i++) {
			output = sc.next();
			System.out.print("\n" + output);
			System.out.print("\n" + output);
		}
		sc.close();
	}

}

Measured memory_bytes: 24020
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000000000000LL

struct edge {
    ll from, to, coin;
};

ll N, M;
edge es[5000];
vector<int> to[2500], r_to[2500];
ll d[2500];
bool from1[2500], toN[2500], ok[2500];

void dfs(int v) {
    if (from1[v]) return;
    from1[v] = true;
    for (int u : to[v]) dfs(u);
}

void r_dfs(int v) {
    if (toN[v]) return;
    toN[v] = true;
    for (int u : r_to[v]) r_dfs(u);
}

bool shortest_path() {
    FOR(i, 1, 2500) d[i] = INF;

    bool update = true;
    REP(_, N) {
        update = false;
        for (edge e : es) {
            if (ok[e.from] && ok[e.to] && d[e.from] != INF && d[e.to] > d[e.from] + e.coin) {
                d[e.to] = d[e.from] + e.coin;
                update = true;
            }
        }
        if (!update) break;
    }
    return update;
}

int main() {
    int P;
    cin >> N >> M >> P;
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        es[i] = {A, B, P - C};
        to[A].push_back(B);
        r_to[B].push_back(A);
    }
    dfs(0);
    r_dfs(N - 1);
    REP(i, N) ok[i] = from1[i] && toN[i];

    if (shortest_path()) {
        cout << -1 << endl;
    }
    else {
        cout << max(0LL, -d[N - 1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 768
N = int(input())
A = list(map(int, input().split()))

d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

A = sorted(set(A))
t = [True] * (10 ** 6 + 1)

for a in A:
    for i in range(a + a, 10 ** 6 + 1, a):
        t[i] = False

for a in d:
    if d[a] > 1:
        t[a] = False

result = 0
for a in A:
    if t[a]:
        result += 1
print(result)


Measured memory_bytes: 44360
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
	const double pi = atan(1)*4;
	double r = 0.00;

	cin >> r;

	cout << fixed << setprecision(6) << pi*r*r << ' ' << 2*pi*r << endl;
}



Measured memory_bytes: 3272
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<map>
#include<stack>
#include<string>
#include<set>
using namespace std;
int main(){
	int x;
	cin >> x;
	if (x >= 400 && x <= 599)cout << 8 << endl;
	else if (x >= 600 && x <= 799)cout << 7 << endl;
	else if (x >= 800 && x <= 999)cout << 6 << endl;
	else if (x >= 1000 && x <= 1199)cout << 5 << endl;
	else if (x >= 1200 && x <= 1399)cout << 4 << endl;
	else if (x >= 1400 && x <= 1599)cout << 3<< endl;
	else if (x >= 1600 && x <= 1799)cout << 2<< endl;
	else if (x >= 1800 && x <= 1999)cout << 1 << endl;
	return 0;
}

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

bool isp(int n){
  if(n<2)return 0;
  if(n==2)return 1;
  if(n%2==0)return 0;
  for(int i=3;i*i<=n;i+=2){
    if(n%i==0)return 0;
  }
  return 1;
}

int main(){
  int n[50001]={0},sum,a;
  for(int i=1;i<=50000;i++){
    if(isp(i)){
      n[i]=1;
    }
  }
  while(1){
    cin>>a;
    if(a==0)break;
    sum=0;
    for(int i=2;i<=a/2;i++){
      if(n[i]==1&&n[a-i]==1)sum++;
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
		if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}
typedef pair<int, int> pii;

const LL MOD = 1e9 + 7;
const int N = 1e5 + 100;
int a[N], b[N];
bool ok[N];
int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) scanf("%d", a + i);
	for(int i = 1; i <= n; i ++) scanf("%d", b + i);
	a[0] = -1, b[n + 1] = -1;
	for(int i = 1; i <= n; i ++) 
		if(a[i] > a[i - 1]) ok[i] = 1;
	for(int i = n; i >= 1; i --) 
		if(b[i] > b[i + 1]) ok[i] = 1;
	long long ans = 1;
	for(int i = 1; i <= n; i ++) {
		if(ok[i]) {
			if(a[i] > a[i - 1] && a[i] > b[i]) ans = 0;
			if(b[i] > b[i + 1] && b[i] > a[i]) ans = 0;
		} else ans = ans * min(a[i], b[i]) % MOD;
	}
	printf("%lld\n", ans);
}		


Measured memory_bytes: 1152
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<pii>> g(n);
	REP(i, n - 1) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}
	vl d(n,INF*INF);
	d[0] = 0;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int p = q.front(); q.pop();
		REP(i, g[p].size()) {
			if (d[g[p][i].first] == INF * INF) {
				d[g[p][i].first] = d[p] + g[p][i].second;
				q.push(g[p][i].first);
			}
		}
	}
	vi c(n);
	REP(i, n) {
		c[i] = d[i] % 2;
	}
	REP(i, n)cout << c[i] << endl;
}

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

int32_t main() 
{
    int n;
    cin>>n;
    int i;
    map<string,int>m;
    for(i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m.insert({s,i});
    }
    cout<<m.size()<<endl;


	
	return 0;
}


Measured memory_bytes: 19228
l = list(map(int,input().split()))
l.sort()
a = l[0]
b = l[1]
c = l[2]
if a%2 == 0 or b%2 == 0 or c%2 == 0:
    print(0)
    exit(0)
vmax,vmin = 0,0
v = a*b*c
vmin = (c//2)*a*b
vmax = v - vmin
print(vmax-vmin)



Measured memory_bytes: 9096
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX_K = 1e4+11;
const int MAX_D = 120;
const int MOD = 1e9+7;
string K;
int D;
ll dp[MAX_K][MAX_D];

int main () {
	cin >> K >> D;
    int l = K.size();
	dp[0][0] = 1;
    FOR (i, 1, MAX_K) REP (j, D) REP (k, 10)
	    (dp[i][j] += dp[i-1][(j-k+10*D)%D]) %= MOD;
	
    ll ans = 0;
	ll s = 0;
    REP (i, l) {
		int k = K[i] - '0';
        FOR (j, 1, k+1) {
			int t = (D*D*D-(s+j-1))%D;
			(ans += dp[l-1-i][t]) %= MOD;	
		}	
		(s += k) %= D;
	}
	if (s%D) (ans += MOD - 1) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll A, B, C; cin >> A >> B >> C;


  vector<ll> m;


  ll cnt = 1;
    while(1){
      ll i = cnt;
      ll amari = (i*A)%B;
      if(amari == C){ cout << "YES" << endl; return 0;}

      m.pb(amari);
      rmsame(m);
      if(m.size()  != cnt) break;
      cnt ++ ;
  }

  cout << "NO" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

using namespace std;

long long a[5043];
int dp[5043];

bool cmp(int u, int v) {
  return u > v;
}

int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d%d", &n, &k);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  sort(a + 1, a + n + 1, cmp);
  int ans = 0;
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    bool flag = false;
    for (int j = 0; j < k; ++j) {
      if (dp[j] == 1 && j + sum >= k) {
        flag = true;
        break;
      } 
    }
    if (!flag) {
      ++ans;
    }
    sum -= a[i];
    for (int j = k - 1; j >= a[i]; --j) {
      dp[j] |= dp[j - a[i]];
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

vector<bool> visited;
vector<vector<int>> E;
array<vector<int>, 2> route;

void dfs(int i, int num, int route_num){
    route[route_num].push_back(i);
    int cnt = 0;
    for (const auto &e: E[i]){
        if (visited[e])
            continue;
        visited[e] = true;
        dfs(e, 1, route_num++);
        if (++cnt >= num)
            break;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    E.resize(n + 1);
    visited.resize(n + 1);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    visited[1] = true;
    dfs(1, 2, 0);

    cout << route[0].size() + route[1].size() << endl;
    copy(route[0].rbegin(), route[0].rend(), ostream_iterator<int>(cout, " "));
    copy(route[1].begin(), route[1].end(), ostream_iterator<int>(cout, " "));
        
}

Measured memory_bytes: 13944
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        String s = scanner.next();
        int ans = 0;
        for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
            if (s.charAt(i) != s.charAt(j)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[]$) {
        try {
            new Main().solve();
            System.out.flush();
        } catch (Throwable t) {
            System.out.flush();
            t.printStackTrace();
        }
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r,c;
    cin>>r>>c;
    int A[r+1][c+1];
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            A[i][j]=0;
        }
    }
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            int t;
            cin>>t;
            A[i][j]=t;
            A[i][c]+=t;
        }
    }
    for(int j=0;j<c+1;j++){
        for(int i=0;i<r;i++){
            A[r][j]+=A[i][j];
        }
    }
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            cout<<A[i][j];
            if(j!=c) cout<<' ';
        }
        cout<<endl;
    }
    
}


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

int main(){
	int a, b, c, d, e=0, n;
	while (cin >> n){
		for (a = 0; a <= 9; a++){
			for (b = 0; b <= 9; b++){
				for (c = 0; c <= 9; c++){
					for (d = 0; d <= 9; d++){
						if (a + b + c + d == n)e++;
					}
				}
			}
		}
		cout << e << '\n';
		e = 0;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    long long n, m;
    cin >> n >> m;
    long long cnt = 0;
    if (m >= n * 2) {
        cnt = n;
        m -= 2 * n;
        cnt += m / 4;
    }
    else {
        cnt = m / 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,x;
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(i=0;i<n;i++) scanf("%d",&x),sum+=x-1;
        printf("%d\n",sum);
    }
    return 0;
}

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

int n;

signed main()
{
	string s;
	cin>>s;
	n=s.size();
	for (int i=0;i<n;i++)
	{
		if (s[i]=='?')  s[i]='D';
	}
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll,ll>> res;
  for (ll a = 2; a * a <= n; a++) {
    if (n % a != 0) continue;
    ll ex = 0;
    while (n % a == 0) { ++ex; n /= a; }
    res.push_back({a, ex});
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

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

int main() {
  IOS;
  ll a,b;
  cin >> a >> b;
  ll g = gcd(a,b);
  auto f = prime_factorize(g);
  COUT(f.size() + 1);
  return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    string ans = "";
    if (n == 0) {
        cout << "0" << endl;
        return 0;
    }
    while (n != 0) {
        if (n%2) {
            ans = "1" + ans;
            n--;
        }
        else ans = "0" + ans;
        n /= -2;
    }
    cout << ans << endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System .in));
		String[] inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);
		int m = Integer.parseInt(inputs[1]);
		System.out.println(n*(n-1)/2 + m*(m-1)/2);
	}
}


Measured memory_bytes: 20948
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using ll = long long;
using namespace std;

int main() {
	string s; cin >> s;
	int before = s.size();
	ll count1=0 ,count0=0;
	rep(i, s.size()) {
		if (s[i] == '1') {
			count1++;
		}
		else if(s[i]=='0' ){
			count0++;
			
		}
	}
	cout << min(count1, count0)*2 << endl;
}


Measured memory_bytes: 512
n = int(input())
for i in range(n):
    p = 0
    out = 0
    x = i % 2
    state = [0,0,0]
    while True:
        s = str(input())

        if s == "HIT":
            if state[0] == 1:
                p += 1
            state[0],state[1],state[2] = state[1],state[2],1
        elif s == "HOMERUN":
            point = state.count(1)
            p = p + point + 1
            state = [0,0,0]
        elif s == "OUT":
            out = out + 1
        if out == 3:
            break

    print(p)



Measured memory_bytes: 5592
#include <stdio.h>

int keta(int n){
  int count = 0;
  for(;n>0;n /= 10){
	count ++;
  }
  return count;
}


int main(void){
  int a,b;
int  n= 0;
  while(n<200){
	
	if(scanf("%d",&a) == EOF || scanf("%d",&b) == EOF){
	  break;
	}
	
	printf("%d\n",keta(a+b));
	n++;

  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,A,B,C,l[10],mn,deep[10],val[10];
int mini (int one,int two, int three){
    int cost = 0;
    cost = (one-1)*10 + (two-1)*10 + (three-1)*10;
    int sum;

    sum = 0;
    for(int i=1;i<=one;i++){
        sum+=val[i];
    }
    cost += abs(sum-A);

    sum=0;
    for(int i=one+1;i<=one+two;i++){
        sum+=val[i];
    }
    cost += abs(sum-B);

    sum=0;
    for(int i=one+two+1;i<=one+two+three;i++){
        sum+=val[i];
    }
    cost += abs(sum-C);

    return cost;
}
void C3 (int lim){
    //cout<<"Combi\n";
    for(int i=1;i<lim;i++){
        for(int j=1;j<lim;j++){
            int c = (lim-i-j);
            if(c>0){
                //cout<<i<<" "<<j<<" "<<c<<endl;
                //cout<<mini(i,j,c)<<endl;
                mn = min(mn,mini(i,j,c));
            }
        }
    }
    //cout<<endl;
}
void permute (int lim){
    int arr[10];
    for(int i=1;i<=lim;i++)arr[i]=i;

    for(int i=1;i<=lim;i++){
        val[i] = l[deep[arr[i]]];
        //cout<<val[i]<<" ";
    }
    C3(lim);
    //cout<<endl;
    while(next_permutation(arr+1,arr+1+lim)){
        for(int i=1;i<=lim;i++){
            //cout<<deep[arr[i]]<<" ";
            val [i] = l[deep[arr[i]]];
            //cout<<val[i]<<" ";
        }//cout<<endl;
        C3(lim);
        //cout<<endl;
    }
}
void choose (int x, int lim){
    int start;
    if(x==1)start = 1;
    else{start = deep[x-1] + 1;}

    int fin = n - lim + x;
    for(int i=start;i<=fin;i++){
        deep[x] = i;
        if(x<lim){choose(x+1,lim);}
        else {
//            cout<<"Permutation\n";
//            for(int j=1;j<=lim;j++){
//                cout<<deep[j]<<" ";
//            }cout<<endl;
            permute(lim);
        }
    }
}
int main(){


    cin>>n>>A>>B>>C;
    for(int i=1;i<=n;i++)cin>>l[i];
    mn = 100000000;

    for(int i=3;i<=n;i++){
        choose(1,i);
    }
    cout<<mn<<endl;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<double> vec(N);

    for (int i=0; i<N; i++){
      cin >> vec.at(i);
    }
  
    sort(vec.begin(), vec.end());
    
    double mazemono = 0.0;
    for (int i=0; i<N; i++){
        if (i == 0) {
          mazemono = vec.at(i);
          continue;
        }
        mazemono = (mazemono + vec.at(i)) / 2;
    }
  
    cout << mazemono << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char str[100010];
int V[200001];
int main(){
	scanf("%s",str);
	int n=strlen(str);
	long long ret=0LL;
	int now=0;
	for(int i=n-1;i>=0;i--){
		ret+=V[-now+100000];
//		printf("%d\n",V[-now+100000]);
		V[-now+100000]++;
		if(str[i]=='(')now++;
		else now--;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1256
n,m=map(int,input().split())
if n==1:
    number=10
    num_lst=[str(i) for i in range(10)]
elif n==2:
    number=90
    num_lst=[str(i) for i in range(10,100)]
else:
    number=900
    num_lst=[str(i) for i in range(100,1000)]
    
for i in range(m):
    s,c=map(int,input().split())
    for j in range(number):
        if num_lst[j][s-1]!=str(c):
            num_lst[j]="NaN"
for i in num_lst:
    if i!="NaN":
        print(int(i))
        exit()
print(-1)

Measured memory_bytes: 65036
n = int(input())
s = [input() for i in range(n)]
count = 0
count_a = 0
count_b = 0
count_ab = 0
for i in range(n):
    count += s[i].count("AB")
    if s[i][-1] == "A" and s[i][0] != "B":
        count_a += 1
    if s[i][0] == "B" and s[i][-1] != "A":
        count_b += 1
    if s[i][0] == "B" and s[i][-1] == "A":
        count_ab += 1


if count_ab == 0:
    print(count+min([count_a,count_b]))
else:
    if count_a + count_b == 0:
        print(count+count_ab-1)
    else:
        print(count+min([count_a,count_b])+count_ab)


Measured memory_bytes: 3700
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
 
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;
 

void solve(){
    int n;
    cin >> n;
    ll b = 1000000000000000000LL;
    vector<ll> a(n,0);
    rep(i,n) cin >> a[i];
    ll ans = 1LL;
    rep(i,n){
        if (a[i] == 0){
            cout << 0;
            rn;
        }
    }
    rep(i,n){
        if (b/a[i] <= ans && (b%a[i] != 0 || b/a[i] != ans ) ){
            cout << -1;
            return;
        }
        ans = ans*a[i];

    }
    cout << ans;
}


 
int main(){
    int T;
    T = 1;
    while(T--){
        solve(); 
    }
}
 


Measured memory_bytes: 3988
#include <iostream>
using namespace std;
#define LEN 100005

typedef struct Process { char name[100]; int time; } P;

P Q[LEN];
int head, tail;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {

    int n, q;
    cin >> n >> q;

    head = 1;
    tail = 1;

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

    P user;
    int total = 0;
    while (head != tail) {
        user = dequeue();
        int cost = 0;
        cost = min(q, user.time);
        user.time -= cost;
        total += cost;
        if (0 < user.time)
            enqueue(user);
        else
            cout << user.name << " " << total << endl;
    }

    return 0;
}

Measured memory_bytes: 11324
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0),eps=1e-8;
const int maxn=1e5+10;
const ll mod=1e9+7;
string s;
int main()
{
	int n;
	cin>>n;
	cin>>s;
	int cnt=0,ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')cnt++;
	}
	for(int i=0;i<cnt;i++){
		if(s[i]=='W')ans++;
	}
	cout<<ans<<endl;
 	return 0;
}


Measured memory_bytes: 3392
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var ans = 1000000000000000000L
    val A = readLine()!!.split(" ").map(String::toLong)
    var r = A.sum()
    var l = 0L
    for (i in 0..N-2) {
        r -= A[i]
        l += A[i]
        ans = Math.min(ans, Math.abs(r - l))
    }
    println(ans)
}

Measured memory_bytes: 80792
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const double EPS=1e-8;

struct point3{
	double x,y,z;
	point3():x(0),y(0),z(0){}
	point3(double x,double y,double z):x(x),y(y),z(z){}
	point3 &operator*=(double c){ x*=c; y*=c; z*=c; return *this; }
	point3 &operator/=(double c){ x/=c; y/=c; z/=c; return *this; }
	point3 operator+(const point3 &a)const{ return point3(x+a.x,y+a.y,z+a.z); }
	point3 operator-(const point3 &a)const{ return point3(x-a.x,y-a.y,z-a.z); }
	point3 operator-()const{ return point3(-x,-y,-z); }
};

point3 operator*(double c,const point3 &a){ return point3(c*a.x,c*a.y,c*a.z); }

double dot(const point3 &a,const point3 &b){ return a.x*b.x+a.y*b.y+a.z*b.z; }

point3 cross(const point3 &a,const point3 &b){ return point3(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x); }

double abs(const point3 &a){ return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); }

double abs2(const point3 &a){ return a.x*a.x+a.y*a.y+a.z*a.z; }

point3 rot(const point3 &p,const point3 &a,double t){
	return cos(t)*p+(1-cos(t))*dot(p,a)*a+sin(t)*cross(a,p);
}

struct line3{
	point3 a,b;
	line3(){}
	line3(const point3 &a,const point3 &b):a(a),b(b){}
};

struct sphere{
	point3 c;
	double r;
	sphere():c(point3(0,0,0)),r(0){}
	sphere(const point3 &c,double r):c(c),r(r){}
};

point3 proj(const point3 &p,const line3 &L){ return L.a+dot(p-L.a,L.b-L.a)/abs2(L.b-L.a)*(L.b-L.a); }

double dist(const point3 &a,const point3 &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

double dist(const line3 &L,const point3 &p){
	return abs(cross(L.b-L.a,p-L.a))/abs(L.a-L.b);
}

int get_intersect(const sphere &S,const line3 &L,vector<point3> &res){
	point3 h=proj(S.c,L);
	double d=abs(S.c-h);
	if(d>S.r+EPS) return 0;
	if(d>S.r-EPS){
		res.push_back(h);
		return 1;
	}
	else{
		point3 v=L.b-L.a;
		v*=sqrt(S.r*S.r-d*d)/abs(v);
		res.push_back(h+v);
		res.push_back(h-v);
		return 2;
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		point3 v; scanf("%lf%lf%lf",&v.x,&v.y,&v.z);
		sphere S[100];
		rep(i,n) scanf("%lf%lf%lf%lf",&S[i].c.x,&S[i].c.y,&S[i].c.z,&S[i].r);

		point3 p;
		while(1){
			int i_next=-1;
			point3 next;
			line3 L(p,p+v);
			rep(i,n) if(dot(v,S[i].c-p)>EPS) {
				vector<point3> Q;
				get_intersect(S[i],L,Q);
				rep(j,Q.size()){
					point3 q=Q[j];
					if(i_next==-1 || dist(p,next)>dist(p,q)) i_next=i, next=q;
				}
			}
			if(i_next==-1) break;

			point3 nor=next-S[i_next].c;
			double phi=acos(dot(-v,nor)/abs(v)/abs(nor));
			point3 h=cross(nor,-v); h/=abs(h);
			v=rot(-v,h,-2*phi);
			p=next;
		}

		printf("%.9f %.9f %.9f\n",p.x,p.y,p.z);
	}

	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
using ll = long long;

int main(){
  ll n, a, b; 
  cin >> n >> a  >> b;
  if(a+b>=n) cout  <<  min(a, n) << endl;
  else cout << a* (n / (a+b)) + min(n%(a+b), a)  << endl;
  return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=[int(x) for x in input().split()]
A=[]
for i in range(N):
    a=[int(x) for x in input().split()]
    A.append(a)
cnt=0
check=0
for i in range(N):
    for j in range(M):
        check+=B[j]*A[i][j]
    if check>-C:
        cnt+=1
    else:
        pass
    check=0
print(cnt)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    long long a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);

    if(c-a-b < 0){
        printf("No\n");
        return 0;
    }
    long long x = (c-a-b) * (c-a-b);
    long long y = 4 * a * b;

    if(x > y){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int A[301010];
map<int, int> cnt;

int main()
{
    cin >> N;
    rep(i, 0, N)
    {
        cin >> A[i];
        cnt[A[i]]++;
    }
    for (auto e : cnt)
    {
        if (e.second >= 2)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 10368
import sys
input = sys.stdin.readline

n, t = map(int, input().split())
food_l = []
for _ in range(n):
    a, b = map(int, input().split())
    food_l.append((a, b))
food_r = food_l[::-1]

dp_l = [ [0]*t for _ in range(n+1) ]
dp_r = [ [0]*t for _ in range(n+1) ]
for i in range(1, n+1):
    a_l, b_l = food_l[i-1]
    a_r, b_r = food_r[i-1]
    for j in range(t):
        dp_l[i][j] = max(dp_l[i][j], dp_l[i-1][j])
        if j + a_l < t:
            dp_l[i][j+a_l] = max(dp_l[i][j+a_l], dp_l[i-1][j]+b_l)
        
        dp_r[i][j] = max(dp_r[i][j], dp_r[i-1][j])
        if j + a_r < t:
            dp_r[i][j+a_r] = max(dp_r[i][j+a_r], dp_r[i-1][j]+b_r)

ans = 0
for i in range(n):
    res = max(food_l[i][1]+dp_l[i][j]+dp_r[n-i-1][t-j-1] for j in range(t))
    ans = max(res, ans)
print(ans)

Measured memory_bytes: 182152
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	long long ln_2,ln_1=-1,ln=2;
	for(int i=0;i<n;i++){
		ln_2=ln_1;
		ln_1=ln;
		ln=ln_2+ln_1;
	}
	cout<<ln<<endl;
}


Measured memory_bytes: 256