akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int D;
int C[26];
int A[365][26];
int con[365];
int score(){
	vector<int>last(26,-1);
	int res=0;
	rep(i,D){
		last[con[i]]=i;
		res+=A[i][con[i]];
		rep(j,26){
			res-=C[j]*(i-last[j]);
		}
	}
	return res;
}
int change(int x,int y){
	int res=A[x][y]-A[x][con[x]];
	int lastold=-1,lastnew=-1;
	rep(i,D){
		if(con[i]==con[x])lastold=i;
		if(con[i]==y)lastnew=i;
		res+=(i-lastold)*C[con[x]];
		res+=(i-lastnew)*C[y];
	}
	lastold=-1,lastnew=-1;
	rep(i,D){
		if(con[i]==con[x]&&i!=x)lastold=i;
		if(con[i]==y||i==x)lastnew=i;
		res-=(i-lastold)*C[con[x]];
		res-=(i-lastnew)*C[y];
	}
	return res;
}
signed main(){
	cin>>D;
	rep(i,26)cin>>C[i];
	rep(i,D){
		int mx=0,idx;
		rep(j,26){
			cin>>A[i][j];
			if(chmax(mx,A[i][j]))idx=j;
		}
		con[i]=idx;
	}
	int score_=score();
	cerr<<score_<<endl;
	while(1000.*clock()/CLOCKS_PER_SEC<=1990){
		int x=rand()%D,y;
		do{
			y=rand()%26;
		}while(con[x]==y);
		int diff=change(x,y);
		if(diff>=0/*||tim<rand()%1990*/){
			score_+=diff;
			con[x]=y;
		}
	}
	rep(i,D)cout<<con[i]+1<<"\n";
	cerr<<score_<<endl;
}


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

