akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

S = inputS()

def check(s):
  l = list(s)
  l_ = l[::-1]
  for i in range(len(l)):
    if l[i]!=l_[i]:
      return False
  return True

L = len(S)

if check(S) and check("".join(list(S)[:(L-1)//2])) and check("".join(list(S)[(L+1)//2:])):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 5692
#include <iostream>
using namespace std;
int main()
{
  	int a, b, c;
  	cin >> a >> b >> c;
  	cout << (((a==5 && b==7 && c==5) || (a==7 && b==5 && c==5) || (a==5 && b==5 && c==7))?"YES":"NO");
}


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

int main() {
	int n, d, a;
	cin >> n >> d >> a;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(p.begin(), p.end());
	d = 2 * d;
	ll ans = 0;
	ll tot = 0;
	queue<pair<ll, ll>> que;
	rep(i, n) {
		ll x = p[i].first;
		ll h = p[i].second;
		while (que.size() && que.front().first < x) {
			tot -= que.front().second;
			que.pop();
		}
		h -= tot;
		if (h > 0) {
			ll num = (h + a - 1) / a;
			ans += num;
			ll damage = num * a;
			tot += damage;
			que.emplace(x + d, damage);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
#define I 900000
using namespace std;
int x[99],z[99],y[99][20],h[100],a,b,c,d,e,f,i,j,k;string S;
int main(){
	while(true){
		for(i=0;i<99;i++){x[i]=I;}
		memset(y,0,sizeof(y));
		memset(h,0,sizeof(h));
		cin>>a>>b>>c;
		if(a==0){break;}
		for(i=0;i<c;i++){
			cin>>d>>e>>f>>S;
			if(S[0]=='W'){
				y[d][e]++;
			}
			else{
				x[d]+=I;
				x[d]-=f+1200*y[d][e];
			}
		}
		for(i=1;i<=a;i++){z[i]=x[i];}
		sort(x+1,x+a+1);
		for(i=a;i>=1;i--){
			for(j=1;j<=a;j++){
				if(z[j]==x[i]&&h[j]==0){
					cout<<j<<' '<<(x[i]+I-1)/I-1<<' '<<(100*I-x[i])%I<<endl;
					h[j]=1;
				}
			}
		}
	}
}

Measured memory_bytes: 1228
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    string ans;
    if((B-A)%2==1){
        ans = "Borys";
    }else{
        ans = "Alice";
    }
    cout << ans;
}


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


int main(){
    int n;
    std::cin >> n;
    //dp[i][j]???i+1????????§?¨???????????????????j(0???j???20)??§????????°
    std::vector<std::vector<long long int> > dp(n, std::vector<long long int>(21, 0));
    //??\????????°???????????¨
    std::vector<int> num(n, 0);
    //??°?????\???
    for(int i = 0; i < n; ++i){
        int x;
        std::cin >> x;
        num[i] = x;
    }
    //?????????
    dp[0][num[0]] = 1;
    for(int i = 1; i < n - 1; ++i){ //2?????????N-1????????§????¨????
        for(int j = 0; j < 21; ++j){
            //??????1??????????¨?????????????j?????´????????°???????????°????????????????±???????
            if(dp[i - 1][j] > 0){
                //???????????????0??\???20??\?????????
                if((j + num[i]) <= 20){
                    dp[i][j + num[i]] += dp[i - 1][j];
                }
                if((j - num[i]) >= 0){
                    dp[i][j - num[i]] += dp[i - 1][j];
                }
            }
        }
    }
    //??????????????????n - 1????????§?¨???????????????????num[n-1]??§????????°
    std::cout << dp[n - 2][num[n - 1]] << std::endl;
    return 0;
}

Measured memory_bytes: 1228
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int N;
double x[300];
double y[300];
inline double dist2(double a, double b)
{
	return a*a+b*b;
}
void exec()
{
	cin >> N;
	if(N==0){
		exit(0);
	}
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i];
	}
	int ret=1;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			double dx=(x[i]-x[j])/2;
			double dy=(y[i]-y[j])/2;
			double r2=dx*dx+dy*dy;
			if(r2>1){
				continue;
			}
			double R=sqrt(1/r2-1);
			double px=x[j]+dx-R*dy;
			double py=y[j]+dy+R*dx;
			double qx=x[j]+dx+R*dy;
			double qy=y[j]+dy-R*dx;
			int sp=0,sq=0;
			for(int k=0;k<N;k++){
				if(k==i||k==j){
					sp++;sq++;
					continue;
				}
				if(dist2(x[k]-px,y[k]-py)<=1){
					sp++;
				}
				if(dist2(x[k]-qx,y[k]-qy)<=1){
					sq++;
				}
			}
			ret=max(ret,sp);
			ret=max(ret,sq);
		}
	}
	cout << ret << endl;
}
int main() {
	while(1)
		exec();
}

Measured memory_bytes: 1244
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iterator>
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5+50;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f first
#define s second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }

void solve(){
    int N,X,T;
    cin>>N>>X>>T;
    int a=N/X;
    int b=N%X;
    if(b!=0)
       b=1;
    else 
       b=0;
    if(a==0)
       cout<<T<<endl;
    else 
        cout<<(a*T)+(b*T)<<endl;
  
}
int main(){
 
   ios::sync_with_stdio(false);
  cin.tie(0);

     solve();
}

Measured memory_bytes: 3632
func gcd(_ a: Int, _ b: Int) -> Int {
    if a % b == 0 {
        return b
    }
    return gcd(b, a % b)
}

func main() {
    var sum = 0;
    let K = Int(readLine()!)!
    
    for a in 1...K {
        for b in 1...K {
            for c in 1...K {
                sum += gcd(gcd(a, b), c)
            }
        }
    }
    
    print(sum)
}

main()


Measured memory_bytes: 7796
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define cl(a) memset((a),0,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))
#define rson(x) ((x<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=1000000007;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1.0);

