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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
 
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] * 4 * M >= sum) {
      count += 1;
    }
  }
  
  if (count >= M) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

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

bool is_prime(int x)
{
  if (x <= 1)
    return false;
  for (int i = 2;  i*i <= x; i++) // ?
    if (x % i == 0)
      return false;
  return true;
}

int main()
{
  int x;
  cin >> x;

  int p = x;
  while (!is_prime(p))
    p++;

  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>

using namespace std;

#define P(s) cout << s << endl;
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int n;
  cin >> n;
  bool has_nine = false;
  if ( n / 90 == 1) {
    has_nine = true;
  }

  if ( (n % 10) == 9 ) {
    has_nine = true;
  }

  if (has_nine) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//
//  main.cpp

#include <iostream>
using namespace std;


int main(){	
	string input,answer="";
	cin >> input;
	
	for(int i=0;i<input.size();i++){
		char c = input[i] - 3;
		if(c < 'A'){
			c += 26;
		}
		answer += c;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
#S = str(input())

print (180*(N-2))


Measured memory_bytes: 3436
#include<stdio.h>
int main(){
  int h,w;
  scanf("%d %d",&h,&w);
  int x[h],y[w],cx = 0,cy = 0;
  x[0] = -1;
  y[0] = -1;
  char s[h][w];
  for(int i = 0;i < h;i++){
    scanf("%s",&s[i]);
    int check = 1;
    for(int j = 0;j < strlen(s[i]);j++){
      if(s[i][j] != '.'){
        check = 0;
        break;
      }
    }
    if(check > 0){
      x[cx] = i;
      cx++;
    }
  }
  for(int i = 0;i < w;i++){
    int check = 1;
    for(int j = 0;j < h;j++){
      if(s[j][i] != '.'){
        check = 0;
        break;
      }
    }
    if(check > 0){
      y[cy] = i;
      cy++;
    }
  }
  cx = 0;
  for(int i = 0;i < h;i++){
    cy = 0;
    if(i == x[cx]){
      cx++;
    }else{
      for(int j = 0;j < w;j++){
        if(j == y[cy]){
          cy++;
        }else{
          printf("%c",s[i][j]);
        }
      }
      printf("\n");
    }
  }
  return 0;
}

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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    if (s=="SUN") cout << 7 << endl;
    if (s=="MON") cout << 6 << endl;
    if (s=="TUE") cout << 5 << endl;
    if (s=="WED") cout << 4 << endl;
    if (s=="THU") cout << 3 << endl;
    if (s=="FRI") cout << 2 << endl;
    if (s=="SAT") cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

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

	unordered_map<string, int> counter;
	for(int i = 0; i < N; i++) {
		string s;
		cin >> s;
		counter[s]++;
	}

	for(const auto &s : {"AC", "WA", "TLE", "RE"}) {
		cout << s << " x " << counter[s] << endl;
	}

	return 0;
}


Measured memory_bytes: 3644
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, K = MAP()

A = LIST()

whole = [0]*N
first = [0]*N

for i in range(N):
	for j in range(N):
		if A[j] < A[i]:
			whole[i] += 1
			if i < j:
				first[i] += 1

ans = 0
for i in range(N):
	ans += (K*first[i]%mod + whole[i]*(K-1)*K//2%mod)%mod

print(ans%mod)



Measured memory_bytes: 5332
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

bool f(int pos, int k, vector<int> card)
{
	const int prev = card[pos];
	card[pos] = 0;

	const int size = card.size();
	vector<vector<bool>> table(size+1, vector<bool>(k+1, false));
	table[0][0] = true;

	for(int i=0; i<size; i++)
	{
		for(int j=0; j<k+1; j++)
		{
			if(table[i][j] == false)
				continue;

			table[i+1][j] = table[i][j];

			int n = j + card[i];
			if(n > k)
				continue;

			table[i+1][n] = true;
		}
	}

	bool flag = false;
	for(int i=max(0, k-prev); i<k; i++)
		if(table[size][i] == true)
			flag = true;

	return flag;
}

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

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

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

	if(f(N-1, K, a) != true)
	{
		cout << N << endl;
		return 0;
	}
	else if(f(0, K, a) == true)
	{
		cout << 0 << endl;
		return 0;
	}

	int left, right;
	left = 0;
	right = N-1;
	while(right-left>1)
	{
		int mid = (left + right)/2;

		if(f(mid, K, a) == true)
			right = mid;
		else
			left = mid;
	}

	cout << left + 1 << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
        
int main() {
  int N,M,L,inf=1001001001;
  cin >> N >> M >> L;
  vector<vector<int>> G(N,vector<int>(N,inf));
  for(int i=0;i<N;i++) G[i][i] = 0;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a][b] = c;
    G[b][a] = c;
  }
  
  for(int k=0;k<N;k++){
    for(int u=0;u<N;u++){
      for(int v=0;v<N;v++){
        G[u][v] = min(G[u][v],G[u][k]+G[k][v]);
      }
    }
  }
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j) G[i][j] = 0;
      else if(G[i][j]<=L){
        G[i][j] = 1;
        G[j][i] = 1;
      }
      else{
        G[i][j] = inf;
        G[j][i] = inf;
      }
    }
  }
  
  for(int k=0;k<N;k++){
    for(int u=0;u<N;u++){
      for(int v=0;v<N;v++){
        G[u][v] = min(G[u][v],G[u][k]+G[k][v]);
      }
    }
  }
  
  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    int s,t;
    cin >> s >> t;
    s--;
    t--;
    if(G[s][t]==inf) cout << -1 << endl;
    else cout << G[s][t]-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h> //ABC 166_c
