akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<long long> C(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i] >> C[i];
  }
  map<string,long long> L, R;
  const long long INF = 1e18;
  L[""] = INF;
  R[""] = INF;
  for(string s = "a"; s <= "z"; ++s[0]){
    L[s] = INF;
    R[s] = INF;
  }
  long long ans = INF;

  priority_queue<tuple<long long,bool,string>,vector<tuple<long long,bool,string>>,greater<>> pq;
  for(int i = 0; i < N; ++i){
    L[S[i]] = C[i];
    pq.emplace(C[i],true,S[i]);
    string s_(S[i].rbegin(), S[i].rend());
    
    if(S[i] == s_)
      ans = min(ans,C[i]);
    
  }

  auto match = [](const string& s, const string& t){
    int l = t.length();
    for(size_t i = 0; i < s.length(); ++i){
      if(i >= t.length()) return true;
      if(s[i] != t[l-1-i]) return false;
    }
    return true;
  };


  while(pq.size()){
    auto [c, f, s] = pq.top();
    // cerr << c << " " << f << " " << s << endl;
    pq.pop();

    if(f and L[s] < c) continue;
    if(!f and R[s] < c) continue;

    if(f){
      for(int i = 0; i < N; ++i){
        const string& t = S[i];
        long long c_ = c + C[i];
        if(c_ >= ans) continue;
        if(!match(s,t)) continue;

        if(s.length() >= t.length()){
          string s_ = s.substr(t.length());
          if((L.find(s_) == L.end()) or L[s_] > c_){
            L[s_] = c_;
            string r(s_.rbegin(), s_.rend());
            if(r == s_) ans = min(ans,c_);
            pq.emplace(c_,true,s_);
          }
        }else{
          string s_ = t.substr(0,t.length()-s.length());
          if(R.find(s_) == R.end() or R[s_] > c_){
            R[s_] = c_;
            string r(s_.rbegin(), s_.rend());
            if(r == s_) ans = min(ans,c_);
            pq.emplace(c_,false,s_);
          }
        }
      }
    }else{
      for(int i = 0; i < N; ++i){
        const string& t = S[i];
        long long c_ = c + C[i];
        if(c_ >= ans) continue;
        if(!match(t,s)) continue;
        if(s.length() >= t.length()){
          string s_ = s.substr(0,s.length()-t.length());
          if(R.find(s_) == R.end() or R[s_] > c_){
            R[s_] = c_;
            string r(s_.rbegin(), s_.rend());
            if(r == s_) ans = min(ans,c_);
            pq.emplace(c_,false,s_);
          }
        }else{
          string s_ = t.substr(s.length());
          if(L.find(s_) == L.end() or L[s_] > c_){
            L[s_] = c_;
            string r(s_.rbegin(), s_.rend());
            if(r == s_) ans = min(ans,c_);
            pq.emplace(c_,true,s_);
          }
        }
      }
    }
  }
  
  if(ans >= INF) ans = -1;
  cout << ans << '\n';
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    
    int n;
    cin >> n;
    vector<pair <int, int>> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i].first >> a[i].second;
    }
    sort(all(a), [](pair<int, int> i,pair<int, int> j){return i.second < j.second;});
    ll sol=0;
    bool check = true;
    for(pair<int, int> x : a){
        sol+=x.first;
        if(x.second<sol){
            check = false;
            break;
        }
    }
    if(!check)
        cout << "No";
    else
        cout << "Yes";
}

Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	private static long lcm(long a, long b) {
		return (a / gcd(a, b)) * b; //a*bがオーバーフローしないように
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		long[] T = nextLongArray(sc, N);

		sc.close();

		long ans = T[0];
		for (int i = 1; i < N; i++) {
			ans = lcm(ans, T[i]);
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}
}


Measured memory_bytes: 21844
n, m = gets.chomp.split.map(&:to_i)
p_y = []
(0..(m - 1)).each do |i|
  p_y << [i] + gets.chomp.split.map(&:to_i)
end

grouped = p_y.group_by { |e| e[1] }.values
grouped = grouped.map do |arr|
  arr.sort_by { |e| e[2] }
end
grouped.each do |arr|
  (0..(arr.length - 1)).each do |i|
    arr[i] += [i + 1]
  end
end

grouped.flatten(1).sort.each do |arr|
  puts "%06d" % arr[1] + "%06d" % arr.last
end

Measured memory_bytes: 58608
#include<stdio.h>