int p[100005];
ll r[100005];
int find(int x)
{
    if(p[x]==x) return x;
    int pre=find(p[x]);
    r[x]+=r[p[x]];
    return p[x]=pre;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int x,y,w;
    bool flag=false;
    rep(i,0,n)
    {
        p[i]=i;
        r[i]=0;
    }
    while(m--)
    {
        scanf("%d%d%d",&x,&y,&w);
        int a=find(x),b=find(y);
        if(a==b)
        {
            if(r[x]-r[y]!=w)
            {
                flag=true;
                break;
            }
        }
        else
        {
            p[a]=b;
            r[a]=w+r[y]-r[x];
        }
    }
    if(!flag)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      int n = sc.nextInt();
      int count=0;
      for(int i=0;i<=9;i++) {
        for(int j=0;j<=9;j++) {
          for(int k=0;k<=9;k++) {
            if(0 <= n-i-j-k && n-i-j-k <= 9) {
	      count++;
            }
          }
        }
      }
      System.out.println(count);
    }    
  }
}

Measured memory_bytes: 26132
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val r = readInt()
    val ans = if(r < 1200) {
        "ABC"
    } else if(r < 2800) {
        "ARC"
    } else {
        "AGC"
    }
    println(ans)

    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
    }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    return v.map { it.toList() }.toList()
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

