akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,m] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let xs = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n m xs
  print ans

compute :: Int -> Int -> [Int] -> Int
compute n m xs = sum $ drop (pred n) ds
  where
    xs1 = sort xs
    ds = sortBy (flip compare) $ zipWith subtract xs1 (tail xs1)
{-
N個の場所にはN-1個の間隙がある。
1個しか石がないと、端から端まで一人で辿り、総和のコストがかかる
1個石が増えるたびに、最大の間隙の向こうに配置することで、そこを超えなくてよくなる。
というだけだ。
-}


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

using namespace std;

int calcLevel(const string _str)
{
	int level = 0;
	for(const auto& c : _str)
	{
		if(c == '.')++level;
		else break;
	}
	return level;
}


int main()
{
	int n;
	while(cin >> n, n != 0)
	{
		vector<string> ans;
		ans.reserve(n);

		int postLevel = 0;

		for(int i = 0; i < n; ++i)
		{
			string input;
			cin >> input;

			int level = calcLevel(input);

			if(level > 0)
			{
				replace(input.begin(), input.end(), '.', ' ');	
				input[level - 1] = '+';
			}
			ans.push_back(input);

			if(level < postLevel)
			{
				for(int index = i-1; index >= 0; --index)
				{
					if(ans[index][level - 1] == ' ')ans[index][level - 1] = '|';
					else break;
				}
			}

			postLevel = level;

		}

		for(const auto& v : ans)
		{
			cout << v << endl;
		}
	}




}

Measured memory_bytes: 3424
n, m, x, y = map(int, input().split())
x_want = list(int(i) for i in input().split())
y_want = list(int(i) for i in input().split())

z = 100
z = max(x_want) + 1

if (x < z and z <= y) and (max(x_want) < z) and (min(y_want) >= z):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	int sum=0;
	int a[n+1];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sum+=a[i]*a[j];
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

