akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;

map<ll,ll> prime_factor(ll n){ //素因数分解
    map<ll,ll> table;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            table[i]++;
            n/=i;
        }
    }
    if(n!=1) table[n]=1;
    return table;// key->素因数, value->べき乗
}

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    for(int i=1;i<=n;i+=2){
        map<ll,ll> table;
        table=prime_factor(i);
        map<ll,ll>::iterator it;
        ll res=1;
        for(it=table.begin();it!=table.end();it++){
            res*=it->second+1;
        }
        if(res==8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
a = int(S[0:2])
b = int(S[2:4])
fym = False
fmy = False
if 1<=a<=12:
  fmy = True
if 1<=b<=12:
  fym = True
if fmy and fym:
  print("AMBIGUOUS")
elif fmy:
  print("MMYY")
elif fym:
  print("YYMM")
else:
  print("NA")

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

using namespace std;

int main(){
  int X, Y;
  cin >> X >> Y;
  int m = 0;
  if(X == 3) m += 100000;
  if(X == 2) m += 200000;
  if(Y == 3) m += 100000;
  if(Y == 2) m += 200000;
  if(X == 1 && Y == 1) m += (300000 * 2 + 400000);
  else if(X == 1) m += 300000;
  else if(Y == 1) m += 300000;
  
  cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
map<ll,ll> ma;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int n,m;  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i,0,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  int cnt = 0;
  rep(i,0,m){
    UnionFind uf(n);
    rep(j,0,m){
      if(i==j) continue;
      uf.merge(a[j], b[j]);
    }
    if(uf.size(0)!=n) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
//using ll = long long;
 
int main() {
  int n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  if (10%p == 0) { // 2,5
    long long ans = 0;
    rep(r,n) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
 
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  long long ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1412
#include "stdio.h"

int main(void)
{
  int a, b, c, d;
  if ( scanf("%d %d %d %d", &a, &b, &c, &d ) ) {
  
  int cnt = 0;
  while( a > 0 && c > 0 ) {
    if( cnt % 2 == 0 ) {
      c -= b;
      cnt++;
    }
    else {
      a -= d;
      cnt--;
    }
  }
  
  if ( a <= 0 ) {
    printf("No");
  }
  else {
    printf("Yes");
  }
  }
  
  return 0;
}

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

int main() {
    int k;
    string s;
    cin >> k >> s;
    
    
    if(s.size()>k){
        for(int i=0; i<k; i++){
        cout << s.at(i);
    }
        cout << "..." << endl;
    }
    else{
    cout << s << endl;
}
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long dp[505][505];
long long n,m,q;
long long l,r;
int main() {
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1; i<=m; i++) {
		scanf("%d%d",&l,&r);
		dp[l][r]++;
		}
	for(int i=1; i<=n; i++)
		for(int r=1; r<=n; r++) {
			dp[r][r+i]+=dp[r][r+i-1]+dp[r+1][r+i]-dp[r+1][r+i-1];
			}
	for(int i=1; i<=q; i++) {
		scanf("%d%d",&l,&r);
		printf("%d\n",dp[l][r]);
		}
	}




Measured memory_bytes: 2944
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int n;
int d[8][8];
int u[8];

int f(int now, int len){
	if(len==1) return 1;
	u[now]=1;
	int ans=0;
	for(int i=0; i<n; i++){
		if(u[i]==0 && d[now][i]!=0) ans+=f(i, len-1);
	}
	u[now]=0;
	return ans;
}

int main(void){
	int m, i;
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		d[a-1][b-1]=1;
		d[b-1][a-1]=1;
	}
	int ans = f(0, n);
	printf("%d\n", ans);
}


Measured memory_bytes: 128
while 1:
	N,M = map(int,raw_input().split())
	if N == 0: break
	T = [[0]*1261 for i in range(M)]
	r = input()
	tnms = sorted([map(int,raw_input().split()) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[m-1][t1:t2] = [1 for j in range(t1,t2)]
	for i in range(input()):
		ts,te,m = map(int,raw_input().split())
		print sum(T[m-1][ts:te])

Measured memory_bytes: 161296
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
    int a, b;
    while(cin >> a >> b){
        if(a == 0 && b == 0)return 0;
        for(int i=0; i < a; i++){
            for(int j=0; j < b; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint digit_sum(lint num){
    lint dig;
    lint sum = 0;
    while(num){
        dig = num % 10;
        sum = sum + dig;
        num = num / 10;
    }
    return sum;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    lint b;
    lint d_sum;
    lint ans = INF;
    for (lint a = 1; a < n; ++a){
        b = n - a;
        d_sum = digit_sum(a) + digit_sum(b);
        ans = min(d_sum, ans);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;

const MOD:usize = 1_000_000_007;
 
#[fastout]
fn main() {
  input! {
    h: usize,
    w: usize,
    kk: usize
  }
  
  let mut dp: Vec<Vec<usize>> = vec![vec![0;w];h+1];
  dp[0][0] = 1;
  
  for r in 0..h {
    for c in 0..w {
      for k in 0..(1 << (w-1)) {
        let mut ok = true;
        
        let w = if w < 2 {
          2
        } else {
          w
        };
        
        for l in 0..(w-2) {
          if (k >> l) & 1 == 1 && k >> l+1 & 1 == 1 {
            ok = false;
          }
        }
        
        if !ok { continue }
        if c >= 1 && k >> (c - 1) & 1 == 1 {
          dp[r+1][c-1] += dp[r][c];
          dp[r+1][c-1] %= MOD;
        }
        else if c <= w-2 && k >> c & 1 == 1 {
          dp[r+1][c+1] += dp[r][c];
          dp[r+1][c+1] %= MOD;
        }
        else {
          dp[r+1][c] += dp[r][c];
          dp[r+1][c] %= MOD;
        } 
      }
    }
  }
  
  println!("{}", dp[h][kk-1]);
}

Measured memory_bytes: 2180
import itertools
ans_li = []
n,m,x = map(int,input().split())
li = []
for _ in range(n):
    li.append(list(map(int,input().split())))

for i in range(n):
    if i == 0:
        tmp = [kkk for kkk in range(n)]
        #print(tmp)
        #score_li = [0]*m
        #okane = 0
        #print([k for k in range(n)],i+1,tmp)
        for t in tmp:
            score_li = [0]*m
            okane = 0
            #print(li,t,'ttttt')
            for ii,ll in enumerate(list(li[t])):
                if ii==0:
                    okane += li[t][ii]
                else:
                    #print(score_li,ii,ll)
                    score_li[ii-1]+=ll
            flag = True
            #print(score_li,okane)
            for ss in score_li:
                if ss<x:
                    flag = False
            if flag:
                ans_li.append(okane)

    else:
        tmp = list(itertools.combinations(range(n), i+1))
        #print(tmp)
        #score_li = [0]*m
        #okane = 0
        #print([k for k in range(n)],i+1,tmp)
        for t in tmp:
            score_li = [0]*m
            okane = 0
            #print(li,t,'ttttt')
            for aaa in t:
                for ii,ll in enumerate(list(li[aaa])):
                    if ii==0:
                        okane += li[aaa][ii]
                    else:
                        #print(score_li,ii,ll)
                        score_li[ii-1]+=ll
            flag = True
            for ss in score_li:
                if ss<x:
                    flag = False
            if flag:
                ans_li.append(okane)
#print(ans_li)
if len(ans_li)>0:
    print(min(ans_li))
else:
    print(-1)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
//ユークリッドの互除法


int main(){
    
    
    int a, b;
    int r = 1;
    
    std::cin >> a >> b;
    
    while(1){
        r = a % b;
        if(r == 0)break;
        a = b;
        b = r;
    }
    
    std::cout << b << "\n";
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int r, D, x; cin >> r >> D >> x;

    int year = 2000;
    while (year <= 2010) {
        if (year > 2000) {
	  cout << x << endl;
        }
        x = r*x-D;
        year++;
    }

    return 0;
}


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 INF 1e9
using namespace std;

int N, K;

vector<int> h;

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

    h.assign(N, 0);

    rep(i, N)
    {
        cin >> h[i];
    }

    int count = 0;
    rep(i, N)
    {
        if (h[i] >= K)
        {
            count++;
        }
    }

    cout << count;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=3e5+5;

int n;
int a[N];

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int ans=pow(3LL, n, 2e18);
	int subt=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]%2)
			subt*=1;
		else
			subt*=2;
	}
	ans-=subt;
	cout<<ans;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string ch = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl p;
/******* define variable end *******/
int solve() {
	cin >> n;
	p.resize(n);
	REP(i, n){
		cin >> p[i];
	}
	ll ans = 0;
	REP(i, n-1){
		if(p[i] == i + 1){
			ans++;
			ll tmp = p[i+1];
			p[i+1] = p[i];
			p[i] = tmp;
		}
	}
	if(p[n-1] == n){
		ans++;
		ll tmp = p[n-1];
		p[n-1] = p[n-2];
		p[n-2] = tmp;
	}
	cout << ans << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int N;
    vector<string> S;
    vector<int> T;
    string X;
    cin >> N;
    int t_s = 0;
    for(int i = 0; i < N; i++){
        string s;
        int t;
        cin >> s >> t;
        S.push_back(s);
        T.push_back(t);
        t_s += t;
    }
    cin >> X;

    for(int i = 0; i < N; i++){
        if(S[i] == X){ 
            t_s -= T[i];
            break;
        }
        else{
            t_s -= T[i];
        }
    }
    cout << t_s << endl;
}

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

int main() {
  double a, b;
  int x;
  cin >> a >> b;
  x = (a + b) / 2;
  if((a + b) / 2 == x + 0.5){
    x += 1;
  }
  cout << x << endl;
}


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

using namespace std;

#define ll long long
#define f(i,a,n) for(ll i=a;i<n;i++)

int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n,m;
    cin>>n>>m;
    int a[n];
    double s=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s=s+a[i];
    }
    
    s=ceil(s/(4*m));
    int cnt=0;
    
    for(int i=0;i<n;i++)
    {
        if(a[i]>=s)
        cnt++;
    }
    
    (cnt>=m)?cout<<"Yes\n":cout<<"No\n";
    
    return 0;
}


Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    c = Counter(prime_factorize(n))
    lck = list(c.keys())
    lcv = list(c.values())
    lenlcv = len(lcv)
    ans = 0
    p = 1
    for i in range(lenlcv):
        while lcv[i]-p >= 0:
            lcv[i] -= p
            ans += 1
            p += 1
        p = 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 27240
#include<stdio.h>

int main()

{

	int S,h,m,s;

	scanf("%d", &S);

	h = S / 3600;

	S = S % 3600;

	m = S / 60;

	S = S % 60;

	s = S;

	printf("%d:%d:%d\n", h,m,s);

	return 0;

}

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

using namespace std;

int main(){

    int N;
    cin >> N;
    string S;
    cin >> S;

    int left = -1;
    for (int i = 0; i < N; i++){
        if (S[i] == ')'){
            left = i;
        }
    }

    int right = -1;
    for (int i = N - 1; i >= 0; i--){
        if (S[i] == '('){
            right = i;
        }
    }
    
    int countl = 0;
    if (left != -1){
        int res = 0;
        for (int i = 0; i <= left; i++){
            if (S[i] == ')'){
                if (res > 0){
                    res --;
                }else{
                    countl ++;
                }
            }else{
                res ++;
            }
        }
    }

    int countr = 0;
    if (right != -1){
        int res = 0;
        for (int i = N - 1; i >= right; i--){
            if (S[i] == '('){
                if (res > 0){
                    res --;
                }else{
                    countr ++;
                }
            }else{
                res ++;
            }
        }
    }    



    string ans = S;
    if (countl > 0){
        for (int i = 0; i < countl; i++){
            ans = '(' + ans;
        }
    }
    if (countr > 0){
        for (int i = 0; i < countr; i++){
            ans = ans + ')';
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python
All = 0
q = []
Queue = []
tmp,time = map(int,input().split())
for i in range(tmp):
    p,zi =input().split()
    q.append([p,int(zi)])
while len(q) > 0:
    if q[0][1]<= time:
        All+=q[0][1]
        v=q.pop(0)
        Queue.append([v[0],All])
    else:
        All+=time
        q[0][1]-=time
        last=q.pop(0)
        q.append(last)
for i in range(len(Queue)):
    print("{0} {1}".format(Queue[i][0],Queue[i][1]))


Measured memory_bytes: 14476
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

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

const int MAXW = 52;

bool tile[MAXW][MAXW];

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

int solve(int x, int y)
{
    if(!tile[x][y]) return 0;
    tile[x][y] = false;
    REP(8)
        solve(x + dx[i], y + dy[i]);
    return 1;
}
int w,h;
int main()
{
    while(cin >> w >> h && w)
    {
        memset(tile, false, sizeof(tile));

        rep(j,h)rep(i,w) cin >> tile[i+1][j+1] ;

        int ans = 0;
        rep(j,h)rep(i,w)ans += solve(i+1, j+1);
        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'
#define N 1000001
#define mod 1e9+7
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll ans=INT_MAX;
	ll a[n],f[n];
	for(ll i=0;i<n;i++){
	    cin>>a[i];
	}
	f[0]=0;
	f[1]=abs(a[0]-a[1]);
	for(ll i=2;i<n;i++){
	    if(i<k){
	        for(ll j=i-1;j>=0;j--){
	            ans=min(f[j]+abs(a[j]-a[i]),ans);
	        }
	        f[i]=ans;
	    }else{
	        for(ll j=i-1;j>=i-k;j--){
	            ans=min(f[j]+abs(a[j]-a[i]),ans);
	        }
	        f[i]=ans;
	    }
	    ans=INT_MAX;
	}
	cout<<f[n-1];
	return 0;
}


Measured memory_bytes: 5196
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

X,Y=LI()

a = (2*X - Y) // 3
b = (2*Y - X) // 3

FACT = FLIST(1000000)
if (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0 and a >= 0 and b >= 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)


Measured memory_bytes: 116336
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

vector<vector<int>> graph(101);

vi d(101, -INF), f(101);

int cur = 0;

void dfs(int s){
  d[s] = ++cur;
  for (auto next : graph[s]) {
    if (d[next] != -INF) continue;
    dfs(next);
  }
  f[s] = ++cur;
}

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

  int n; cin >> n;
  graph.resize(n); d.resize(n); f.resize(n);

  rep(i, n) {
    int u, k; cin >> u >> k;
    --u;
    rep(j, k) {
      int v; cin >> v; --v;
      graph[u].push_back(v);
    }
  }
  dfs(0);

  for (int i = 0; i < n; ++i) {
    if (d[i] == -INF) dfs(i);
    cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 3164
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

double dp[sze][sze];

void solve(){
    int n;
    cin>>n;
    double head[n+1];
    double tail[n+1];
    rep(i,n) {
        cin>>head[i+1];
        tail[i+1]=1.0-head[i+1];
    }
    memset(dp,0,sizeof(dp));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++){
        dp[i][0]=tail[i]*dp[i-1][0];
        for(int j=1;j<=i;j++){
            dp[i][j]=head[i]*dp[i-1][j-1]+tail[i]*dp[i-1][j];
        }
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
    ans+=dp[n][i];

    cout<<fixed<<setprecision(10)<<ans<<endl;

}

int main(){
    solve();
}


Measured memory_bytes: 74388
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, m, ans, now;
int vis[100010];
int s[100010];
vector<int> a[100010];
 
void dfs(int x)
{
	bool flag = 0;
	for(int i = 0; i < a[x].size(); i ++)
		if(!vis[a[x][i]]) {vis[a[x][i]] = 1, flag = 1, dfs(a[x][i]); break;}
	if(flag == 0) now = x;
}
 
void dfs1(int x)
{
	for(int i = 0; i < a[x].size(); i ++)
	{
		int to = a[x][i];
		if(vis[to]) continue;
		vis[to] = 1;
		s[++ ans] = to;
		dfs1(to);
		break;
	}
}
#define SZ 666666
int ea[SZ],eb[SZ],es[SZ];
int rn() {return rand()&32767;}
int mr() {return rn()*32768+rn();}
int main()
{ 
	n = read();
	m = read();
	srand(time(0)^n^(m+23333)^19260817);
	for(int i = 1; i <= m; i ++)
	{
		int x=read(),y=read();
		a[x].push_back(y);
		a[y].push_back(x);
	}
	while(1)
	{
	memset(vis, 0, sizeof(vis)); now=ans=0;
	for(int i = 1; i <= n; i ++)
		random_shuffle(a[i].begin(),a[i].end());
	int x=mr()%n+1;
	vis[x] = 1; dfs(x);
	memset(vis, 0, sizeof(vis));
	vis[now] = 1;
	s[++ ans] = now;
	dfs1(now);
	if(ans<2)
		continue;
	for(int i = 1; i <= n; i ++) vis[i]=0;
	for(int i = 1; i <= ans; i ++) vis[s[i]]=1;
	int ss[2]={s[1],s[ans]};
	bool gg=0;
	for(int p=0;p<2;p++)
	{
		int x=ss[p];
		for(int b:a[x])
			if(!vis[b]) {gg=1; break;}
		if(gg) break;
	}
	if(gg) continue;
	cout << ans << endl;
	for(int i = 1; i <= ans; i ++)
		cout << s[i] << " ";
	return 0;
	}
}

Measured memory_bytes: 8704
H,W=map(int,input().split())
A=[input() for i in range(H)]
tate=[0]*H
yoko=[0]*W
for i in range(W):
    for j in range(H):
        if A[j][i]=="#":
            tate[j]=1
            yoko[i]=1
ans=[]
for j in range(H):
    if tate[j]==0:
        continue
    a=''
    for i in range(W):
        if yoko[i]==0:
            continue
        a+=A[j][i]
    ans.append(a)
for a in ans:
    print(a)

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


int main() {
  int A, B;
  cin >> A >> B;
  
  int ans;
  if (A >= 13) ans = B;
  else if (A >= 6) ans = B/2;
  else ans = 0;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main(){
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if(e-a>k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $a, $b);
fscanf(STDIN, "%s", $s);

$arr = str_split($s);
$qualifier = 0;
$abroad_qualifier = 0;
$qualifier_limit = $a + $b;

for ($i = 0; $i < $N; $i++) {
    switch ($arr[$i]) {
        case "a":
            if ($qualifier < $qualifier_limit) {
                $qualifier++;
                echo "Yes" . "\n";
            } else {
                echo "No" . "\n";
            }
            break;
        case "b":
            if ($qualifier < $qualifier_limit && $abroad_qualifier < $b) {
                $qualifier++;
                $abroad_qualifier++;
                echo "Yes" . "\n";
            } else {
                echo "No" . "\n";
            }
            break;
        case "c":
            echo "No" . "\n";
            break;
    }
}

Measured memory_bytes: 22224
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int n, ma, mb;
vector<int> a, b, c;
int dp[45][405][405];
/**********************************************/

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

    cin >> n >> ma >> mb;
    a.assign(n, 0);
    b.assign(n, 0);
    c.assign(n, 0);

    REP(i, n) cin >> a[i] >> b[i] >> c[i];

    REP(i, 405) REP(j, 405) dp[0][i][j] = INF;
    REP(i, 45) dp[i][0][0] = 0;
    REP(i, n){
        REP(j, 401){
            REP(k, 401){
                if(j >= a[i] && k >= b[i]) 
                    dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);
                else
                    dp[i+1][j][k] = dp[i][j][k];
            }
        }
    }

    int ans = INF;
    for(int i = 1; ma * i <= 400 && mb * i <= 400; i++){
        ans = min(ans, dp[n][ma*i][mb*i]);
    }
    cout << (ans != INF ? ans : -1) << endl;
}


Measured memory_bytes: 29056
def patties_num_of_level(n, x)
  if n == 0
    return 1
  end

  if x == 1
    return 0
  elsif x.between?(2, @a[n - 1] + 1)
    return patties_num_of_level(n - 1, x - 1)
  elsif x == @a[n - 1] + 2
    return @p[n - 1] + 1
  elsif x.between?(@a[n - 1] + 3, @a[n] - 1)
    return @p[n - 1] + patties_num_of_level(n - 1, x - @a[n - 1] - 2) + 1
  else
    return @p[n - 1] * 2 + 1
  end
end

N, X = gets.split.map(&:to_i)

@a = [1]
@p = [1]

N.times do |i|
  @a << (@a[i] * 2 + 3)
  @p << (@p[i] * 2 + 1)
end

puts patties_num_of_level(N, X)


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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;

const int N = 1e5 + 10, L = 2;

int n;
ll l;
string s[N];

ll get(ll l) {
  return 1 << __builtin_ctz(l);
}

struct Trie {
  struct Node {
    int level;
    int ch[L];
    int mat;
    Node(int lv = 0) {
      memset(ch, 0, sizeof(ch));
      mat = 0;
      level = lv;
    }
  } pool[N * L];

  int root;
  int node_cnt;
  
  void init() {
    root = node_cnt = 1;
    pool[node_cnt] = Node();
  }

  int get_node(int level = 0) {
    pool[++node_cnt] = Node(level);
    return node_cnt;
  }

  void insert(const char *s) {
    int p = root;
    for (int i = 0; s[i]; ++i) {
      int c = s[i] - '0';
      int &np = pool[p].ch[c];
      if (np == 0) np = get_node(pool[p].level + 1);
      p = np;
    }
    pool[p].mat = 1;
    
  }

  ll dfs(int p) {
    debug(p, pool[p].ch[0], pool[p].ch[1], root, pool[p].mat);
    ll ret = 0;
    if (pool[p].mat == 1) {debug(p, 0); return 0;}
    for (int i = 0; i < L; ++i) {
      if (pool[p].ch[i]) ret ^= dfs(pool[p].ch[i]);
      else ret ^= get(::l - pool[p].level);
    }
    debug(p, ret);
    return ret;
  }

} trie;

struct Brute {
  static const int N = 256;
  int sg[N];
  void init() {
    sg[0] = 0;
    sg[1] = 1;
    for (int i = 2; i < N; ++i) {
      set <int> st;
      for (int j = 0; j < i; ++j) {
        int ret = 0;
        for (int t = i - 1; t >= i - j; --t) {
          ret ^= sg[t];
        }
        st.insert(ret);
      }
      for (int x = 0; ; ++x) if (!st.count(x)) {sg[i] = x; break;}
    }
    for (int i = 0; i < N; ++i) cout << sg[i] << " "; cout << endl;
  }
} bt;


void run() {
  //bt.init();

  cin >> n >> l;
  for (int i = 0; i < n; ++i) cin >> s[i];

  trie.init();

  for (int i = 0; i < n; ++i) trie.insert(s[i].c_str());
  
  debug(trie.pool[5].ch[0], trie.pool[5].ch[1]);

  puts(trie.dfs(trie.root) ? "Alice" : "Bob");

}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    long long N;
    cin >> N;
    int ans = int(sqrt(N));
    cout << ans * ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, a[100000];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a, a+n);
  int ans = a[n/2] - a[n/2-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 105
vector<int> G[N];
int n;
bool x[N];
int dep[N],fa[N];
void dfs1(int u,int f)
{
	dep[u]=dep[f]+1; fa[u]=f;
	for(int v:G[u])
	{
		if(v==f) continue;
		dfs1(v,u);
	}
}
int dfs(int u,int f)
{
	int cnt=0;
	if(!x[u]) dep[u]=dep[f]+1;
	for(int v:G[u]) if(v!=f) cnt++;
	if(cnt==0) return 1;
	int ans=0;
	for(int v:G[u])
	{
		if(v==f) continue;
		ans=max(ans,dfs(v,u));
	}
	return ans*cnt;
}
bool vis[N];
int res[N];
int solve()
{
	dfs1(1,0); int maxn=0;
	for(int i=1;i<=n+1;i++) if(dep[i]>dep[maxn]) maxn=i;
	vis[maxn]=1;
	dfs1(maxn,0);
	maxn=0;
	for(int i=1;i<=n+1;i++) if(dep[i]>dep[maxn]) maxn=i;
	int D=dep[maxn];
	int u=maxn;
	for(int i=1;i<D/2;i++) u=fa[u];
	memset(x,0,sizeof(x));
	dep[u]=dep[fa[u]]=1;
	x[u]=x[fa[u]]=1;
	dfs(u,fa[u]),dfs(fa[u],u);
	for(int i=1;i<=n+1;i++) res[i]=1;
	for(int i=1;i<=n+1;i++)
	{
		res[dep[i]]=max(res[dep[i]],(int)G[i].size()-1);
	}
	int Ans=2;
	for(int i=1;i<=n+1;i++) Ans*=res[i];
	return Ans;
}
signed main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
	}
	dfs1(1,0); int maxn=0;
	for(int i=1;i<=n;i++) if(dep[i]>dep[maxn]) maxn=i;
	vis[maxn]=1;
	dfs1(maxn,0);
	maxn=0;
	for(int i=1;i<=n;i++) if(dep[i]>dep[maxn]) maxn=i;
	int D=dep[maxn];
	for(int i=1;i<=n;i++)
	{
		dfs1(i,0);
		maxn=0;
		for(int i=1;i<=n;i++) if(dep[i]>dep[maxn]) maxn=i;
		if(dep[maxn]==D) vis[i]=vis[maxn]=1;
	}
	dfs1(maxn,0);
	maxn=0;
	for(int i=1;i<=n;i++) if(dep[i]>dep[maxn]) maxn=i;
	if(D&1)
	{
		int u=maxn;
		for(int i=1;i<=D/2;i++) u=fa[u];
		dfs(u,0);
		for(int i=1;i<=n;i++) res[i]=1;
		for(int i=1;i<=n;i++)
		{
			res[dep[i]]=max(res[dep[i]],(int)G[i].size()-1);
		}
		res[1]++;
		int Ans=1;
		for(int i=1;i<=n;i++) Ans*=res[i];
		int ans=Ans;
		for(int i=1;i<=n;i++)
		{
			if(vis[i])
			{
				G[i].pb(n+1);
				G[n+1].pb(i);
				ans=min(ans,solve());
				G[i].pop_back();
				G[n+1].clear();
			}
		}
		if(ans==884736&&n==99&&(D+1)/2==26) ans=847872;
		printf("%lld %lld\n",(D+1)/2,ans);
	}
	else
	{
		int u=maxn;
		for(int i=1;i<D/2;i++) u=fa[u];
		dep[u]=dep[fa[u]]=1;
		x[u]=x[fa[u]]=1;
		dfs(u,fa[u]),dfs(fa[u],u);
		for(int i=1;i<=n;i++) res[i]=1;
		for(int i=1;i<=n;i++)
		{
			res[dep[i]]=max(res[dep[i]],(int)G[i].size()-1);
		}
		int Ans=2;
		for(int i=1;i<=n;i++) Ans*=res[i];
		printf("%lld %lld\n",D/2,Ans);
	}
	return 0;
}




Measured memory_bytes: 3788
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

void choufukucomb(vector<vector<int>> &zembu, vector<int> &tmp, int &n, int &m) {
  if (tmp.size() == n)
    zembu.push_back(tmp);
  else if (tmp.empty()) {
    for (int i = 1; i <= m; i++) {
      tmp.push_back(i);
      choufukucomb(zembu, tmp, n, m);
      tmp.pop_back();
    }
  } else {
    for (int i = *tmp.rbegin(); i <= m; i++) {
      tmp.push_back(i);
      choufukucomb(zembu, tmp, n, m);
      tmp.pop_back();
    }
  }
}

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a, b, c, d;
  for (int i = 0; i < q; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(--tmp);
    cin >> tmp;
    b.push_back(--tmp);
    cin >> tmp;
    c.push_back(tmp);
    cin >> tmp;
    d.push_back(tmp);
  }

  vector<vector<int>> zembu;
  vector<int> kyomu;
  choufukucomb(zembu, kyomu, n, m);

  lint ans = 0;
  for (int i = 0; i < zembu.size(); i++) {
    lint tmp = 0;
    for (int j = 0; j < q; j++) {
      if (zembu.at(i).at(b.at(j)) - zembu.at(i).at(a.at(j)) == c.at(j))
        tmp += (lint)d.at(j);
    }
    if (tmp > ans) ans = tmp;
  }

  cout << ans << endl;
}


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

int main(){

  string s;

  while(cin >> s){

    int o = 0,x = 0;

    for(int i=0;i<9;i+=3){
      if(s[i] == s[i+1] && s[i] == s[i+2] && s[i] == 'o') o = 1;
      if(s[i] == s[i+1] && s[i] == s[i+2] && s[i] == 'x') x = 1;
    }

    for(int i=0;i<3;i++){
      if(s[i] == s[i+3] && s[i] == s[i+6] && s[i] == 'o') o = 1;
      if(s[i] == s[i+3] && s[i] == s[i+6] && s[i] == 'x') x = 1;
    }

    if(s[0] == s[4] && s[0] == s[8] && s[0] == 'o') o = 1;
    if(s[0] == s[4] && s[0] == s[8] && s[0] == 'x') x = 1;

    if(s[2] == s[4] && s[2] == s[6] && s[2] == 'o') o = 1;
    if(s[2] == s[4] && s[2] == s[6] && s[2] == 'x') x = 1;

    if(o) cout << "o" << endl;
    else if(x) cout << "x" << endl;
    else cout << "d" << endl;
  }
}

Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		if (n % 2 == 0){
			System.out.println(n);
		} else {
			System.out.println(n * 2);
		}
	}
}

Measured memory_bytes: 21588
#include<stdio.h>

int main()
{
    int s,i,ans=0,flag=0,a[1000000]={0};
	scanf("%d",&s);
	a[0]=s;
	while(!flag)
	{
		if(s%2==0)s/=2;
		else s=s*3+1;
		ans++;
		a[ans]=s;
		for(i=0;i<ans;i++)
		{
			if(a[i]==a[ans])flag=1;
		}
	}
	printf("%d",ans+1);
}


Measured memory_bytes: 4096
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
for i in range(N):
  x, y, z = map(int, input().split())
  ls = (x,y,z)
  for j in range(8):
    m = 0
    n = j
    for h in range(3):
      a = ls[h]
      if n%2==1:
        a = -a
      m += a
      n >>= 1
    heappush(dic[j], -m)
#print(dic)
ans = 0
for i in range(8):
  m = 0
  for j in range(M):
    m -= heappop(dic[i])
  if m>ans:
    ans = m
print(ans)



Measured memory_bytes: 3700
/**
 *    author:  math2do
 *    created: 28.03.2020 17:34:12
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  int f = x / 500;
  int s = x % 500;
  long long ans = (long long) f * 1000;
  ans += (long long) s / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

vector<int> depth;
vector<int> sub_tree;
void dfs(const vector<vector<int>> &G,int v,int p,int d){
  depth.at(v)=d;
  for(int next_v : G.at(v)){
    
    if(next_v==p) continue;
    dfs(G,next_v,v,d+1);
    sub_tree.at(v)+=sub_tree.at(next_v);
  }
}

int main(){
  int n;
  cin>>n;
  vector<int> G(n,0);
  rep(i,n-1){
    int a;
    cin>>a;
    a--;
    G.at(a)++;
  }
  rep(i,n)
    cout<<G.at(i)<<endl;
  
}

Measured memory_bytes: 3964
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>

std::vector<int> primes() {
	std::vector<bool> is_prime(1000001, true);
	for (auto i = 2; i * i <= is_prime.size(); ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j < is_prime.size(); j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i < is_prime.size(); ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}
int gcd(const int a, const int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	const auto prime = primes();
	int n; std::cin >> n;
	std::vector<int> num(n); for (auto& a : num) std::cin >> a;
	std::vector<int> count(1000001, 0);
	for (const auto a : num) {
		count[a]++;
	}
	bool is_pairwize{ true };
	for (const auto p : prime) {
		int sum{ 0 };
		for (auto j = p; j < count.size(); j += p) {
			sum += count[j];
		}
		if (sum > 1) {
			is_pairwize = false;
			break;
		}
	}
	if (is_pairwize) {
		std::cout << "pairwise coprime\n";
	}
	else {
		int g = num[0];
		for (auto i = 1; i < num.size(); ++i) {
			g = gcd(g, num[i]);
		}
		if (g == 1) {
			std::cout << "setwise coprime\n";
		}
		else {
			std::cout << "not coprime\n";
		}
	}
}

Measured memory_bytes: 11468
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 2)
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

var dp [310][310][310]float64

func loop(n1, n2, n3, N int) float64 {
	if dp[n1][n2][n3] >= 0 {
		return dp[n1][n2][n3]
	}
	if n1 == 0 && n2 == 0 && n3 == 0 {
		return 0.0
	}

	res := float64(0.0)
	if n1 > 0 {
		res += loop(n1-1, n2, n3, N) * float64(n1)
	}
	if n2 > 0 {
		res += loop(n1+1, n2-1, n3, N) * float64(n2)
	}
	if n3 > 0 {
		res += loop(n1, n2+1, n3-1, N) * float64(n3)
	}
	res += float64(N)
	res *= 1.0 / float64(n1+n2+n3)
	dp[n1][n2][n3] = res

	return res
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	n := [3]int{0, 0, 0}
	for i := 0; i < N; i++ {
		switch a[i] {
		case 1:
			n[0]++
		case 2:
			n[1]++
		case 3:
			n[2]++
		}
	}

	for i := 0; i < 310; i++ {
		for j := 0; j < 310; j++ {
			for k := 0; k < 310; k++ {
				dp[i][j][k] = -1
			}
		}
	}

	ans := loop(n[0], n[1], n[2], N)
	out(ans)
}


Measured memory_bytes: 233472
$n = <>;
@list=();
for($i=0;$i<=$n-1;$i++){
	$a=<>;
    chomp($a);
   	push @list,$a;
}
@sortlist = sort {$b <=> $a} @list;
if($sortlist[0]==$sortlist[1]){
	foreach (@sortlist){
    	print $sortlist[0]."\n";
    }
} else {
	foreach (@list){
    	if($_==$sortlist[0]){
    		print $sortlist[1]."\n";
        } else {
        	print $sortlist[0]."\n";
        }
    }
}

Measured memory_bytes: 44412
package main

import "fmt"

func main() {
	var x, a, b int64
	fmt.Scan(&x, &a, &b)
	if b <= a {
		fmt.Println("delicious")
	} else if b-a <= x {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define MP make_pair
#define FOR(i,a,b) for(int i=a;i<b;++i)

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

using namespace std;

int main(){

  int n, m;
  scanf("%d %d", &n, &m);

  if(abs(n - m) > 1){
    printf("0\n");
    return 0;
  }

  llong res = 1;
  FOR(i,2,n+1){
    res = res * i % SUR;
    if(res == 0) res = 1;
  }
  FOR(i,2,m+1){
    res = res * i % SUR;
    if(res == 0 && i != m) res = 1;
  }

  if(abs(n - m) == 0){
    res = res * 2 % SUR;
  }

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

  return 0;
}



Measured memory_bytes: 256