akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  int a, b, c;
  cin>>a>>b>>c;
  if(a+b == c or a+c == b or c+b== a)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 256
import sys
n=int(input())
ab=[]
for i in range(n):
  AB=[int(x) for x in input().rstrip().split()]
  ab.append(AB)
# ab=sorted(ab,key=lambda x :x[0])
ab=sorted(ab,key=lambda x :x[1])

time=0
for a,b in ab:
  if time+a<=b:
    time+=a
  else:
    print("No")
    sys.exit()

print("Yes")

Measured memory_bytes: 45352
n=int(input())
l=[1,6,36,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5]
l.sort(reverse=True)
dp=[float("inf")]*1000000
dp[0]=0
for i in range(1,n+1):
    for j in l:
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+1)
print(dp[n])

Measured memory_bytes: 73436
n = int(input())
cnt=0
p=list(map(int,input().split()))

for i in range(n-2):
    l=[p[i],p[i+1],p[i+2]]
    l.sort()
    if l[1]==p[i+1]:
        cnt+=1
        l=[]
    else:
        l=[]
print(cnt)


Measured memory_bytes: 3060
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
sum,max = 2.times.map{Array.new(n+1,0)}
ans = 0
for i in 1..n
  sum[i] = sum[i-1]+a[i-1]
  max[i] = max[i-1]
  max[i] += a[i-1] if a[i-1] > 0
end
for i in 0..n-k
  temp = max[i]-max[0]+max[n]-max[i+k]
  temp += sum[i+k]-sum[i] if sum[i+k]-sum[i] > 0
  ans = ans > temp ? ans : temp
end
puts ans

Measured memory_bytes: 11404
#include <stdio.h>
int main(void)
{
	char str[10];
	int a;
	int b;

	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d", &a, &b);
	printf("%d %d\n", a*b, 2*(a+b));

	return 0;
}

Measured memory_bytes: 604
# ALDS1_3_B.py
from collections import deque as queue
N, Q = map(int, input().split())
q = queue()
for i in range(N):
    n, t = input().split()
    q.append((n, int(t)))
total = 0
while len(q) != 0:
    n, t = q.popleft()
    if t <= Q:
        total += t
        print(n, total)
    else:
        total += Q
        q.append((n, t-Q))



Measured memory_bytes: 12536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        class Node
        {
            internal int id;
            internal int key;
            internal int parentId { get { return id / 2; } }
            internal int leftId { get { return id * 2; } }
            internal int rightId { get { return id * 2 + 1; } }

            public Node(int i, int k)
            {
                id = i;
                key = k;
            }
        }

        static void Main(string[] args)
        {
            int h = int.Parse(Console.ReadLine());
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Node[] A = new Node[h + 1];

            for (int i = 0; i < h; i++) A[i + 1] = new Node(i + 1, input[i]);

            StringBuilder sb;
            for (int i = 1; i <= h; i++)
            {
                sb = new StringBuilder();
                sb.Append("node " + A[i].id + ": key = " + A[i].key + ", ");
                if (A[i].parentId >= 1) sb.Append("parent key = " + A[A[i].parentId].key + ", ");
                if (A[i].leftId <= h) sb.Append("left key = " + A[A[i].leftId].key + ", ");
                if (A[i].rightId <= h) sb.Append("right key = " + A[A[i].rightId].key + ", ");
                Console.WriteLine(sb);
            }
        }
    }
}

Measured memory_bytes: 9324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 1LL<<25;

int main()
{
ll n , m , x ;
cin >> n >> m >> x ;
vector<vector<ll>> v(n, vector<ll>(m,0) );
vector<ll> c(n,0);
rep(i,n){
  cin >> c[i] ;
  rep(j,m)cin >> v[i][j];
}
rep(i,1LL<<n){
  vector<ll> t(n,0);
  ll co=0;
  rep(j,n)if(i>>j&1LL){
    rep(k,m)t[k]+=v[j][k];
    co+=c[j];
  }
  bool ok=1;
  rep(i,m)if(t[i]<x)ok=0;
  if(ok)ans=min(co,ans);
}
cout << (ans>(1LL<<24)?-1:ans) << endl;
return 0;
}

Measured memory_bytes: 3632
/*
 *  Author :: Kattu37
 */

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortallr(x) sort(allr(x))
#define PI 3.1415926535897932384626
#define mod 1000000007

typedef pair<int, int>  pii;
typedef pair<ll, ll>  pll;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pll>   vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;

void solve()
{
	ll n, d;
	cin >> n >> d;
	ll x, y;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> x >> y;
		if (sqrt(x * x + y * y) <= d)
			count++;
	}
	cout << count << "\n";
}

int main(void)
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

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

	return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

