akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=5e5+5;

typedef long long LL;

typedef double db;

int n,L,Head,Tail,q,l[N],t,v,Now;

db D[N],ans;

char c;

int read()
{
    int x=0,sig=1;
    for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
    for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
    return x*sig;
}

int main()
{
	n=read(); L=read();
	t=read(); v=read();
	printf("%.10lf\n",(db)t);
	l[Head=Tail=1]=v; D[1]=t;
	ans=(db)t*L; Now=L;
	for (int i=2;i<=n;i++)
	{
		t=read(); v=read();
		Now+=v;
		for (;Now>L;)
		{
			if (Now-l[Head]>=L)
			{
				Now-=l[Head];
				ans-=l[Head]*D[Head];
				Head++;
			}else
			{
				ans-=D[Head]*(Now-L);
				l[Head]-=Now-L;
				Now=L;
			}
		}
		l[++Tail]=v; D[Tail]=t; ans+=(db)t*v;
		for (;Head<Tail && D[Tail]<=D[Tail-1];Tail--)
		{
			ans-=D[Tail-1]*l[Tail-1]+D[Tail]*l[Tail];
			D[Tail-1]=(D[Tail-1]*l[Tail-1]+D[Tail]*l[Tail])/(l[Tail]+l[Tail-1]);
			l[Tail-1]+=l[Tail];
			ans+=D[Tail-1]*l[Tail-1];
		}
		printf("%.10lf\n",ans/L);
	}
    return 0;
}

Measured memory_bytes: 16256
S=input()

if S=='SUN':
    print(7)
elif S=='MON':
    print('6')
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left)  + 1;
	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
		return T[T[u].parent].right;
	return NIL;
}

void print(int u) {
	int deg = 0;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	if(T[u].left  != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);
	
	if(T[u].parent == NIL) {
		printf("root\n");
	} else if(T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}

int main(void) {
	int i, v, l, r, root = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++) T[i].parent = NIL;
	for(i=0;i<n;i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left  = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}
	
	for(i=0; i<n; i++)
	if(T[i].parent == NIL) root = i;
	
	setDepth(root,0);
	setHeight(root);
	
	for(i=0;i<n;i++) print(i);
	
	return 0;
}



Measured memory_bytes: 2040
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    rr = []

    def f():
        n = I()
        if n == 0:
            return

        m = I()
        xy = [LI_() for _ in range(m)]

        nn = n // 2
        aa = [[0] * n for _ in range(n)]
        wl = [[0] * 2 for _ in range(n)]
        for x, y in xy:
            aa[x][y] = aa[y][x] = 1
            wl[x][0] += 1
            wl[y][1] += 1

        for i in range(n):
            if wl[i][0] > nn or wl[i][1] > nn:
                rr.append(0)
                return True

        kh = []
        for x in range(n):
            for y in range(x+1, n):
                if aa[x][y] == 0:
                    kh.append((x,y))
        ks = len(kh)

        def ff(wl, i):
            if i == ks:
                return 1

            r = 0
            x,y = kh[i]
            if wl[x][0] < nn and wl[y][1] < nn:
                wl[x][0] += 1
                wl[y][1] += 1
                r += ff(wl, i+1)
                wl[x][0] -= 1
                wl[y][1] -= 1

            if wl[x][1] < nn and wl[y][0] < nn:
                wl[x][1] += 1
                wl[y][0] += 1
                r += ff(wl, i+1)
                wl[x][1] -= 1
                wl[y][0] -= 1

            return r

        rr.append(ff(wl, 0))

        return True

    while f():
        pass

    return JA(rr, "\n")


print(main())





Measured memory_bytes: 9136
while True:
    try:
        a=map(int,raw_input().split())
        b=map(int,raw_input().split())
        c1=0
        c2=0
        for i,e in enumerate(b):
            if e in a:
                if e==a[i]: c1+=1
                else: c2+=1
        print c1, c2
    except:
        break

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