#define ll long long
using namespace std;
const int maxn=1e5+5;
int h[maxn],son[maxn],n,m,a,b,ans;
int main(){
	cin>>n>>m;;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		son[a]=max(son[a],h[b]);
		son[b]=max(son[b],h[a]);
	}
	for(int i=1;i<=n;i++){
		if(h[i]>son[i]) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline
N = int(input())


def get_id(i, j):
    if j < i:
        i, j = j, i
    return i * N + j


g = [[] for _ in range(N * N)]
S = []
for i in range(N):
    pre = None
    for j in map(int, input().split()):
        j -= 1
        id_ = get_id(i, j)
        if pre is None:
            S.append(id_)
        else:
            g[pre].append(id_)
        pre = id_


dp = [-1] * (N * N)
visited = [False] * (N * N)


def dfs(v):
    visited[v] = True
    if dp[v] != -1:
        return dp[v]
    for u in g[v]:
        if dp[u] != -1:
            res = dp[u]
        else:
            if visited[u]:
                raise ValueError('find loop!')
            res = dfs(u)
        dp[v] = max(dp[v], res + 1)
    if len(g[v]) == 0:
        dp[v] = 1
    return dp[v]


ans = 0
try:
    for s in S:
        ans = max(ans, dfs(s))
    print(ans)
except ValueError:
    print(-1)


Measured memory_bytes: 201388
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        int K = sc.nextInt();	
	        
	        long ans=0;
	        if(K==0) {
	        	System.out.println((long)N*N);
	        	return;
	        }
	        for(int i=K+1;i<=N;i++) {
	        	ans=ans+(i-K)*(N/i);
	        	if(N%i>=K) {
	        		ans=ans+(N%i-K+1);
	        	}
	        }
	        System.out.println(ans);
	    }
	}

Measured memory_bytes: 23764
package main

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

func check(w []int, k int, p int) bool {
	sum := 0
	for i := 0; i < len(w); i++ {
		if k <= 0 {
			return false
		}
		if sum + w[i] <= p {
			sum += w[i]
		} else {
			k--
			sum = w[i]
		}
	}
	return k > 0
}

