akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
A=[I()-1 for i in range(n)]
i=0
point=0
while i<n:
    point=A[point]
    i+=1
    if point==1:
        print(i)
        sys.exit()
print(-1)

    
    
        

            
                
                
        
        
        

            


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

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (i + 1 == A[A[i] - 1]) ans++;
        }
        ans /= 2;
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 21984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    map<ll,ll> mp;
    ll su = 0;
    rep(i,n) {
        ll s; cin >> s;
        mp[s]++;
        su+= s;
    }
    int q; cin >> q;
    rep(i,q) {
        ll b ,c; cin >> b >> c;
        su += (c-b)*mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << su << endl;
    }
    
}


Measured memory_bytes: 9444
n=int(input())
a=list(map(int,input().split()))
q=int(input())
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1

ans=sum(a)
for i in range(q):
  a,b=map(int,input().split())
  if a in dic:
    ans=ans-a*dic[a]+b*dic[a]
    if b in dic:
      keep=dic[a]
      dic[b]+=keep
      dic[a]=0
    else:
      keep=dic[a]
      dic[b]=keep
      dic[a]=0
  print(ans)

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

int main() {
  int D, G;
  std::cin >> D >> G;
  G /= 100;
  std::vector<int> p(D), c(D);
  for (int i=0; i<D; i++) {
    std::cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  
  std::vector<int> cands;
  int n_pat = (1 << D);
  for (int pat=0; pat<n_pat; pat++) {
    int cnt = 0;
    int score = 0;
    std::vector<int> rest(p);
    for (int i=0; i<D; i++) {
      if ((pat >> i) & 1) {
        cnt += p[i];
        score += (i+1)*p[i] + c[i];
        rest[i] = 0;
      }
    }
    if (score >= G) {
      cands.push_back(cnt);
    } else {
      for (int i=D-1; i>=0; i--) {
        if (rest[i] > 0) {
          int remain = ((G - score) + (i+1) - 1) / (i+1);
          if (remain < rest[i]) {
            cands.push_back(remain + cnt);
          }
          break;
        }
      }
    }
  }
  std::cout << *std::min_element(std::begin(cands), std::end(cands)) << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

long long result, n,m,k;



int main() {

	cin >> n>>m >> k;
	
	if (n + m >= k) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	//cout << result << endl;

return 0;
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if(x + r >W || x - r <0)
    cout << "No" << endl;
    else if(y + r >H || y - r <0)
    cout << "No" << endl;
    else
    cout << "Yes" << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<tuple<string,int,int>> restraunt(n);
  for(int i=0;i<n;i++){
    cin >> get<0>(restraunt.at(i));
    cin >> get<1>(restraunt.at(i));
    get<1>(restraunt.at(i)) = 100 - get<1>(restraunt.at(i));
    get<2>(restraunt.at(i)) = i+1;
  }
  sort(restraunt.begin(),restraunt.end());
  for(auto x : restraunt) cout << get<2>(x) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
long long dfs(long long x)
{
	if(x==1){
		return 1;
	}
	else{
			long long s=dfs(x/2)*2+1;
			return s;
	}
}
int main()
{
	cin>>n;
	cout<<dfs(n);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <math.h>

using namespace std;

int main() {
	char A[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string B;
  	int N;
  	cin >> N;
  	cin >> B;
  	for(int i=0;i<B.length();i++){
    	for(int j=0;j<26;j++){
        	if(B[i]==A[j]){
              	//cout << B[i] << " " << A[j] << " " << A[(j+N)%26] << endl;
            	B[i]=A[(j+N)%26];
              	break;
            }
        }
    }
  	cout << B << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long sum = 0;
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 1; i <= N; i++) {
			if (i % 3 == 0 && i % 5 == 0) {
			} else if (i % 3 == 0) {

			} else if (i % 5 == 0) {

			} else {
				list.add(i);
			}
		}
		for (int i = 0; i < list.size(); i++) {
			sum = sum + list.get(i);
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 42480
#include <stdio.h>

int main(void)
{
    int a, b, c, x;

    scanf("%d %d %d", &a, &b, &c);

    if (a > b) {
        x = a;
        a = b;
        b = x;
    }
    if (b > c) {
        x = b;
        b = c;
        c = x;
    }
    if (a > b) {
        x = a;
        a = b;
        b = x;
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}



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

#define debug(n) cerr << #n << ':' << n << endl;

int main(){
  int H,W; cin >> H >> W;
  int cnt = 0;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      char c; cin >> c;
      if(c == '#')cnt++;
    }
  }  
  cout << (cnt == H + W - 1?"Possible\n":"Impossible\n");
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

N = input()

# TLE (Python3 3.4.3)
# AC  (PyPy3 (2.4.0))

# DP
INF = pow(10, 8)
L = len(N)
dp = [[INF] * 2 for _ in range(L+2)]
dp[0][0] = 0

# reverse
N = N[::-1] + '0'


for i in range(L+1):
    n = int(N[i])

    # 更新後のdp
    ni = i + 1

    # 前の桁で繰り下がりなし
    # 同じだけ払う
    dp[ni][0] = min(dp[ni][0], dp[i][0] + n)

    # 繰り下がりあり
    if n > 0:
        dp[ni][1] = min(dp[ni][1], dp[i][0] + (10 - n))
    else:
        dp[ni][0] = min(dp[ni][0], dp[i][0])

    # 前の桁で繰り下がりあり
    n += 1

    # 同じだけ払う
    if n == 10:
        dp[ni][1] = min(dp[ni][1], dp[i][1])
    else:
        dp[ni][0] = min(dp[ni][0], dp[i][1] + n)

    # 繰り下がりあり
    dp[ni][1] = min(dp[ni][1], dp[i][1] + (10 - n))


ans = min(dp[L+1][0], dp[L+1][1])

print(ans)


Measured memory_bytes: 150728
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  vector<char>s(4);
  for(int i=0;i<4;i++){
    cin>>s[i];
  }
  for(int p=0;p<(1<<3);p++){
    string t;int sum=s[0]-'0';
    t.push_back(s[0]);
    for(int i=0;i<3;i++){
      if((p>>i)&1){sum+=(s[i+1]-'0');t.push_back('+');}
      else{sum-=(s[i+1]-'0');t.push_back('-');}
      t.push_back(s[i+1]);
    }
    t+="=7";
    if(sum==7){cout<<t<<endl;return 0;}
  }
  return 0;
}

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


int main() {
    string str;
    cin>>str;
    int l= str.size();
    int r=0;int maxo = 0;

    for(int i=0;i<l;i++){
        if(str[i]=='A' || str[i] == 'C'||str[i]=='G'||str[i]=='T' ){
            r++;
        }
        else{
            maxo = max(r,maxo);
            r=0;
            
        }
    }
    maxo = max(r,maxo);
    cout << maxo << endl;
    return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
struct lop{
	string s;
}a[201];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].s;
		for(int j=1;j<=i-1;j++)
		{
			if(a[i].s==a[j].s)
			{
				cout<<"No";
				return 0;
			}
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i].s[0]!=a[i-1].s[(a[i-1].s).size()-1])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int N,K,ans=0,temp=1;

    cin >> N >> K;

    while(1){
        ans +=1;
        temp *= K;

        if(temp>N)break;
    }

    cout << ans << endl;

}

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

signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  rep(j,K){
    vector<int> B(N+1);
    rep(i,N){
      int L=max(0,i-A[i]);
      int R=min(i+A[i]+1,N);
      B[L]++;
      B[R]--;
    }
    rep(i,N)B[i+1]+=B[i];
    B.pop_back();
    if(A==B) break;
    A=B;
  }
  rep(i,N)cout<<A[i]<<endl;
  return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

ll n, a, b;
void solve() {
    cin >> n >> a >> b;

    auto tmp = n / (a + b);
    cout << tmp * a + min(n - tmp * (a + b), a) << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
K,N = map(int,input().split())
A = list(map(int,input().split()))

distance = [A[i+1]-A[i] for i in range(len(A)-1)]

max_distance = max(distance)

#print(distance)
#print(max_distance)

candidate = A[0] + (K-A[N-1])
#print(candidate)

max_distance = max(max_distance,candidate)

#print(max_distance)

ans = K - max_distance
print(ans)

Measured memory_bytes: 26060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define AS 200001
#define inf 1e9
#define mod 1000000007
int solve(vector<int>&ar, int n, int k) {
	vector<int>dp;
	dp.resize(n + 1);
	for (int i = 2; i <= n; i++) {
		dp[i] = inf;
		for (int j= i - 1; j >= 1 and (i - j) <= k; j--) {
			dp[i] = min(dp[i], abs(ar[i] - ar[j]) + dp[j]);
		}
	}
	return dp[n];
}
int main() {
	fastIO

	int n;
	cin >> n;
	int k;
	cin>>k;
	vector<int>ar;
	ar.resize(n + 1);
	F1(ar, n);
	cout << solve(ar, n, k) << endl;


}


Measured memory_bytes: 1024
# train : 1 -> 2, 1m, A
# bus : 2 -> 3, 1m, B 
# taxi : 3 -> 4, 1m, C
# airplane : 4 -> 5, 1m, D
# ship : 5 -> 6, 1m, E

N = int(input())
transportation_facilities_num = [int(input()) for _ in range(5)]
min_num = min(transportation_facilities_num)

ans = N//min_num
if N % min_num > 0:
    ans += 1
ans += 4

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<int> idx(n);
	rep(i,n){
		int a;
		cin >> a;
		idx[a - 1] = i;
	}

	int t = 1, maxi = 1;
	rep(i,n - 1){
		if(idx[i] < idx[i + 1]){
			t++;
		}else{
			t = 1;
		}
		maxi = max(maxi, t);
	}
	cout << n - maxi << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[100005];
int N;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    scanf("%s",s + 1);
    N = strlen(s + 1);
    int p = 1,q = N;
    int ans = 0;
    while(p < q) {
        if(s[p] == s[q]) {++p;--q;}
        else {
            if(s[p] == 'x') {++p;++ans;}
            else if(s[q] == 'x') {--q;++ans;}
            else {puts("-1");return 0;}
        }
    }
    out(ans);enter;return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll H,W,K;
char c[310][310];
ll ans[310][310];
ll last[310]={};
ll lastH[310]={};
int main(){
    cin>>H>>W>>K;
    for(ll i=0;i<H;i++){
        cin>>c[i];
        for(ll j=0;j<W;j++){
          if(c[i][j]=='#'){
            last[i]=j;
          }
        }
    }
    for(ll j=0;j<W;j++){
      for(ll i=0;i<H;i++){
        if(c[i][j]=='#'){
            lastH[j]=i;
          }
      }
    }
    ll cnt=1;
    ll startHeight=0;
    for(ll i=0;i<H;i++){
      ll startWidth=0;
      bool f=false;
      for(ll j=0;j<W;j++){
        if(c[i][j]=='#'){
          for(ll k=startHeight;k<=((lastH[j]!=i)?i:(H-1));k++){
            for(ll l=startWidth;l<=((last[i]!=j)?j:(W-1));l++){
              ans[k][l]=cnt;
            }
          }
          cnt++;
          startWidth=j+1;
          f=true;
        }
      }
      if(f){
        startHeight=i+1;
      }
    }
    for(ll i=0;i<H;i++){
      for(ll j=0;j<W;j++){
        cout<<ans[i][j]<<" ";
      }cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1536
# coding: utf-8
#Problem Name: Circumscrived Circle of a Triangle
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

def __det(matrix):
    return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]

def __sqdist(p1,p2):
    return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**.5

n = int(raw_input())
for i in range(n):
    x1,y1,x2,y2,x3,y3 = map(float,raw_input().split(' '))
    det = __det([[(x2-x1),(y2-y1)],[(x3-x1),(y3-y1)]])
    c1 = (x1**2-x2**2+y1**2-y2**2)/2
    c2 = (x1**2-x3**2+y1**2-y3**2)/2
    px = __det([[c1,(y1-y2)],[c2,(y1-y3)]])/det
    py = __det([[(x1-x2),c1],[(x1-x3),c2]])/det
    r = __sqdist([x1,y1],[px,py])
    print '{0:.3f} {1:.3f} {2:.3f}'.format(px,py,r)

Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)



int main(){
	int n;
	cin >> n;
	vector<int> c(n);
	int a = 0;
	int b = n-1;
	string tmp;
	cout << a << endl;
	cin >> tmp;
	if(tmp=="Male"){
		c[0] = 0;
	}else if(tmp=="Female"){
		c[0] = 1;
	}else{
		return 0;
	}
	cout << b << endl;
	cin >> tmp;
	if(tmp=="Male"){
		c[n-1] = 0;
	}else if(tmp=="Female"){
		c[n-1] = 1;
	}else{
		return 0;
	}
	string s;
	while(1){
		int k = (a+b)/2;
		cout << k << endl;
		cin >> s;
		if(s=="Male"){
			c[k] = 0;
		}else if(s=="Female"){
			c[k] = 1;
		}else{
			return 0;
		}
		if((k-a)%2==0&&c[a]!=c[k]){
			b = k;
		}else if((k-a)%2==1&&c[a]==c[k]){
			b = k;
		}else if((b-k)%2==0&&c[k]!=c[b]){
			a = k;
		}else{
			a = k;
		}
	}
	return 0;
}

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

ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
    int n;
    cin >> n;
    vector<ll> T(n);
    rep(i, n) cin >> T[i];
    ll ans = 1LL;
    for (int i = 0; i < n; i++)
    {
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    lint n, k, s;
    cin >> n >> k >> s;

    if(s == 1e9) {
        vector<lint> a(n, 1);
        for(lint i=0; i<k; i++)  a[i] = 1e9;
        for(auto& e : a)  cout << e << " \n"[&e == &a.back()];        
    } else {
        vector<lint> a(n, 1e9);
        for(lint i=0; i<k; i++)  a[i] = s;
        for(auto& e : a)  cout << e << " \n"[&e == &a.back()];        
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vector<int>>;  // int <=> ll
using P = pair<int, int>;
const int INFTY = 1e9+7;

int main() {
  int N, K;
  cin >> N >> K;
  Graph edge(N);
  rep(i,N-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  queue<P> que;  // P(v, prev)
  que.push(P(0,-1));
  ll ans = K;
  
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int v = p.first;
    int prev = p.second;
    int color = K-2;
    if (v == 0) color = K-1;

    for (auto nv : edge[v]) {
      if (nv == prev) continue;
      (ans *= color) %= INFTY;
      --color;
      que.push(P(nv,v));
    }
  }

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


Measured memory_bytes: 6904
"use strict";
const main = arg => {
  let info = arg.split("\n");
  let amount = info[0];
  let nums = info[1].split(" ");
  let ans = 0;
  for(let i = 1; i < amount; i++){
  	for(let j = 0; j < i; j++){
  		ans += nums[i] * nums[j];
  	}
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11468
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  int N,D,A; cin >> N >> D >> A;
  vector<P> AS(N);
  rep(i, N) {
    cin >> AS[i].first >> AS[i].second;
    AS[i].second = (AS[i].second + A - 1) / A;
  }
  sort(AS.begin(), AS.end(), [&](P &a, P &b) {
    return a.first < b.first;
  });
  vector<P> bombs;

  ll ans = 0;
  ll nums = 0;
  int bf = 0;
  rep(i, N) {
    int x = AS[i].first;
    int h = AS[i].second;

    while(bombs.size() > bf) {
      auto &bomb = bombs[bf];
      if(bomb.first + D < x) {
        ++bf;
        nums -= bomb.second;
        continue;
      } else {
        break;
      }
    }

    h -= nums;
    if(h <= 0) continue;

    ans += h;
    bombs.push_back({x + D, h});
    nums += h;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3956
H,W=map(int, input().split())
maze=[]
maze.append(list("#"*(W+2)))
for h in range(H):
    maze.append(list("#"+input()+"#"))
maze.append(list("#"*(W+2)))

from collections import deque
import itertools
import copy

def chk_bfd(sy,sx):
    m_max=0
    ma=copy.deepcopy(maze)
    ma[sy][sx]=0
    d=[(1,0),(-1,0),(0,1),(0,-1)]
    q=deque([[sy,sx]])
    while q:
        y,x=q.popleft()
        for dy,dx in d:
            if ma[y+dy][x+dx]=='.':
                q.append([y+dy,x+dx])
                ma[y+dy][x+dx]=ma[y][x]+1
                m_max=max(m_max,ma[y+dy][x+dx])
    return m_max

s=[]
for h in range(H+2):
    for w in range(W+2):
        if maze[h][w]=='.':
            s.append([h,w])

res=0
for sy,sx in s:
    res=max(res,chk_bfd(sy,sx))

print(res)  

Measured memory_bytes: 3444
import bisect
num = int(input())
targ = []
for n in range(num):
    targ.append(int(input()))
ans = []
for n in range(num):

    if ans == []:
        ans.append(targ[n])
    elif ans[-1] < targ[n]:
        ans.append(targ[n])
    else:
        ans[bisect.bisect_left(ans,targ[n])] = targ[n]
print(len(ans))

Measured memory_bytes: 12312
#include<iostream>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0)break;
        int a[9];
        for(int i=0;i<9;i++){
            cin>>a[i];
            n-=a[i];
        }
        cout<<n<<endl;
    }
}


Measured memory_bytes: 3072
/* Be strong, be fearless, be beautiful :D
And believe that anything is possible :))
when you have the right people there
to support you :) */
//RTn_E
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define __Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define __file freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ;
#define ll long long
#define ld long double
#define pb push_back
#define ld long double
#define F first
#define S second
#define mk make_pair
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using mordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 100;
const ll inf = 1e12;

//Main CODE :/\

int main() {
    __Sync;
    ll a , b , c , k;
    cin >> a >> b >> c >> k;
    if (k % 2)
        cout << -a + b << "\n";
    else
        cout << -b + a << "\n";
    return 0;
}
//The_End
//Game Over :D


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  int count = 0;
  while (1)
  {
    for (int &a : A)
    {
      if ((a % 2) == 1)
      {
        cout << count << endl;
        return 0;
      }
      a /= 2;
    }
    count++;
  }
  cout << count << endl;
}


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

int main()
{
	int x, y, i, a, b, c;
	cin >> x >> y;
	a = max(x, y);
	for (i = a; i > 0; i--) {
		if (x%i == 0 && y%i == 0) {
			b = i;
			break;
		}
	}
	c = 1 + x + y - b;
	cout << c << endl;
	return 0;
}



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

int main(){
    int N;
    long T;
    cin >> N >> T;
    long long t_list[200010];
    for(int i=0; i<N; i++){
        cin >> t_list[i];
    }
    long long time = 0;
    for(int i=0; i<N-1; i++){
        if(t_list[i+1]-t_list[i] >= T){
            time += T;
        }else{
            time += t_list[i+1]-t_list[i];
        }
    }
    time += T;
    cout << time;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1792
table = [(0,0)] * 31
dp = [0] * 31

w = int(input())
h = int(input())
for i in range(1,h + 1):
    a,b = (int(_) for _ in input().split(","))
    table[i] = (a,b)

# あみだくじ
for i in range(1,w + 1):
    dest = i
    for j in range(1,h + 1):
        if table[j][0] == dest:
            dest = table[j][1]
        elif table[j][1] == dest:
            dest = table[j][0]
    dp[dest] = i    
    
for i in range(1,w + 1):
    print(dp[i])


Measured memory_bytes: 5604
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect

    n = int(input())
    l = sorted(list(map(int, input().split())))
    ans = 0

    # KeyInsight
    # a < b < c かつ a + b < cとなる組み合わせ
    # 2つの値a, bを決め打ち
    # See:
    # https://www.youtube.com/watch?v=3U_N7zelnMM
    for i in range(n):
        for j in range(i + 1, n):
            ab = l[i] + l[j]
            right = bisect(l, ab - 1)
            left = j + 1
            ans += right - left

    print(ans)


if __name__ == '__main__':
    main()


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

bool is_palindromic_num(int num) {
  int s1 = num / 10000;
  num -= s1 * 10000;
  int s2 = num / 1000;
  num -= s2 * 1000;
  int s3 = num / 100;
  num -= s3 * 100;
  int s4 = num / 10;
  num -= s4 * 10;
  int s5 = num % 10;
  return s1 == s5 && s2 == s4;
}

int main() {
  int A, B;
  cin >> A >> B;

  int cnt = 0;
  for (int i = A; i < B + 1; i++) {
    if (is_palindromic_num(i)) {
      cnt++;
    }
  }

  cout << cnt << endl;
}



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

int N,L;
int A[100010];

int main()
{
    scanf("%d%d",&N,&L);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    int last = 0;
    for(int i = 1; i < N; i++)
    {
        if(A[i] + A[i - 1] >= L)
        {
            last = i;
            break;
        }
    }
    if(last == 0)
    {
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    for(int i = 1; i < last; i++)printf("%d\n",i);
    for(int i = N - 1; i > last; i--)printf("%d\n",i);
    printf("%d\n",last);
    return 0;
}


Measured memory_bytes: 1280
n, m = map(int, input().split())
ans = [10]*n

sl = []
cl = []
for _ in range(m):
    s, c = map(int, input().split())
    if s in sl:
        if cl[sl.index(s)] != c:
            print(-1)
            exit(0)
    sl.append(s)
    cl.append(c)

for i in range(m):
    if ans[sl[i]-1] > cl[i]:
        ans[sl[i]-1] = cl[i]

if ans[0] == 0 and len(ans) != 1:
    print(-1)
    exit(0)

for i in range(len(ans)):
    if i == 0 and ans[i] == 10 and n != 1:
        ans[i] = 1
    elif ans[i] == 10:
        ans[i] = 0

ans2 = []
for i in ans:
    ans2.append(str(i))
ans3 = "".join(ans2)
ans3_len = len(str(int(ans3)))
if n == ans3_len:
    print(int(ans3))
else:
    print(-1)


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

int recur(int st,vector<int>& dp,vector<int> &vec){
    if(!st) return 0;
    if(st<0) return 1e7;
    int &ret=dp[st];
    if(ret!=-1) return ret;
    ret=abs(vec[st]-vec[st-1])+recur(st-1,dp,vec);
    if(st>1) ret=min(ret,abs(vec[st]-vec[st-2])+recur(st-2,dp,vec));
    return ret;
}

signed main(){
    int i,n; scanf("%d",&n);
    vector<int> vec(n),dp(n,-1);
    for(i=0;i<n;++i) scanf("%d",&vec[i]);
    cout<<recur(n-1,dp,vec);
    return 0;
}

Measured memory_bytes: 11876
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>
using namespace std;

//https://beta.atcoder.jp/contests/arc083/tasks/arc083_a

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

int dp[500000]; //bool dp

string s;

int main(){
  int n,isonilpt=-10,onept=-20;
  cin>>n;
  cin>>s;
  s='0'+s;
  REP(i,n+1){
    if(i<=1){
      dp[i]=0;
    }else if(s[i]=='0'){
      dp[i] = dp[i-1];
    }else{
      if(s[i-1]=='0'&&s[i-2]=='1'){
	dp[i]=dp[i-1];
	REP(j,i-1-onept)
	  dp[i] = max(dp[i],dp[onept-1+j]+i-1-onept-j);
      }else if(s[i-1]=='0'){
	dp[i] = dp[i-1];
      }else{
	dp[i] = onept-1==isonilpt?max(dp[isonilpt-2]+i-isonilpt,dp[i-1]):dp[i-1];
      }
    }
    if(i>0&&s[i]=='1'&&s[i-1]=='0')
      onept=i;
    if(i>1&&s[i]=='1'&&s[i-1]=='0'&&s[i-2]=='1')
      isonilpt=i-1;
  }
  cout << dp[n] << endl;
  return 0;
}


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


int main() {
    int A, B;
    cin >> A >> B;
    cout << A*B << endl;

    return 0;
}

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

int main()
{
int N;long long ans=0;scanf("%d",&N);vector<vector<bool>> con(N,vector<bool>(N,true));
vector<vector<int>> A(N,vector<int>(N));vector<vector<int>> B(N,vector<int>(N));
for(int i=0;i<N;i++)for(int j=0;j<N;j++)scanf("%d",&A[i][j]);
for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
{
  B[i][j]=min(A[i][j],A[i][k]+A[k][j]);
  if(B[i][j]!=A[i][j]){printf("-1\n");return 0;}
  if(B[i][j]==A[i][k]+A[k][j]&&i!=k&&j!=k)con[i][j]=false;
}
for(int i=0;i<N;i++)for(int j=0;j<N;j++)
{
  if(con[i][j])ans+=B[i][j];
}
printf("%lld\n",ans/2);
}

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

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for(auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back

typedef long long lli;
typedef long double ld;
typedef pair<int, int> ii;

const int N = 101;
const int K = 4;

lli mem[N][K][2];
short done[N][K][2], timer = 0;
string num;
int k;

lli dp(int i, int cnt, bool small) {
  if (cnt > k)  
    return 0LL;
  if (i == sz(num))
    return cnt == k;
  lli &ans = mem[i][cnt][small];
  if (done[i][cnt][small] != timer) {
    done[i][cnt][small] = timer;
    ans = 0;
    int lo = 0, hi = small ? 9: num[i] - '0';
    fore (x, lo, hi + 1) 
      ans += dp(i + 1, cnt + (x != 0), small | (x < hi));
  } 
  return ans;
} 

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> num >> k) {
    ++timer;
    cout << dp(0, 0, 0) << '\n';
  }
  return 0;
}


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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s, t; cin >> s >> t;
	map<char, char> S, T;
	bool ok = true;
	for(int i = 0; i < s.size(); i++){
		char a = s.at(i), b = t.at(i);
		if(S.count(a)) if(S.at(a) != b) ok = false;
		if(T.count(b)) if(T.at(b) != a) ok = false;
		S[a] = b; T[b] = a;  
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
} 

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  int ans = 0;
  FOR(i, 1, min(n,k)+1) {
    vector<int> jew(i);
    repr(j, i) {
      int nvalue = 0;
      rep(l, j) {
        jew[l] = v[l];
      }
      rep(l, i-j) {
        jew[j+l] = v[n-1-l];
      }
      sort(jew.begin(), jew.end());
      rep(l, k-i) {
        if (l > i-1 || jew[l] >= 0) break;
        if (jew[l] < 0) jew[l] = 0;
      }
      rep(l, i) {
        nvalue += jew[l];
      }
      ans = max(ans, nvalue);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))

f=True
c=0
o=0

for i in range(N):
    if a[i]%2!=0:
        f=False
        o+=1
    if a[i]%4==0:
        c+=1

if f:
    print("Yes")
    exit()
if c>=o:
    print("Yes")
    exit()
if c>=N//2:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 14252
N,K= map(int,input().split())
mod = 10**9+7
def comb(n,k):
  """power_funcを用いて(nCk) mod p を求める"""
  p = 10**9+7
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
R = N-K


for i in range(1,K+1):
    # blue
#    if i == 1:
#        b_div = 2
#    else:
#    print(R,i)
    b_div = comb(K-1,i-1)%mod
    # RED
#    if (R+1)<i:
#        print('0')
#    else:
    r_div = comb(R+1,i)%mod
#        if i == K+1:
#            r_div += comb(R+1,i+1)%mod
        
#        print(b_div,r_div)
    print(int(b_div*r_div)%mod)

Measured memory_bytes: 76124
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] + a[1] == a[2]) cout << "Yes" << endl;
  else  cout << "No" << endl;
}

Measured memory_bytes: 256
using System;


namespace Card_Game
{
	class Program
	{
		static int Main ( string[] args )
		{
			while (true)
			{
				//??\???
				int processCount = int.Parse (Console.ReadLine ());

				if (processCount == 0)
				{
					break;
				}

				Cards[] cards = new Cards[processCount];
				for (int lp = 0; lp < cards.Length; lp++)
				{
					string[] inputStr = Console.ReadLine ().Trim ().Split (' ');
					cards[lp] = new Cards (inputStr[0], inputStr[1]);
				}

				//??????
				PlayerPoint playerA = new PlayerPoint ();
				PlayerPoint playerB = new PlayerPoint ();

				foreach (var item in cards)
				{
					//A??´?????????
					if (item.Card1 > item.Card2)
					{
						int sum = item.Card1 + item.Card2;
						playerA.Sum (sum);
					}
					//B??´?????????
					else if (item.Card1 < item.Card2)
					{
						int sum = item.Card1 + item.Card2;
						playerB.Sum (sum);
					}
					//???????????????
					else
					{
						playerA.Sum (item.Card1);
						playerB.Sum (item.Card2);
					}
				}

				//??????
				Console.WriteLine (playerA.Point + " " + playerB.Point);
			}

			return 0;
		}
	}
}


class PlayerPoint
{
	public PlayerPoint ()
	{
		this.Point = 0;
	}
	public int Point { private set; get; }
	public void Sum ( int point )
	{
		this.Point += point;
	}
}

class Cards
{
	public Cards ( string card1, string card2 )
	{
		this.Card1 = int.Parse (card1);
		this.Card2 = int.Parse (card2);
	}
	public int Card1 { private set; get; }
	public int Card2 { private set; get; }
}

Measured memory_bytes: 9828
n = gets.chomp.split("").map(&:to_i)
n.reverse!
n << 0
ans = 0
n.each_with_index do |digit, index|
  if digit <= 4
    ans += digit
  elsif digit == 5
    n[index + 1] += 1 if n[index + 1] >= 5
    ans += 5
  else
    ans += 10 - digit
    n[index + 1] += 1
  end
end
puts ans


Measured memory_bytes: 76664
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
using namespace std;

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

    int N;
    cin >> N;

    vector<int> a;
    vector<double> b;

    REP(i, N) {
        double x;
        string y;
        cin >> x >> y;

        if (y == "JPY")
            a.push_back(int(x));
        else
            b.push_back(x);
    }

    double sum = 0;
    REP(i, a.size()) sum += a[i];
    REP(i, b.size()) sum += 380000 * b[i];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    vector<ll> sc;
    vector<ll> sab;

    rep(i,x){ cin>>a[i]; }
    rep(i,y){ cin>>b[i]; }
    rep(i,z){cin>>c[i]; }

    sort(c.rbegin(),c.rend());

    vector<ll> ab;
    for(int long long i=0;i<y;i++){
        for(int long long j=0;j<x;j++){
            ab.push_back(a[j]+b[i]);
        }
    }

    sort(ab.rbegin(),ab.rend());
    ll absize=ab.size();
    ll u=min(k,absize);
    rep(i,u){
        sab.push_back(ab[i]);
    }
    //sort(sab.rbegin(),sab.rend());

    vector<ll> ans;

    for(int long long i=0;i<c.size();i++) {
        for (int long long j = 0; j < sab.size(); j++) {
            ans.push_back(sab[j] + c[i]);
        }
    }

    sort(ans.rbegin(),ans.rend());

    rep(i,k){
        cout<<ans[i]<<endl;
    }

    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    int tmp = 0;
    int mx = 0;
    for (int i=1; ; i++) {
        tmp += i;
        if (tmp >= N) {
            // DUMP2(i, tmp);
            mx = i;
            break;
        }
    }

    while (N > 0 && mx > 0) {
        if (N >= mx) {
            N -= mx;
            cout << mx << endl;
        }
        mx--;
    }
    assert(N == 0);
}



Measured memory_bytes: 384
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
		if (a==b){
        	System.out.print(c);
        }else if(b==c){
        	System.out.print(a);
        }else{
		    System.out.print(b);
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k;
	cin>>n>>k;
	double a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	double L=0,R=1e9;
	for(int ii=0;ii<100;ii++){
		double M=(L+R)/2;
		int cur=0;
		for(int i=0;i<n;i++){
			cur+=max(0,(int)ceil(a[i]/M)-1);
		}
		if(cur<=k){
			R=M;
		}else{
			L=M;
		}
	}
	cout<<(int)ceil(R)<<"\n";
}



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

int main(){

    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
    }

    int m;
    cin >> m;
    vector<string> t(m);
    for(int i=0; i<m; i++){
        cin >> t.at(i);
    }

    int count=1;
    int ans=0;
    for(int i=0; i<n-1; i++){
        for(int j=n-1; j>0; j--){
            if(s.at(i)==s.at(j)) count++;
        }
        for(int j=0; j<m; j++){
            if(s.at(i)==t.at(j)) count--;
        }
        ans=max(count,ans);
        count=0;
    }   
    cout << ans <<endl;
//    if(s.at(0)==s.at(2)) cout << 1 << endl;
}

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

N,Q=[int(x) for x in input().strip().split()]
S=input().strip()
n=[]
cnt=0
p=''
for s in S:
    if p=='A' and s =='C':
        cnt+=1
        p=''
    else:
        p=s
    n.append(cnt)

for _ in range(Q):
    l,r=[int(x) for x in input().strip().split()]
    ans = n[r-1]-n[l-1]
    print(ans)


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

string s;
int X, Y;

const int R_MAX = 8000;

int main () {
  cin >> s >> X >> Y;
  vector<set<int>> sr(2);

  int x0 = 0;
  while(s[x0] == 'F') x0++;
  sr[0].insert(x0);
  sr[1].insert(0);

  for(int i = x0+1, dir = 1; i < s.size(); i++, dir ^= 1) {
    int d = 0;
    while(s[i] == 'F') {
      i++;
      d++;
    }
    set<int> s;
    for(int r: sr[dir]) {
      s.insert(r+d);
      s.insert(r-d);
    }
    sr[dir] = s;
  }

  if(sr[0].find(X) != sr[0].end() && sr[1].find(Y) != sr[1].end()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 768
#!/usr/bin python3
# -*- coding: utf-8 -*-

import numpy as np

n = int(input())
s = [list(input())*2 for _ in range(n)]
s = s * 2
s = np.array(s)
ret = 0
for a in range(n):
    si = s[a:a+n, :n]
    if (si == si.T).all():
        ret += 1
print(ret*n)


Measured memory_bytes: 29404