double distance(double x1,double y1,double x2,double y2){
	return sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int factorial(int n){
	if( n == 0) return 1;
	return n*factorial(n-1);
}
int main()
{
	int N;
	cin>>N;
	double *X = new double[N];
	double *Y = new double[N];
	int *index = new int[N];
	for(int i = 0; i < N; i++){
		index[i] = i;
		cin>>X[i]>>Y[i];
	}
	double sum = 0;
	do{
		for(int i = 0; i < N - 1; i++){
			sum += distance(X[index[i]],Y[index[i]],X[index[i+1]],Y[index[i+1]]);
		}
	}while(next_permutation(index,index + N));
	printf("%.10lf\n",sum/factorial(N));
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
mt19937 ran(time(nullptr));
inline int get_mod(int x){
	return x<mod?x:x-mod;
}
struct Hasher{
	int v,v2;
	Hasher(int _v=0,int _v2=0):v(_v),v2(_v2){}
	inline Hasher operator+(const Hasher& rhs) const{
		return Hasher(get_mod(v+rhs.v),get_mod(v2+rhs.v2));
	}
	inline Hasher operator-(const Hasher& rhs) const{
		return Hasher(get_mod(v+mod-rhs.v),get_mod(v2+mod-rhs.v2));
	}
	inline Hasher operator*(const Hasher& rhs) const{
		return Hasher((ll)v*rhs.v%mod,(ll)v2*rhs.v2%mod);
	}
	inline bool operator<(const Hasher& rhs) const{
		return v!=rhs.v?v<rhs.v:v2<rhs.v2;
	}
	inline bool operator==(const Hasher& rhs) const{
		return v==rhs.v && v2==rhs.v2;
	}
} mul_pow[500010],inv_pow[500010],mul=Hasher(ran()%mod,ran()%mod),hash_v[250010];
map<Hasher,int> dic;
char str[250010];
inline Hasher qpow(Hasher base,int pw){
	Hasher res=Hasher(1,1);
	while(pw){
		if(pw&1) res=res*base;
		base=base*base;
		pw>>=1;
	}
	return res;
}
int main(){
	int n;
	scanf("%d%s",&n,str+1);
	mul_pow[0]=Hasher(1,1);
	inv_pow[0]=Hasher(1,1);
	Hasher mul_inv=qpow(mul,mod-2);
	for(int i=1;i<=2*n;i++){
		mul_pow[i]=mul_pow[i-1]*mul;
		inv_pow[i]=inv_pow[i-1]*mul_inv;
	}
	int pos=n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(str[i]=='+'){
			hash_v[i]=hash_v[i-1]+mul_pow[pos];
		}else if(str[i]=='-'){
			hash_v[i]=hash_v[i-1]-mul_pow[pos];
		}else if(str[i]=='>'){
			pos++;
			hash_v[i]=hash_v[i-1];
		}else if(str[i]=='<'){
			pos--;
			hash_v[i]=hash_v[i-1];
		}
	}
	pos=n;
	for(int i=1;i<=n;i++){
		if(hash_v[i]==hash_v[n]) ans++;
		if(str[i]=='>') pos++;
		else if(str[i]=='<') pos--;
		ans+=dic[hash_v[i]];
		if(pos<n)
			dic[hash_v[n]*inv_pow[n-pos]+hash_v[i]]++;
		else
			dic[hash_v[n]*mul_pow[pos-n]+hash_v[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 41472
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n;
long long x;
vector<long long> v, w;

long long llm = (1ll << 62);

long long f(int m) {
  long long ret = x * (n + m);
  long long k = 1;
  ret += 2 * (w[n] - w[n - m]);
  for (int i = n - 1; i >= 0;) {
    if (ret + (2 * k + 1) * (w[i + 1] - w[max(0, i + 1 - m)]) < ret)
      return llm;
    ret += (2 * k + 1) * (w[i + 1] - w[max(0, i + 1 - m)]);
    k++;
    i -= m;
  }
  return ret;
}

int main() {
  cin >> n >> x;
  v.resize(n);
  w.resize(n + 1);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i < n; i++)
    w[i + 1] = w[i] + v[i];
  long long m = f(1);
  for (int i = 2; i <= n; i++)
    m = min(m, f(i));
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ss[110];
int main()
{
    int n,m,c;
    while(~scanf("%s",&ss))
    {
        int len=strlen(ss);
        cout<<ss[0]<<len-2<<ss[len-1]<<endl;
        memset(ss,0,sizeof(ss));
    }
    return 0;
}


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

int main() {
  long N;
  cin >> N;
  char c;
  vector<bool> s(N,0);
  for (int i = 0; i < N; i++) {
    cin >> c;
    if (c == 'R') {
      s.at(i) = 1;
    }
  }
  
  int start;
  for (start = 0; start < N; start++) {
    if (s.at(start) == 0) {
      break;
    }
  }
  int count = 0, end = N-1;
  vector<int> sw(N,0), sr(N,0);
  for (int i = start; i < N; i++) {
    if (s.at(i) == 0) {
      for (int j = end; j > i; j--) {
        if (s.at(j) == 1) {
          end = j-1;
          count++;
          break;
        }
        end = j;
      }
    }
    if (start >= end) {
      break;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 4836
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(B) > sum(A):
    print(-1)
else:
    diff = [a-b for a,b in zip(A,B)]
    plus = []
    minus_num = 0
    lack = 0
    for d in diff:
        if d >= 0:
            plus.append(d)
        elif d < 0:
            minus_num += 1
            lack += d
    plus.sort(reverse=True)
    i = 0
    while lack < 0:
        lack += plus[i]
        i += 1
        
    print(N-len(plus)+i)

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

int h, w, n, sr, sc;
string s, t;

int f(int p, int q, char x, char y) {
	int i, k;
	for(i=0, k=p; i<n; i++) {
		if(s[i]==x) k--;
		if(k<=0) return 1;
		if(t[i]==y) k = min(q, k+1);
	}
	for(i=0, k=p; i<n; i++) {
		if(s[i]==y) k++;
		if(k>q) return 1;
		if(t[i]==x) k = max(1, k-1);
	}
	return 0;
}

int main() {
	cin >> h >> w >> n >> sr >> sc >> s >> t;
	if(f(sc, w, 'L', 'R') || f(sr, h, 'U', 'D')) puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 776
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  int a = sqrt(N);
  co(a * a);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define N 1000002
vector<int> cl(N,-1);
int collatz(int n){
	int c=0;
	while(n<N){
		if(cl[n]!=-1)
			return c+cl[n];
		if(n%2==0){
			n/=2;
			++c;
		}else if(n%2==1){
			n=n*3+1;
			++c;
		}
	}
	return 0;
}
int main()
{
	cl[1]=0;
	for(int i = 1; i < N; ++i){
		cl[i] = collatz(i);
	}

	while(true){
		int n;
		
		cin>>n;
		if(n==0)break;

		cout << cl[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 998244353;//1e9 + 7;

long long int pow_m1(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int DP[110000] = {};
long long int DP2[110000] = {1};

int main(){
    int N;
    cin >> N;
    DP[0] = 1;
    for(int i = 0; i < N - 1; i++){
        DP[0] *= 2;
        DP[0] %= MOD;
    }
    int S = 0;
    long long int rev2 = pow_m1(2);
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        for(int j = 100000; j >= a; j--){
            DP[j] += DP[j - a] * rev2;
            DP[j] %= MOD;
            DP2[j] += DP2[j - a];
            DP2[j] %= MOD;
        }
        S += a;
    }
    long long int ans = 1;
    for(int i = 0; i < N; i++){
        ans *= 3;
        ans %= MOD;
    }
    for(int i = 100000; i >= S / 2 + (S % 2); i--){
        ans -= DP[i] * 6;
        ans += MOD * 10;
        ans %= MOD;
    }
    if(S % 2 == 0){
        ans += DP2[S / 2] * 3;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import time

N, Y = map(int, input().split())

start = time.time()
judge_flag = False
first_a = -1
second_b = -1
theard_c = -1
for a in range(N + 1):
    for b in range(N + 1):
        if Y == 10000 * a + 5000 * b + 1000 * (N - a - b) and (N - a - b) >= 0:
            first_a = a
            second_b = b 
            theard_c = (N - a - b)
            break
    if Y == 10000 * a + 5000 * b + 1000 * (N - a - b) and (N - a - b) >= 0:
         break

elapsed_time = time.time() - start
print("{} {} {}".format(first_a, second_b, theard_c))
# print('elapsed_time {}'.format(elapsed_time))


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, a;
  ll p = 0, q = 0;
  cin >> n;
  set<int> s;
  rep(i,n)
  {
    cin >> a;
    if (s.end() == s.find(a)) {
      s.insert(a);
    } else {
      if (p <= a) {
        q = p;
        p = a;
      } else if (q < a) {
        q = a;
      }
      s.erase(a);
    }
  }
  if (q > 0) {
    cout << p * q;
  } else {
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 4992
/*
csc -debug B.cs && mono --debug B.exe <<< "3 7"
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var K = cin.NextLong();
        var X = cin.NextLong();

        var min = -1000000L;
        var max =  1000000L;

        var ans = new List<long>();

        for (var a = Math.Max(min, X - K + 1); a <= Math.Min(max, X + K - 1); a++)
            ans.Add(a);

        System.Console.WriteLine(ans.Join());
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr, string sep = " ") {
        return string.Join(sep, arr);
    }

    public static void Swap<T>(ref T a, ref T b) {
        var tmp = a;
        a = b;
        b = tmp;
    }

    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
          
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define fa fflush(stdout); 
#define mp make_pair
using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);;                                                      
} 
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};
  
const int N = 5e3 + 100;
const ll mod = 1e9 + 7; //998244353;
const ll big = 1e9;

ll dp[N]; 
int main() 
{
	data();
	//freopen("mountains.in", "r", stdin);
   	//freopen("mountains.out", "w", stdout);          
   	int n;
   	cin >> n;
   	dp[0] = 1;
   	for (int i = 0; i <= n; i++)
   	{
   		if (dp[i] > 0)
   		{
   			dp[i] %= mod;
   			for (int j = 3; j <= n; j++)
   			{
   				if (i + j <= n)
   				{
   		    		dp[i + j] += dp[i];
   				}
   			}
   		}
   	}
   	cout << dp[n];
}                    

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

int main()
{
    int D; cin >> D;
    int c[27];
    for(int i=1; i<27; i++) cin >> c[i];
    int s[D+1][27];
    for(int i=1; i<=D; i++){
        for(int j=1; j<27; j++) cin >> s[i][j];
    }
    int t[D+1];
    int last[D+1][27];
    int pre_last[D+1][27];
    for(int i=1; i<=D; i++){
        for(int j=1; j<27; j++) last[i][j] = 0;
    }

    long long int sat = 0;
    long long int cur_sat = 0;
    int max_index_i = -1;
    
    
    for(int d=1; d<=D; d++){
        long long int max_sat = 0;
        for(int i=1; i<27; i++){
            //iを選んだ場合
            //得られる満足度
            sat = cur_sat;
            sat += s[d][i];
            for(int dd = d; dd<=D; dd++){
                pre_last[dd][i] = last[dd][i];
                last[dd][i] = d;
            }
                
            //失われる満足度
            for(int j=1; j<=26; j++){
                sat -= c[j]*(d-last[d][j]);
            }
            if(sat > max_sat) { max_sat = sat; max_index_i = i; }
            for(int dd = d; dd<=D; dd++){
                last[dd][i] = pre_last[dd][i];
            }
        }
        cur_sat = max_sat;
        for(int dd = d; dd<=D; dd++){
            last[dd][max_index_i] = d;
        }
        t[d] = max_index_i;
    }

    for(int d=1; d<=D; d++) cout << t[d] << endl;

    return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a>b)
	printf("a > b\n");
	else if(a==b)
	printf("a == b\n");
	else
	printf("a < b\n");
	return 0;
}


Measured memory_bytes: 1972
#include <stdio.h>
#include <vector>
#include <algorithm>

int main()
{
  std::vector<int> hills(10);
  for (int i = 0; i < 10; i++) {
    int temp;
    scanf("%d", &temp);
    hills[i] = temp;
  }
  std::sort(hills.begin(), hills.end());
  std::reverse(hills.begin(), hills.end());
  for (int i = 0; i < 3; i++) {
    printf("%d\n", hills[i]);
  }
  return 0;
}



Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+4;
pair<int,int>p[M];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		p[i]={x,i};
	}
	sort(p,p+n);
	for(int i=0;i<n;i++)
	cout<<p[i].second+1<<" ";
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int N, dummy;
	dummy = scanf("%d", &N);

	short input[100000][3];
	int tmp[3];

	memset(input, 0, sizeof(input));

	int tmp1, tmp2, tmp3;
	for (int i = 0; i < N; i++) {
		dummy = scanf("%d %d %d", &tmp1, &tmp2, &tmp3);
		input[i][0] = tmp1;
		input[i][1] = tmp2;
		input[i][2] = tmp3;
	}

	tmp[0] = input[0][0];
	tmp[1] = input[0][1];
	tmp[2] = input[0][2];

	for (int n = 1; n < N; n++) {
		int tmp01 = tmp[0] + input[n][1];
		int tmp02 = tmp[0] + input[n][2];
		int tmp10 = tmp[1] + input[n][0];
		int tmp12 = tmp[1] + input[n][2];
		int tmp20 = tmp[2] + input[n][0];
		int tmp21 = tmp[2] + input[n][1];
		tmp[0] = max(tmp10, tmp20);
		tmp[1] = max(tmp01, tmp21);
		tmp[2] = max(tmp02, tmp12);
	}
	
	printf("%lld\n", max(tmp[0], max(tmp[1], tmp[2])));
	
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "<\n";
    } else if (a > b) {
        cout << ">\n";
    } else {
        cout << "=\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n&&m){
    int cnt[111]={};
    int ans=0;
    for(int i=0;i<n;i++){
      int d,v;
      cin>>d>>v;
      cnt[d]=max(cnt[d],v);
    }
    for(int i=1;i<=m;i++)ans+=cnt[i];
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3028
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - last[j]);
        }
        println!("{}", res);
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut v = vec![];
    for _ in 0..d {
        input! {
            buf:[isize;26]
        }
        v.push(buf);
    }
    let mut plan = vec![];
    for _ in 0..d {
        input! {t:Usize1}
        plan.push(t);
    }
    calc(&v, &plan, &c);
}


Measured memory_bytes: 2280
fn gcd(a: i64, b: i64, buf: &mut std::collections::HashMap<(i64, i64), i64>) -> i64 {
    if let Some(v) = buf.get(&(a, b)) {
        return *v;
    }
    let ret = if b == 0 { a } else { gcd(b, a % b, buf) };
    buf.insert((a, b), ret);
    ret
}

fn main() {
    proconio::input! {
        k: i64,
    }
    let mut buf = std::collections::HashMap::new();
    let mut sum = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                let ab = gcd(a, b, &mut buf);
                sum += gcd(ab, c, &mut buf);
            }
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4604
#!/usr/bin/env python3
import sys

def solve(X: int):

    for i in range(-150, 150):
        for j in range(-150, 150):
            if j**5 - i**5 == X:
                print(j, i)
                return
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63564
import scala.io.StdIn.readLine
 
object Main {
  def euclid(m:Int,n:Int):Int = if(n==0) m else euclid(n,m%n)
  def main(args:Array[String]) = {
      val n = readLine.split(" ").map(_.toInt)
      println(euclid(n(0),n(1)))
  }
}

Measured memory_bytes: 43736
S = [input() for i in range(3)]

flag = True
num_who = 0

while flag:
    if num_who == 0:
        if S[num_who].startswith('a'):
            S[num_who] = S[num_who][1:]
        elif S[num_who].startswith('b'):
            S[num_who] = S[num_who][1:]
            num_who = 1
        elif S[num_who].startswith('c'):
            S[num_who] = S[num_who][1:]
            num_who = 2
        else:
            print("A")
            flag = False
    elif num_who == 1:
        if S[num_who].startswith('a'):
            S[num_who] = S[num_who][1:]
            num_who = 0
        elif S[num_who].startswith('b'):
            S[num_who] = S[num_who][1:]
        elif S[num_who].startswith('c'):
            S[num_who] = S[num_who][1:]
            num_who = 2
        else:
            print("B")
            flag = False
    elif num_who == 2:
        if S[num_who].startswith('a'):
            S[num_who] = S[num_who][1:]
            num_who = 0
        elif S[num_who].startswith('b'):
            S[num_who] = S[num_who][1:]
            num_who = 1
        elif S[num_who].startswith('c'):
            S[num_who] = S[num_who][1:]
        else:
            print("C")
            flag = False


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

int main(void)
{
    long long A, V;
    cin >> A >> V;

    long long B, W;
    cin >> B >> W;

    long long T;
    cin >> T;

    if (W >= V) {
        cout << "NO" << endl;

        return 0;
    }

    long long dv = V - W;
    long long d = abs(A - B);
    if (d <= dv * T)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std; 
int main()
{
int N,a,ans;
cin>>N;
a=N/15;
ans=800*N-a*200;
cout<<ans; 
return 0;
}


Measured memory_bytes: 256
from itertools import combinations
N, K = map(int, input().split())

if K > ((N - 1) * (N - 2)) // 2:
    print(-1)
    exit()

print(N - 1 + ((N - 1) * (N - 2)) // 2 - K)
for i in range(2, N + 1):
    print(1, i)

t=list(combinations([j+2 for j in range(N-1)],2))
for i in range(((N - 1) * (N - 2)) // 2 - K):
    print(*t[i])



Measured memory_bytes: 3992
// g++ -std=c++11 test.cpp && ./a.out
// g++ -std=c++11 bfs.cpp && cat bfs.txt | ./a.out

#include <algorithm>
#include <iostream>
#include <queue>
#include <functional>
#include <numeric>
#include <math.h>

using namespace std;

#define PRINT(A) {for (int i = 0; i < A.size(); i++) { cout << A[i] << " ";} cout << endl;}
#define SUM(A) accumulate(A.begin(), A.end(), 0)
#define MAX(A) *max_element(A.begin(), A.end())
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int main() {
    int N;
    long D;
    cin >> N >> D;
    VVI points;
    int ans = 0;
    REP(i, N) {
        long X, Y;
        cin >> X >> Y;
        if (X*X + Y*Y <= D*D) {
            ans += 1; 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <algorithm>

using namespace std;

int main (){
    int N;
    cin >> N;
    vector<tuple<string, int ,int>> a;

    for(int i=0; i<N; ++i){
        string S;
        int P;
        cin >> S >> P;
        P = -P;
        a.push_back(tie(S,P,i));
    }

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

    for (int i = 0; i < N; i++){
        cout << get<2>(a[i])+1 << endl;
    }

}

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

const int MAX = 1000;
int main() {
	int N;
	pair<int64_t, int64_t> P[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) cin >> P[i].first >> P[i].second;
	
	for (int i = 1;i < N;++ i) { // 不可能条件を先に消すよ！
		if ((abs(P[i].first - P[0].first + P[i].second - P[0].second) & 1) != 0) { // 偶奇一致しないと無理
			cout << -1;
			return 0;
		}
	}
	int m = 30;
	bool isEven = (abs(P[0].first + P[0].second) & 1) == 0;
	cout << m + (isEven ? 2 : 1) << endl;
	for (int i = m;i >= 0;-- i) cout << (1 << i) << " ";
	if (isEven) cout << 1;
	cout << endl;
	
	for (int i = 0;i < N;++ i) {
		if (isEven) ++ P[i].first;
		for (int j = m;j >= 0;-- j) {
			if (abs(P[i].first) >= abs(P[i].second)) {
				if (P[i].first >= 0) {
					P[i].first -= 1 << j;
					cout << 'R';
				} else {
					P[i].first += 1 << j;
					cout << 'L';
				}
			} else {
				if (P[i].second >= 0) {
					P[i].second -= 1 << j;
					cout << 'U';
				} else {
					P[i].second += 1 << j;
					cout << 'D';
				}
			}
		}
		if (isEven) cout << 'L';
		cout << endl;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、全て|X|, |Y|上で考える
え、負数どうするのって？後で符号反転すれば良いでしょ

で、その時のX_i+Y_iとX_j+Y_jの差が偶数の時、その差の半分のアームが2個あれば両方に対応できる
小さい方には折り畳み、そうでない方は伸ばせば良いからね

制約から、1,1,2,4,8,...,2^38を考えてみよう
この時、これを2^37まで片方に伸ばして最後だけ折りたたむと原点に戻る
後は逆方向に1個やると、その値の2倍だけ長さが減る
逆に、横方向に1個やると、その値と同値だけ長さが減る
偶奇一致してないとダメそう、-1
逆に一致してるなら、最初のある点の位置まで動かすアームを2個導入すれば、全ての値が偶数になるので何とかなりそう

次に、横方向をまずは合わせる
これは、値についてそのbitの位置を動かせば良い
例えば7なら1,2,4を横向きに
例えば10なら2,8を横向きに
この後、縦方向から横方向の値を引き算する
残った値を縦方向で調節、これは逆方向に残った値分動かすイメージでおｋ

おや、同値どうする？例えば4, 8
1, 1, 2を横方向、残り……?とかの時
これは4が余るので、1, 1, 2を畳んでしまうと良い
お、大きい方から作れば必ず作れるのでは
例えば15, 7を考えて、15=1+2+4+8とする
その時7は……えーと、15=16-1にすれば7=1+2+4かいけるな(面倒な)
これ、何らかの計算で導出できないかな？
両方を奇数と仮定しようか(偶数なら動かせば良いので)
その時、両方に1を配り、残りを何とかすれば良い
ここで、a±1, b±1の4通りのうちどれか一つは必ず被らない作り方がある、これは真か？
13と13を考えると、12=4+8,14=16-2……行けるか……？
ちょっとアプローチを変えて、次のようなことを考えてみる
a <= bとする
この時、先にbに対してb以上の最小の2^xを割り当てる(使われているなら2^x-1を割り当てる)

以下、解説AC
考察はこのまま残しておきます
*/

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

int main(){
    long a;
    cin >> a;
    long b;
    cin >> b;
    long c[a];
    long d = 0;
    for(long i = 0; i < a; i++){
        cin >> c[i];
        d += c[i];
    }
    sort(c,c + a);
    long cnt = 0;
    for(long i = a - 1; i >= 0; i--){
        if(cnt < b){
            d -= c[i];
            cnt++;
        }
        else break;
    }
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int main(){
  char s[100]; scanf("%s",s);
  int l,hl,c=0; l=strlen(s);
  if(l%2==0) hl=l/2; else hl=(l+1)/2;
  for(int i=0; i<hl; i++){
    if (s[i]!=s[l-i-1]) c++;
  }printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>

int cum[200001];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int p[200000];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", p + i);
		cum[i + 1] = cum[i] + p[i];
	}
	int max = 0;
	int maxi = 0;
	for (int i = 0; i <= n - k; ++i)
	{
		if (max < cum[i + k] - cum[i])
		{
			max = cum[i + k] - cum[i];
			maxi = i;
		}
	}
	double ans = 0;
	for (int i = 0; i < k; ++i)
	{
		ans += (double)(p[maxi + i] + 1) / 2.;
	}
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 1792
N = gets.to_i
S = gets.chomp

tbl1 = Array.new(26, 0)
tbl2 = Array.new(26, 0)

N.times do |i|
  c = S[i].ord - 'a'.ord
  tbl2[c] += 1
end

ans = 0
N.times do |i|
  c = S[i].ord - 'a'.ord
  tbl1[c] += 1
  tbl2[c] -= 1
  cnt = 26.times.count { |j| tbl1[j].positive? && tbl2[j].positive? }
  ans = [ans, cnt].max
end

puts ans


Measured memory_bytes: 1916
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//222
	int n;
	cin>>n;
	while(n--){
		int val;
		cin>>val;
		if(val&1){
			cout<<"first";
			return;
		}
	}cout<<"second";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3588
class Fixnum
    def pow_binary_mod(y)
        x = self
        z = 1
        while y != 0
            while y % 2 == 0
                x = x * x % $N
                #y = y / 2
                y = y >> 1
            end
            y = y - 1
            z = z * x % $N
        end
        z
    end
    def /(n)
        m=(n%$N+$N)%$N
        raise if m==0
        self*m.pow_binary_mod($N-2)%$N
    end
end
loop{
    n,exp=gets.chomp.gsub(' ','').split(':')
    $N=n.to_i
    break if $N==0
    begin
        puts "#{exp} = #{(eval(exp)%$N+$N)%$N} (mod #{$N})"
    rescue
        puts :NG
    end
}

Measured memory_bytes: 15864
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	const int N=10000000;
	deque<bool> isp(N+1,true);
	isp[0]=isp[1]=false;
	rep(i,N+1) if(isp[i]) for(int j=i+i;j<=N;j+=i)
		isp[j]=false;
	
	for(int n;cin>>n,n;){
		for(int i=n;;i--)
			if(isp[i] && isp[i-2] && isp[i-6] && isp[i-8]){
				cout<<i<<endl;
				break;
			}
	}
	
	return 0;
}

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


import sys
import math

#1整数
#n = int(input())

#空白区切り2整数
#n ,m = list(map(int, input().split()))

#空白区切りリスト
#a=list(map(int, input().split()))

s = input().split('/')



if int(s[0]) > 2019:
    print('TBD')
    quit()
if int(s[0]) == 2019 and int(s[1]) > 4:
    print('TBD')
    quit()

print('Heisei')





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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	string s;
  ll n, result = 0, cand = 0;
  cin >> n >> s;
  FOR(i, 1, n) {
    set<char> x;
    set<char> y;
    cand = 0;
    rep(j, i) x.insert(s[j]);
    FOR(j, i, n) y.insert(s[j]);
    for(auto j : x) {
      for(auto k : y) {
        if (j == k) cand++;
      }
    }
    result = max(result, cand);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
main = getLine >>= print . (theList !!) . pred . read

theList = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]


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

int n;
double d,x,ans;

void work()
{
	scanf("%d %lf %lf",&n,&d,&x);
	for (; n; n--)  ans+=d+(2*n-1)*x/2,d=((2*n+2)*d+5*x)/2/n,x*=(n+2.0)/n;
	printf("%.10lf",ans);
}

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


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

int main(){
	int n,W;
	cin >> n >> W;
	int w[n+1], v[n+1];
	for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];
	ll dp[n+1][W+1] = {0};
	memset(dp,0,sizeof(dp));
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j < w[i]; ++j) dp[i][j] = dp[i-1][j];
		for (int j = w[i]; j <= W; ++j){
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
			//cout << i << " " << j << " " << dp[i][j] << '\n';
		}
	}
	cout << dp[n][W] << '\n';
	return 0;
}

Measured memory_bytes: 79104
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

constexpr int MAX = 1000100;

int to_v(int i, int j, int N) {
    if (i > j) swap(i, j);
    return N * i + j;
}

vector<int> G[MAX];
vector<int> in(MAX, 0);

int main() {

    int N;
    cin >> N;

    vector<vector<int>> A(N, vector<int>(N - 1));
    for (int i = 0; i < N; i++) for (int j = 0; j < N - 1; j++) cin >> A[i][j], A[i][j]--;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 2; j++) {
            int from = A[i][j];
            int to = A[i][j + 1];
            G[to_v(i, from, N)].push_back(to_v(i, to, N));
            in[to_v(i, to, N)]++;
        }
    }

    queue<int> Q;
    for (int i = 0; i < MAX; i++) {
        if (in[i] == 0) {
            Q.push(i);
        }
    }

    vector<int> ans(MAX, 0);
    while (!Q.empty()) {
        int v = Q.front();
        int now = ans[v];
        Q.pop();
        for (auto to: G[v]) {
            in[to]--;
            ans[to] = max(ans[to], now + 1);
            if (in[to] == 0) {
                Q.push(to);
            }
        }
    }

    if (*max_element(in.begin(), in.end()) == 0) {
        cout << *max_element(ans.begin(), ans.end()) + 1 << endl;
    }else{
        cout << -1 << endl;
    }

}






























































Measured memory_bytes: 53120
import re
from math import factorial

def combi(n, r):
    a = factorial(n) // factorial(r) // factorial(n - r)
    return a

N, K = [int(i) for i in re.split(" ", input())]


for i in range(1, K + 1):
    if i > K:
        count = 0
    else:
        n_pattern = combi(K - 1, i - 1)
        if i > N - K + 1:
            count = 0
        else:
            count = combi(N - K + 1, i) * n_pattern
    print(count % (10**9 + 7))

Measured memory_bytes: 3572
#!/usr/bin/env python3

def main():
    N = int(input())
    sa = input().split(' ')
    a = [int(s) for s in sa]

    d = dict()
    for k in a:
        if k in d:
            d[k] = d[k] + 1
        else:
            d[k] = 1

    c = 0
    for k, v in d.items():
        if k <= v:
            c += v - k
        else:
            c += v


    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24440
#include <stdio.h>

int gcd(int, int);

int main(void){

	int a,b;

	scanf("%d %d\n",&a,&b);
	printf("%d\n",gcd(a,b));
	
	return 0;
}


int gcd(int a, int b){

	if((a == 0) || (b == 0)) return 0;

	while(a != b){
		if(a > b) a = a - b;
		else	b = b - a; 
	}

	return a;
}

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

int main (void) {
    int N;
    std::cin >> N;

    std::vector<int> A(N - 1);
    for (int i = 0; i < N - 1; i++) {
        std::cin >> A[i];
        A[i]--;
    }
    std::vector<int> xs(N);
    for (const auto& a : A) {
        xs[a]++;
    }
    for (const auto x : xs) {
        std::cout << x << std::endl;
    }
    return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<uint64_t> nums(n);
  for(vector<uint64_t>::iterator it=nums.begin(); it != nums.end(); ++it) {
    cin >> *it;
  }

  uint64_t mod = 1e9+7;
  uint64_t sum = 0;
  for(uint64_t i = 0; i < 60; ++i) {
    uint64_t mask = (uint64_t)1<<i;
    uint64_t c0 = 0;
    uint64_t c1 = 0;
    for(vector<uint64_t>::iterator it=nums.begin(); it != nums.end(); ++it) {
      if((*it & mask) != 0) c1++;
      else c0++;
    }
    sum += (((c0 * c1) % mod) * (mask % mod)) % mod;
  }

  cout << sum % mod << endl;

  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    vector<long long> B(N + 1, 0);
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i + 1] = B[i] + A[i];
    }
    for (int i = 0; i < N; i++)
    {
        long long sum = (B[N] - B[i + 1]) % mod;
        ans += A[i] * sum;

        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5564
n = int(input())
w = [input() for _ in range(n)]

if len(set(w)) != len(w):
    print("No")
else:
    flag = 1
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            flag = 0
    
    if flag ==1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        int[] arr;
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }

        int w = arr[0];
        int h = arr[1];
        int x = arr[2];
        int y = arr[3];
        int r = arr[4];


        boolean res;
        
        res  = x - r >= 0;
        res &= x + r <= w;
        res &= y - r >= 0;
        res &= y + r <= h;

        System.out.println(res?"Yes":"No");
    }

}



Measured memory_bytes: 31012
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N = int(input())
A = [0] + inpl() + [0]

S1 = [abs(a-b) for a, b in zip(A[:-1], A[1:])]
S2 = [abs(a-b) for a, b in zip(A[:-2], A[2:])]

S = sum(S1)
for i in range(N):
    print(S - S1[i] - S1[i+1] + S2[i])

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

int main() {
    int N, L;
    string s[110];  // 最大 100 個ですが余裕をもたせます
    cin >> N >> L;
    for (int i = 0; i < N; ++i) cin >> s[i];

    sort(s, s + N);  // a[0:N] を大きい順にソート
    
    string str = "";
    for (int i = 0; i < N; ++i) {
        str += s[i];
    }
    
    cout << str << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = b; i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define VALL(v) v.begin(), v.end()
#define VSORT(v) sort(VALL(v));
using namespace std;
typedef vector<int> vi;

int main(){
    vi m(10);
    REP(i,10) cin >> m[i];
    VSORT(m);
    RFOR(i, 7, 9) cout << m[i] << endl;
}

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

int main() {
  int N;
  cin >> N;
  if (N<1 || N>100000000){
    return 0;
  }
  int num = N;
  int sum = 0;
  while(num > 0){
    sum += num % 10;
    num /= 10;
  }
  if(N % sum == 0){
  cout << "Yes";
  }
  else{
    cout << "No";
  }
  cout << endl;
  return 0;
}

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

int main() {
	string input,opr;
int C;
bool Cap;
cin >>input;
opr = input;
C=0;
Cap=false;
if ((opr[1]>= 'A') && (opr[1]<='Z'))
Cap= true;
for (int i= 2;i<opr.size()-1;i++){
if (opr[i]=='C')
C++;
else if ((opr[i]>= 'A') && (opr[i]<='Z')){
Cap=true;
}
}
if ((opr[opr.size()-1]>= 'A') && (opr[opr.size()-1]<='Z')){
Cap=true;
}
if (input[0]=='A'&&C==1&&!Cap)
cout << "AC" << endl;
else
cout << "WA" << endl;
	return 0;
}

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


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

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> data(3, vector<ll>(4));
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //

int main() {
  double N,K;
  double ans=0;
  cin >> N >> K;
  double n = 1/N;
  rep2(i,N){
    double l=i;

    if(l>=K){
      ans+= n;
      continue;
    }
    double m=1;
    while(l<K){
      l*=2;
      m*=2;
    }
    ans+= n*1/m;
  }


  cout << setprecision(11) << ans << endl;
}

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

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a%2==1) cnt++;
    }
    if (cnt%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256