int main(){
    int dice[6];
    for(int i=0;i<6;i++){
        scanf("%d",&dice[i]);    
    }
    char direct[100]={};
    scanf("%s",direct);
    int nowstate[6]={1,6,3,5,2,4};
    int nextstate[6]={};
    for(int i=0;direct[i]!='\0';i++){
        switch(direct[i]){
            case 'E':
            nextstate[2]=nowstate[0];
            nextstate[5]=nowstate[1];
            nextstate[1]=nowstate[2];
            nextstate[3]=nowstate[3];
            nextstate[4]=nowstate[4];
            nextstate[0]=nowstate[5];
            break;
            case 'W':
            nextstate[5]=nowstate[0];
            nextstate[2]=nowstate[1];
            nextstate[0]=nowstate[2];
            nextstate[3]=nowstate[3];
            nextstate[4]=nowstate[4];
            nextstate[1]=nowstate[5];
            break;
            case 'N':
            nextstate[3]=nowstate[0];
            nextstate[4]=nowstate[1];
            nextstate[2]=nowstate[2];
            nextstate[1]=nowstate[3];
            nextstate[0]=nowstate[4];
            nextstate[5]=nowstate[5];       
            break;
            case 'S':
            nextstate[4]=nowstate[0];
            nextstate[3]=nowstate[1];
            nextstate[2]=nowstate[2];
            nextstate[0]=nowstate[3];
            nextstate[1]=nowstate[4];
            nextstate[5]=nowstate[5];          
            break;
        }
        for(int i=0;i<6;i++){
            nowstate[i]=nextstate[i];
        }
    }
    printf("%d\n",dice[nowstate[0]-1]);
}


Measured memory_bytes: 2736
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>


using namespace std;

vector<int> G;
int A[1000000];
long long cnt = 0;