func binarySearch(w []int, k int, l int, u int) int {
	if u - l <= 1 {
		return u
	}
	m := (u + l) / 2
	if check(w, k, m) {
		return binarySearch(w, k, l, m)
	} else {
		return binarySearch(w, k, m, u)
	}
}

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

	pmin := 0
	psum := 0
	w := make([]int, n)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		w[i], _ = strconv.Atoi(s.Text())
		
		psum += w[i]
		if w[i] > pmin {
			pmin = w[i]
		}
	}

	fmt.Println(binarySearch(w, k, pmin - 1, psum))
}



Measured memory_bytes: 2360
#include<stdio.h>
 
int main()
{
  int i,j,n,count=0;
  int G[101][101],color[101],d[101],pi[101],mincost,ii;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=2001;
  }
  d[0]=0;
 
  while(1){
    mincost=2001;
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<mincost){
        mincost=d[i];
        ii=i;
      }
    }
    if(mincost==2001)break;
    color[ii]=2;
    for(i=0;i<n;i++){
      if(G[ii][i]!=-1 && color[i]!=2 && G[ii][i]<d[i]){
    pi[i]=ii;
    d[i]=G[ii][i];
    color[i]=1;
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=-1)count+=G[i][pi[i]];
    }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
 string n;
/******* define variable end *******/
int solve() {
	cin >> n;
	if(n.substr(n.size()-1, 1) == "2" || n.substr(n.size()-1, 1) == "4" || n.substr(n.size()-1, 1) == "5" || n.substr(n.size()-1, 1) == "7" || n.substr(n.size()-1, 1) == "9"){
		cout << "hon" << endl;
	}else if(n.substr(n.size()-1, 1) == "0" || n.substr(n.size()-1, 1) == "1" || n.substr(n.size()-1, 1) == "6" || n.substr(n.size()-1, 1) == "8"){
		cout << "pon" << endl;
	}else{
		cout << "bon" << endl;
	}
	return 0;
}

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

	return end_solve;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int h[100001];