int main() {
  int n;
  cin >> n;
  int x[3];
  x[0] = n / 100;
  x[1] = (n % 100) / 10;
  x[2] = n % 10;

  int ans = 0;
  for(int i = 0; i < 3; i++) {
    if(x[i] == 1) ans++;
  }

  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 2005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
pair<ll,ll>  p[N+1];
ll dp[N][N];
ll solve1(ll id,ll first,ll last)
{
     if(id==0)    return 0;
     ll crt = p[id].ss;
     ll dif1 = abs(crt-first);
     ll dif2 = abs(crt-last);
     ll ans=dp[id][first];
     if(ans!=-1)   return ans;
     ans = max((solve1(id-1,first,last-1)+p[id].ff*dif2),(solve1(id-1,first+1,last)+p[id].ff*dif1));
     return dp[id][first] = ans;
}
void solve()
{
     ll n;
     cin >> n;
     for(ll i=1;i<=n;i++)
     {
          cin >> p[i].ff;
          p[i].ss = i;
     }
     sort(p+1,p+n+1);
     set<ll> s;
     memset(dp,-1,sizeof(dp));
     ll ans = solve1(n,1,n);
     cout<<ans;
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 35220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[300];
int main()
{
    int cut=0;
    for(int i=105; i<=200; i++)
    {
        int ans=0;
        for(int j=1; j<=i; j++)
        {
            if(i%j==0)
                ans++;
        }
        if(ans==8&&i%2==1)
        cut++;
        a[i]=cut;
    }
    int n;
    while(cin>>n)
    cout << a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
po = gets.split.map(&:to_i)
po.sort!
if m == 1
  puts 0
  exit
end
dis = Array.new(m-1, 0)
for i in 0..m-2
  dis[i] = po[i+1] - po[i]
end
dis.sort!
ans = 0
for i in 0..m-n-1
  ans += dis[i]
end
puts ans


Measured memory_bytes: 9712
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)((n+1) * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}


int64 dist[2*(10*10*10*10*10)+1];

int main()
{
  int64 N, K;
  int64 *A;
  int64 i;
  int64 maxd = 0; 
  int64 maxi = 0;
  int64 len;
  int64 diff;
  
  get_NK(&K, &N);

  A = get_NSeq (N);

  dist[0] = 0;
  diff = A[0];
  A[0] = 0;
  A[N] = K;
  for (i=1; i<=N; i++) {
    if (i!=N) {
      A[i] = A[i] - diff;
    }
    dist[i] = A[i] - A[i-1];
    if (maxd < dist[i]) {
      maxd = dist[i];
      maxi = i;
    }
    //printf("i=%d dist=%d A=%d A[i-1]=%d maxi=%d\n", i, dist[i], A[i], A[i-1], maxi);// for debug
  }

  len = A[maxi-1] + (K - A[maxi]);

  printf("%lld", len);
  return 0;
}



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

map<int, int> mp;
long dp[100010][35];
int main() {
	int N, M; cin >> N >> M;
	long ans=1, mod=1000000007;
	dp[0][0]=1;
	for(int i=0; i<N; ++i){
	    for(int f=0; f<35; ++f){
	        for(int t=f; t<35; ++t){
	            dp[i+1][t]=(dp[i+1][t]+dp[i][f])%mod;
	        }
	    }
	}
	for(int i=2; i*i<=M; ++i){
	    while(M%i==0){
	        ++mp[i];
	        M /= i;
	    }
	}
	if(M>1) mp[M]=1;
	for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
	    ans=(ans*dp[N][itr->second])%mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    int n;cin >> n;
    vector<int> a(n);
    set<int> s;
    for(int i=0; i<n; i++) cin >> a[i];
    bool ok=true;
    for(int i=0; i<n; i++){
        if(s.count(a[i])) ok=false;
        s.insert(a[i]);
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 10368
#include<iostream>

using namespace std;

int main()
{
	int b1 = 0, b2 = 0, b3 = 0;
	bool flag = false;

	cin >> b1 >> b2 >> b3;

	if(b1 == 1 && b2 == 1)
	{
		cout << "Open" << endl;
	}
	else if(b3 == 1)
	{
		cout << "Open" << endl;
	}
	else
	{
		cout << "Close" << endl;
	}

	return false;
}

Measured memory_bytes: 1156
#include "cstdio"
#include "algorithm"

using namespace std;

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

int main()
{
    int m, n;
    scanf("%d%d", &m, &n);
    int nums[m];
    for(int i=0; i<m; ++i)
    {
        scanf("%d", &nums[i]);
    }
    sort(nums, nums+m, cmp);
    int output=0;
    for(int i=0; i<n; ++i)
    {
        output += nums[i];
    }
    printf("%d\n", output);
    return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>

int main(void){
  int a, list[101] = {0};
  int i, value[110] = {0}, n, max;

  while (scanf("%d", &a) != EOF) {
    list[a]++;
  }

  max = -1;
  for (i = 1; i <= 100; i++) {
    if (max < list[i]) {
      max = list[i];
    }
  }

  n = 0;
  for (i = 1; i <= 100; i++) {
    if (list[i] == max ) {
      value[n] = i;
      n++;
    }
  }

  for (i = 0; i < n; i++) {
    printf("%d\n", value[i]);
  }

  return 0;
}


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

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

vector<string> m;
int ans = 0;

void dfs(int x, int y){
  m[y][x] = '#';
  ans++;
  for(int i=0; i<4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= w || nx < 0 || ny >= h || ny < 0) continue;
    if(m[ny][nx] == '.'){
      dfs(nx,ny);
    }
  }
}


int main(){

  while(1){
    cin >> w >> h;
    if(!w and !h) break;
    m.clear();
    
    for(int i=0; i<h; i++){
      string s; cin >> s;
      m.push_back(s);
    }

    int sx,sy;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
	if(m[i][j] == '@'){
	  sx = j;
	  sy = i;
	}
      }
    }
    ans =0;
    dfs(sx,sy);
    cout << ans <<  endl;

  }

}

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


int main(){
    long long a,b,c,d;
    cin >>a >> b>>c>>d;
    long long ans1=a*c,ans2=a*d,ans3=b*c,ans4=b*d;
    long long ans;
    ans = max(ans1,ans2);
    ans = max(ans,ans3);
    ans = max(ans,ans4);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
/*
 * ALDS1_9_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<algorithm>

int size = 0;

void insert(int* H, int k) {
	size++;
	H[size] = k;
	int h = size;
	while(h/2 > 0 && H[h/2] < H[h]){
		std::swap(H[h/2], H[h]);
		h /= 2;
	}
}

void maxHeapify(int* H, int n, int i) {
	int l = 2*i;
	int r = 2*i + 1;
	int largest = i;
	if(l <= n && H[l] > H[i]) {
		largest = l;
	}
	if(r <= n && H[r] > H[largest]) {
		largest = r;
	}
	if(largest != i) {
		std::swap(H[i], H[largest]);
		maxHeapify(H, n, largest);
	}
}

void extractMax(int* H) {
	if(size == 0) return;
	printf("%d\n", H[1]);
	H[1] = H[size];
	size--;
	maxHeapify(H, size, 1);
}

int main() {
	int H[2000001];

	char s[10];
	int k;
	while(true) {
		scanf("%s", s);
		if(s[2] == 'd') break;
		if(s[0] == 'i') {
			scanf("%d", &k);
			insert(H, k);
		}
		else extractMax(H);
	}
}



Measured memory_bytes: 6472
n=int(input())
s=[]
t=[]
ans=0
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    t.append(input())
for i in range(n):
    ans=max(ans,s.count(s[i])-t.count(s[i]))
print(ans)


Measured memory_bytes: 38256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    frag=1
    for i in range(3):
        if s[i]==s[i+1]:
            frag=0
    if frag==1:
        print('Good')
    else:
        print('Bad')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	double h1,h2,h3;
	h1=-1;
	h2=-1;
	h3=-1;
	double h;
	for(int i=0;i<10;i++) {
		cin >> h;
		if(h > h1) {
			h3 = h2;
			h2 = h1;
			h1 = h;
		}
		else if(h > h2) {
			h3 = h2;
			h2 = h;
		}
		else if(h > h3) {
			h3 = h;
		}
	}
	
	cout << h1 << endl;
	cout << h2 << endl;
	cout << h3 << endl;
	
	return 0;
}

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

int main()
{
	long long h, w;
	int n;
	scanf("%lld%lld%d", &h, &w, &n);
	std::vector<std::pair<int, int>> coor;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		for (int x = -1; x <= 1; x++)
			for (int y = -1; y <= 1; y++)
				if (a + y > 1 && a + y < h && b + x > 1 && b + x < w)
					coor.push_back({a + y, b + x});
	}
	std::sort(coor.begin(), coor.end());
	coor.push_back({-1, -1});
	int start{};
	long long table[10]{(h - 2) * (w - 2)};
	for (unsigned int i{}; i < coor.size(); i++)
	{
		if (coor[start] == coor[i]) continue;
		table[i - start]++;
		table[0]--;
		start = i;
	}
	for (int i = 0; i < 10; i++) printf("%lld\n", table[i]);

	return 0;
}

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

int main(void)
{
    string s;
    while (getline(cin, s) && s != "0") {
        int sum = 0;
        for (char c : s)
            sum += c - '0';
        cout << sum << endl;
    }

    return 0;
}



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

using namespace std;

int main(){
  int a[5],k;
  
  cin >> a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
  
  for(int i=0;i<5;i++){
    for(int j=i;j<5;j++){
      if(abs(a[i]-a[j])>k){
        cout<<":(";
        return 0;
      }
    }
  }
  cout<<"Yay!";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int lcm(int a, int b){
  return a/gcd(a,b)*b;
}
int main(void){
    long long int a,b,n,x,i=0,h[200000],ans=0,c=0;
    string s;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<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)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n;
    string s;
    cin >> s;
    cin >> k;

    REP(i, n)
    {
        if(s[k-1] != s[i]) s[i] = '*';
    }
    cout << s << endl;
}

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

int n;
vector<vector<int>> g;

void bfs(vector<int> sums, vector<int> &anss){
  vector<int> seen(n,-1);
  seen[0] = 1;
  queue<int> q;
  q.push(0);
  anss[0] = sums[0];
  while(!q.empty()){
    int now = q.front();
    q.pop();

    for(int next:g[now]){
      if(seen[next]==-1){
        q.push(next);
        anss[next] = sums[next] + anss[now];
        seen[next] = 1;
      }
    }
  }
}

int main(){
  int q;
  cin >> n >> q;
  g.assign(n,vector<int>());

  for (int i = 0; i < n-1; i++)
  {
    int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> anss(n);
  vector<int> sums(n);
  for (int i = 0; i < q; i++)
  {
    int p,x;
    cin >> p >> x;
    p--;
    sums[p]+=x;
  }
  bfs(sums,anss);
  
  for (int i = 0; i < n; i++)
  {
    cout << anss[i] << endl;
  }
}

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

using lint = long long;

int main(void)
{
    int N;
    cin >> N;
    vector<int> v(N);

    for(auto& x: v){
        cin >> x;
    }

    int x1 = 0;
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            x1 += v[i];
        }else{
            x1 -= v[i];
        }
    }
    vector<int> ans(N);
    ans[0] = x1;
    for(int i = 1; i < N; i++){
        ans[i] = (v[i-1] - ans[i-1]/2)*2;
    }
    for(int i = 0; i < N; i++){
        cout << ans[i];
        if(i == N-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 2048
# coding: utf-8
# Your code here!
while(1):
    a,op,b=input().split(" ")
    a=int(a)
    b=int(b)

    if op=="?":
        break
    if op=="+":
        print(int(a+b))
    if op=="-":
        print(int(a-b))   
    if op=="*":
        print(int(a*b))
    if op=="/":
        print(int(a/b))        
        


Measured memory_bytes: 5596
"""
強連結成分分解
"""

import sys

sys.setrecursionlimit(1000000)

def dfs(v, visited, edges, order):
  visited[v] = True
  for to in edges[v]:
    if not visited[to]:
      dfs(to, visited, edges, order)
  order.append(v)

def search_strongly_connection(v, visited, reverse_edges, parent, num):
  visited[v] = True
  for to in reverse_edges[v]:
    if not visited[to]:
      parent[to] = num
      search_strongly_connection(to, visited, reverse_edges, parent, num)

def main():
  v_num , e_num = map(int, input().split())
  edges = [[] for _ in range(v_num)]
  reverse_edges = [[] for _ in range(v_num)]
  for _ in range(e_num):
    s, t = map(int, input().split())
    edges[s].append(t)
    reverse_edges[t].append(s)
  
  
  order = []
  visited = [False] * v_num
  for v in range(v_num):
    if not visited[v]:
      dfs(v, visited, edges, order)
  order.reverse()
  
  
  visited = [False] * v_num
  parent = [i for i in range(v_num)]
  for v in order:
    if not visited[v]:
      search_strongly_connection(v, visited, reverse_edges, parent, v)
  
  q_num = int(input())
  for _ in range(q_num):
    u, v = map(int, input().split())
    print(1 if parent[u] == parent[v] else 0)

main()


Measured memory_bytes: 19236
N = int(input())
ans_Alice = 0
ans_Bob = 0

a = list(map(int,input().split()))

a_new = sorted(a, reverse = True)


for i in range(0, N, 2):
	ans_Alice += a_new[i]
	
for j in range(1, N, 2):
	ans_Bob += a_new[j]


print(str(ans_Alice - ans_Bob))

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

using namespace std;

int main()
{
  int N, count = 0, count1 = 0;
  cin >> N;
  string S;
  cin >> S;
  for (int i = 0; i < N; i++)
  {
    if (S.at(i) == 'R')
    {
      count++;
    }
    else
    {
      count1++;
    }
  }
  if (count1 < count)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

class UnionFinder {

public:
  int n;
  vector<int> par;
  vector<int> rank; // to speed up the proccess
  int nUnion; // number of unions
  
  UnionFinder(int num)
    : n(num), nUnion(num)
  {
    par.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      rank[i] = 0;
    }
  }

  void merge (int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }

    if (rank[x] > rank[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (rank[x]==rank[y]) {
	rank[y]++;
      }
    }
    nUnion--;
  }
  
  int root (int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]); // path compression
    }
  }
};

int main () {
  int N, M;
  cin >> N >> M;
  UnionFinder uf(N);
  for (int i = 0; i < M; i++) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    uf.merge(X-1, Y-1);
  }
  cout<<uf.nUnion<<endl;
  return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<long long> A(M);
    for(int i=0; i<M; ++i) cin >> A[i];
    
    long long sum = accumulate(begin(A), end(A), 0LL);
    if(sum > N) cout << -1 << endl;
    else cout << N - sum << endl;
}

Measured memory_bytes: 3680
n,b,f[50001];main(a){for(;++a<50001;)if(!f[a])for(b=a;b+a<50001;)f[b+=a]=1;for(;scanf("%d",&n),n;printf("%d\n",b))for(b=0,a=1;a++<n/2;)f[a]+f[n-a]||b++;exit(0);}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;

ll cp[2520][52], nx[2520][52];

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, a;
	cin >>n >>a;
	VI x(n);
	rep(i,n) cin >> x[i];
	
	memset(cp, 0, sizeof cp);
	cp[0][0]=1;
	
	rep(i, n){
		memset(nx, 0, sizeof nx);
		rep(j, a*n) rep(k,n) {
			nx[j][k] += cp[j][k];
			if( j+x[i] <= a*n ) nx[j+x[i]][k+1] += cp[j][k];
		}
		swap(cp, nx);
	}
	
	ll ans =0;
	rep(i, a*n+1) rep2(j,1,n+1){
		if(i==j*a){
			ans += cp[i][j];
			//printf("%d:%d:%lld  ",i,j,cp[i][j]);
		}
	}
	cout << ans <<endl;
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair

using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	int n; cin >> n;
	int a; cin >> a;
	int b; cin >> b;
	vector<int> v(n); for (int o = 0; o < n; o++) { cin >> v[o]; }
	int t1, t2, t3;
	t1 = t2 = t3 = 0;
	for (int i = 0; i < n; ++i)
	{
		if (v[i] <= a)
			t1++;
		else if (v[i] <= b)
			t2++;
		else
			t3++;
	}
	cout << min(t1, min(t2, t3));
}

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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

// A
int main(void){
    Cin(int, n, m);
    printf("%.15f\n", 6.28318530717958623200
*n);
}


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

using namespace std;
typedef long long ll;
#define N 105

int grid[3][N];
int dp[3][N];
int main(){
    int n;
    scanf ("%d", &n);
    for (int i = 1; i <= 2; i++){
        for (int j = 1; j <= n; j++){
            scanf ("%d", &grid[i][j]);
        }
    }

    for (int i = 1; i <= 2; i++){
        for (int j = 1; j <= n; j++){
            dp[i][j] = max (dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
        }
    }
    cout << dp[2][n] << endl;
    return 0;
}


Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[i])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140172
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    vector<int> v(3);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(), v.end());
    cout << v[0]*v[1]/2 << "\n";
    return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

ok = a[-1]
ng = 0
while abs(ok - ng)>1:
    X = (ok + ng)//2
    
    cnt = 0
    for i in range(n):
        temp = a[-(i + 1)]
        if temp <= X:break
        temp_cnt = (temp + X - 1)//X - 1
        cnt += temp_cnt
    
    if cnt <= k:ok = X
    else:ng = X
    
print(ok)

Measured memory_bytes: 104140
marks = ["S", "H", "C", "D"]
cards = {}

n = int(input())

for _ in range(0, n):
    mark, num = input().split()

    if mark not in cards:
        cards[mark] = []

    cards[mark].append(int(num))

for mark in marks:
    for n in range(1, 14):
        if n in cards[mark]:
            continue

        print("{} {}".format(mark, n))



Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >>s;
    int ans = 0;
    rep(i,1000) {
        int x = i;
        string t;
        rep(j,3) {
            t += x%10+'0';
            x /= 10;
        }
        reverse(t.begin(),t.end());
        int ti = 0;
        rep(j,n) {
            if(s[j] == t[ti]) {
                ++ti;
            }
            if(ti == 3) break;
        }
        if(ti == 3) {
            ans ++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = [input() for _ in range(N)]
M = I()
T = [input() for _ in range(M)]

d = defaultdict(int)
for s in S:
    d[s] += 1
for t in T:
    d[t] = max(0, d[t] - 1)

print(max(d.values()))

Measured memory_bytes: 38256
#include <cstdio>

int gcd(int m, int n)
{
    if (n == 0)
        return m;
    if (m < n)
        return gcd(m, n % m);
    return gcd(n, m % n);
}

int main()
{
    int a, b;
    std::scanf("%d%d", &a, &b);
    std::printf("%d\n", gcd(a, b));
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
using ll = long long;
int main(){
  long int a;
  long double b;
  cin >> a>> b;
  int y = (b*100)+0.5;
  cout << (a*y)/100 << endl;
   return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>

int N;
std::vector<int> k(10000,0);

int main(void){
    while(std::cin>>N, N!=0){
        int num_0 = 0;
        int num_1 = 0;
        for(int i=0; i<N; ++i){
            std::cin >> k[i];
            if(k[i] == 0){
                num_0++;
            }
            if(k[i] == 1){
                num_1++;
            }
        }

        if((num_0+num_1) >= N){
            std::cout << "NA" << std::endl;
            continue;
        }

        std::cout << (N-num_0+1) << std::endl;
    }
}

Measured memory_bytes: 3124
import java.util.*;
public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		List<Node> l1 = new ArrayList<Node>();
		List<Node> l2 = new ArrayList<Node>();
		int n=sc.nextInt();
		for (int i=0;i<n;i++) {
			Node nd=new Node();
			nd.num=i;
			nd.x=sc.nextInt();
			nd.y=sc.nextInt();
			l1.add(nd);
			l2.add(nd);
		}
		
		Collections.sort(l1, new Comparator<Node>() {
			public int compare(Node n1, Node n2) {
				return n1.x-n2.x;
			}
		});
		Collections.sort(l2, new Comparator<Node>() {
			public int compare(Node n1, Node n2) {
				return n1.y-n2.y;
			}
		});
		
		List<Edge> l3=new ArrayList<Edge>();
		for(int i=0;i<n-1;i++) {
			Edge e=new Edge();
			e.from=l1.get(i).num;
			e.to=l1.get(i+1).num;
			e.length=l1.get(i+1).x-l1.get(i).x;
			l3.add(e);
			
			e=new Edge();

			e.from=l2.get(i).num;
			e.to=l2.get(i+1).num;
			e.length=l2.get(i+1).y-l2.get(i).y;
			l3.add(e);
		}
		
		Collections.sort(l3, new Comparator<Edge> () {
			public int compare(Edge e1, Edge e2) {
				return e1.length-e2.length;
			}
		});
		
		UnionFind u=new UnionFind(n);
		
		long price=0;
		
		for(Edge e : l3) {
			if(u.find(e.from)!=u.find(e.to)) {
				u.union(e.from,e.to);
				price+=e.length;
			}
		}
		
		System.out.println(price);
		
	}

}

class Node {
	int num;
	int x;
	int y;
}

class Edge  {
	int from;
	int to;
	int length;
}

class UnionFind {
	int[] parent;
	int[] rank;
	public UnionFind(int size) {
		parent = new int[size];
		rank = new int[size];
		for(int i=0;i<size;i++) {
			parent[i]=i;
			rank[i]=0;
		}
	}
	public int find(int x) {
		if(parent[x]==x) {
			return x;
		} else {
			return(find(parent[x]));
		}
	}
	public void union(int x, int y) {
		int xRoot=find(x);
		int yRoot=find(y);
		if(rank[xRoot] < rank[yRoot]) {
			parent[xRoot]=yRoot;
		} else if (rank[xRoot] > rank[yRoot]) {
			parent[yRoot]=xRoot;
		} else if (xRoot!=yRoot) {
			parent[yRoot]=xRoot;
			rank[xRoot]++;
		}
	}
}

Measured memory_bytes: 100536
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < ll  int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;
        bool cnt(ll n)
          {
              int k=0;
              while(n>0)
              {
                  n/=10;
                  k++;
              }
              if(k%2) {return true;}
              else return false;
          }
        void solve()
           {
               ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,x,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1,w;
               cin>>n;
               rep(i,1,n+1)
                  {
                      y+=(cnt(i)==true);
                  }
                  cout<<y;




           }
        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


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

vector<vector<int>> V;
vector<int> vis;

void dfs(int a, int b, int f){
	if(vis[f]) return;
	vis[f] = 1;
	for(int t:V[f]) if(f!=a || t!=b) dfs(a, b, t);
}

int main(){
	int N, M; cin>>N>>M;
	vector<pair<int,int>> E;
	for(int i=0; i<M; ++i){
		int a,b; cin>>a>>b; --a, --b;
		E.emplace_back(a,b);
	}
	V.resize(N);
	for(auto [a,b]:E){
		V[a].push_back(b);
		V[b].push_back(a);
	}
	vis.resize(N);
	int ans = 0;
	for(auto [a,b]:E){
		for(auto& x:vis) x = 0;
		dfs(a, b, a);
		if(!vis[b]) ans++;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3608
#include <iostream>

int MOD = 1e9 + 7;

int expo(long long base, int ex){
    long long cp = 1;
    while(ex){
        if(ex%2) cp *= base;
        base *= base;
        cp %= MOD;
        base %= MOD;
        ex /= 2;
    }
    return cp;
}

int inv_mod(int n){
    return expo(n, MOD-2);
}

int ncr(int n, int r){
    long long base = 1;
    for (int i = 0; i < r; ++i) {
        base *= n-i;
        base %= MOD;
        base *= inv_mod(i+1);
        base %= MOD;
    }
    return base;
}

int main(){
    int x, y;
    std::cin >> x >> y;
    if((x+y)%3){
        std::cout << 0;
        return 0;
    }
    int step = (x+y)/3;
    x -= step;
    y -= step;
    if(x<0 or y<0){
        std::cout << 0;
        return 0;
    }
    std::cout << ncr(step, std::min(x,y));
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >Q2;
vector<pair<int, int> >X[820], Y[820]; queue<int>Q;
int n, a[820], b[820], dist[820]; vector<pair<int, int> > p[820];
void BFS(int V, int s) {
	for (int i = 1; i <= V; i++) { dist[i] = 1 << 30; }dist[s] = 0; Q.push(s);
	while (!Q.empty()) {
		long long u = Q.front(); Q.pop();
		for (int i = 0; i < X[u].size(); i++) {
			int to = X[u][i].first; if (dist[to] == 1 << 30) { dist[to] = dist[u] + 1; Q.push(to); }
		}
	}
}
void dijkstra(int V, int E, int s) {
	for (int i = 1; i <= V; i++) { dist[i] = 1 << 30; }
	dist[s] = 0; Q2.push(make_pair(0, s)); int cnt = 0;
	while (!Q2.empty()) {
		pair<int, int>p = Q2.top(); Q2.pop();
		for (int i = 0; i < Y[p.second].size(); i++) {
			int to = Y[p.second][i].first, leng = Y[p.second][i].second;
			if (dist[to] > dist[p.second] + leng) {
				dist[to] = dist[p.second] + leng;
				Q2.push(make_pair(dist[to], to));
			}
		}
	}
	return;
}
int main() {
	while (true) {
		for (int i = 0; i < 820; i++)X[i].clear();
		cin >> n; int S = 0; if (n == 0)break;
		for (int i = 2; i <= n; i++)cin >> a[i];
		for (int i = 2; i <= n; i++) {
			cin >> b[i]; S += b[i];
			X[i].push_back(make_pair(a[i], b[i]));
			X[a[i]].push_back(make_pair(i, b[i]));
		}
		int P = 1 << 30;
		for (int i = 1; i <= n; i++) {
			BFS(n, i); int T = 0;
			for (int j = 0; j < 820; j++) { p[j].clear(); Y[j].clear(); }
			for (int j = 1; j <= n; j++) {
				for (int k = 0; k < X[j].size(); k++) {
					if (dist[j] > dist[X[j][k].first]) p[X[j][k].first].push_back(make_pair(j, X[j][k].second));
				}
			}
			for (int j = 1; j <= n; j++) {
				if (p[j].size() >= 1) {
					for (int k = 0; k < p[j].size(); k++) {
						int to = p[j][k].first;
						if (p[to].size() == 0)continue;
						Y[j].push_back(make_pair(to, p[j][k].second));
						Y[to].push_back(make_pair(j, p[j][k].second));
					}
				}
				else {
					for (int k = 0; k < X[j].size(); k++) {
						T += X[j][k].second;
					}
				}
			}
			int maxn = 0, mn = 0, mID = 0;
			dijkstra(n, n - 1, i);
			for (int i = 1; i <= n; i++) {
				if (p[i].size() == 0)continue;
				if (mn < dist[i]) {
					mn = dist[i]; mID = i;
				}
			}
			if (mID == 0)goto E;
			dijkstra(n, n - 1, mID);
			for (int i = 1; i <= n; i++) {
				if (p[i].size() == 0)continue;
				maxn = max(maxn, dist[i]);
			}
		E:;
			P = min(P, S * 3 - T * 2 - maxn);
		}
		cout << P << endl;
	}
	return 0;
}

Measured memory_bytes: 1420
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> pi;
int main(){
	int n;
	cin>>n;
	int xx = 0;
	int yy = 0;
	int tc = 0;
	bool possible = true;
	while(n--){
		int t;
		int x,y;
		cin>>t>>x>>y;
		int d = abs(x-xx)+abs(y-yy);
		if(t-tc<d || ((t-tc)-d)%2) possible = false;
		tc = t;
		xx = x;
		yy = y;
	}
	if(possible) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3136
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M);
    ll sum = 0;
    rep(i,M) {
        cin >> A.at(i);
        sum += A[i];
    }
    if (N - sum >= 0) {
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3708
//05
#include<iostream>
#include<algorithm>
#include<complex>
#include<cmath>

using namespace std;

typedef complex<double> P;

double cr(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

double dt(P a,P b){
  return a.real()*b.real()+a.imag()*b.imag();
}

int main(){
  for(int n,m,l;cin>>n>>m>>l,n|m|l;){
    double d[100][100]={{}};
    int x[100],y[100],a[100],r[100];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>a[i]>>r[i];
      for(int j=0;j<i;j++){
	double ml=1<<30;
	for(int k=0;k<5;k++){
	  P aa=P(x[i],y[i])+polar(r[i]+.0,(a[i]+72*k+90)/180.*acos(0)*2);
	  P bb=P(x[i],y[i])+polar(r[i]+.0,(a[i]+72*k+144+90)/180.*acos(0)*2);
	  for(int l=0;l<5;l++){
	    P cc=P(x[j],y[j])+polar(r[j]+.0,(a[j]+72*l+90)/180.*acos(0)*2);
	    P dd=P(x[j],y[j])+polar(r[j]+.0,(a[j]+72*l+144+90)/180.*acos(0)*2);
	    if(cr(aa-bb,cc-bb)*cr(aa-bb,dd-bb)<0&&cr(cc-dd,aa-dd)*cr(cc-dd,bb-dd)<0){
	      ml=0;
	    }else{
	      P ls[2][2]={aa,bb,cc,dd};
	      for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
		  P a=ls[i][0];
		  P b=ls[i][1];
		  P c=ls[!i][j];
		  double dp;
		  if(dt(a-b,c-b)>0&&dt(b-a,c-a)>0){
		    dp=fabs(cr(a-b,c-b)/abs(a-b));
		  }else{
		    dp=min(abs(a-c),abs(b-c));
		  }
		  ml=min(ml,dp);
		}
	      }
	    }
	  }
	}
	d[i][j]=d[j][i]=ml;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
	}
      }
    }
    cout.precision(6);
    cout<<fixed<<d[m-1][l-1]<<endl;
  }
  return 0;
}
	    

Measured memory_bytes: 1344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  string s;
  cin >> s;

  if(s.length() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
def insertionsort(a, n, g):
    cnt = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
        a[j + g] = v
    return cnt


def shellsort(a, n):
    g = []
    gap = 1
    while gap <= n:
        g.append(gap)
        gap = 3 * gap + 1
    g = g[::-1]
    m = len(g)
    print(m)
    print(*g)
    cnt = 0
    for i in range(m):
        cnt += insertionsort(a, n, g[i])
    print(cnt)

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
shellsort(a, n)
print("\n".join(map(str, a)))

Measured memory_bytes: 189888
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <climits>
#include <map>
#include <math.h>
using namespace std;

int main(void)
{
    int N = 0;
    unsigned long long ans = 0;
    unsigned long long L0 = 2;
    unsigned long long L1 = 1;
    unsigned long long L0_t = 0;
    unsigned long long L1_t = 1;
    cin >> N;
    for (int i = 0; i < N - 1; i++)
    {
        unsigned long long tmp = L0_t;
        L0_t = L1_t;
        L1_t = tmp + L1_t;
    }
    ans = L0 * L0_t + L1 * L1_t;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;

public class Test
{
    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var N = line1[0];
        var T = line1[1];
        var t = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        long sum = 0;

        for (int i = 0; i < t.Length - 1; i++)
        {
            sum += Math.Min(t[i + 1] - t[i], T);
        }

        sum += T;

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 28384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  vector<ll> ans_list(S.length() + 1, 0);
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '<') {
      ans_list[i + 1] = max(ans_list[i] + 1, ans_list[i + 1]);
    }
  }
  for (int i = S.length() - 1; i >= 0; i--) {
    if (S[i] == '>') {
      ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i]);
    }
  }
  ll ans = 0;
  for (auto e : ans_list) {
    ans += e;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4740
N,M = map(int, input().strip().split(' '))
P = list(map(int, input().strip().split(' ')))
P = [p-1 for p in P]

class UnionFind:
  def __init__(self, n):
    self.tree = list(range(n))
    
  def root(self, n):
    if self.tree[n] == n:
      return n
    else:
      self.tree[n] = self.root(self.tree[n])
      return self.tree[n]
  
  def marge(self, x, y):
    if not self.root(x) == self.root(y):
      self.tree[self.root(y)] = self.root(x)
  
# グループごとに考えればよい
uf = UnionFind(N)
for _ in range(M):
  x,y = map(int, input().strip().split(' '))
  x,y = x-1,y-1
  uf.marge(x,y)

groups = [set() for _ in range(N)]
for i in range(N):
  groups[uf.root(i)].add(i)

ans = 0
for g in groups:
  if len(g) == 0: continue
  ans += len(set(P[i] for i in g) & g)

print(ans)



Measured memory_bytes: 122732
#include <iostream>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<deque>
#include<iomanip>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
#include<unordered_set>
using namespace std;
//	int x=atoi(s.c_str()); s_to_in;
int dx[] = { -1,0,0 };
int dy[] = { 0,1,-1 };
#define endl '\n'
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
long long gcd(long long x, long long y)
{
	if (x == 0)
		return y;
	return gcd(y%x, x);
}
long long fast_power(long long x, long long y, long long mo)
{
	long long p = 1;
	while (y)
	{
		if (y & 1)
			p = (p*x) % mo;
		y = (y >> 1); //y/=2
		x = (x*x) % mo;
	}

	return p;
}
long long convert_to_num(string x) {
	long long  num = 0;
	for (int i = 0; i < x.size(); i++) {
		num *= 2;
		num += x[i] - '0';
	}
	return num;
}

long long com(long long n, long long r) {
	long long p = 1, p1 = 1;
	for (long long i = r + 1; i <= n; i++) {
		p = p * i;
		p /= p1;
		p1++;
	}
	return p;
}


int main()
{
	trust_yourself();
	
	int n,m,c=0; long long a[1001]; double s=0;
  cin>>n>>m;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  s=(s/(m*4.0));
  for(int i=0;i<n;i++){
    if(a[i]>=s)
      c++;
  }
  if(c>=m)
    cout<<"Yes";
  else
    cout<<"No";
	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll K;
  cin>>K;
  ll N = 50;
  ll a[N];
  for(int i=0;i<N;++i) {
    if(i<K%N) a[i] = (N+1)*(K/N+1)-K+N-1;
    else a[i] = (N+1)*(K/N)-K+N-1;
  }
  cout<<N<<endl;
  for(int i=0;i<N;++i) cout<<a[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
#include<queue>
using namespace std;

long long int mod = 1000000007;
vector<bool> isPrime(long long int n){
  vector<bool> prime(n+1, true);
  prime[0] = false;
  prime[1] = false;
  for(long long int i=2; i<=sqrt(n); i++){
    if( !prime[i] ) continue;
    for(long long int j=i*2; j<=n; j+=i){
      prime[j] = false;
    }
  }
  return prime;
}

int main(void) {

  int n;
  vector<bool> b = isPrime(2*123456+1);
  while( cin >> n ){
    if(n==0) break;
    int cnt = 0;
    for(int i=n+1; i<=2*n; i++){
      if( b[i] ) cnt++;
    }
    cout << cnt << endl;
  }


  return 0;
}

Measured memory_bytes: 3036