const int MAX = 210000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n, k;
    cin >> n >> k;
    COMinit();
    for (ll i = 1; i <= k; i++) {
        cout << (COM(k - 1, i - 1) * COM(n - k + 1, i)) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <cstdint>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<math.h>

using namespace std;

typedef long long ll;

double abs(double d){
    if(d>=0)return d;
    return -1.0*d;
}

int main() {
    int n;
    ll x;
    cin>>x;
    ll s=0;
    for(int i=1;;i++){
        s+=i;
        if(s>=x){
            cout<<i<<endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  ll n;
  cin>>n;
  ll cnt=0;
  vector<int>v1,v2;
for(int i=1;i<=n;i++)
   {
    char ch ;
    cin>>ch;
    if(ch=='W')
      v1.push_back(i);
    else
      v2.push_back(i);
   }
  ll i =0,j=v2.size()-1;
 
  while(i<v1.size() && j>=0 )
  {
   // cout<<v1[i]<< " " <<v2[j]<<endl;
    if(v1[i]<v2[j])
    cnt++;
    i++;
    j--;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool b[26];
signed main(){
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++)b[s[i]-'a']=true;
  for(int i=0;i<26;i++){
    if(b[i]!=true){
      cout<<(char)(i+97);
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 512
// abc121_b
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	vector<vector<int>> A;
	for (int i = 0; i < N; i++) {
		vector<int> vec(M);
		for (int j = 0; j < M; j++) {
			cin >> vec[j];
		}
		A.push_back(vec);
	}
	/*
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cout << A[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;

	for (int i = 0; i < M; i++) {
		cout << B[i] << " ";
	}
	cout << endl;
	*/

	int count = 0;
	for (int i = 0; i < N; i++) {
		int ans = 0;
		for (int j = 0; j < M; j++) {
			ans += (A[i][j] * B[j]);
		}
		ans += C;
		// cout << "ans=" << ans << endl;
		if (ans > 0) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
import math

a, b, c, d = map(int, input().split())
count = 0
if(a // d > c // b):
    count = c//b
else:
    count = a//d

c -= b*count
a -= d*count
if c==0:
    print("Yes")
    quit()
if a==0:
    print("No")
    quit()

if c-b <= 0: print("Yes")
else: print("No")

Measured memory_bytes: 62424
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

struct era{ string name; int pass, now; };
vector<era> v;
bool comp(const era& e1, const era &e2)
{
	return e1.now < e2.now;
}

int main()
{
	int n, q;
	while (cin >> n >> q, n)
	{
		v.clear();
		REP(i, n)
		{
			int a, b;
			string s;
			cin >> s >> a >> b;
			v.push_back(era{ s, a, b });
		}
		v.push_back(era{ "", 0, INF });
		sort(ALL(v), comp);
		REP(i, q)
		{
			int m;
			cin >> m;
			int j = 0;
			for (; j < n; j++)
			{
				if (v[j].now >= m) break;
			}
			if (v[j].now - m < v[j].pass) cout << v[j].name << " " << v[j].pass - (v[j].now - m) << endl;
			else puts("Unknown");
		}
	}
	return 0;
}

Measured memory_bytes: 1300
#include <iostream>

using namespace std;

int main(void){
	
	int n;
	cin >> n;
	
	int a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	
	int max = 0, smax = -1;
	for(int i = 1; i < n; ++i){
		if(a[max] < a[i]){
			smax = max;
			max = i;
		}
	}
	if(max == 0 && smax == -1) smax = 1;
	if(max + 1 < n){
		for(int i = max+1; i < n; ++i){
			if(a[smax] < a[i]){
				smax = i;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		if(i == max){
			cout << a[smax] << endl;
		}else{
			cout << a[max] << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2432
"use strict";

function Main(input) {
  let num = input.trim().length;
  let Rinput = input.trim().split("").reverse().join("");
  let ans = 0;

  for(let i = 0; i < num; i++){
  	if(input[i] != Rinput[i]){
    	ans++;
    }
  }
  console.log(Math.ceil(ans/2));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.util.Scanner;
public class Main {
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a >= b){
			gcd(a,b);
		}else{
			gcd(b,a);
		}
	}
	
	static void gcd(int n,int m){
		if((n % m) == 0) {
			System.out.println(m);
		}else if(m == 1){
			System.out.println(1);
		}else{
			int m1 = (n % m);
			gcd(m,m1);
		}
	}
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
//ここから書き始める


int main()
{
	cout <<setprecision(10);
	string w;
	cin >> w;
	for(char c = 'a' ; c <= 'z'; c++){
		int count = 0 ;
		rep(i,w.size()){
			if(w[i]==c){
				count++;
			}
		}
		if(count % 2 != 0){
			coN();
			return 0;
		}
	}
	coY();

}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;cin>>H>>W;
  repeat(i,H){
    string C;cin>>C;
    repeat(k,2){
      repeat(j,W){
        cout<<C[j];
      }
      cout<<endl;
    }
  }
  return 0;
}


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

int p, q, a, n;

int dfs(int nume, int deno, int x, int k) {
  if(p*deno == q*nume) { return 1; }
  
  // p/q < nume/deno
  if(p*deno < q*nume) { return 0; }
  
  if(k == n) { return 0; }
  
  int ret = 0;
  for(int i=x; deno*i <= a; i++) {
    // A/B + 1/C = (AC+B)/BC
    ret += dfs(nume*i+deno, deno*i, i, k+1);
  }
  
  return ret;
}

int main() {
  
  while(cin >> p >> q >> a >> n && (p|q|a|n))
    cout << dfs(0, 1, 1, 0) << endl;
  
  return 0;
}

Measured memory_bytes: 1160
# 2019/07/11

from heapq import heappop,heappush

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1
    v-=1
    edge[u].append((c,v))
    edge[v].append((c,u))


def dijkstra(s):
    d=[float('inf')]*n
    visited=[False]*n
    d[s]=0
    visited[s]=True
    que=[]
    for e in edge[s]:
        heappush(que,e)
    while que:
        c,v=heappop(que)
        if visited[v]:continue
        d[v]=c
        visited[v]=True
        for cost,vtx in edge[v]:
            if visited[vtx]:continue
            hq=(cost+d[v],vtx)
            heappush(que,hq)

    return d

q,k=map(int,input().split())
k-=1

res=dijkstra(k)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(res[x]+res[y])



Measured memory_bytes: 46680
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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 ans=0,n;string s;
    cin>> n >>s;
    rep(i,1000)
    {
      int c[3]={i/100,(i/10)%10,i%10};
      int digit=0;
      rep(j,n)
      {
        if(s[j]==('0'+c[digit]))digit++;
        if(digit==3){ans++;break;}
      }
    }

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  double d;
  while(cin >> d){
    string s;
    if(d<=48.0) s="light fly";
    else if(d<=51.0) s="fly";
    else if(d<=54.0) s="bantam";
    else if(d<=57.0) s="feather";
    else if(d<=60.0) s="light";
    else if(d<=64.0) s="light welter";
    else if(d<=69.0) s="welter";
    else if(d<=75.0) s="light middle";
    else if(d<=81.0) s="middle";
    else if(d<=91.0) s="light heavy";
    else s="heavy";
    cout << s << endl;
  }
  return 0;
}

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

// 比較演算子を自動生成
#define CAT(a, b) a ## b
#define COMP_1(v1) return lhs.v1 < rhs.v1
#define COMP_2(v1, ...) if (lhs.v1 != rhs.v1) COMP_1(v1); COMP_1(__VA_ARGS__)
#define COMP_3(v1, ...) if (lhs.v1 != rhs.v1) COMP_1(v1); COMP_2(__VA_ARGS__)
#define COMP_4(v1, ...) if (lhs.v1 != rhs.v1) COMP_1(v1); COMP_3(__VA_ARGS__)
#define COMP_5(v1, ...) if (lhs.v1 != rhs.v1) COMP_1(v1); COMP_4(__VA_ARGS__)
#define LESS_THAN(n, ...) bool operator<(const A & rhs) const { auto& lhs = *this; CAT(COMP_, n)(__VA_ARGS__); }

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define FOR(i, s, n) for(ll i = (s); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()

// 10^x (by math)
#define TEN(x) ((ll)1e##x)

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

template<int64_t mod> struct GF {
	typedef int64_t T;
	T v;
	GF() = default;
	GF(T v) : v((v% mod + mod) % mod) {}
	GF& operator+=(GF x) { v = (v + x.v) % mod; return *this; }
	GF& operator*=(GF x) { v = (v * x.v) % mod; return *this; }
	GF& operator-=(GF x) { v = (v - x.v + mod) % mod; return *this; }
	GF& operator/=(GF x) { return (*this) *= x.inverse(); }
	GF operator+(GF rhs) const { GF lhs = *this; return lhs += rhs; }
	GF operator*(GF rhs) const { GF lhs = *this; return lhs *= rhs; }
	GF operator-(GF rhs) const { GF lhs = *this; return lhs -= rhs; }
	GF operator/(GF rhs) const { GF lhs = *this; return lhs /= rhs; }
	GF inverse() const { // http://topcoder.g.hatena.ne.jp/iwiwi/20130105/1357363348
		T a = v, b = mod, x = 1, y = 0;
		while (b) {
			T t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return x;
	}
	GF pow(T n) const {
		GF r; r.v = 1;
		for (T x = v; n > 0; n >>= 1) {
			if (n & 1) (r.v *= x) %= mod;
			(x *= x) %= mod;
		}
		return r;
	}
	typedef size_t U;
	static GF fact(U n) {
		static vector<GF> data;
		U m = data.size();
		if (m <= n) {
			data.resize(n + 1);
			if (m == 0) { data[0].v = 1; m++; }
			for (U i = m; i < n + 1; ++i) data[i] = data[i - 1] * i;
		}
		return data[n];
	}
	static GF nCr(U n, U r) { return fact(n) / fact(r) / fact(n - r); }
	static GF nPr(U n, U r) { return fact(n) / fact(r); }
};

static const ll mod = 998244353;

void solution(istream& cin, ostream& cout) {
	ll n, m, k;
	cin >> n >> m >> k;
	
	GF<mod> a = 1;
	vector<GF<mod>> cnt(n);
	REP(i, n) {
		cnt[i] = GF<mod>::nCr(n - 1, i) * a * m;
		a *= m - 1;
	}
	GF<mod> ans = 0;
	REP(i, k + 1) ans += cnt[n - 1 - i];
	cout << ans.v << endl;
}

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	solution(cin, cout);
}


Measured memory_bytes: 6312
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000000;
const long long MOD = 1000000007;

bool f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  slen--;
  for (int i = 0; i < s.length(); i++)
  {
    if(s[i]!=s[slen-i])
      return false;
  }
  return true;
}

int main()
{
  long long N, M, X;
  cin >> N >> M >> X;

  //料金所があればtrue
  vector<bool> data(N+1,false);
  for (int i = 0; i < M;i++){
    long long a;
    cin >> a;
    data[a] = true;
  }
  long long ans = 0;
  for (int i = X; i < N;i++){
    if(data[i+1])
      ans++;
  }
  long long ans2 = 0;
  for (int i = X; i >0; i--)
  {
    if (data[i - 1])
      ans2++;
  }
  cout << min(ans, ans2) << endl;
}


Measured memory_bytes: 256
import fractions

n,k = map(int,input().split())

a = list(map(int,input().split()))

gcd = a[0]

max_a = max(a)

for i in range(1,n):
    gcd = fractions.gcd(gcd,a[i])

if k%gcd==0 and k <= max_a:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

int main(){
    int s;
    bool yymm = 1;//〇年〇月
    bool mmyy = 1;//〇月〇年
    cin >> s;
    if(s/100 > 12 || s/100 == 0)mmyy = 0;
    if(s%100 > 12 || s%100 == 0)yymm = 0;

    if(yymm && mmyy)cout << "AMBIGUOUS" << endl;
    if(!(yymm) && mmyy)cout << "MMYY" << endl;
    if(yymm && !(mmyy))cout << "YYMM" << endl;
    if(!(yymm) && !(mmyy))cout << "NA" << endl;
}

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

int main() {
  int a[3];
  rep(i,3) cin >> a[i];
  int sum = 0;
  rep(i,3){
    sum += a[i];
  }
  if(sum >= 22) puts("bust");
  else puts("win");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,last,res;
int a[100005],b[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(last) res-=a[i],last=0;
		else res+=a[i],last=1;
	}
	b[1]=res;
	for(int i=2;i<=n;i++) b[i]=2*a[i-1]-b[i-1];
	for(int i=1;i<=n;i++) printf("%d ",b[i]);
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s,t;
    cin >> s>>t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s<t)
    {
        cout <<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }

    return 0;
}

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

int main(){
    int64_t i,j,k,l;//preparation for
    int64_t n,m;

    cin>>n>>m;

    int a[m],s,d;
    
    s=0;

    for(i=0;i<m;i++){
        cin>>a[i];
        s+=a[i];
    }

    if(n-s<0){
        d=-1;
    }
    else{
        d=n-s;
    }

    cout<<d;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
//#define sort(v)	sort(v.begin(),v.end());
//#define rsort(v) sort(v.rbegin(),v.rend());
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
#define sllit set<long long int>::iterator
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}


/******************************START********************************/
bool found(lli arr[],lli n,lli x)
{
	for(lli i=0;i<n;i++){
		if(arr[i]==x)	return true;
	}
	return false;
}
int main()
{
	//init();
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,t,b,c,n,z,m,sum=0,ans=0,temp;
    cin >> n >> a;
    if(n>=10)	cout << a << endl;
    else{
    	a+=100*(10-n);
    	cout << a << endl;
	}
    
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

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

int main() {
 int l,r,l2,r2,k,s,t=2019;   cin>>l>>r; k=r-l;l2=l%2019,r2=r%2019;
  if(k>2017) cout<<0<<endl;
  else if(l2==0)cout<<0<<endl;
  else if(r2<l2)cout<<0<<endl;
  else if(1){
    
    for(int i=0;i<k;i++){
    for(int j=0 ;j<k;j++){
      
      if(r2-i>l2+j){
        s=(r2-i)*(l2+j);
      if(s>2019) s=s%2019;
      if(t>s)t=s;
    }
    }
       }
    
  
    cout<<t<<endl;
    
  }
    

    
  
  
  
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;


signed main(){
    int n;
    cin >> n;
    int T,A;
    cin >> T >> A;
    rep(i,n-1){
        int t,a;
        cin >> t >> a;
        if(T*a == t*A){}
        else if(t == a){
            T = max(T,A);
            A = T;
        }else if(t > a){
            int AA = A,TT = T;
            if(A%a != 0){
                AA += a - A%a;
            }
            TT = t*(AA/a);
            if(TT >= T){
                T = TT;
                A = AA;
            }
            else{
                if(T%t != 0){
                    T += t - T%t;
                }
                A = a*(T/t);
            }
        }else{
            int AA = A,TT = T;
            if(T%t != 0){
                TT += t - TT%t;
            }
            AA = a*(TT/t);
            if(AA >= A){
                T = TT;
                A = AA;
            }
            else{
                if(A%a != 0){
                    A += a - A%a;
                }
                T = t*(A/a);
            }
        }
        cerr << T << " " << A << endl;
    }
    cout << T+A << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {

  ll N;
  cin>>N;
  ll mozi[N]['z'+1];
  FOR(i,0,N-1){
    FOR(j,0,'z'+1){
      mozi[i][j]=0;
    }
  }
  FOR(i,0,N-1){
    string S;
    cin>>S;
    FOR(j,0,S.size()-1){
      mozi[i][S[j]]++;
    }
  }
  ll mozimax['z'+1]={};
  FOR(i,0,N-1){
    ll tmp=99;
    FOR(j,0,'z'){

      tmp=min(tmp,mozi[i][j]);
    }
    mozimax[i]=tmp;
  }

  FOR(i,'a','z'){
    ll tmp=99;
    FOR(j,0,N-1){
      tmp=min(tmp,mozi[j][i]);
    }
    mozimax[i]=tmp;
    //cout<<tmp<<endl;
  }

  FOR(i,'a','z'){
    if(mozimax[i]>0){
      FOR(j,0,mozimax[i]-1){
        char ans=i;
              cout<<ans;
      }
    }
  }


  cout<<endl;



  return 0;
}
 


Measured memory_bytes: 256
def check(learn_total):
    for i in range(m):
        if learn_total[i] < x:
            return False  
    return True 

def calc_price(bit):
    price_total = 0 
    learn_total = [0] * m 

    for i in range(n):
        if (bit >> i) & 1:  
            price_total += c[i]  
            learn = a[i]  
            for j, la in enumerate(learn): 
                learn_total[j] += la

   
    if check(learn_total):
        return price_total 
    else:
        return INF

if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))

    # 空のリストを作って、appendで追加していきます
    c = []  # 参考書の値段です
    a = []  # 各参考書に入る理解度です

    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))  # こうすると、2つ目以降をリストで受け取れます
        c.append(c_temp)
        a.append(a_temp)

    INF = float("inf")
    ans = INF

    for bit in range(1 << n):
        price = calc_price(bit)  # 条件を満たすならそのときの値段、満たさないならINFが返ってきます
        ans = min(ans, price)  # 答えを更新します

    if ans == INF:
        print(-1)  # どうやっても条件を満たせなかった
    else:
        print(ans) 

Measured memory_bytes: 9248
program Megalomania
    implicit none
    integer(4):: n,i
    integer(4),allocatable:: a(:), b(:)
    integer(8):: time=0

    read*, n
    allocate(a(n), b(n))

    do i=1,n
        read*, a(i),b(i)
    end do

    call merge_sort(a,b,1,n)

    do i=1,n
        time=time+int(a(i),kind=8)
        if (b(i) < time) then
            print*, 'No'
            stop
        end if
    end do

    print*, 'Yes'


contains
recursive subroutine merge_sort(ar1, ar2, l,r)
    integer(4):: ar1(:), ar2(:), l, r
    integer(4):: tmp, m

    if (r-l <= 1) then
        if (ar2(l) > ar2(r)) then
            tmp = ar2(r)
            ar2(r) = ar2(l)
            ar2(l) = tmp
            tmp = ar1(r)
            ar1(r) = ar1(l)
            ar1(l) = tmp
        end if
        return
    end if

    m = (l+r)/2
    call merge_sort(ar1,ar2,l,m)
    call merge_sort(ar1,ar2,m+1,r)
    call merge_(ar1,ar2,l,m,r)
end subroutine

subroutine merge_(ar1,ar2,l,m,r)
    integer(4):: ar1(:), ar2(:), l,m,r
    integer(4),allocatable:: t1(:), t2(:)
    integer(4):: li, ri, ti
    allocate(t1(r-l+1), t2(r-l+1))
    li=l
    ri=m+1
    ti=1

    do while(li <= m .and. ri <= r)
        if (ar2(li) <= ar2(ri)) then
            t1(ti) = ar1(li)
            t2(ti) = ar2(li)
            li=li+1
        else
            t1(ti) = ar1(ri)
            t2(ti) = ar2(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (li <= m) then
        t1(ti:) = ar1(li:m)
        t2(ti:) = ar2(li:m)
    else
        t1(ti:) = ar1(ri:r)
        t2(ti:) = ar2(ri:r)
    end if

    ar1(l:r) = t1(:)
    ar2(l:r) = t2(:)
    deallocate(t1,t2)
end subroutine
end program Megalomania

Measured memory_bytes: 3544
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 1000 + 10;

int N, M, K;

bool chk()
{
	for (int i = 0; i <= N; i ++)
		for (int j = 0; j <= M; j ++)
		{
			int Ans = i * M + j * N - 2 * (i * j);
			if (Ans == K) return 1;
		}
	return 0;
}

void Work()
{
	scanf("%d%d%d", &N, &M, &K);
	printf(chk() ? "Yes\n" : "No\n");
}

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

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void)
{
    int a, b;
    cin >> a >> b;
    if( a >= 1 && a <= 9 && b >= 1 && b <= 9 )
    {
        cout << a * b << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 1; i < n-1;i++){
    if(s.substr(i,1)=="B"){
      if(s.substr(i-1,1)=="A" && s.substr(i+1,1)=="C")
        cnt++;
    }
  }

    cout << cnt << endl;
}


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

using namespace std;

int main() {

	while (1) {
		int n, x;
		cin >> n >> x;

		if (n == 0 && x == 0) {
			break;
		}

		int count = 0;
		for (int i = 1; i <= n - 2; i++) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) {
						count++;
					}
				}
			}
		}

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

	}

	return 0;
}

Measured memory_bytes: 1144
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long Pm(int x);

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int Ans = a + b + c - max(a,max(b,c));
  printf("%d\n",Ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 500001
#define prob "B"
#define pb push_back
#define ll long long
#define io freopen(prob".inp","r",stdin); freopen(prob".out","w",stdout);
#define fast ios_base::sync_with_stdio(1); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
int n,h[N],k;
int f[N];
int main()
{
    fast
//    io
    cin>>n>>k;
    for(int i=1;i<=n;i++) f[i]=INT_MAX;
    for(int i=1;i<=n;i++) cin>>h[i];
    f[1]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k&&i+j<=n;j++)
        f[i+j]=min(f[i+j],f[i]+abs(h[i]-h[i+j]));
      //  cout<<f[i]<<endl;
    }
    cout<<f[n];
}



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



int main() {
    
    int a,b,c;
    
    scanf("%d %d %d\n",&a,&b,&c);
    
    if (c>=a && c<=b){
        
        printf("Yes");
        
    }else{
        
        printf("No");
        
    }
        	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
    int i,k,cnt,N,M;
    scanf("%d %d",&N,&M);
    int friend[N],vote[M][N],target[M];
    for(i = 0; i < M; i ++ )scanf("%d",&target[i]);
    for(k = 0; k < N; k ++ )friend[k] = 0;
    for(i = 0; i < M; i ++ ){
        cnt = 0;
        friend[target[i]-1] ++;
        for(k = 0; k < N; k ++ ){
            scanf("%d",&vote[i][k]);
            if(target[i]-1 != k){
                if(vote[i][k] == target[i])friend[k] ++;
                else cnt ++;
            }
        }
        friend[target[i]-1] += cnt;
    }
    for(i = 0; i < N; i ++ )printf("%d\n",friend[i]);

    return 0;
}

Measured memory_bytes: 632
def getDivNum(num):
    divN = 0
    for i in range(1, num+1):
        if num%i == 0:
            divN += 1
    return divN

n = int(input())
cnt = 0
for x in range(1, n+1, 2):
    if ( getDivNum(x) == 8 ):
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
N,M = map(int,input().split())


#iから進める場所をリストにして保管
edges = {i:[] for i in range(1,N+1)}
for i in range(M):
  a,b = [int(a) for a in input().split()]
  edges[a].append(b)
  edges[b].append(a)


#深さ優先探索
def dfs(list):
    #lst(通過点)の数がN(頂点数)と等しくなったら探索終了（成功）
  if len(list) == N:
    return 1
  else:
    a = list[-1]
    #lstの最後尾（現在地）が次に進める場所をnextとしてリスト化
    #nextに以前通った場所が入っていないか確認
    next = [n for n in edges[a] if n not in list]
    #次に進める場所がなくなったら探索終了（失敗）
    if len(next) == 0:
      return 0

    total = 0
    #再帰でさらに探索
    for n in next:
      total += dfs(list + [n])

    return total


ans = dfs([1])

print(ans)


Measured memory_bytes: 9216
#include<iostream>

using namespace std;

int main(){

  int a[4];
  int b[4];
  int x=0,y=0;

  for(int i=0;i<4;i++){
    cin >> a[i];
    x=x+a[i];
  }

  for(int t=0;t<4;t++){
    cin >> b[t];
    y=y+b[t];
  }

  if(x>=y){
    cout << x;
  }else{
    cout << y;
  }

  cout << endl;


  return 0;
}
 

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next().toUpperCase();
        String b = sc.next().toUpperCase();
        String c = sc.next().toUpperCase();
        int idxa = 0;
        int idxb = 0;
        int idxc = 0;
        char temp = 'A';
        while (true) {
            if (temp == 'A') {
                if (idxa >= a.length()) {
                    break;
                }
                temp = a.charAt(idxa);
                idxa++;
            } else if (temp == 'B') {
                if (idxb >= b.length()) {
                    break;
                }
                temp = b.charAt(idxb);
                idxb++;
            } else if (temp == 'C') {
                if (idxc >= c.length()) {
                    break;
                }
                temp = c.charAt(idxc);
                idxc++;
            }
        }
        System.out.println(temp);
    }
}

Measured memory_bytes: 23892
//***Wherever you are, and whatever you do, be in love.***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll n;
    cin>>n;
    n=n%10;
    if((n==2)||(n==4)||(n==5)||(n==7)||(n==9)) cout<<"hon";
    if((n==1)||(n==0)||(n==6)||(n==8)) cout<<"pon";
    if(n==3) cout<<"bon";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll n;
  cin >> n;
  ll row[n];
  ll result = 1;
  for (int i = 0; i < n; i++) {
    cin >> row[i];
    if (row[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if ((ll)1e+18 / result < row[i]) {
      cout << -1 << endl;
      return 0;
    }
    result *= row[i];
  }
  if (result > (ll)1e+18) result = -1;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 4412
c = [list(map(int, input().split())) for i in range(3)]
x = c[0][2]-c[0][1]
y = c[0][1]-c[0][0]
for i in range(1, 3):
    if c[i][1]-c[i][0] != y:
        print('No')
        break
    if c[i][2]-c[i][1] != x:
        print('No')
        break

else:
    print('Yes')


Measured memory_bytes: 9188
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        string s = Console.ReadLine();
        Console.WriteLine(Min(s.Zip(s.Skip(1), (x, y) => x == y ? 1 : 0).Sum() + 2 * k, n - 1));
    }
}


Measured memory_bytes: 13536
/*
ABC154B - I miss you...
*/

#include <stdio.h>
#include <string.h>

int main()
{
	char s[101];
	int i, length;

	scanf("%s", s);

	length = strlen(s);

	for (i = 1; i <= length; i++) {
		printf("%c", 'x');
	}

	return 0;
}


Measured memory_bytes: 128
import sys
import numpy as np

N=int(input())
count = 0

for i in range(1,N+1):
    i_ins=[]
    for x in range(1,i+1):
        if i//x != 0 and i%x == 0:
            i_ins.append(x)
    for j in range(1,N+1):
        i_j_ins=[]
        for y in i_ins:
            if j//y != 0 and j%y == 0:
                i_j_ins.append(y)
        if i_j_ins[-1]==1:
            #            print(i,j,i_j_ins[-1])
            count = count + i_j_ins[-1]*N
        else:
            for k in range(1,N+1):
                i_j_k_ins=[]
                for z in reversed(i_j_ins):
                    if k//z != 0 and k%z == 0:
                        i_j_k_ins.append(z)
                        break
            #    print(i,j,k,i_j_k_ins[-1])
                count = count + i_j_k_ins[-1]

print(count)

Measured memory_bytes: 27048
#include<iostream>
using namespace std;
int main(){
	int a[10],b,c;
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	for(int i=0;i<10;i++){
		for(int j=9;j>i;j--){
			if(a[j]<a[j-1]){
				b=a[j];
				a[j]=a[j-1];
				a[j-1]=b;
			}
		}
	}
	cout<<a[9]<<'\n'<<a[8]<<'\n'<<a[7]<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

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


void Main()
{
	string s, t;
	cin >> s >> t;

	sort(s.begin(), s.end(), less<char>());
	sort(t.begin(), t.end(), greater<char>());

	cout << (s < t ? "Yes" : "No") << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int OK = 1;
vector<int> eda[1001];
int X[1001];

pair<int, int> sagasu(int A) {
	if (OK) {
		int saishou = 0;
		int saidai = 0;
		map<int, int> MP;
		for (int i : eda[A]) {
			pair<int, int> P = sagasu(i);
			saishou += P.first;
			saidai += P.second;
			MP[P.second - P.first]++;
		}
		if (X[A] >= saishou && X[A] < saidai) {
			int ikeru[5001] = {};
			ikeru[saishou] = 1;
			for (auto itr : MP) {
				rep(i, 5000) {
					if (ikeru[i]) {
						rep1(ii, itr.second) {
							if (i + ii * itr.first < 5001) {
								ikeru[i + ii * itr.first] = 1;
							}
						}
					}
				}
			}
			int girigiri = 10000;
			for (int i = X[A]; i >= 0; i--) {
				if (ikeru[i]) {
					girigiri = i;
					break;
				}
			}
			return make_pair(min(X[A], saishou + saidai - girigiri), max(X[A], saishou + saidai - girigiri));
		}
		else if (X[A] < saishou) {
			OK = 0;
			return make_pair(10000, 0);
		}
		else {
			return make_pair(saishou, X[A]);
		}
	}
	else return make_pair(10000, 0);
}

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

	
	int N;
	cin >> N;

	rep1(i, N - 1) {
		int P;
		cin >> P;
		eda[P].push_back(i + 1);
	}
	rep1(i, N) cin >> X[i];

	sagasu(1);

	if (OK) co("POSSIBLE");
	else co("IMPOSSIBLE");

	Would you please return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 505;
int a[N][N];
int main()
{
	int k = read() , n = 500;
	if(k <= n)
	{
		printf("%d\n",k);
		for(int i = 1;i <= k;i ++ , puts("")) for(int j = 1;j <= k;j ++) printf("%d ",i);
	}
	else
	{
		printf("%d\n",n); k -= n;
		for(int i = 1;i <= n;i ++) for(int j = 1;j <= n;j ++)
		{
			int x = (i + j - 2) % n + 1;
			a[i][j] = x;
			if(x <= k && (j & 1)) a[i][j] = n + x;
		}
		for(int i = 1;i <= n;i ++ , puts("")) for(int j = 1;j <= n;j ++) printf("%d ",a[i][j]);
	}
	return 0;
}

Measured memory_bytes: 2176
def count(l):
    res = {'a':0, 'b':0, 'c':0}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

string = input()
cnt = count(string).values()
if max(cnt) - min(cnt) < 2:
    print('YES')
else:
    print('NO')



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

int main() {
	string O;
	string E;
	cin >> O >> E;
	int Olen = O.length();
	int Elen = E.length();
	int maxlen = max(Olen,Elen);

	for (int i = 0; i < maxlen; i++)
	{
		if(i < Olen) cout << O[i];
		


		if(i < Elen) cout << E[i];

	}





}


Measured memory_bytes: 256
# 2019/07/13

s=list(map(int,list(input())))
k=int(input())

if len(s)>=k and sum(s[:k-1])==k-1:
    ans=s[k-1]
else:
    for e in s:
        if e!=1:
            ans=e
            break

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b;
	cin >> a >> b;
	if (a == 2 || b == 2)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
} 

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

int main()
{
  int n, tmp;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<ll> gone(n, -1);
  rep(i, n) {
    cin >> tmp;
    a[i] = tmp - 1;
  }
  int st = 0;
  ll cnt = 0;
  gone[st] = cnt;
  for (ll i = k; i > 0; i--) {
    st = a[st];
    cnt++;
    if (gone[st] != -1) {
      int phase = cnt - gone[st];
      rep(j, (i - 1) % phase) {
        st = a[st];
      }
      break;
    }
    gone[st] = cnt;
  }
  cout << st + 1 << endl;

  return 0;
}


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

int main()
{
	int num;
	int i, j, s, t;
	
	while(cin >> num){
		int count = 0;
		
		for(i=0; i<=9; i++){
			for(j=0; j<=9; j++){
				for(s=0; s<=9; s++){
					for(t=0; t<=9; t++){
						if((i+j+s+t) == num){
							++count;
						}
					}
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

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

typedef pair<int, int> P;
vector<P> v;

int main(){
    long long n, k;
    cin >> n >> k;

    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        v.push_back(P(x, y));
    }

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

    long long tmp = 0;
    for(int i=0; i < n; i++){
        tmp += v[i].second;
        if(tmp >= k){
            cout << v[i].first << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define ll long long

int main(){
	int N,K,C; scanf("%d %d %d",&N,&K,&C);
	char S[N+2]; scanf("%s",S);
	int fast[K],last[K];
	int n=0;
	for(int i=0;i<K;){
		if( n >= N ) break;
		//printf("judge %d ",n);
		if( S[n]!='x' ){
			fast[i]=n;
			n += C+1;
			i++;
			//printf("Yes\n");
		}else{
			n++;
			//printf("No\n");
		}
	}
	n = N-1;
	for(int i=0;i<K;){
		if( n<0 ) break;
		if( S[n]!='x' ){
			last[K-1-i]=n;
			n -= C+1;
			i++;
		}else{
			n--;
		}
	}
	//rep(i,0,K) printf("%d %d\n",fast[i],last[i]);
	rep(i,0,K) if( fast[i]==last[i] ) printf("%d\n",fast[i]+1);
	return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (T& x : v) is >> x;
    return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    if (!v.empty()) {
        os << v.front();
        for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
    }
    return os;
}

int main() {
#ifdef LBT
    freopen("test.in", "r", stdin);
    int nol_cl = clock();
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k, a, b, c;
    ll t;
    cin >> n >> m >> k >> a >> b >> c >> t;
    vector<int> s(m), cur(m);
    cin >> s;
    priority_queue<pair<int, int>> pq;
    int ans = -1;
    function<void(int)> update = [&](int i) {
        if ((s[i] - 1) * (ll)b + (cur[i] - s[i]) * (ll)c <= t && cur[i] < s[i + 1]) {
            int np = min(s[i + 1] - 1LL, cur[i] + (t - (s[i] - 1) * (ll)b - (cur[i] - s[i]) * (ll)c) / a);
            pq.emplace(np - cur[i] + 1, i);
        }
    };
    for (int i = 0; i < m - 1; ++i)
        if ((s[i] - 1) * (ll)b <= t) {
            int np = min(s[i + 1] - 1LL, s[i] + (t - (s[i] - 1) * (ll)b) / a);
            cur[i] = np + 1;
            ans += np - s[i] + 1;
            update(i);
        }
    if ((s[m - 1] - 1) * (ll)b <= t)
        ++ans;
    k -= m;
    while (k-- && !pq.empty()) {
        int upd, i;
        tie(upd, i) = pq.top();
        pq.pop();
        ans += upd;
        cur[i] += upd;
        update(i);
    }
    cout << ans << '\n';

#ifdef LBT
    LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
    return 0;
}


Measured memory_bytes: 3228
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

n = int(input())
s = input()
def ceil(a, b):
   return a // b + (a % b > 0)
ans = 0
for i in range(n-1):
   for idx, j in enumerate(z_algo(s[i:])):
      ans = max(min(idx, j), ans)

print(ans)

Measured memory_bytes: 48604
s = input()
max_acgt_len = 0

for i in range(len(s)):
    current_str = s[i:]

    for j in reversed(range(1, len(current_str) + 1)):
        acgt_count = 0
        acgt_count += current_str[:j].count('A')
        acgt_count += current_str[:j].count('G')
        acgt_count += current_str[:j].count('C')
        acgt_count += current_str[:j].count('T')

        if acgt_count == len(current_str[:j]):
            max_acgt_len = max(max_acgt_len, acgt_count)
print(max_acgt_len)

Measured memory_bytes: 3064