int h2[100001];
int main()
{
	int n;
	int k;
	cin >> n >> k;
	
	rep(i, n) {
		cin >> h[i];
		h2[i] = INF;
	}
	h2[0] = 0;
	rep(i, n) {
		REP(j, 1, k + 1) {
			if (i - j < 0) break;
			h2[i] = min(h2[i], abs(h[i] - h[i - j]) + h2[i - j]);
		}
	}
	cout << h2[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	int a, b, c,d; cin >> a>>b>>c;
	//string s,t,u; cin >> s>>t>>u;
	//vector<int> n(3);
	cout << (a + b) * c / 2;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int sum = 0;
  
  for(int i=0; i<M;i++){
   int a;
    cin >> a;
    sum+=a;
  }
  if(sum>N){
   cout << -1 << endl; 
  }else{
   cout << N-sum << endl; 
  }
  
 
  return 0;
}


Measured memory_bytes: 3648
N,M=map(int,input().split())
first=[]
second=[]
for m in range(M):
    a,b=map(int,input().split())
    if a==1:
        first.append(b)
    elif b==N:
        second.append(a)
first_and_second=set(first)&set(second)
if len(first_and_second)==0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')


Measured memory_bytes: 71128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int n;
ll x;
ll dfs(ll xx, int nn) {
    if(nn == 1) {
        int h = 0;
        switch(xx) {
            case 4:
            case 5:
            ++h;
            case 3:
            ++h;
            case 2:
            ++h;
        }
        return h;
    }

    ll c = (1LL<<(nn+2))-3;
    
    if(c == xx) {
        return (1LL<<nn+1)-1;
    }
    if(xx == 1) {
        return 0;
    }
    if(c/2 >xx) {
        return dfs(xx-1, nn-1);
    } else if(c/2 == xx) {
        return dfs(xx-1, nn-1);
    } else if(xx == c/2+1) {
        return 1LL<<n;
    } else {
        xx -= c/2+1;
        return dfs(xx, nn-1) + (1LL<<nn);
    }
}


int main() {
    cin >> n >> x;
    cout << dfs(x, n) << endl;
}

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

#define INF (INT64_MAX/2)

int main()
{
	int N;
	long long x;
	cin >> N >> x;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	long long ans = INF;
	vector<vector<int>> b( N, vector<int>( N ) );
	for( int k = 0; k < N; k++ ) {
		long long ans1 = 0;
		for( int i = 0; i < N; i++ ) {
			if( k == 0 ) b[k][i] = a[i];
			else {
				int n = i - k;
				if( n < 0 ) n = N - k + i;
				b[k][i] = min( b[k - 1][i], a[n] );
			}
			ans1 += b[k][i];
		}
		ans1 += k * x;
		ans = min( ans, ans1 );
	}

	cout << ans << endl;
}


Measured memory_bytes: 16000
#include<stdio.h>
int main(void)
{
  int n,x,sum,count,i,j,k,l;
  while(1)
{
  count=0;
  scanf("%d%d",&n,&x);
  if(n==0&&x==0) break;
  for(i=1;i<=n;i++)
    for(j=i+1;j<=n;j++)
      for(k=j+1;k<=n;k++)
        {
          sum=i+j+k;
          if(sum==x) count++;
        }
  printf("%d\n",count);
}
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int d;
  cin >> d;
  if (d == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  } else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (d == 24) {
    cout << "Christmas Eve" << endl;
  } else {
    cout << "Christmas" << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

	if (a!=0) {
		ll an = (a-1)/x;
		ll bn = b/x;
		cout << bn-an << endl;
	} else {
		cout << b/x+1 << endl;
	}
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0)
		cout << "Possible" << endl;
	else if (b % 3 == 0)
		cout << "Possible" << endl;
	else if ((a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <set>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;

void solve() {
    int n;
    cin >> n;
    ll sum = 0;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ll ans = 0;
    ll cnt = 0;
    sum = v[0];
    if (v[0] < 1) {
        cnt = 1 - v[0];
        sum = 1;
    }
    for (int i = 1; i < n; ++i) {
        if (sum > 0) {
            if (sum + v[i] >= 0) {
                cnt += sum + v[i] + 1;
                sum = -1;
            } else {
                sum += v[i];
            }
        } else {
            if (sum + v[i] <= 0) {
                cnt += -sum -v[i] + 1;
                sum = 1;
            } else {
                sum += v[i];
            }
        }
    }
    ans = cnt;
    cnt = 0;
    sum = v[0];
    if (v[0] > -1) {
        cnt = 1 + v[0];
        sum = -1;
    }
    for (int i = 1; i < n; ++i) {
        if (sum > 0) {
            if (sum + v[i] >= 0) {
                cnt += sum + v[i] + 1;
                sum = -1;
            } else {
                sum += v[i];
            }
        } else {
            if (sum + v[i] <= 0) {
                cnt += -sum -v[i] + 1;
                sum = 1;
            } else {
                sum += v[i];
            }
        }
    }
    ans = min(ans, cnt);
    cout << ans;
}

int main() {
    iostream::sync_with_stdio(false);
    cout.precision(20);
    solve();
}

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

int main() {
  int N;
  string S;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S;
      if(S == "Y") {
        cout << "Four" << endl;
        break;
      }
    if(i == N-1) {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vector<pll> rec;
    rep(i, N){
        rec.push_back(pll(B[i], -A[i]));
    }
    sort(rec.begin(), rec.end());
    ll t=0;
    rep(i, N){
        t -= rec[i].second;
        if(t > rec[i].first){
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9456
#include <iostream>
using namespace std;
template <class T>
inline bool chmax(T& a, T b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T& a, T b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int N;
long long W, weight[110], value[110];

//DP table
long long dp[110][100100] = { 0 };

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
        cin >> weight[i] >> value[i];

    // dp loop
    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            //i番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            //i番目の品物を選ばない場合
            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll  n;
  cin>>n;
  ll a[2][n];
  for(int i=0;i<2;i++)
  {
    for(int j=0;j<n;j++)
    {
      cin>>a[i][j];
    }
  }
if(n==1)
{
  cout<<a[0][0]+a[1][0]<<endl;
}
else
{
  ll dp[2][n];
  dp[1][n-1]=a[1][n-1];

for(int j=n-2;j>=0;j--)
{
  dp[1][j]=dp[1][j+1]+a[1][j];
}
/*for(int j=n-1;j>=0;j--)
{
cout<<dp[1][j]<<" ";
}
cout<<endl<<endl<<endl;*/
dp[0][n-1]=a[0][n-1];
/*for(int i=0;i<2;i++)
  {
    for(int j=0;j<n;j++)
    {
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl<<endl;*/
for(int i=0;i>=0;i--)
{
  for(int j=n-2;j>=0;j--)
  {
         dp[i][j]=max(dp[i+1][j],dp[i][j+1])+a[i][j];
  }
}
cout<<dp[0][0]<<endl;
}
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

double p,q,a,n,syou;
int ans;

int check(double a,double b)
{
	if(a - b < 1e-9 && b - a < 1e-9)return 0;
	else if(a > b)return 1;
	else return 2;
}


void dfs(double sum,int seki,int now,int mae)
{
	for(int i = mae;i < a;i++)
	{
		if(seki * i > a)break;
		double aa = (double)1/i;
		int tmp = check(syou,sum+aa);
		if(tmp == 0)
		{
		//	cout << "!!!!!" << i << endl;
			ans++;
		}
		else if(tmp == 1)
		{
			if(now < n)
			{
				dfs(sum+aa,seki*i,now+1,i);
			}
		}
	}
}

int main()
{
	
	while(cin>>p>>q>>a>>n,p != 0)
	{
		syou = p/q;
		ans = 0;
		dfs(0,1,1,1);
		cout << ans << endl;
	}	
	
	return 0;
}

Measured memory_bytes: 3192
package main

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

type Task struct {
	name string
	time int
}

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

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	que := make([]Task, 0, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		n := scanner.Text()
		scanner.Scan()
		t, _ := strconv.Atoi(scanner.Text())

		que = append(que, Task{n, t})
	}

	total := 0
	for len(que) != 0 {
		t := que[0]
		que = que[1:]
		if t.time <= q {
			total += t.time
			fmt.Printf("%v %v\n", t.name, total)
		} else {
			t.time -= q
			total += q
			que = append(que, t)
		}
	}
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  int big = max(n, m);
  ll dp[100003];
  dp[1] = 1;
  for (int i = 2; i <= big; ++i) dp[i] = (dp[i - 1] * i) % MOD;
  ;
  ll ans = 0;
  if (abs(n - m) > 1)
    ans = 0;
  else if (n == m)
    ans = (2 * dp[m] * dp[n]) % MOD;
  else
    ans = (dp[m] * dp[n]) % MOD;

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


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

#define l long

int main() {
    int n;
    cin>>n;
    int a[n],max_i = -1,max_i2 = -1;
    for(int i = 0; i < n; i++) {
        cin>>a[i];
        if(a[i] > a[max_i]) max_i = i;
    }
    
    for(int i = 0; i < n; i++) {
        if(i == max_i) continue;
        if(a[i] > a[max_i2]) max_i2 = i;
    }
    
    for(int i = 0; i < n; i++) {
        if(i == max_i) cout<<a[max_i2]<<"\n";
        else cout<<a[max_i]<<"\n";
    }
    
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"No"<<endl
#define YES() cout<<"Yes"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n;
    vll v(n);
    take(v,n);
    ll ans=0;
    f(i,1,n)
    {
        if(v[i]<v[i-1])
        {
            ans+=v[i-1]-v[i];
            v[i]=v[i-1];
        }
    }
    cout<<ans<<ee;
    
}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 4780
#include <iostream>
//#include <fstream>
//#include <iomanip>
//#include <omp.h>
//#include <vector>
#include <string>
//#include <stdlib.h>

using namespace std;

int main()
{
	char aa = 'a';
	int checkLength = (int)aa;
	int checkArray[26] = {0};
	string input;
	cin >> input;
	int index = 0;
	string answer = "yes";
	for (int i = 0; i < input.size(); i++) {
		//cout << (int)input.at(i) - checkLength << " ";
		index = (int)input.at(i) - checkLength;
		if (checkArray[index] == 0) {
			checkArray[index] = 1;
		}
		else {
			answer = "no";
			break;
		}
	}
	cout << answer;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int main() {
  int N, C[SIZE];

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf("%d", C+i);
  }

  sort(C, C+N);

  ll ans = 0;

  for (int i=0; i<N; i++) {
    ll t = power(2, i, mod);

    ll s = power(2, N-i-1, mod); //変更回数
    ll s2 = N-i-2 >= 0 ? power(2, N-i-2, mod) * (N - i - 1) % mod : 0; //コスト
    t = t * (s + s2) % mod;

    ans += t * C[i] % mod;
  }

  ans = ans % mod * power(2, N, mod) % mod;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define MOD (1000000007)
using namespace std;
long long int height,width,dp[1001][1001],mat[1001][1001];
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin>>height>>width;
	char ch;
	for(int i=0;i<height;i++){
		for(int j=0;j<width;j++){
			cin>>ch;
			if(ch=='.'){
				mat[i][j]=0;
			}
			else{
				mat[i][j]=1;
			}
		}
	}
	mat[0][0]=1;
	dp[0][0]=1;

	for(int i=0;i<height;i++){
		for(int j=0;j<width;j++){
			if(mat[i][j]==0){
				if(i==0){
					dp[i][j]=(dp[i][j-1]%MOD);
				}
				else if(j==0){
					dp[i][j]=(dp[i-1][j]%MOD);
				}
				else{
					dp[i][j]=((dp[i-1][j]+dp[i][j-1])%MOD);
				}
			}
		}
	}
	cout<<((dp[height-1][width-1])%MOD);
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pf push_front
#define pb push_back
deque<int> A, B;
LL n;
int now = 1;

void work(LL x) {
    if (x == 1) return; else work(x / 2);
    A.pf(++now), B.pf(now);
    if (x & 1) A.pf(++now), B.pb(now);
}
 
int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n;
    work(n + 1);
    printf("%d\n", A.size() + B.size());
    for(int i = 0; i < A.size(); i++) printf("%d ", A[i]);
    for(int i = 0; i < B.size(); i++) printf("%d ", B[i]);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a, b, c, k;
  int i;
  
  scanf("%d %d %d", &a, &b, &c);
  
  k = b / a;
  if(k > c)
    k = c;
  
  printf("%d", k);
  
  return 0;
}

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

int main(){
  int H,Hmax=0,N,count=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> H;
    if(Hmax<=H){
      count++;
      Hmax=H;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
//
// Created by yoshihito.hotta on 2018/06/10.
//
#include <iostream>
#include <climits>
using namespace std;

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

    int *r;
    r = new int[n];

    for (int i = 0; i < n; i++){
        cin >> r[i] ;
    }

    int minr;
    int maxv;

    minr = r[0];
    maxv  = - INT_MIN;
    for (int i = 1; i < n; i ++) {
        if (r[i] - minr > maxv) {
            maxv = r[i] - minr;
        }
        if (r[i] < minr) {
            minr = r[i] ;
        }

    }

    cout << maxv << endl;


    return 0;
}



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

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;


	for (int i = 0; i < n; i++)
	{
		int mn = a + i * c, mx = a + i * d;
		int kek1 = mn - (n - i - 1ll) * d, kek2 = mx - (n - i - 1ll) * c;
		if (b >= kek1 && b <= kek2)
		{
			cout << "YES";
			return 0;
		}
	}

	cout << "NO";

	return 0; 
}

Measured memory_bytes: 256
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define trace(x) cerr << #x << " = " << x << endl
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define sl(a)   scanf("%lld",&a)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define pi acos(-1)
#define en '\n'
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

int main()
{
    speed();
    ll a,i,x,ans=0,sum=0;
    cin>>a;
    ll b[a],c[a];
    rep(i,a)
    {
        cin>>b[i]>>c[i];
        if(b[i]==c[i])
        {
            ans++;
        }
        else
        {
            ans=0;
        }
        if(ans==3)
            sum = 1;
    }
    if(sum)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/12/2018
 
 12:05-12:23,12:42-13:42 give up
 15:45-16:00 add solution
 
 Key:
  - Very large board => No need to paint optimally
  - No checkboard!!!
 
 Summary:
  - Start analysis from check board => death 😞
   - https://twitter.com/eiya5498513/status/977905602222374913
  - I had a plan to put floating one block. However I didn't have idea to paint black/white firstly 👎
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 12:05-12:23,12:42-13:42 give up
const int MAX_N=100+1;
int A,B;
int G[MAX_N][MAX_N]={};
void solve_wrong() {
  ZERO(G);
  int a=A,b=B;
  if(a<b) swap(a,b);
  if(a>=2*b) {
    REP(i,50) {
      dump3(i,a,b);
      if(b>1) assert(a>=b);
      int i1=2*i,i2=i1+1;
      REP(j,50) {
        int j1=2*j,j2=j1+1;
        if(a>0) G[i1][j1]=1,--a;
        if(b>1) G[i2][j2]=1,--b,--a;
      }
    }
  } else {
    
  }
  REP(i,100) {
    REP(j,100) cout<<G[i][j];
    cout<<endl;
  }
}

void solve() {
  ZERO(G);
  REP(i,100) REP(j,100) G[i][j]=j>=50?0:1;
  --A,--B;
  REP(k,50) REP(l,24) {
    int i=2*k+1,j=2*l+1;
    if(A) G[i][j]=0,--A;
  }
  REP(k,50) REP(l,24) {
    int i=2*k+1,j=50+2*l+1;
    if(B) G[i][j]=1,--B;
  }

  cout<<100<<' '<<100<<endl;
  REP(i,100) {
    REP(j,100) cout<<(G[i][j]?'#':'.');
    cout<<endl;
  }
}

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


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(x: u64, y: u64) -> u64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    input!{
        A: u64,
        B: u64,
        K: usize,
    }
    let gcd = gcd(A, B);
    let mut x = vec![];
    for i in (1..gcd+1).rev() {
        if gcd % i == 0 {
            x.push(i)
        }
    }
    println!("{}", x[K-1]);
}



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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

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

    ll ans = 0;

    for (ll i = 1; i<=N; i++) {
        ll n = N/i;
        ll nmax = i*n;
        ans += (i+nmax)*n/2;
        //cout << i << " " << nmax << " " << n << " " <<  (i+nmax)*n/2 << endl;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
string s,ss;
int main()
{
    getline(cin,s);
    ss=s;
	reverse(ss.begin(),ss.end());
    for(int i=0;i<ss.size();i++)
        switch(ss[i])
		{
            case 'b':ss[i]='d';break;
            case 'd':ss[i]='b';break;
            case 'p':ss[i]='q';break;
            case 'q':ss[i]='p';break;
        }
    s==ss?printf("Yes\n"):printf("No\n");
    return 0;
}

Measured memory_bytes: 512
xs = gets.chomp.split
stack = []

xs.each { |x|
    case x
    when '+'
        a = stack.pop.to_i
        b = stack.pop.to_i
        stack.push(b + a)
    when '-'
        a = stack.pop.to_i
        b = stack.pop.to_i
        stack.push(b - a)
    when '*'
        a = stack.pop.to_i
        b = stack.pop.to_i
        stack.push(b * a)
    else
        stack << x
    end
}

puts stack.pop


Measured memory_bytes: 6868
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from collections import deque
n,x,y = inm()
ans = [0]*n
for i in range(1,n+1):
    #ddprint(f"- - - - i {i}")
    done = [False]*(n+1)
    #if i>1:
    #    done[i-1] = True
    q = deque([(i,0)])
    while len(q)>0:
        z,d = q.popleft()
        #ddprint(f"z {z} d {d}")
        if done[z]:
            #ddprint("skip")
            continue
        done[z] = True
        if z>i:
            ans[d] += 1
        if z>1 and not done[z-1]:
            q.append((z-1,d+1))
        if z<n and not done[z+1]:
            q.append((z+1,d+1))
        if z==x and not done[y]:
            q.append((y,d+1))
for i in range(1,n):
    print(ans[i])


Measured memory_bytes: 50396
def hantei(D,i):
  if D[i][0] == D[i][1]:
    if D[i+1][0] == D[i+1][1]:
      if D[i+2][0] == D[i+2][1]:
        return True
      else:
        return False
    else:
      return False
  else:
    return False

N = int(input())
D = [input().split(" ") for i in range(N)]
ans = False
for i in range(N-2):
  if hantei(D,i):
    ans = True
    break
if ans:
  print('Yes')
else:
  print('No')
  

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

const int maxn = 1e5+5;
int n;
vector<int> adj[maxn];
int par[maxn];
int depth[maxn];
int sz[maxn];

void dfs(int i, int p) {
    par[i] = p;
    depth[i] = depth[p] + 1;
    sz[i] = 1;
    for (int j: adj[i]) {
        if (j == p) continue;
        dfs(j,i);
        sz[i] += sz[j];
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,1);
    int d = (depth[n]-depth[1]-1)/2;
    int c = n;
    while (d--) {
        c = par[c];
    }
    int a = n-sz[c];
    int b = sz[c];
    if (d&1) {
        //b just moved
        cout << (b >= a ? "Snuke" : "Fennec") << '\n';
    }
    else {
        cout << (a >= b ? "Fennec": "Snuke") << '\n';
    }
}



Measured memory_bytes: 13184
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int fash(int a){
	return(max(0,min(255,a)));
}
ll twox(ll a){
	return a*a;
}
int main(){
	int n,m;
	VV dp(20010,V(260));
	vector<int> c(20);
	vector<int> x(20010);
	ll ans=INFLL;
while(1){
	cin >>n>>m;
	if(n==0 and m==0)return 0;
	ans=INFLL;
	rep(i,20010){
		rep(j,260){
			dp[i][j]=INFLL;
		}
	}
	rep(i,m){
		cin>>c[i];
	}
	rep(i,n){
		cin>>x[i];
	}
	dp[0][128]=0LL;
	rep(i,n){
		rep(j,256){
			rep(at,m){
				chmin(dp[i + 1][fash(j + c[at])], dp[i][j] + twox(fash(j + c[at])-x[i]));
			}
		}
	}
	rep(i,256){
		chmin(ans,dp[n][i]);
	}
	cout<<ans<<endl;
	}
}


Measured memory_bytes: 44120
N, K = map(int,input().split())
s = input()
res = 0
if s[0] == 'R' and s[1] == 'R':
    res += 1
for i in range(1,N-1):
    if s[i-1] == 'R' and s[i] == 'L':
        continue
    elif s[i+1] == 'L' and s[i] == 'R':
        continue
    res += 1
if s[N-1] == 'L' and s[N-2] == 'L':
    res += 1
res = min([N-1, res+2*K])
print(res)

Measured memory_bytes: 3316
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
    }
    let result = match n == m {
        true => "Yes",
        false => "No",
    };
    println!("{}", result);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;

bool good(int a, int b, int c)
{
   return (a < b + c && b < a + c && c < a + b) && (a != b && a != c && b != c);
}


vector<int> v;

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

   v.resize(n);

   for (int i = 0; i < n; i++)
   {
      cin >> v[i];
   }

   int cnt = 0;
   for (int i = 0; i < n; i++)
   {
      for (int k = i + 1; k < n; k++)
      {
         for (int j = k + 1; j < n; j++)
         {
            cnt += good(v[i], v[k], v[j]);
         }
      }
   }

   cout << cnt;

   return 0;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
			A[i] = X[i];
		}
		Arrays.sort(X);

		int med1, med2;
		med1 = X[N/2 - 1];	//left
		med2 = X[N/2];	//right
		for (int i = 0; i < N; i++) {
			if(A[i] < med2) {
				System.out.println(med2);
			} else {
				System.out.println(med1);
			}
		}
	}
}

Measured memory_bytes: 92084