void insertionSort(int A[], int n, int g)
{
    for (int i = g; i < n; i++)
    {
        int temp = A[i];
        int j = i - g;
        while ((j >= 0) && (A[j] > temp))
        {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = temp;
    }
}
void shellSort(int A[], int n)
{
    int i = 1;
    while (i <= n)
    {
        G.push_back(i);
        i = 3 * i + 1;
    }
    for (int i = G.size() - 1; i >= 0; i--)
    {
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i > 0; i--)
    {
        printf("%d ", G[i]);
    }
    printf("1\n");

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

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

    return 0;
}


Measured memory_bytes: 7180
import numpy as np

L = int(input())

branches = []
# ノード数は (2^n - 1) のときに 1 増える
node_count = int(np.log2(L)) + 1

# (0, 1), (0, 2), (0, 4), ... って2個ずつブランチ引く。
# これで 0 から 2^n - 1 (< L) まで作れる
for n in range(node_count - 1):
    branches.append((n, n + 1, 0))
    branches.append((n, n + 1, 2 ** n))

# これが '1' のノードから最後まで線を引きたい
byte_list = list(reversed(format(L, 'b')))[:-1]
# 長さはそれっぽい感じにする
a = 2 ** (node_count - 1)
for i in reversed(range(len(byte_list))):
    if byte_list[i] == '1':
        branches.append((i, node_count - 1, a))
        a += 2 ** i

print(node_count, len(branches))
for u, v, w in branches:
    print(u + 1, v + 1, w)


Measured memory_bytes: 12484
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
    @nums = []
  end

  def main
    s = gets.chomp.chars.sort
    t = gets.chomp.chars.sort
    # puts s
    # puts t

    if s[0] < t[-1]
      puts "Yes"
      return
    elsif t[-1] < s[0]
      puts "No"
      return
    end

    if s[0] == s[-1] && t[0] == t[-1]
      if s.length < t.length
        puts "Yes"
        return
      else
        puts "No"
        return
      end
    end

    puts "No"
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n, q = map(int, input().split())
edges=[[] for i in range(1+n)]
for i in range(n-1):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    edges[_].append(__)
    edges[__].append(_)
    """
"""#weighted->erase
cnt=[0]*(1+n)
for i in range(q):
    x,p=map(int,input().split())
    cnt[x]+=p
def f(now,pars_value,par):
    cnt[now]+=pars_value
    a=cnt[now]
    for i in edges[now]:
        if i!=par:f(i,a,now)
f(1,0,-1)
print(*cnt[1:])

Measured memory_bytes: 234440
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (b >= c) {
    cout << b + c << endl;
    return 0;
  }

  ll ans = b * 2;
  c -= b;
  if (c > a) {
    ans += a + 1;
  } else {
    ans += c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int N,A,B,C;
vector<int> v;

int dfs(int i,int a,int b, int c){
      if(i == N){
            if(a == 0 || b == 0 || c == 0){
                  return 1000000;
            }else{
                  return abs(A - a) + abs(B - b) + abs(C - c) - 30;
            }
      }
      
      vector<int> t(4);
      t[0] = dfs(i + 1,a,b,c);
      t[1] = dfs(i + 1,a + v[i],b,c) + 10;
      t[2] = dfs(i + 1,a,b + v[i],c) + 10;
      t[3] = dfs(i + 1,a,b,c + v[i]) + 10;
      return min(t[0],min(t[1],min(t[2],t[3])));
}
int main(void){
    cin >> N >> A >> B >> C;
    v.resize(N);
    for(int i = 0;i < N;i++){
          cin >> v[i];
    }
    cout << dfs(0,0,0,0);
}


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

int main(){
    int a,b;
    cin>>a>>b;
    
    if(a>b)
        cout<<"a > b"<<endl;

    if(a<b)
        cout<<"a < b"<<endl;

    if(a==b)
        cout<<"a == b"<<endl;

    return 0;
}

Measured memory_bytes: 1160
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

	a := nextInt()
	b := nextInt()
	c := nextInt()

	cnt := isSame(a, b)
	cnt += isSame(b, c)
	cnt += isSame(c, a)

	if cnt == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func isSame(x, y int) int {
	if x == y {
		return 1
	} else {
		return 0
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

Measured memory_bytes: 640
N = int(input())
X = input()

memo = {}


def popcount(n):
    return bin(n).count('1')


def f(n):
    if n == 0:
        return 0
    if n in memo:
        return memo[n]
    memo[n] = 1 + f(n % popcount(n))
    return memo[n]


def solve(N, X):
    Xint = int(X, 2)
    p = popcount(Xint)
    if 1 < p:
        x1 = Xint % (p - 1)
    x2 = Xint % (p + 1)
    ans = []
    b = 1
    if 1 < p:
        bmod1 = b % (p - 1)
    bmod2 = b % (p + 1)
    for i in range(N):
        if X[-1 - i] == '1':
            if 1 < p:
                ans.append(1 + f((x1 - bmod1) % (p - 1)))
            else:
                ans.append(0)
        else:
            ans.append(1 + f((x2 + bmod2) % (p + 1)))
        b <<= 1
        if 1 < p:
            bmod1 = bmod1 * 2 % (p - 1)
        bmod2 = bmod2 * 2 % (p + 1)

    return list(reversed(ans))


for x in solve(N, X):
    print(x)

Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
int n,m,res;
vector<vector<int>> d(8);
string L;

void dfs(int i,string s,int p=0){
    if(i==n-1){
        //cout<<s<<" "<<L<<endl;
        if(s==L){
            res++;
            return;
        }
    }
    for(int j=0;j<d[p].size();j++){
        string ss = s;
        int x = d[p][j];
        if(ss[x]=='0'){
            ss[x]='1';
            dfs(i+1,ss,x);
            //cout<<ss<<endl;
        }
        
    }
    return;
}

int main(){
    cin>>n>>m;
    res=0;
    L="1";
    string sss = "1";
    for(int i=0;i<n-1;i++){
        L+="1";
        sss+="0";
    }
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;a--;b--;
        d[a].push_back(b);
        d[b].push_back(a);
    }
    dfs(0,sss);
    cout<<res<<endl;
}

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

int main(){
  int N,W;
  cin>>N>>W;
  long long w[110];
  long long v[110];
  int maxv=100100;
  int maxn=110;
  long long  INF=10000000000;
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  
  long long dp[maxn][maxv];

  for(int i=0;i<maxn;i++){
    for(int j=0;j<maxv;j++){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;  
  for(int i=0;i<N;i++){
    for(int sumv=0;sumv<maxv;sumv++){
      if(sumv-v[i]>=0){
        dp[i+1][sumv]=min(dp[i+1][sumv],dp[i][sumv-v[i]]+w[i]);
      }
      dp[i+1][sumv]=min(dp[i+1][sumv],dp[i][sumv]);
    }
  }
  
  long long ans=0;
  for(int i=0;i<=maxv;i++){
    //cout<<dp[N][i]<<endl;
    if(dp[N][i]<=W) ans=i;
  }
  cout<<ans<<endl;
  //cout<<dp[0][0]<<endl;
  return 0;
}



Measured memory_bytes: 89632
class RollingHash:
    def __init__(self, S):
        N = len(S)
        self.N = N
        self.base1 = 1007
        self.mod1 = 10**9 + 7
        self.hash1 = [0] * (N+1)
        self.power1 = [1] * (N+1)

        for i, e in enumerate(S):
            self.hash1[i+1] = (self.hash1[i] * self.base1 + ord(e)) % self.mod1
            self.power1[i+1] = (self.power1[i] * self.base1) % self.mod1
    
    def get(self, lv, rv):
        return (self.hash1[rv] - self.hash1[lv] * self.power1[rv-lv] % self.mod1) % self.mod1

S = input()
T = input()
rh_s = RollingHash(S)
rh_t = RollingHash(T)
ns = len(S)
nt = len(T)

for i in range(ns - nt+1):
    if rh_t.get(0,nt) == rh_s.get(i, i+nt):
        print(i)




    


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

int main() {
    vector<int>a(3);
    for(int i=0; i<3; ++i){
        cin >> a[i];
    }
    int sum;
    sum=a[0]+a[1]+a[2];
    if(sum>=22){
        cout << "bust" << endl;
    }
    else if(sum<22){
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	ll n,k;
	cin >> n >> k;

	vector<ll> to(n);
	rep(i,n){
		ll v; cin >> v;
		to[i] = --v;
	}

	if(k <= n + 5){
		ll res = 0;
		rep(i,k) res = to[res];
		cout << res + 1 << endl;
		return 0;
	}





	vector<bool> checked(n, false);
	ll now = 0;
	ll t = 0;
	// cycleの開始点を探す
	rep(i,n){
		checked[now] = true;
		if(checked[to[now]]) break;
		now = to[now];
		t++;
	}
	ll cycleini = now;
	

	// cycleの長さを求める
	ll cyclelen = 0;
	now = cycleini;
	while(true){
		now = to[now];
		cyclelen++;
		if(now == cycleini) break;
	}

	
	k -= t;
	k %= cyclelen;

	ll res = cycleini;
	rep(i,k) res = to[res];

	cout << res + 1 << endl;
	
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 4828
N, M = map(int, input().split())
A = list(map(lambda x: (-int(x), 1), input().split()))

for _ in range(M):
  b, c = map(int, input().split())
  A += [(-c, b)]

import heapq
heapq.heapify(A)
ans = 0
for _ in range(N):
  a = heapq.heappop(A)
  ans += a[0]
  if a[1] > 1:
    heapq.heappush(A, (a[0], a[1]-1))

print(-ans)


Measured memory_bytes: 29140
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const int inf = 1e9+7;
#define int long long

void dfs(int K,vector<int> &d,vector<vector<int>> &to,vector<vector<int>> &cost){
	int now = K;
	for(int i=0;i<to[now].size();i++){
		int next = to[now][i];
		if(d[next]!=-1)continue;
		d[next] = d[now] + cost[now][i];
		dfs(next,d,to,cost);
	}
}
signed main(void){
	int N;
	cin >> N;
	vector<vector<int>> to(N+1),cost(N+1);
	for(int i=0;i<N-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		to[a].push_back(b);
		cost[a].push_back(c);
		to[b].push_back(a);
		cost[b].push_back(c);
	}
	int Q,K;
	cin >> Q >> K;
	K--;
	vector<int> d(N+1,-1);
	d[K] = 0;
	//全ての点からKに行くための最短経路を求めていく
	dfs(K,d,to,cost);
	vector<int> ans;
	for(int i=0;i<Q;i++){
		int x,y;
		cin >> x >> y;
		x--;y--;
		ans.push_back(d[x]+d[y]);
	}
	for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 20728
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10000],i,j,n,c=0,b[100000];
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);


    for(i=0;i<n;i++)
    {
        if(a[i]==b[i]) c++;
    }

    if(n-c==2 || c==n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  for(int i=0; i<S.size(); i++){
  int t=int(S.at(i))+N;
  if(t>90) t-=26;
  S.at(i)=char(t);
  }
  
  cout << S << endl;
}

Measured memory_bytes: 256
X,N = map(int, input().split())
if(N == 0):
  print(X)
  exit()
else:
  p_list = list(map(int, input().split()))

i = X
ans_big = X

while(True):
  #print("1",i)
  if((i in p_list)==True):
    pass
  else:
    ans_big = i
    break
  i = i + 1
    
i = X
ans_small = X
while(True):
  #print("2",i)
  if((i in p_list)==True):
    pass
  else:
    ans_small = i
    break
  i = i - 1

#print(ans_big,ans_small)
if(abs(X-ans_small)>abs(X-ans_big)):
  print(ans_big)
else:
  print(ans_small)

Measured memory_bytes: 9220
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	string s,s1,s2;
	cin>>s;
	int b=s.size();
	for(int i=s.size()-2;i>=0;i-=2){
		b-=2;
		s1="";
		s2="";
		for(int j=0;j<b/2;++j){
			s1+=s[j];
			s2+=s[j+b/2];
		}
//		cout<<s1<<" "<<s2<<endl;
		if(s1==s2)break;
	}
	cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    N = Scanner.int()
    L = Scanner.map_int()
    L.sort()

    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += bisect.bisect_left(L, L[i] + L[j], j + 1) - j - 1
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 43864
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;

int main (){

    int H, W; cin >> H >> W;
    vector<string> maze(H);
    queue<P> que;
    vector<P> start;
    rep(i, H){
        cin >> maze[i];
        rep(j, W){
            if (maze[i][j] == '#') {
                que.push(P(i, j));
                start.push_back(P(i, j));
            }
        }
    }

    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    vector<vector<int> > dist(H, vector<int>(W, -1));

    for (P p1 : start){
        dist[p1.first][p1.second] = 0;
    }

    int ans = 0;

    while (!que.empty()){

        P p2 = que.front();
        que.pop();
        // cout << "ok" << endl;

        rep(i, 4){
            
            int ny = p2.first + dy[i];
            int nx = p2.second + dx[i];
            // cout << "ok" << endl;

            if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
            // cout << "ok" << endl;
            if (dist[ny][nx] != -1) continue;
            // cout << "ok" << endl;
            
            que.push(P(ny, nx));
            dist[ny][nx] = dist[p2.first][p2.second] + 1;
            ans = max(ans, dist[ny][nx]);

            // rep(j, H){
            //     rep(k, W){
            //         cout << dist[j][k] << " ";
            //     }cout << endl;
            // }
        }
    }

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


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

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

const int INF = 1e9 + 7;

using namespace std;

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string str;
    cin >> str;

    map<char, int> mm;
    for (char ch : str) {
	mm[ch]++;
	if (mm.size() > 2 || mm[ch] > 2) {
	    cout << "No" << endl;
	    return 0;
	}
    }

    cout << "Yes" << endl;

    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  cout << setprecision(15);
  u64 N;
  cin >> N;
  vector<i32> X(N);
  ArrayInput(X);
  vector<u32> Res(100, 0);
  for (u32 i = 1; i < 101; ++i) {
    i32 tmp = 0;
    for (u32 j = 0; j < N; ++j) {
      tmp += (X[j] - i) * (X[j] - i);
    }
    Res[i - 1] = tmp;
  }
  cout << *min_element(Res.begin(), Res.end()) << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int INF = 100000000;

	public static void main(String[] args) {
		// DPを用いた解法
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int []dp = new int [n+1];
		
		for(int i = 0 ; i <= n ;i++) {
			dp[i] = INF;
			}
		
		dp[0] = 0;
		
		for(int i = 0 ;i < n ;i++) {
			for(int pow9 = 1 ; i + pow9 <= n ; pow9 *= 9) {
				dp[i+pow9] = Math.min(dp[i+pow9], dp[i]+1);
			}
			for(int pow6 = 1 ; i + pow6 <= n ;  pow6 *= 6) {
				dp[i+pow6] = Math.min(dp[i+pow6], dp[i]+1);
			}
		}
		
		System.out.println(dp[n]);

		
		
	}

}


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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  ll n;
  cin >> n;
  vl p(n);
  rep(i,n) cin >> p[i];
  int cnt = 0;
  vl m(n);
  rep(i,n){
    if(i==0) m[i] = p[i];
    else m[i] = min(m[i-1] , p[i]);
  }
  rep(i,n){
    if(m[i]==p[i]) cnt++;
  }
  cout << cnt;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



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

using namespace std;

struct times{
    int a;
    int b;
};

int main(){
	int x, a;

    cin >> x >> a;

    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var n = h[0];
		var map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[h[1]].Select(_ => read())) map[r[0]].Add(r[1]);

		var m = double.MaxValue;
		for (int k = 0; k < n; k++)
		{
			var dp = new double[n + 1];
			for (int i = n - 1; i > 0; i--)
			{
				if (i == k && map[i].Count > 1)
				{
					var sum = 0.0;
					var max = 0.0;
					foreach (var j in map[i])
					{
						sum += dp[j];
						max = Math.Max(max, dp[j]);
					}
					dp[i] = (sum - max) / (map[i].Count - 1) + 1;
				}
				else
				{
					var sum = 0.0;
					foreach (var j in map[i])
					{
						sum += dp[j];
					}
					dp[i] = sum / map[i].Count + 1;
				}
			}
			m = Math.Min(m, dp[1]);
		}
		Console.WriteLine(m);
	}
}


Measured memory_bytes: 20384
A,B,C = map(int, input().split())
K = int(input())

kk=0
while B<=A:
    B = B*2
    kk+=1

while C<=B:
    C = C*2
    kk+=1

if kk<=K:
    ans="Yes"
else:
    ans = "No"

print(ans)

Measured memory_bytes: 9176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int C[N-1],S[N-1],F[N-1];
    rep(i,N-1) cin >> C[i] >> S[i] >> F[i];
    for(int i=0;i<N-1;i++){
        int now=0;
        for(int j=i;j<N-1;j++){
            now=max(now,S[j]);
            now=((now+F[j]-1)/F[j])*F[j];
            now+=C[j];
        }
        cout << now << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;

class Program {
	public static int Main() {
#if DEBUG
		Console.WriteLine("DEBUG Mode");
#endif
		while (true)
		{
			int n = int.Parse(Console.ReadLine());
			if (n == 0)
			{
				break;
			}
			int[] dp = new int[31];
			dp[0] = 1;
			for (int i = 1; i <= n; i++)
			{
				for (int j = 1; j < 4; j++)
				{
					if (i - j < 0)
					{
						break;
					}
					dp[i] += dp[i - j];
				}
			}
			dp[n] = dp[n]/10 + Convert.ToInt32(dp[n] % 10 != 0);
			Console.WriteLine(dp[n] / 365 + Convert.ToInt32(dp[n] % 365 != 0));
		}
		return 0;
	}
}

Measured memory_bytes: 5668
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,m;
	cin>>n>>m;
	int a[n];
	int sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	double num=sum;
	num/=4*m;
	int cnt=0;
	rep(i,n){
		if(a[i]>=num){
			cnt++;
		}
	}
	if(cnt>=m){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	re 0;
}

Measured memory_bytes: 256
def main():
	N, M = map(int, input().split())
	l, r = 0, 10**9+7
	for _ in range(M):
		L, R = map(int, input().split())
		l = max(L, l)
		r = min(R, r)
	print(max(r-l+1, 0))


if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

int min(int a,int b){
    return a<b?a:b;
}
int main(void){
    int N,M;
    int ans = 0;
    int num[4] = {-1,-1,-1,-1};
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int s,c;
        cin >> s >> c;
        if(num[s] != -1 && num[s] != c){
            cout << -1 <<endl;
            return 0;
        }
        else{
            if(N > 1 && s == 1 && c == 0){
                cout << -1 << endl;
                return 0;
            }
            else{
                num[s] = c;
            }
        }
    }
    
    for(int i=1;i<=N;i++){
        ans *= 10;
        if(N > 1 && i == 1 && num[i] == -1){
            ans += 1;
        }
        else{
            ans += num[i] == -1 ? 0 : num[i];
        }
    }
    cout << ans;
}


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

bool Even_or_Odd(int x){
  bool res;
  if(x%2==0){
    res = true;
  }else{
    res = false;
  }
  return res;
}
 
int main() {
  int a, b;
  cin >>a >>b;
   bool ans;
   ans = false;
  if(Even_or_Odd(a)){
    ans = true;
  }else if(Even_or_Odd(b)){
    ans = true;
  }

           
   if(ans ==true){
cout <<"Even" <<endl;
           }else
           {cout << "Odd" <<endl;}
  
  
  
  
  
}

Measured memory_bytes: 256
# C - IDC

import bisect
import sys
readline = sys.stdin.readline

base = 1000000000000
N, M = map(int, readline().split())
PY = []
T = [[] for _ in range(N+1)]

for i in range(M):
    P, Y = map(int, readline().split())
    PY.append((P, Y))

PY_sorted = sorted(PY, key=lambda x: x[1])
PY_sorted = sorted(PY_sorted, key=lambda x: x[0])

for i in range(M):
    T[PY_sorted[i][0]].append(PY_sorted[i][1])

for i in range(M):
    n = bisect.bisect_right(T[PY[i][0]], PY[i][1])
    print(str(base + PY[i][0]*1000000 + n)[1:])


Measured memory_bytes: 30436
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	long int t=1;
// 	cin>>t;
	while(t--)
	{
	    long int s;
	    cin>>s;
	    long long int dp[s+1]={0},mod = 1e9+7;
	    dp[0]=1;
	    for(long int i=0;i<=s;i++)
	    {
	        for(long int j=3;j<=s;j++)
	        {
	            if(i+j<=s)
	            dp[i+j]=(dp[i+j]+dp[i])%mod;
	        }
	    }
	    cout<<dp[s]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
-- vim: set fdm=marker : -- {{{
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.Fix (fix)
import Data.Maybe
import Data.Array.Unboxed
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
-- }}}

-- Input functions with ByteString
-- {{{
tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

readInt :: Num a => BS.ByteString -> a
readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntTuple :: Num a => BS.ByteString -> (a, a)
readIntTuple = tuplify2 . map readInt . BS.words
readIntList :: Num a => BS.ByteString -> [a]
readIntList = map readInt . BS.words

getInt :: Num a => IO a
getInt = readInt <$> BS.getLine
getIntList :: Num a => IO [a]
getIntList = readIntList <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents
-- }}}

main = do
    [x,a] <- getIntList :: IO [Int]
    print $ if x < a then 0 else 10


Measured memory_bytes: 380
n = int(input())
numlist = map(int, input().split())
numarr = list(numlist)
isevenList = [i for i in numarr if i % 2 == 0]
answerList = []
for i in isevenList:
    if i % 3 == 0 or i % 5 == 0:
        answerList.append("APPROVED")
    else:
        answerList.append("DENIED")
if "DENIED" in answerList:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 9180
#include<cstdio>
int main(void){
  int x,a,b;
  a=0;
  b=0;
  for(int i=0;i<3;i++){
  scanf("%d",&x);
    if(x==5)a++;
    if(x==7)b++;
  }
  if(a==2&&b==1)printf("YES\n");
  else printf("NO");
  return 0;
}
  

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 200 + 10;

int N;
int A, K;

long long SG(long long A, long long K)
{
	if (A % K == 0)
		return A / K;
	if (A / K == 0)
		return 0;

	long long lb = A / K * K;
	// A - lb >= ? * (A / K + 1)
	long long q = (A - lb) / (A / K + 1); 
	if (q == 0) q = 1;
	return SG(A - q * (A / K + 1), K);
}

void Work()
{
	scanf("%d", &N);
	long long Ans = 0;
	for (int i = 0; i < N; i ++)
	{
		scanf("%d%d", &A, &K);
		Ans ^= SG(A, K);
	}
	printf((Ans == 0) ? "Aoki\n" : "Takahashi\n");
}

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

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define F first
#define S second
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
*/
////////////////////////////////////////////////////



int main()
{
	bool fis = false;
	int n;
	int mm[4] = {10,50,100,500};
	while (cin >> n&&n)
	{
		if (fis)cout << endl;
		fis = true;
		int a[4];
		int ans = 999999999;
		int ANS[4] = { 999, 999, 999, 999 };
		cin >> a[0] >> a[1] >> a[2] >> a[3];
		int k = 0;
		rep(i, 4)k += a[i];
		rep(u, a[0]+1)
		{
			rep(i, a[1]+1)
			{
				rep(o, a[2]+1)
				{
					rep(p, a[3] +1)
					{

						int now = -1*n;
						now += u*mm[0] + i*mm[1] + o*mm[2] + p*mm[3];
						if (now < 0)continue;
						int NOW[4] = { -1, -1, -1, -1 };
						int nowans = k;
						nowans -= u + i + o + p;
						for (int l = 3; l >=0; l--)
						{
							NOW[l]=now / mm[l];
							nowans += NOW[l];
							now -= NOW[l] * mm[l];
						}
						if (nowans < ans)
						{
							if (NOW[0] != 0)if (u)continue;
							if (NOW[1] != 0)if (i)continue;
							if (NOW[2] != 0)if (o)continue;
							if (NOW[3] != 0)if (p)continue;

							ans = nowans;
							ANS[0] = u;
							ANS[1] = i;
							ANS[2] = o;
							ANS[3] = p;
						}
					}
				}
			}
		}

		for (int i = 0; i < 4; i++)
		{
			if (ANS[i]!=0)
			{
				cout << mm[i] << " " << ANS[i] << endl;

			}
		}
		

	}


}

Measured memory_bytes: 1164
# N, K = 5, 3
# HRR = [10, 30, 40, 50, 20]

N, K = 3, 1
HRR = [10, 20, 10]

N, K = 2, 100
HRR = [10, 10]

N, K = 10, 4
HRR = [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]

N, K = map(int, input().split())
HRR = list(map(int, input().split()))


def calculate(n, k, hrr):
    result = []
    for i in range(n):
        if i == 0:
            result.append(0)
            continue

        mins = -1
        for j in range(1, k + 1):
            index = i - j
            if index >= 0:
                value = result[index] + abs(hrr[i] - hrr[index])
                if mins == -1:
                    mins = value
                else:
                    if value < mins:
                        mins = value
        result.append(mins)

    print(result[-1])


calculate(N, K, HRR)


Measured memory_bytes: 57568
def slove():
    import sys
    input = sys.stdin.readline
    l, r = list(map(int, input().rstrip('\n').split()))
    mmod = 10 ** 10
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            mmod = min(mmod, (i * j) % 2019)
            if mmod == 0:
                break
        if mmod == 0:
            break
    print(mmod)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38896
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
} p;

void kock(int n, p p1, p p2)
{
  p s, t, u;
  double pi=M_PI/3;
  if(n==0) return;
  // p1, p2 から s, t, u を計算
  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)*cos(pi)-(t.y-s.y)*sin(pi)+s.x;
  u.y=(t.x-s.x)*sin(pi)+(t.y-s.y)*cos(pi)+s.y;
  
  kock(n-1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);
  kock(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  kock(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  kock(n-1, t, p2);
}

int main(void)
{
  int n;
  p p1, p2;
  scanf("%d", &n);
  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;
  printf("%.8f %.8f\n", p1.x, p1.y);
  kock(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);
  return 0;
}


Measured memory_bytes: 2144
#include <stdio.h>
int main(void){   
	while(1) {   
		int i, n;   
		int card[ 200 ];   
		int x;   
		int a = 1, b = 1;  
		int t, h;  
		int count = 0;    
		scanf( "%d", &n );   
		if(n==0)     
			break;  
		t = n;   
		h = n;     
		for( i = 0; i < n * 2; i++ )  
			card[ i ] = 2;    
		for( i = 0; i < n; i++ ) { 
			scanf( "%d", &x );      
			card[ x - 1 ] = 1;  
		}       while( b) {    
			for( i = 0; i < n * 2; i++ ) {  
				if( a == 1 ) {        
					if( card[ i ] == 1 ) {   
						card[ i ] = 0;         
						a = 2;         
						t--;    
					}      
				} else {      
					if( card[ i ] == 2 ) {   
						card[ i ] = 0;       
						a = 1;     
						h--;     
					}      
				}    
				if(t==0 || h==0) {   
					b = 0;      
					break;     
				}     
			}      
			if( a == 1 )
				a = 2;   
			else      
				a = 1;  
		}    
		for( i = 0; i < n * 2; i++ )  
			if( card[ i ] )    
				count++;   
		if(t==0)     
			printf( "%d\n0\n", count );  
		else    
			printf( "0\n%d\n", count ); 
	}  
	return( 0 );
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void){
	int num[10];

	while(scanf("%1d", &num[0]) != EOF){
		for(int i=1; i<10; i++){
			scanf("%1d", &num[i]);
		}

		for(int j=9; j>0; j--){
			for(int i=0; i<j; i++){
				num[i] = (num[i] + num[i+1]) % 10;
			}
		}
		printf("%d\n", num[0]);
	}
	
	return 0;
}

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

#define ll long long

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

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

    if (n * a > b) cout << b << endl;
    else cout << n * a << endl;;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main()
{
    ll n, l;
    cin >> n >> l;
    vector<ll> v(n + 1, 0);
    rep(i, n)
    {
        cin >> v[i + 1];
        v[i + 1] += v[i];
    }

    for (int i = 0; i < n - 1; i++)
    {
        if (v[i + 2] - v[i] >= l)
        {
            cout << "Possible" << endl;
            for (int j = n-1; i+1 < j; j--)
            {
                cout << j << endl;
            }

            for (int j = 1; j<=i; j++)
            {
                cout<<j<<endl;
            }
            cout<<i+1<<endl;

            return 0;
        }
    }

    cout << "Impossible" << endl;
}

Measured memory_bytes: 1664
l = input()
gcnt, pcnt, wcnt, lcnt = 0,0,0,0

for i in range(len(l)):
	if pcnt + 1 <= gcnt: #show "p"
		pcnt += 1
		if l[i] == 'g':
			wcnt += 1
	else: #show "g"
		gcnt += 1
		if l[i] == 'p':
			lcnt += 1

print(wcnt - lcnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   vector<int> l(n); 
   rep(i,n) cin >> l[i];
   ll ans=0;
   sort(l.begin(),l.end());
   rep(i,n-2){
       rep1(j,i+1,n-1){
           rep1(k,j+1,n){
               if(l[i]+l[j]>l[k]){
                   ans++;
                   continue;
               }
               break;
           }
       }
   }
   cout << ans;
}

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

typedef long long int ll;
typedef long double ld;

using namespace std;


int main()
{
    ld x,ans, pi = 3.14159266;
    cin>>x;
    ans= 2*pi*x;
    cout<<ans<<endl;

    //cout<<"Case "<<cn<<": "<<"good"<<endl;
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>

using namespace std;

#define MAX 10000
int Par[MAX], Rank[MAX];

void init(int n){
	for(int i=0; i<n; i++){
		Par[i] = i;
		Rank[i] = 0;
	}
}

int root(int x){
	if(Par[x] != x){ Par[x] = root(Par[x]); }
	return Par[x];
}

bool same(int x, int y){
	if(root(x) == root(y)){ return true; }
	else{ return false; }
}

void unite(int x, int y){
	x = root(x);
	y = root(y);

	if(x != y){
		if(Rank[x] < Rank[y]){
			Par[x] = y;
		} else{
			Par[y] = x;
			if(Rank[x] == Rank[y]){ Rank[x]++; }
		}
	}
}

int main(){
	int n, q;
	int com, x, y;
	cin >> n >> q;

	init(n);

	for(int i=0; i<q; i++){
		cin >> com >> x >> y;
		
		if(com==0){
			unite(x, y);
		} else{
			if(same(x, y)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3176
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        if (s[2] == s[3] and s[4] == s[5]) out << "Yes" << endl;
        else out << "No" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

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

    std::vector<long long> a(n), b(n), c(m), d(m);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }

    for (int i = 0; i < m; i++) {
        std::cin >> c[i] >> d[i];
    }
       
    for (int i = 0; i < n; i++)
    {
        int minID = -1;
        long long min = __LONG_LONG_MAX__;
        for (int j = 0; j < m; j++)
        {
            long long dist = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
     
            if (min > dist)
            {
                min = dist;
                minID = j + 1;
                
            }
        }

        std::cout << minID << "\n";
    }
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    string S;
    cin >> S;

    int topS = atoi(S.substr(0, 2).c_str());
    int lowS = atoi(S.substr(2, S.size()).c_str());

    if ((topS < 1 || topS > 12) && (lowS < 1 || lowS > 12)) {
        cout << "NA" << endl;
    }
    else {
        if ((topS < 1 || topS > 12)) {
            cout << "YYMM" << endl;
        }
        else if (lowS < 1 || lowS > 12) {
            cout << "MMYY" << endl;
        }
        else {
            cout << "AMBIGUOUS" << endl;
        }

    }

    return 0;
}


Measured memory_bytes: 3536