int main(){
  int N,K,x,B,ans=0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    cin >> x;
    B = K - x;
    if (x < B) ans += x*2;
    else ans += B*2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
signed main(){
int X, N, i;
scanf("%d%d",&X, &N);
int p[N];

while(i<N){
    scanf("%d",&p[i]);
    i++;
}
/* --------ここまで X N p  の入力-------------*/

int flag[105] = {};/*真偽を保持している。
                    0の時添字の値が使える 1の時添字が使えない*/

int ans =0;
for(i=0; i<N; i++){
    flag[p[i]] =1;/*
    p[i]は使えないので flag を1にする          */
}
for(i=1; i<=101; i++){
    if(flag[i] == 0){/* i が使える値だったら*/
    int abs1, abs2;
    abs1 = X - ans;
    abs2 = X - i;


    if(abs1 < 0){
        abs1 = abs1 * -1;
    }

    if(abs2 < 0){
        abs2 = abs2 * -1;
    }

    if(abs1>abs2){/*取得した絶対値同士を比べて最小を求める*/
        ans=i;
    }

   } 
 }    
 printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 1732
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c = input().split()
str = a[0] + b[0] + c[0]
print(str.upper())

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ


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


int main()
{
    int n ;
	cin >> n ;
	int cnt = 0 ;
    vector<int> vec(n) ;
    REP(i,n){
        cin >> vec.at(i) ;
    }
    for(int i=0;i<n;i++){
        int minj = i ;
        for(int j=i;j<n;j++){
            if(vec.at(j)<vec.at(minj)){
                minj = j ;
            }
        }
        if(minj!=i){
            cnt++ ;
            int swap = vec.at(minj) ;
            vec.at(minj) = vec.at(i) ;
            vec.at(i) = swap ;
        }
    }
    REP(i,n){
        cout << vec.at(i);
        if(i!=n-1){
            cout <<" ";
        }
    }
    cout <<endl;
    
    cout <<cnt<<endl ;
    
    return 0 ;
}
    


Measured memory_bytes: 3104
n = int(input())
xy=[list(map(int,input().split())) for i in range(n)]

d1 = []
d2 = []
for x,y in xy:
    d1.append(x-y)
    d2.append(x+y)

ans1=max(d1)-min(d1)
ans2=max(d2)-min(d2)

print(max(ans1,ans2))

Measured memory_bytes: 129304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n;cin>>n;
    ll a[n];f(i,0,n)cin>>a[i];
    ll k=1;
    f(i,0,n){
        if(a[i]==k)k++;
    }
    if(k!=1)cout<<n-k+1;
    else if(k==1)cout<<-1;
    return 0;
}   

Measured memory_bytes: 1792
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    H, W, A, B = in_nn()

    ans = [[0 for _ in range(W)] for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if 0 <= x < A and 0 <= y < B:
                ans[y][x] = 0
            elif A <= x < W and B <= y < H:
                ans[y][x] = 0
            else:
                ans[y][x] = 1

    for i in range(H):
        print(''.join(map(str, ans[i])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17884
#include <iostream>
#include <string>
#include <map>

using namespace std;

map<char, int> data;

main(){
  string str;
  data['a'] = 0;
  data['b'] = 0;
  data['c'] = 0;
  data['d'] = 0;
  data['e'] = 0;
  data['f'] = 0;
  data['g'] = 0;
  data['h'] = 1;
  data['i'] = 1;
  data['j'] = 1;
  data['k'] = 1;
  data['l'] = 1;
  data['m'] = 1;
  data['n'] = 1;
  data['o'] = 1;
  data['p'] = 1;
  data['q'] = 0;
  data['r'] = 0;
  data['s'] = 0;
  data['t'] = 0;
  data['u'] = 1;
  data['v'] = 0;
  data['w'] = 0;
  data['x'] = 0;
  data['y'] = 1;
  data['z'] = 0;

  while(cin >> str){
    if(str == "#") break;
    int p = data[str[0]];
    int ans = 0;
    for(int i=1;i<str.size();i++){
      if(p != data[str[i]]) ans++;
      p = data[str[i]];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
	int a, b;
	cin >> a >> b;

	if (a > b) {
		int tmp = b;
		b = a;
		a = tmp;
	}
	int ans = 0;
	int mul = 1;
	rep(i, b) {
		ans += a * mul;
		mul *= 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
t = readl()

left = 0
right = 1
mx = 0
current = 0
if n == 1:
    print(0)
    exit()
while(1):
    if t[left] >= t[right]:
        current += 1
        mx = max(current, mx)
    else:
        current = 0
    left += 1
    right += 1
    if left >= n or right >= n:
        break
print(mx)


Measured memory_bytes: 16644
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int[] min = new int[26];
	for (int i = 0; i < 26; i++) {
	    min[i] = Integer.MAX_VALUE;
	}

	int N = Integer.parseInt(scan.next());
	for (int i = 0; i < N; i++) {
	    String s = scan.next();
	    int[] count = new int[26];
	    for (int j = 0; j < s.length(); j++) {
		count[s.charAt(j) - 'a']++;
	    }
	    for (int j = 0; j < 26; j++) {
		if(count[j] < min[j]) min[j] = count[j];
	    }
	}

	StringBuilder str = new StringBuilder();
	for (int i = 0; i < 26; i++) {
	    for (int j = 0; j < min[i]; j++) {
		str.append((char)(i + 'a'));
	    }
	}

	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,to=b;i<to;++i)
using namespace std;
typedef long long ll;

int n,a,b;
ll x[100005];
ll y[100005];
pair<pair<ll,ll>,int> p[100005];
bool vis[100005];
vector<int> g[100005];
int d[100005];
unordered_set<int> r[100005];
unordered_map<ll,vector<int> > w0; // x+y
unordered_map<ll,int> w0s;
unordered_map<ll,int> w0s2;
unordered_map<ll,vector<int> > w1; // x-y
unordered_map<ll,int> w1s;
unordered_map<ll,int> w1s2;
ll k;

void doit(){
	fore(i,0,n)p[i]=mp(mp(x[i],y[i]),i);
	sort(p,p+n);
	fore(i,0,n){/*
		while(p[i].fst.fst-p[j].fst.fst>k){
			w0[p[j].fst.fst+p[j].fst.snd].erase(p[j].snd);
			w1[p[j].fst.fst-p[j].fst.snd].erase(p[j].snd);
			j++;
		}*/
		ll xx=p[i].fst.fst,yy=p[i].fst.snd;
		int l=p[i].snd;
		if(w0.count(xx+yy-k)){
			vector<int> &v=w0[xx+yy-k];
			int &s=w0s[xx+yy-k];
			int &s2=w0s2[xx+yy-k];
			while(s<v.size()&&xx-x[v[s]]>k)s++;
			while(s2<v.size()&&xx-x[v[s2]]>k)s2++;
			d[l]+=v.size()-s2;
			if(s2<v.size()){
				g[l].pb(v[s2]);
				g[v[s2]].pb(l);
			}
			while(s<v.size()-1){
				g[v[s]].pb(v[s+1]);
				g[v[s+1]].pb(v[s]);
				s++;
			}/*
			for(unordered_set<int>::iterator it=w0[xx+yy-k].begin();it!=w0[xx+yy-k].end();++it){
				g[l].pb(*it);
				g[*it].pb(l);
			}*/
		}
		if(w1.count(xx-yy-k)){
			vector<int> &v=w1[xx-yy-k];
			int &s=w1s[xx-yy-k];
			int &s2=w1s2[xx-yy-k];
			while(s<v.size()&&xx-x[v[s]]>=k)s++;
			while(s2<v.size()&&xx-x[v[s2]]>=k)s2++;
			d[l]+=v.size()-s2;
			if(s2<v.size()){
				g[l].pb(v[s2]);
				g[v[s2]].pb(l);
			}
			while(s<v.size()-1){
				g[v[s]].pb(v[s+1]);
				g[v[s+1]].pb(v[s]);
				s++;
			}
			/*
			for(unordered_set<int>::iterator it=w1[xx-yy-k].begin();it!=w1[xx-yy-k].end();++it){
				if(y[*it]==yy)continue;
				g[l].pb(*it);
				g[*it].pb(l);
			}*/
		}
		w0[xx+yy].pb(l);
		w1[xx-yy].pb(l);
	}
}

void dfs(int x){
	if(vis[x])return;
	vis[x]=true;
	fore(_,0,g[x].size()){
		int y=g[x][_];
		dfs(y);
	}
}

int main(){
	scanf("%d%d%d",&n,&a,&b);a--;b--;
	fore(i,0,n){
		scanf("%lld%lld",x+i,y+i);
		//w0[x[i]+y[i]].pb(i);
		//w1[x[i]-y[i]].pb(i);
	}
	k=abs(x[a]-x[b])+abs(y[a]-y[b]);
	doit();
	dfs(a);
	ll rr=0;
	fore(i,0,n)if(vis[i])rr+=d[i];
	//rr/=2;
	printf("%lld\n",rr);
	return 0;
}

Measured memory_bytes: 39368
N,X,Y = list(map(int, input().split()))

ans = [0]*(N+1)

for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans[min(j-i,abs(j-Y)+abs(i-X)+1)] += 1

for j in range(1,N):
    print(ans[j])



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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::string S){
    int ans = 0;
    REP(i, N-2) {
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
	int i;
	int n;
	while(scanf("%d",&n),n){
		for(i=0;i<n;++i){
			int a,b,c,d,e,f,g,h;
			scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
			printf("%d %d %d %d\n",a*e-b*f-c*g-d*h,a*f+b*e+c*h-d*g,a*g+c*e-b*h+d*f,a*h+d*e+b*g-c*f);
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;

ll n, k;
int main(){
  cin >> n >> k;
  cin.ignore();
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }

  ll m = n % k;
  ll an_m = k - m;
  if(m < an_m){
    cout << m << endl;
    return 0;
  }
  cout << an_m << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
double dp[305][305][305];
int a[5];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for (int k=0;k<=n;k++)
	for (int j=0;j<=n;j++)
	for (int i=0;i<=n;i++)
	if (i||j||k) {
		if (i) dp[i][j][k]+=dp[i-1][j][k]*i/(i+j+k);
		if (j) dp[i][j][k]+=dp[i+1][j-1][k]*j/(i+j+k);
		if (k) dp[i][j][k]+=dp[i][j+1][k-1]*k/(i+j+k);
		dp[i][j][k]+=(double)n/(i+j+k);
	}
	printf("%.15lf\n",dp[a[1]][a[2]][a[3]]);
	return 0;
} 

/*
dp[i][j][k]表示当前有i个1 j个2 k个3 的期望步数

dp[0][0][0]=0

dp[i][j][k]=dp[i-1][j][k]*i/n+dp[i+1][j-1][k]*j/n+dp[i][j+1][k-1]*k/n+dp[i][j][k]*(n-i-j-k)/n+1
dp[i][j][k]*(i+j+k)/n=dp[i-1][j][k]*i/n+dp[i+1][j-1][k]*j/n+dp[i][j+1][k-1]*k/n+1
dp[i][j][k]*(i+j+k)=dp[i-1][j][k]*i+dp[i+1][j-1][k]*j+dp[i][j+1][k-1]*k+n
dp[i][j][k]=dp[i-1][j][k]*i/(i+j+k)+dp[i+1][j-1][k]*j/(i+j+k)+dp[i][j+1][k-1]*k/(i+j+k)+n/(i+j+k)

*/

Measured memory_bytes: 219264
#include<bits/stdc++.h>
using namespace std;
long long n;
long long a[1000001],kq[10000001];
int main()
{
    cin>>n;
    for(long i=1;i<=n;i++)
        cin>>a[i];
        kq[2]=abs(a[2]-a[1]);
    for(long i=3;i<=n;i++)
    {
        kq[i]=min(abs(a[i]-a[i-2])+kq[i-2],abs(a[i]-a[i-1])+kq[i-1]);
        //cout<<kq[i]<<" ";
    }
    cout<<kq[n];
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

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

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n,m;
    cin>>n>>m;
    Vi h(n);
    REP(i,0,n) cin>>h[i];
    Vi a(m),b(m);
    REP(i,0,m){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
    }

    VVi edges(n);
    REP(i,0,m){
        edges[a[i]].pb(b[i]);
        edges[b[i]].pb(a[i]);
    }

    int ans=0;
    REP(i,0,n){
        bool check=true;
        REP(j,0,edges[i].size()){
            if(h[i]<=h[edges[i][j]]) check=false;
        }
        if(check) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11380
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <queue>
using namespace std;
typedef struct {
    int  time;
    string name;
} working;

int main(){
    int n,q;
    int goneTime=0; 
    cin >> n >>  q;
    queue<working> Q;
    for(int i=0;i<n;i++){
        working w;
        cin >> w.name >> w.time;
        Q.push(w);
    }
    
    
    while(!Q.empty()){
        working w  = Q.front();
        Q.pop();
        if(w.time - q <= 0){
            goneTime += min(w.time,q);
            cout << w.name << " " << goneTime << endl;
        }else{
            goneTime += q;
            w.time -= q;
            Q.push(w);
        }
        
    }
}


Measured memory_bytes: 6272
n = int(input())
s = input()

w = 0
wlist = []
elist = [0]*n
e = 0
for i in range(n):
    if s[i] == 'W':
        w += 1
    wlist.append(w)

for i in range(n-1,-1,-1):
    if s[i] == 'E':
        e += 1
    elist[i] = e
mn = 10**9
for i in range(n):
    mn = min(mn, elist[i]+wlist[i])
#print(elist,wlist)
print(mn-1)

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

int main() {
  int r , d ,x;
  cin >> r >> d >> x;
  long x1;
  for( int i = 0; i< 10 ; i++){
    x1 = r*x -d;
    cout << x1 << endl;
    x = x1;
  }

 
}

Measured memory_bytes: 256
n = gets.to_i
n.times do
  p = 1
  sum = 0
  str = gets.chomp.gsub(/\s/, '')
  str.chars do |c|
    if c == 'm'
      sum += p*1000
      p = 1
    elsif c == 'c'
      sum += p*100
      p = 1
    elsif c == 'x'
      sum += p*10
      p = 1
    elsif c == 'i'
      sum += p
      p = 1
    else
      p = c.to_i
    end
  end

  txt = ''
  h = { 1000 => 'm', 100 => 'c', 10 => 'x', 1 => 'i' }
  h.each do |k, v|
    begin
      i = (sum.to_i/k.to_i).ceil
      if i == 0
        next
      else
        txt += i >= 2 ? "#{i}#{v}" : v
        sum -= i*k.to_i
      end
    end
  end
  puts txt
end

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

int main()
{
    int i=2, j=3,y=0,p;
    char c[i][j];
    for(int m=0; m<i; m++)
    {
        for(int n=0; n<j; n++)
        {
            cin>>c[m][n];
        }
    }

    for(int n=0,p=j,m=0; n<j; n++,p--)
    {
        if(c[m][n]!=c[m+1][p-1])
        {
            y=1;

        }
    }

    if(y==0)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int h, w; cin >> h >> w;
  string board[50];
  for(int i = 0; i < h; ++i) cin >> board[i];
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(board[i][j] == '#') continue;
      int num = 0;
      for(int k = 0; k < 8; k++) {
        int ni = i + dy[k];
        int nj = j + dx[k];
        if(ni < 0 or h <= ni) continue;
        if(nj < 0 or w <= nj) continue;
        if(board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num+'0');
    }
  }
  for(int i = 0; i < h; i++) cout << board[i] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

bool leap_year(int year)
{
    if (year % 400 == 0) {
        return true;
    } else if (year % 100 == 0) {
        return false;
    } else if (year % 4 == 0) {
        return true;
    } else {
        return false;
    }
}

int main(void)
{
    int y_ini, y_fin;
    int count = 0;
    int new_line = 0;
    while(1) {
        scanf("%d %d", &y_ini, &y_fin);
    
        if (y_ini == 0 && y_fin == 0) {
            break;
        }
        
        if (new_line != 0) {
            printf("\n");
        }

        for (int year = y_ini; year <= y_fin; year++) {
            if (leap_year(year) == true){
                printf("%d\n", year);
                count++;
            }
        }
        
        if (count == 0) {
            printf("NA\n");
        }
        
        new_line++;        
        count = 0;
    }
            
    return 0;
}

Measured memory_bytes: 1044
import sys

line =  sys.stdin.readline()
line =  sys.stdin.readline()
nums = list(map(int, line.split()))
dp = [0]

for i in range(1, len(nums)):
    cands = []
    for j in range(max(0, i-2), i):
        cands.append(abs(nums[i] - nums[j]) + dp[j])
    dp.append(min(cands))

print(dp[-1])

Measured memory_bytes: 14196
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1<<i)<=x;i++);
    return i;
}

vector<int> osci(vector<int> v) {
	vector<int> v1;
	int n=v.size();
	int i=0,j=n-1;
	for(int k=0;k<n;k++) {
		if(k%2==0)
			v1.pb(v[i++]);
		else
			v1.pb(v[j--]);
	}
	reverse(all(v1));
	return v1;
} 

int b[125451]={0};
 
int32_t main() {
    fio
	cout << fixed << setprecision(15);
    
    int n;cin >> n;
    int a[n];
    fff(i,n)
    cin >> a[i];
    
    if(n==1) {
        cout << 1;
        return 0;
    }
    
    fff(i,n) {
        if(a[i]!=0)
        b[a[i]-1]++;
        b[a[i]+1]++;
        b[a[i]]++;
    }
    
    cout << *max_element(b,b+n);
    
    return 0;
    
}

Measured memory_bytes: 9344
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
d = [int(i) for i in input().split()] # 配列で数字

m = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()]

def bs(nums, target):
    l = 0
    r = len(nums) - 1
    while l <= r:
        mid = (l + r) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] > target:
            r = mid - 1
        else:
            l = mid + 1
    return -1

if n < m:
    print('NO')
else:
    d.sort()
    t.sort()
    i = j = 0
    while i < n and j < m:
        if d[i] == t[j]:
            i += 1
            j += 1
        else:
            i += 1
    if j == m:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 127696
#ABC064C
N = int(input())
ai = list(map(int, input().split()))
colors = [0]*8
kinds = 0
all_col = 0
for a in ai:
    if a < 400:
        colors[0] = 1
    elif a < 800:
        colors[1] = 1
    elif a < 1200:
        colors[2] = 1
    elif a < 1600:
        colors[3] = 1
    elif a < 2000:
        colors[4] = 1
    elif a < 2400:
        colors[5] = 1
    elif a < 2800:
        colors[6] = 1    
    elif a < 3200:
        colors[7] = 1
    else:
        all_col += 1 
for color in colors:
    if color == 1:
        kinds += 1
min_c = 0
max_c = 0
min_c = kinds
if kinds == 0:
    min_c = 1
max_c += kinds + all_col
print(str(min_c) + " " + str(max_c))




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> dp(3, 0), a(n);
    for(int i = 0; i < n; i++) {
        vector<int> new_dp(3, 0);
        for(int j = 0; j < 3; j++) {
            cin >> a[j];
        }
        for(int f = 0; f < 3; f++) {
            for(int s = 0; s < 3; s++) {
                if (f != s) {
                    new_dp[s] = max(new_dp[s], dp[f] + a[s]);
                }
            }
        }
        dp = new_dp;
    }
    cout << max({dp[0], dp[1], dp[2]});
    return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	lli n;
	cin >> n;
	int ans = 0;
	while(n > 0){
		n /= 2;
		ans++;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
 
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
		   tree_order_statistics_node_update> oset;
*/
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) { __print(x.first); cout << ','; __print(x.second); }
template<typename T>
void __print(const T &x) {int f = 0; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); }
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define d(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define d(x...)
#endif
 
#define IO            ios::sync_with_stdio(false);cin.tie(0);
//#define clock()       std::chrono::high_resolution_clock::now()
//#define duration(x,y) std::chrono::duration_cast<std::chrono::milliseconds>(y-x).count()
 
#define ll            long long
#define pi            pair<int,int>
#define pii           pair<pi,int>
#define pl            pair<ll,ll>
#define vi            vector<int>
#define vl            vector<ll>
#define vll           vector<vl>
#define vs            vector<string>
#define vb            vector<bool>
#define vii           vector<vector<int>>
#define vpi           vector<pi>
#define vpl           vector<pl>
#define pb            push_back
#define mp            make_pair
#define eb            emplace_back
#define ff            first
#define ss            second
#define fo(i,val,n)   for(int i=val;i<n;i++)
#define rfo(i,val,j)  for(int i=val;i>=j;i--)
#define all(x)        x.begin(),x.end()
#define inf           INT_MAX
#define endl          '\n'
	
const int N=2e5+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
 	
	IO

	ll n;
	cin>>n;

	vl v(n);
	map<ll,ll> m;
	fo(i,0,n) cin>>v[i] , m[v[i]]++;

	map<ll,ll> ans;
	ll sum = 0;
	for(auto it:m){
		if(it.ss>1){
			sum += (it.ss * (it.ss-1)) / 2;
		}
	}

	fo(i,0,n){
		cout << sum - (m[v[i]]-1) << endl;
	}
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  string s, t;
  cin >> s >> t;

  ll cnt = 0;
  rep (i, s.size()) {
    if (s[i] == t[i]) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	string N;
	cin >> N;
	int cnt = 0;
	for (char c : N) {
		if (c == '2') {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
cnt=0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
                if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[i]+l[k]>l[j]:
                    cnt+=1              
print(cnt)



Measured memory_bytes: 9192
import collections
N,K = list(map(int,input().split()))
R,S,P = list(map(int,input().split()))
T = list(input())
for i in range(N):
    if i+K < N and T[i] == T[i+K]:
        T[i+K] = 'x'
C = collections.Counter(T)
ans = 0
ans += C['r']*P
ans += C['s']*R
ans += C['p']*S
print(ans)

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll mini = 0, sum = 0;
  REP(i, n) {
    if (s[i] == '(') {
      sum++;
    } else {
      sum--;
    }
    mini = min(mini, sum);
  }
  mini = max(0LL, -mini);
  sum += mini;
  // DUMP(mini);
  // DUMP(sum);
  REP(i, mini) { cout << '('; }
  cout << s;
  REP(i, sum) { cout << ')'; }
  cout << endl;
}

Measured memory_bytes: 256
#ABC080C
N=int(input())
F=[]
P=[]
for n in range(N):
	F.append(list(map(int,input().split())))
for n in range(N):
	P.append(list(map(int,input().split())))
def DP(a,i):
	if i!=10:
		ans=max(DP(a+[1],i+1),DP(a+[0],i+1))
	elif any(a):
		ans=0
		for n in range(N):
			c=0
			for i in range(10):
				if F[n][i] and a[i]:
					c+=1
			ans+=P[n][c]
	else:
		ans=-float('inf')
	return ans
print(DP([],0))

Measured memory_bytes: 3064
nk = input().split(" ");
n = int(nk[0]);
k = int(nk[1]);
ab = [[0] * 2 for i in range(n)]
for i in range(n) :
	ab_i = input().split(" ");
	ab[i][0] = int(ab_i[0]);
	ab[i][1] = int(ab_i[1]);
ab.sort(key=lambda x:x[0] );
j = 0;
l = 0;
while l + ab[j][1] < k :
	l = l + ab[j][1];
	j = j + 1;
print(ab[j][0]);

Measured memory_bytes: 21288
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
ll a[100010],b[100010] = {};
int main(){
    int i,n; cin >> n;
    for(i=0;i<=n;i++){
        cin >> a[i];
    }
    b[0] = 1;
    ll ans = n + 1;
    if(n==0){
        if(a[0]==1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(a[0]!=0){
        cout << -1 << endl;
        return 0;
    }
    a[n]--;
    int l = -1;
    for(i=1;i<=n;i++){
        if(a[i]==0) continue;
        while(a[i]>0){
            if(l==i){
                cout << -1 << endl;
                return 0;
            }
            if(l<0 || b[l]==0){
                l++;
                b[l + 1] += b[l];
            }else{
                if(a[i]>b[l]){
                    a[i] -= b[l]; ans += (i - l)*b[l];
                    b[l + 1] += b[l]; b[i] -= b[l]; b[l] = 0;
                }else{
                    b[l] -= a[i]; ans += (i - l)*a[i];
                    b[l + 1] += a[i]; b[i] -= a[i]; a[i] = 0;
                }
            }
        }
    }
    cout << ans << endl;
}

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


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x


def main():
    H, W = map(int, input().split())
    S = []
    for h in range(H):
        S.append(input().strip())

    uf = UnionFind(H*W)
    for i in range(H):
        for j in range(W):
            if i < H-1 and S[i][j] != S[i+1][j]:
                uf.union(i*W+j, (i+1)*W+j)
            if j < W-1 and S[i][j] != S[i][j+1]:
                uf.union(i*W+j, i*W+(j+1))
    D = {}
    for i in range(H):
        for j in range(W):
            r = uf.find(i*W+j)
            if r not in D:
                D[r] = [0, 0]
            if S[i][j] == "#":
                D[r][0] += 1
            else:
                D[r][1] += 1
    ans = 0
    for d in D.values():
        ans += d[0]*d[1]
    print(ans)


if __name__ == '__main__':
    main()


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

int main(void)
{

	int n,q;
	int m,d;

	vector<int> v(101);

	int i1,i2;

	int max;
	int day;



	while(1){


		cin >> n >> q;
		if (n == 0 && q == 0) break;

		for (i1=0;i1<101;i1++){
			v[i1] = 0;
		}

		for (i1=0; i1<n; i1++){

			cin >> m;
			for(i2=0;i2<m;i2++){
				cin >> d;

				v[d]++;
			}
		}


		max = 0;
		day = 100;
		for(i1=0;i1<101;i1++){
			if (max < v[i1]){
				max = v[i1];
				day = i1;
			}
			else if (max == v[i1]){
				if (day > i1){
					day = i1;
				}
			}
		}


		if (max >= q){

			cout << day << endl;
		}
		else {
			cout << "0" << endl;
		}


	}

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c) : from(f), to(t), cost(c) { }
    bool operator <(const Edge& e) const {
        return cost < e.cost;
    }
};

const int INF = (int)1e9;
typedef pair<int, int> P;

vector<int> dijkstra(const vector<vector<Edge> >& g, int s) {
    vector<int> res(g.size(), INF);
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0, s));
    res[s] = 0;
    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        if(p.first > res[p.second]) continue;
        for(int i = 0; i < (int)g[p.second].size(); i++) {
            Edge e = g[p.second][i];
            if(res[e.to] > p.first + e.cost) {
                res[e.to] = p.first + e.cost;
                Q.push(P(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int N; cin >> N;
    vector<vector<Edge> > es(N);
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k;
        while(k--) {
            int v, c; cin >> v >> c;
            es[u].push_back(Edge(u, v, c));
        }
    }
    vector<int> res = dijkstra(es, 0);
    for(int i = 0; i < N; i++) {
        cout << i << ' ' << res[i] << endl;
    }
}

Measured memory_bytes: 1284
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // Initialize
          	var intA = cin.ReadInt;
          	var intB = cin.ReadInt;
          	var strAns = "";
            // Process
          	strAns = intA < intB ? 
                new String( (char)(intA+'0') , intB ) 
              : new String( (char)(intB+'0') , intA );
            // Output
        	WriteLine( strAns );
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 27536
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
 
typedef vector<int> vec;
typedef long long ll;
typedef unsigned long long ull;


int main(){
    fast_cin();
    int n, m;cin>>n>>m;
    vec v(n);
    int sum =0;
    rep(i, 0, n){
    	cin>>v[i];
    	sum+=v[i];
    }
    //cout<<sum<<endl;
    float select = sum/(4.0*m);
    int ans =0;
    //cout<<select<<endl;
    trav(i, v)
    if(i>=select)
    	ans++;
     //cout<<ans<<endl;
    if(ans >= m)
    	cout<<"Yes\n";
    else
    	cout<<"No\n";

}


Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
n = int(input())  
ps = primes(10 ** 6)
if n == 2:
  print(2)
else:
  for i in range(len(ps)):
    if ps[i] < n <= ps[i + 1]:
      print(ps[i + 1])
      break

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

#include <cmath>
#include <map>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]){

  int A, P;

  cin >> A >> P;
  cout << (3*A+P)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    ll n, m;
    cin >> n >> m;
    lf ans = 0;
    fore(i,1,n+1) {
        ll p = 1, cnt = 0;
        while (p*i < m) {
            p *= 2;
            cnt++;
        }
        p = 1<<cnt;
        ans += 1.0/lf(p);
    }
    ans *= 1.0/lf(n);
    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin>>N;
	bool ans = true;
	for(int i=0;i<N;i++){
		ll k;
		cin >> k;
		if(k&1)ans = false;
	}
	if(ans){
		cout << "second" << endl;
	}else{
		cout << "first" << endl;
	}
}

Measured memory_bytes: 256
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(x,y))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{
    ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x);
    return v;}

vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }
    return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void solve(){
    ll N;
    cin>>N;
    bool flag=false;
    for(int i=1;i<10;i++)
    if(N%i == 0)
    if(N/i < 10  &&  N/i > 0)
    flag=true;

    flag ? cout<<"Yes" : cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

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

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

int A[1000000];

int main() {
    int n; cin >> n;
    int MIN = 100010;
    int MAX = 0;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        MIN = min(MIN,a[i]-1);
        MAX = max(MAX,a[i]+1);
        A[a[i]]++;
        A[a[i]-1]++;
        A[a[i]+1]++;
    }
    

    int ans = 0;
    for(int j = MIN; j <= MAX; j++){
        ans = max(ans,A[j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
kyori=[]
if n>=m:
    print(0)
    
else:
    for i in range(m-1):
        kyori.append(a[i+1]-a[i])
    b=0
    kyori.sort()
    for i in range(m-n):
        b+=kyori[i]
    
    print(b)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" );
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}


Measured memory_bytes: 256