int main() {
  char OP[2] = {'-','+'};

  char A[4];
  cin >> A;

  stringstream ss;
  for (int i = 8; i--; ) {
    int result = A[0] - '0';
    int ops[3] = {};
    for (int j = 0; j < 3; ++j) {
      int neg = -1;
      if (i >> j & 0x1) {
        neg = 1;
        ops[j] = 1;
      }
      result += (A[j+1] - '0') * neg;
    }

    if (result == 7) {
      for (int k = 0; k < 3; ++k) {
        ss << A[k] << OP[ops[k]];
      }
      ss << A[3] << "=7";
      break;
    }
  }

  cout << ss.str() << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
using namespace std;

int func(int x, int y){
   int res = 0;
   while (x){
      res += x % 10;
      x = x / 10;
   }
   while (y){
      res += y % 10;
      y = y / 10;
   }
   return res;
}

int main(){
   int n;
   int tmp;
   cin >> n;
   tmp = func(1, n-1);
   for (int a = 1; a < n; a++){
      if (func(a, n-a) < tmp) tmp = func(a, n-a);
   }
   cout << tmp << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
typedef long long lint;
using namespace std;
 
int main(){
    vector<string>v;
    int n;
    string s[110][11];
    cin>>n;
    bool flag=true;
    for(int t=0;t<n;t++){
        cin>>s[t][11];
        auto result=find(v.begin(),v.end(),s[t][11]);
        if(result!=v.end()){
            flag=false;
            break;
        }
        v.push_back(s[t][11]);
    }

    for(int t=0;t<n-1;t++){
        if(s[t][11].back()!=s[t+1][11].front()){
            flag=false;
            break;
        }
    }

    if(flag){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
/*
文字列の配列の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        long[] a=new long[n];
        long edge1=0,edge2=0;
        TreeMap<Long,Long> tm=new TreeMap<>();
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextLong();
            tm.put(a[i],tm.getOrDefault(a[i],0l)+1);
        }
        while (tm.size()>0&&edge1==0){
            Map.Entry<Long,Long> temp=tm.pollLastEntry();
            if(temp.getValue()>1){
                edge1=temp.getKey();
                tm.put(temp.getKey(),temp.getValue()-2);
            }
        }
        while (tm.size()>0&&edge2==0){
            Map.Entry<Long,Long> temp=tm.pollLastEntry();
            if(temp.getValue()>1){
                edge2=temp.getKey();
            }
        }
        out.println(edge1*edge2);
    }
}

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

using namespace std;

class union_find {
    vector<int> p;
    vector<int> r;

public:
    union_find(int n) {
        p = vector<int>(n);
        r = vector<int>(n);

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

    int root(int a) {
        if (p[a] != a) {
            p[a] = this->root(p[a]);
        }

        return p[a];
    }

    void unite(int a, int b) {
        int ra = this->root(a);
        int rb = this->root(b);

        if (ra == rb) {
            return;
        }

        if (r[ra] < r[rb]) {
            p[ra] = rb;
        } else {
            p[rb] = ra;

            if (r[ra] == r[rb]) {
                r[ra]++;
            }
        }
    }
};

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

    union_find uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        uf.unite(x - 1, y - 1);
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        if (i == uf.root(i)) {
            res++;
        }
    }

    cout << res << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define rrep(i, b, a) for(int i = b; i >= a; --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 1001;
const int INF = 1e9;
const int X = 5001;
int n;
int parent[N];
vector<int> children[N];
int weight[N];
int other_weight[N];
bool visited[N];

int main() {
  cin.tie(0); cin.exceptions(cin.failbit);

  bool possible = true;

  scanf("%d", &n);

  // all a null child to the beginning of each vector
  rep(i, 1, n+1){
    children[i].PB(0);
  }

  rep(i, 2, n+1){
    scanf("%d", parent+i);
    children[parent[i]].PB(i);
  }
  rep(i, 1, n+1) scanf("%d", weight+i);

  queue<int> q;

  // add parents of the leaves
  rep(i, 1, n+1){
    if(sz(children[i]) == 1){ // no children
      if(parent[i]) { // has a parent
        q.push(parent[i]);
        visited[i] = true;
      }
    }
  }
  visited[0] = true;

  // bottom up BFS
  while(!q.empty()){
    int v = q.front();
    q.pop();
    if(visited[v]) continue;

    int nc = sz(children[v]);

    bool children_visited = true;
    rep(i, 1, nc){
      if(!visited[children[v][i]]){
        children_visited = false;
        break;
      }
    }
    if(!children_visited) continue;

    visited[v] = true;
    q.push(parent[v]);
    // printf("v: %d\n", v);

    int hi = weight[v];

    // [# children used][weight of white] = is possible?
    bool dp[nc][hi+1];

    memset(dp, false, sizeof(dp));

    dp[0][0] = true;

    int total = 0;
    rep(i, 1, nc){
      int c = children[v][i];
      int wc = weight[c], owc = other_weight[c];

      total += wc + owc;

      rep(w, 0, hi+1){
        if(!dp[i-1][w]) continue;

        if(w + wc <= hi) dp[i][w+wc] = true;
        if(w + owc <= hi) dp[i][w+owc] = true;
      }
    }

    int ans = -1;
    rrep(w, hi, 0){
      if(dp[nc-1][w]){
        ans = total - w;
        break;
        // printf("ans: %d\n", ans);
      }
    }

    if(ans == -1){
      possible = false;
      break;
    } else {
      other_weight[v] = ans;
    }
  }

  printf("%s\n", possible ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


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

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long n;
	cin >> n;
	long long now = 1;
	long long ans = 0;
	while (n) {
		ans += now;
		n >>= 1;
		now <<= 1;
	}
	cout << ans;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            pass
        else:
            print("DENIED")
            exit() 
        
print("APPROVED")

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

#define endl '\n'
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back
#define MAXN 200005

int n, m;

int main(){ios_base::sync_with_stdio(false);
    
    ll sum=0;
    int x;
    cin >> n >> m;
    while(m--){
        cin >> x;
        sum += x;
    }

    cout << (n-sum<0?-1:n-sum) << endl;


    return 0;
}



Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    char S[1001];
    ins(S);
    ll isN=0, isS=0, isW=0, isE=0, i=0;
    while(S[i]!='\0'){
        if(S[i]=='N') isN=1;
        else if(S[i]=='S') isS=1;
        else if(S[i]=='W') isW=1;
        else isE=1;
        i++;
    }
    if((isN+isS+isE+isW)%2) puts("No");
    else if(!((isN+isS)%2)) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int n;cin>>n;
    long long int arr[n][n];
    for(long long int i=0;i<n;i++){
        cin>>arr[i][i];
    }
    for(long long int i=2;i<=n;i++){
        for(long long int j=0;i+j<=n;j++){
            arr[j][i+j-1]=max(arr[j][j]-arr[j+1][i+j-1],arr[i+j-1][i+j-1]-arr[j][i+j-2]);
        }
    }
    cout<<arr[0][n-1]<<"\n";;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

#define pb push_back
#define mp make_pair
#define fst first
#define snd second

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
inline void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
inline void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void print(T &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) cout << " ";
    cout << *it;
  }
  cout << endl;
}

i64 power(i64 x, i64 n) {
  i64 res = 1;
  if (n > 0) {
    res = power(x, n / 2);
    res = (res * res) % MOD;
    if (n % 2 == 1) res = (res * x) % MOD;
  }
  return res;
}

int main() {
  int m, n;
  cin >> m >> n;
  cout << power(m, n) << endl;
}


Measured memory_bytes: 3100
use strict;

my $str = get_array_from_stdin();

my @top = split //, $str;

my $point = 0;
my $gp = 0;
foreach my $top (@top) {
  if ($top eq "g") {
    if ($gp > 0) {
      # パーを出して勝つ
      $point++;
      $gp--;
    } else {
      # グーを出して引き分け
      $gp++;
    }
  } else {
    if ($gp > 0) {
      # パーを出して引き分け
      $gp--;
    } else {
      # グーを出して負け
      $gp++;
      $point--;
    }
  }
}

print "$point\n";

### common sub routine ###

sub get_array_from_stdin {
  my $input = <STDIN>;
  chomp($input);
  if (wantarray) {
    return split /\s+/, $input;
  } else {
    return $input;
  }
}


Measured memory_bytes: 14080
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector> //*max_element(all(変数))で最大値を獲得
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int n,k;  cin >> n >> k;
  vi p(n);  rep0(i,n) cin >> p[i];
  vector<double> Expected_value(n);
  rep0(i,n) Expected_value[i] = (p[i]+1)/2.0;
  vector<double> sum(n+1);
  rep0(i,n) sum[i+1] = sum[i] + Expected_value[i];
  double ans = 0.0;
  rep0(i,n-k+1) chmax(ans, sum[i+k]-sum[i]);
  cout << setprecision(10) << ans;
}


Measured memory_bytes: 4096
#include <stdio.h>

main(){
  int a, d = 0, s = 1, n, dta[251];
  
  scanf("%d", &n);
  for(a=1;a<=n;a++) scanf("%d", &dta[a]);
  for(a=1;a<=n;a++){
    printf("node %d: key = %d, ", a, dta[a]);
    
    if(a/2) printf("parent key = %d, ", dta[a/2]);
    if(2*a<=n) printf("left key = %d, ", dta[2*a]);
    if(2*a+1<=n) printf("right key = %d, ", dta[2*a+1]);
    
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2052
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
for i in range(n+1):
    ans += abs(a[i]-a[i+1])
for i in range(1,n+1):
    if (a[i-1] <= a[i] <= a[i+1]) or (a[i-1] >= a[i] >= a[i+1]):
        print(ans)
    else:
        print(ans-2*min(abs(a[i-1]-a[i]), abs(a[i]-a[i+1])))

Measured memory_bytes: 20424
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	
	std::function<std::pair<int, int> (int)> dfs = [&](int s) {
		std::vector<int> min_cost(n, -1);
		std::queue<int> qu; qu.push(s); min_cost[s] = 0;
		while(!qu.empty()) {
			auto p = qu.front(); qu.pop();
			
			for(auto e: g[p]) {
				if(min_cost[e] != -1) continue;
				min_cost[e] = min_cost[p] + 1;
				qu.push(e);
			}
		}
		
		int ret = 0;
		for(int i = 0; i < n; i++) {
			if(min_cost[ret] >= min_cost[i]) continue;
			ret = i;
		}
		return std::pair<int, int>{ret, min_cost[ret]};
	};
	auto X = dfs(0);
	auto Y = dfs(X.first);
	
	if((Y.second % 3) != 1) printf("First\n");
	else printf("Second\n");
	return 0;
}


Measured memory_bytes: 13556
#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c; cin >> a >> b >> c;
    if(b / a >= c) cout << c << endl;
    else cout << b / a << endl;;

    return 0;
}

Measured memory_bytes: 256
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define INF 1e18
#define N 1000100
typedef pair<ll,ll> pll;
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%MOD;
    if(b&1)
        ans=(a*ans)%MOD;
    return ans;
}
ll inv(ll a)
{
    return power(a,MOD-2,MOD);
}
//code begins



signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin.sync_with_stdio(false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        ll h,a;cin>>h>>a;
        cout<<ceil(h*1.0/a*1.0)<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=400 && n<=599)
        cout<<"8\n";
    if(n>=600 && n<=799)
        cout<<"7\n";
    if(n>=800 && n<=999)
        cout<<"6\n";
    if(n>=1000 && n<=1199)
        cout<<"5\n";
    if(n>=1200 && n<=1399)
        cout<<"4\n";
    if(n>=1400 && n<=1599)
        cout<<"3\n";
    if(n>=1600 && n<=1799)
        cout<<"2\n";
    if(n>=1800 && n<=1999)
        cout<<"1\n";
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;

int main()
{
    long long n,ans,k,i;
    cin>>n;
    for (i=1;i<=10000;i++)
    {
        if (i*(i+1)/2>=n) break;
    }
    ans=i;
    k=i*(i+1)/2-n;
    for (i=1;i<=ans;i++)
        if (i!=k) cout<<i<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vs = vector<string>;

int main() {
  int N;
  cin >> N;
  
  vs W(N);
  rep(i,N) cin >> W.at(i);
  
  rep1(i,N-1) {
    if (W.at(i).at(0) != W.at(i-1).at(W.at(i-1).size()-1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  rep(i,N-1) {
    repm(j,i+1,N) {
      if(W.at(i) == W.at(j)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;
   
  int ans=0;
  for(int i=0; i<n-2; i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ans++;
    }
  }
  
    cout << ans << endl;
}
  


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

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

void solve(std::string S)
{
    bool flag=true;
    for(unsigned int i=0;i<S.size();i+=2)
        if(S[i]=='h'&&S[i+1]=='i')
            continue;
        else
        {
            flag=false;
            break;
        }            
    if(flag)    cout<<YES<<endl;
    else    cout<<NO<<endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys
import copy
a = [int(c) for c in input().split()]
cnt=0
while True:
    if a[0]==a[1] and a[1]==a[2] and a[0] != 1:
        print(-1)
        sys.exit(0)
    
    if a[0]%2 == 0 and a[1]%2 == 0 and a[2]%2 == 0:
        b = copy.deepcopy(a)
        a[0] = int((b[1]+b[2])/2)
        a[1] = int((b[2]+b[0])/2)
        a[2] = int((b[0]+b[1])/2)
    else:
        print(cnt)
        sys.exit(0)

    cnt+=1

Measured memory_bytes: 9224
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define set setprecision　//小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)//最大公約数
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)//最小公倍数
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % 2019; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % 2019;
	if (k != 0)rip(i, k)j = j * a % 2019;
	return(j);
}
int main() {
	string s;
	cin >> s;
	if (s[1] == 'B')cout << "ARC" << endl;
	else cout << "ABC" << endl;
}

Measured memory_bytes: 3636
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


int main()
{	
	int X;
	cin >> X;
	double big = 0;
	if (X == 1) { big = 1; }
	else {
		vector <double> b(10000);
		for (int i = 1; i <= X; i++) {
			double t = i;
			for (int j = 1; j <= 1000; j++) {

				t *= i;
				if (t > X) {
					b[i] = t / i;
					if (b[i] == i) {
						b[i] = 0;
					}
					break;
				}
			}
		}
		double num = 0;
		for (int i = 1; i <= X; i++) {
			num = b[i];
			if (num > big) {
				big = num;
			}
		}
	}	cout << big << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこの,プロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    unordered_map<string, int> M;
    loop (n, i) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        M[s]++;
    }

    ll ans = 0;
    for (auto e : M) {
        ll v = e.second;
        ans += v * (v - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 10660
#include<stdio.h>

#define MAX 10000
#define NIL -1

struct node {
  int p,l,r;
};

struct node T[MAX];
int n;

void pre(int a){
  if(a == NIL) return;
  printf(" %d",a);
  pre(T[a].l);
  pre(T[a].r);
}

void in(int a){
  if(a == NIL) return;
  in(T[a].l);
  printf(" %d",a);
  in(T[a].r);
}

void post(int a){
  if(a == NIL) return;
  post(T[a].l);
  post(T[a].r);
  printf(" %d",a);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  
  printf("Inorder\n");
  in(root);
  printf("\n");

  printf("Postorder\n");
  post(root);
  printf("\n");
  
  return 0;
}




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

int n, pos;
vector<int>pre, in, post;

void rec(int l, int r)
{
	if(l >= r)
		return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l ,m);
	rec(m + 1, r);
	post.push_back(root);	
} 
 
void solve()
{
	pos = 0;
	rec(0, pre.size());
	for(int i = 0; i < n; i++)
	{
		if(i)
		 cout << " ";
		cout << post[i];
	}
	cout << endl;
}
int main()
{
	int  x;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> x;
		pre.push_back(x);
	}
	for(int i = 0; i < n; i++)
	{
		cin >> x;
		in.push_back(x);
	}
	solve();
	
	return 0;
}



Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <stack>
using namespace std;

typedef long long ll;
const int maxn = 1e6 + 17;
const ll INF = 1e18;
int n, a[maxn];
ll f[maxn], g[maxn], ans = INF;

inline int getint() {
	char ch = getchar(); int res = 0, ops = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') ops = 0;
	for(; isdigit(ch); ch = getchar()) res = res * 10 + ch - '0';
	return ops ? res : -res;
}

void getf() {
	f[n] = 0, f[n + 1] = 0;
	stack<int> stk;
	for(int i = n - 1; i >= 1; i--) {
		f[i] = f[i + 1];
		ll cur = 1ll * a[i], lst = 1ll * a[i + 1]; 
		while(cur > lst) {
			int tmp = n;
			if(!stk.empty()) tmp = stk.top(), stk.pop();
			f[i] += 2ll * (tmp - i);
			lst *= 4;
		}
		while(cur * 4 < lst) {
			stk.push(i);
			cur *= 4;
		}
	}
}
void getg() {
	g[1] = 1, g[0] = 0;
	stack<int> stk;
	for(int i = 2; i <= n; i++) {
		g[i] = g[i - 1] + 1;
		ll cur = 1ll * a[i], lst = 1ll * a[i - 1]; 
		while(cur > lst) {
			int tmp = 1;
			if(!stk.empty()) tmp = stk.top(), stk.pop();
			g[i] += 2ll * (i - tmp);
			lst *= 4;
		}
		while(cur * 4 < lst) {
			stk.push(i);
			cur *= 4;
		}
	}
}

int main() {
	n = getint();
	for(int i = 1; i <= n; i++) a[i] = getint();
	getf();
	getg();
//	for(int i = 1; i <= n; i++) printf("%d%c", f[i], " \n"[i == n]);
//	for(int i = 1; i <= n; i++) printf("%d%c", g[i], " \n"[i == n]);
	for(int i = 1; i <= n + 1; i++) ans = min(ans, g[i - 1] + f[i]);
	cout << ans << endl;
	return 0;
}

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

int main()
{
 int N;
 cin >> N;
 int sum = 0;
 int max_L = -1, L;
 for (int i = 0; i < N;i++) {
     cin >> L;
     sum += L;
     max_L = max(max_L, L);
 }

 if (sum - max_L > max_L)
     cout << "Yes";
 else
     cout << "No";
 return 0;

}

Measured memory_bytes: 256
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let s:String = r.readl();
    let mut res = 0;
    for i in s.chars() {
        if(i == '1') {
            res += 1;
        }
    }
    println!("{}",res);
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AInfiniteCoins solver = new AInfiniteCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class AInfiniteCoins {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() % 500 <= in.nextInt() ? "Yes" : "No");
        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define ff first
#define ss second 
#define pb push_back
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Craig ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015
#define vll vector<ll>

int main()
{ 
    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

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

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

#include <cassert>
#include <functional>

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

int main() {
  int N, K;

  cin >> N >> K;

  int X = (N - 1) * (N - 2) / 2;

  if (X < K) {
    puts("-1");
    return 0;
  }

  debug(X);

  int M = (N - 1) + (X - K);

  printf("%d\n", M);

  for (int i=1; i<N; i++)
    printf("%d %d\n", 1, i+1);

  int sum = X;
  for (int i=1; i<N && K < sum; i++) {
    for (int j=i+1; j<N && K < sum; j++) {
      printf("%d %d\n", i+1, j+1);
      sum--;
    }
  }


  return 0;
}


Measured memory_bytes: 256
//解説を参考に諸々を簡略化
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin>> n >> k;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin>> a[i];
  
  //全丸太の長さをx以下にするのに必要な回数がk以下になる最小のxを二分探索
  int left=0, right=1e9; //left:不可能 right:可能
  while(right-left>1){
    double x=(left+right)/2.0;
    int64_t count=0;
    for(int i=0; i<n; i++) count+=ceil(a[i]/x)-1;
    if(count<=k) right=ceil(x); //xで可能ならx以上で可能
    else left=floor(x); //xで不可能ならx以下で不可能
  }
  cout<< right << endl;
}

Measured memory_bytes: 3956
N,A,B = map(int,input().split())
cnt = 0
sum = 0
i = 0
for i in range(N+1):
    j = 0
    tmpsum = 0
    l = list(str(i))
    for j in l:
        tmpsum += int(j)
    if tmpsum>=A and tmpsum <=B:
        sum += i
print(sum)

Measured memory_bytes: 9124
#include <iostream>
#define MAX_NUM 10000
using namespace std;

int inputnumber(int *n){
	cin >> *n;
	return 0;
}

int inputsequence(int n, int *s){
	for(int i=0;i<n;i++)
		cin >> *(s+i);
	return 0;
}

void swap(int i, int j ,int *a){
	int value=*(a+i);
	*(a+i)=*(a+j);
	*(a+j)=value;
}

int selectionsort(int n,int *seq){
	int i,j,count=0;
	int seln;

	for(i=0;i<n;i++){
		seln=i;
		for(j=i+1;j<n;j++){
			if(*(seq+j)<*(seq+seln)){
				seln=j;
			}
		}
		if(i != seln){
			swap(i,seln,seq);
			count++;
		}
	}
	return count;
}

int printsequence(int n, int *seq){
	for(int i=0;i<n-1;i++)
		cout << *(seq+i) << ' ';
	cout << *(seq+n-1) << endl;
	return 0;
}

int main() {
	int n, a[MAX_NUM];
	int count;

	inputnumber(&n);
	inputsequence(n,a);
	count=selectionsort(n,a);
	printsequence(n,a);

	cout << count << endl;
	return 0;
}



Measured memory_bytes: 3128
import java.util.Scanner;

public class Main{
	
	private static final int A = 0;
	private static final int B = 1;
	private static final int C = 2;
	
	private static final int WEIGHT = 0;
	private static final int PRICE = 1;
	private static final int SHOPDISCOUNT_PACK = 3;
	
	private static final int[][] WHEAT = {
		{200, 380},
		{300, 550},
		{500, 850},
		{1000, 1520},
		{1200, 1870},
		{1500, 2244}
	};
	
	public static void main(String[] args){
		int[] price = getMinPrice();
		Scanner sc = new Scanner(System.in);
		int weight = 0;
		while((weight = sc.nextInt()) != 0){
			System.out.println(price[weight]);
		}
		sc.close();
	}
	
	private static final int MAX_WEIGHT = 5001;
	private static final int INF = Integer.MAX_VALUE;
	public static int[] getMinPrice(){
		//initialize
		int[] price = new int[MAX_WEIGHT];
		for(int i = 0; i < price.length; i++){
			price[i] = INF;
		}
		price[0] = 0;
		price[100] = 0;
		
		//solve
		for(int w = 200; w < MAX_WEIGHT; w += 100){
			int tmpPrice = INF;
			for(int i = 0; i < WHEAT.length; i++){
				int sourceWeight = w - WHEAT[i][WEIGHT];
				if(sourceWeight < 0 || sourceWeight == 100)	continue;
				tmpPrice = price[sourceWeight] + WHEAT[i][PRICE];
				price[w] = Math.min(price[w], tmpPrice);
			}
		}
		return price;
	}
	/**
	 * 指定された個数を購入した場合の価格を算出する。
	 */
	public static int getPrice(int vOnA, int vDiscountedOnA, int vOnB, int vDiscountedOnB, int vOnC, int vDiscountedOnC){
		int sum = 0;
		sum += getPriceOn(A, vOnA, vDiscountedOnA);
		sum += getPriceOn(B, vOnB, vDiscountedOnB);
		sum += getPriceOn(C, vOnC, vDiscountedOnC);
		return sum;
	}
	
	private static int getPriceOn(int shop, int volume, int volumeDiscounted){
		int sum = 0;
		sum += WHEAT[shop][PRICE] * volume;
		sum += WHEAT[shop + SHOPDISCOUNT_PACK][PRICE] * volumeDiscounted;
		return sum;
	}
	
}

Measured memory_bytes: 17216
# 入力値を数値で返す
def gets_i
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返す
def gets_i_list
  gets.chomp.split(" ").map(&:to_i)
end

N = gets_i
x_list = gets_i_list.sort

min = (1..x_list.max).map do |i|
  x_list.map do |x|
    (x - i)**2
  end.inject(:+)
end.to_a.min

puts min


Measured memory_bytes: 1916
#include <iostream>

using namespace std;

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

	if (b > c) {
		t = b;
		b = c;
		c = t;
	}

	if (a > b) {
		t = a;
		a = b;
		b = t;
	}

	if (b > c) {
		t = b;
		b = c;
		c = t;
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
const ll mod = 1000000007;

using namespace std;

int n, m;
int s[2001], t[2001];
int dp[2010][2010];

signed main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> s[i + 1];
    for (int i = 0; i < m; i++) cin >> t[i + 1];

    for (int i = 0; i <= n; i++) dp[i][0] = 1;
    for (int i = 0; i <= m; i++) dp[0][i] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
            dp[i][j] += mod - dp[i - 1][j - 1];
            dp[i][j] %= mod;
            if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
            dp[i][j] %= mod;
        }
    }

    cout << dp[n][m] << endl;
}

// 共通部分列


Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b&&b==c&&a==c)||(a!=b&&b!=c&&a!=c)){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
  return 0;
}


Measured memory_bytes: 256