akhauriyash/Code-Regression huggingface dataset:
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1200031;

long long A,B,n;

long long strat(){
	long long ta=A;
	long long tb=B;
	long long ret=0;
	ret+=ta-1;
	tb-=(ta-1);
	ta-=(ta-1);
	tb--;
	ret++;
	return ret+(tb-ta)/2;
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
 //   cin.tie(0);

    cin>>n>>A>>B;

    if (A%2==B%2){
    	cout<<(B-A)/2<<endl;
    }
    else
    {
    	long long res=strat();
    	A=n-A+1;
    	B=n-B+1;
    	swap(A,B);
    	cout<<min(res,strat())<<endl;
    }

    //    cin.get(); cin.get();
    return 0;
}


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


public class Hello{
    public static void Main(){
        // Your code here!
        
        int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = a[0];
        int X = a[1];
        int ans = Math.Abs(X - x[0]);
        
        for(int i = 1; i < N; i++)
        {
            ans = gcd(ans, Math.Abs(X - x[i]));
        }
         Console.WriteLine(ans);
        
    }
    
    public static int gcd(int a, int b) //最大公約数を求める
    {
        if(a < b) //a < bのとき，aとbを入れ替える．
        {
            int tmp = a;
            a = b;
            b = tmp;
        }
        
        if(b < 1) //aとbは自然数でないとだめ．bが自然数でないならば-1を返す．
        {
            return -1;
        }
        
        int r = a % b;
        
        //終了条件
        if(r == 0)
        {
            return b;
        }
        
        return gcd(b, r);
    }
}


Measured memory_bytes: 21728
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
const int MOD = 1000000007;
bool custom(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(55555);
  vector<int> prime;
  for(int i=2;i<a.size();i++) {
    if(!a[i]) {
      prime.emplace_back(i);
      for(int j=i;j<a.size();j+=i) {
        a[j] = 1;
      }
    }
  }
  vector<int> b;
  vector<int> c;
  for(int i=0;i<prime.size();i++) {
    if(prime[i]%5==2)b.emplace_back(prime[i]);
    else if(prime[i]%5==4)c.emplace_back(prime[i]);
  }
  for(int i=0;i<n;i++) {
    cout << b[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#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 <ctime>
#include <cstdio>

using namespace std;

uint64_t n, a, r;
uint64_t cnt = 0, sum = 0;

int main()
{
	cin >> n;

	for (int i = 1; i <= n; ++i)
	{
		cin >> a;
		
		if (a == 0) {
			r = 0;
			continue;
		}

		if (r == 1) {
			cnt += 1;
			a -= 1;
		}

		cnt += a / 2;
		r = a % 2;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;


int main() {
	int L; cin >> L;
	vector<ll> a(L + 2);
	for (int i = 0; i < L; i++) cin >> a[i];
	vector<vector<ll>> dp(L + 2, vector<ll>(7, 1e18));
	dp[0][0] = 0;
	auto d = [&](int i, int j) -> ll {
		if (j == 0 || j == 4) return a[i];
		if (j == 1 || j == 3) {
			if (a[i] == 0) return 2;
			return a[i] & 1;
		}
		if (j == 2) return 1 - (a[i] & 1);
		else return 0;
	};
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = j; k < 5; k++) {
				dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + d(i, k));
			}
		}
	}
	ll ans = 1e18;
	for (int i = 0; i < 5; i++) ans = min(ans, dp[L][i]);
	cout << ans << endl;
}


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

int main(){
  int n,sum=0;
  cin>>n;
  vector<int> value(n),cost(n);
  for(int i=0;i<n;i++){
    cin>>value[i];
  }for(int i=0;i<n;i++){
    cin>>cost[i];
  }for(int i=0;i<n;i++){
    if(value[i]>cost[i]) sum+=value[i]-cost[i];
  }
  cout<<sum<<endl;
}


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

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

  // load
  vector <int> card(n);
  for (int i = 0; i < n; i++)
    cin >> card.at(i);

  // sort
  sort(card.begin(), card.end(), std::greater<int>());

  // count up score
  int score = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      score += card.at(i);
    else
      score -= card.at(i);
  }

  // output
  cout << score << endl;

}


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

int main(){
    string s;
    cin >> s;
    vector<string> d = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    int day;
    rep(i, 7) {
        if(d[i] == s){
            day = 7 - i;
        }
    }
    cout << day << endl;
    return 0;
}

Measured memory_bytes: 384
def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def f3(n, AA, x):
    tmp = n + AA[0]
    if len(AA) == 1:
        try: x[tmp] = 1
        except: pass
    else:
        f3(n, AA[1:], x)
        try:
            x[tmp] = 1
            f3(tmp, AA[1:],x)
        except:
            pass
    return

n = f()
A = sorted(f2())
q = f()
M = f2()

x = [0 for i in range(max(M)+1)]
f3(0, A, x)

for e in M:
    if x[e] == 1:
        print 'yes'
    else:
        print 'no'

Measured memory_bytes: 4312
# include<iostream>
# define N 10000
using namespace std;

int n, A[N], q, m[N];
bool solve(int i, int m){
    if(m == 0) return true;
    if(i >= n) return false;
    bool rec = (solve(i+1, m) || solve(i+1, m-A[i]));
    return rec;
}
int main(){
    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    cin >> q;
    for(int i=0; i<q; i++) cin >> m[i];
    for(int i=0; i<q; i++){
        if(solve(0,m[i])) cout << "yes\n";
        else cout << "no\n";
    }
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
int main(void)
{
	int A,B,C;
	scanf("%d%d%d",&A,&B,&C);
	if (C <= (A + B))
	{
		printf("%d",B + C);
	}
	else
	{
		printf("%d",A + 2*B + 1);
	}
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
   int N, M;
   cin >> N >> M;
   if(N==M) cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
struct node{
	ll a;
	ll b;
};
bool cmp(node x,node y){
	return x.a+x.b >y.a+y.b ;
}
int main()
{
	
	ll n;
	scanf("%lld",&n);
	vector<node> nu(n);
	for(int i=0;i<n;i++)
		scanf("%lld%lld",&nu[i].a,&nu[i].b);
	sort(nu.begin(),nu.end(),cmp);
	ll an1=nu[0].a;
	ll an2=0;
	for(int i=1;i<n;i++)
	{
		if(i%2!=0)
			an2+=nu[i].b;
		else 
			an1+=nu[i].a;
	}
	printf("%lld\n",an1-an2);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	int a,b;
	
	cin >> a >> b;
	
	int ans = a - 2*b;
	
	if(ans <= 0)cout << 0 << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int a,b,dp[16][16];
bool bad[16][16];

void solve() {
  memset(dp, 0, sizeof dp);
  memset(bad, false, sizeof bad);
  int n,x,y; cin>>n;
  rep(i,n) {cin>>x>>y;bad[--y][--x]=true;}
  dp[0][0]=1;
  for(int i=1;i<a;++i) if(!bad[0][i]) dp[0][i]=dp[0][i-1];
  for(int i=1;i<b;++i) if(!bad[i][0]) dp[i][0]=dp[i-1][0];
  for(int i=1;i<b;++i) {
    for(int j=1;j<a;++j) {
      if(!bad[i][j]) dp[i][j] = dp[i-1][j] + dp[i][j-1];
    }
  }
  // rep(i,b) {
  //   rep(j,a) printf("%3d",dp[i][j]);
  //   puts("");
  // }
  cout<<dp[b-1][a-1]<<endl;
}

int main() {
  while(cin>>a>>b,a) solve();
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

vector<int> mod13 = { 1,10,9,12,3,4 };

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() {
	string s;
	cin >> s;
	static ll memo[100001][13] = {};
	memo[0][0] = 1;
	int n = SZ(s);
	FOR(i, 1, n) {
		if (s[n - i] == '?' ) {
			ll tmp = mod13[(i - 1) % 6];
			FOR(j, 0, 12) {
				FOR(k, 0, 9) {
					memo[i][(j + k*tmp) % 13] += memo[i - 1][j];
					memo[i][(j + k*tmp) % 13] %= MOD;
				}
			}
		}
		else {
			ll num = s[n - i] - '0';
			ll tmp = mod13[(i - 1) % 6];
			FOR(j, 0, 12) {
				memo[i][(j+num*tmp)%13] += memo[i - 1][j];
				memo[i][(j + num*tmp) % 13] %= MOD;
			}
		}
	}
	pv(memo[n][5])
}

Measured memory_bytes: 10624
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc126/tasks/abc126_b

intext = input()

head2 = int(intext[0:2])
tail2 = int(intext[2:])

# is_head_yy = False
is_head_mm = False
# is_tail_yy = False
is_tail_mm = False

if 0 < head2 <= 12:
    is_head_mm = True
if 0 < tail2 <= 12:
    is_tail_mm = True

if is_head_mm and is_tail_mm:
    print('AMBIGUOUS')
elif is_head_mm:
    print('MMYY')
elif is_tail_mm:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	#ifndef ONLINE_JUDGE
//    	freopen("input.txt", "r", stdin);
 //   	freopen("output.txt", "w", stdout);
//	#endif
	int h,w;
	cin>>h>>w;
	char x;
	int a[h][w];
	rep(i,h){
		rep(j,w){
			cin>>x;
			if(x=='.')a[i][j]=1;
			else a[i][j] = 0;
		}
	}	
	ll dp[h][w];
	rep(i,h)rep(j,w)dp[i][j]=0;
	dp[0][0]=1;
	repa(i,1,h){
		if(a[i][0] == 0)break;
		dp[i][0] = 1;		
	}
	repa(i,1,w){
		if(a[0][i] == 0)break;
		dp[0][i]=1;
	}	
	repa(i,1,h){
		repa(j,1,w){
			if(a[i][j])dp[i][j] = dp[i-1][j]+dp[i][j-1];
			dp[i][j] %= mod;
			// cout<<dp[i][j]<<" ";
		}
	}
	// rep(i,h){
	// 	rep(j,w){
	// 		cout<<dp[i][j];
	// 	}
	// 	cout<<"\n";
	// }
	cout<<dp[h-1][w-1];
	return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  int dp[h][w];
  rep(i,h){
    rep(j,w) dp[i][j]=0;
  }
  vector<string> board(h);
  rep(hi,h){
    cin >> board[hi];
  }
  
  dp[0][0]=1;
  rep(i,h){
    rep(j,w){
      if(i+1<h && board[i+1][j]=='.'){
        dp[i+1][j] += dp[i][j]%INF;
        dp[i+1][j] = dp[i+1][j]%INF;
      }
      if(j+1<w && board[i][j+1]=='.')
        dp[i][j+1] += dp[i][j]%INF;
        dp[i][j+1] = dp[i][j+1]%INF;
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int a[100][100];
int b[100];
int n;
int dp[100][100];
int solve(int i, int j) {
	int sum = a[i][j];
	if (i == n) return 0;
	if (i + 1 < (n + 1) / 2) {
		if (dp[i + 1][j + 1]!=-1)
			sum = max(sum, a[i][j] + dp[i + 1][j + 1]);
		else sum = max(sum, a[i][j] + (dp[i + 1][j + 1] = solve(i + 1, j + 1)));
		if (dp[i + 1][j] != -1)
			sum = max(sum, a[i][j] + dp[i + 1][j]);
		else sum = max(sum, a[i][j] + (dp[i + 1][j] = solve(i + 1, j)));
	}
	else {
		if (i == n - 1) {
			int o = 0;
		}
		if (j < b[i + 1]) {
			if (dp[i + 1][j] != -1)
				sum = max(sum, a[i][j] + dp[i + 1][j]);
			else
				sum = max(sum, a[i][j] + (dp[i + 1][j] = solve(i + 1, j)));
		}
		if (j - 1 >= 0) {
			if (dp[i + 1][j - 1] != -1)
				sum = max(sum, a[i][j] + dp[i + 1][j - 1]);
			else
				sum = max(sum, a[i][j] + (dp[i + 1][j - 1] = solve(i + 1, j - 1)));
		}
	}
	return sum;
}
int main() {
	string s;
	int i = 0;
	int sum = 0;
	while (cin>>s) {
		s = s + ",";
		string h = "";
		sum = 0;
		for (int j = 0; j < s.length(); j++) {
			if (s[j] == ',') {
				a[i][sum] = stoi(h);
				sum++;
				h = "";
			}
			else h += s[j];
		}
		b[i] = sum;
		if (sum == 1 && i != 0) break;
		i++;
	}
	n = i+1;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++)
			dp[i][j] = -1;
	}
	cout << solve(0, 0) << endl;
}

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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

bool is_distance_int(vector<int> y, vector<int> z){
    int dist = 0;
    REP(i, y.size()){
        dist += pow(y[i]-z[i], 2);
    }

    for (int i=1; i*i <= dist; i++) {
        if (i*i == dist) return true;
    }
    return false;
}

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    REP(i, n)REP(j, d)cin >> x[i][j];

    int ans = 0;
    REP(i, n){
        FOR(j, i+1, n) {
            if (is_distance_int(x[i], x[j])) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
ans = set()
other = 0
 
for i in a:
    if i <400:
        ans.add("gray")
    elif i <800:
        ans.add("green")
    elif i < 1200:
        ans.add("brown")
    elif i <1600:
        ans.add("light_blue")
    elif i<2000:
        ans.add("blue")
    elif i<2400:
        ans.add("yellow")
    elif i <2800:
        ans.add("orange")
    elif i <3200:
        ans.add("red")
    else:
        other += 1
 
color = len(ans)
if other == N:
    print(1," ",min(other,8))
else:
    print(color, " " ,min(N,color +other))

Measured memory_bytes: 3064
#include<iostream>

using namespace std ;

int main ()

{
       int n,max1=0,mx;

       cin>>n;

       for(int i=0;i<n ;i ++)
       {
              int x ,y ;

              cin>>x>>y;

              if(x>max1)
                   {

                    max1=x;

                    mx=y+x;
                   }

       }

       cout<<mx;
       return 0;
}


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

using namespace std;

vector<int>E[100005];
int dist[2][100005];
int N;

void dfs(int d,int type,int pos){
	if(dist[type][pos]>=0){return;}

	dist[type][pos]=d;

	int i;
	for(i=0;i<E[pos].size();i++){

		if(dist[type][E[pos][i]]==-1){

			dfs(d+1,type,E[pos][i]);
		}
	}
}

int main(){

	scanf("%d",&N);

	int i;
	for(i=0;i<N-1;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		E[a].push_back(b);
		E[b].push_back(a);
	}

	memset(dist[0],-1,sizeof(dist[0]));
	memset(dist[1],-1,sizeof(dist[1]));

	dfs(0,0,1);
	dfs(0,1,N);

	int ans=0;

	for(i=1;i<=N;i++){
		if(dist[0][i]<=dist[1][i]){ans++;}//sente
		else{ans--;}//gote
	}

	if(ans>0){printf("Fennec\n");}
	else{printf("Snuke\n");}

	return 0;
}

Measured memory_bytes: 12800
from collections import deque
N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
score = sum(c) - max(c)
num = [-1] * N
que = deque()
que.append(0)
i = 0
while que:
    v = que.popleft()
    if num[v] != -1:
        continue
    num[v] = c[i]
    i += 1
    for nv in adj[v]:
        que.append(nv)
print(score)
print(*num)


Measured memory_bytes: 12096
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int a[100],n,k;

  cin>>n>>k;

  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
reverse(a,a+n);
  int result=0;
  for(int i=0;i<k;i++) result+=a[i];
  cout<<result<<endl;
  return 0;
}












Measured memory_bytes: 256
def is_valid(n, conditions):
    ns = [int(i) for i in str(n)]
    return all(ns[s - 1] == c for s, c in conditions)


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

sc = []
for _ in range(M):
    s, c = map(int, input().split())
    sc.append((s, c))

candidates = (i for i in range(1000) if len(str(i)) == N and is_valid(i, sc))

try:
    print(next(candidates))
except StopIteration:
    print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n[5];
    char c;
    REP(i,5){
      if(i) cin >> c;
      n[i]=0;
      cin >> n[i];
      if(n[i] == 0) return 0;
    }
    int num[16];
    REP(i,16) num[i]=0;
    REP(i,5) ++num[n[i]];
    num[14]=num[1];
    string s="null";
    REP(i,11){
      int st=0;
      REP(j,5) if(num[i+j]) ++st;
      if(st==5) s="straight";
    }
    int pa=0;
    REP(i,5) REP(j,i) if(n[i]==n[j]) ++pa;
    if(pa==1) s="one pair";
    if(pa==2) s="two pair";
    if(pa==3) s="three card";
    if(pa==4) s="full house";
    if(pa==6) s="four card";
    cout << s << endl;



  }
}

Measured memory_bytes: 1200
/*IT'S A VERY LONG ROAD BUT IT WILL BE WORTH IT*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int
signed main() 
{ 
    fast;
    int n,k;
    cin>>n>>k;
    int r,s,p;
    cin>>r>>s>>p;
    string ss;
    cin>>ss;
    int ans = 0;
    ss = '$'+ss;
    char pr;
    for(int i=1;i<=n;i++)
    {
        if(i<=k)
        {
            if(ss[i] == 'r')
            {
                ans+=p;
                ss[i] = 'p';
            }
            else if(ss[i] == 'p')
            {
                ans+=s;
                ss[i] = 's';
            }
            else
            {
                ans+=r;
                ss[i] = 'r';
            }
        }
        else
        {
            if(ss[i] == 'r')
            {
                if(ss[i-k] == 'p')
                {
                    ss[i] = '$';
                }
                else
                {
                    ans+=p;
                    ss[i] = 'p';
                }
            }
            else if(ss[i] == 'p')
            {
                if(ss[i-k] == 's')
                    ss[i] = '$';
                else{
                ans+=s;
                ss[i] = 's';
                }
            }
            else
            {
                if(ss[i-k] == 'r')
                    ss[i] = '$';
                else
                {
                    ans+=r;
                    ss[i] = 'r';
                }
            }
        }
    }
    cout<<ans;
} 


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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="7767";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        System.out.println(Math.min(calc(H, W), calc(W, H)));
    }

    private static long calc(long x, long y) {
        long ans = Long.MAX_VALUE;
        for (int a = 1; a <= x - 1; a++) {
            long b;
            long c;
            long t;
            if (x - a >= 2) {
                b = (x - a) / 2;
                c = x - a - b;
                t = Math.max(Math.max(a, b), c) * y - Math.min(Math.min(a, b), c) * y;
                ans = Math.min(ans, t);
            }
            b = y / 2;
            c = y - b;
            t = Math.max(Math.max(a * y, b * (x - a)), c * (x - a)) - Math.min(Math.min(b * (x - a), c * (x - a)), a * y);
            ans = Math.min(ans, t);
        }
        return ans;
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  lint sz,a,b,pa,pb,i;string s;
  cin>>sz>>a>>b>>pa>>pb>>s;a--;b--;pa--;pb--;
  
  //caricurate
  vint mp(sz);
  lint rrnz=0;lint mrnz=0;
  bool rock=false;bool vag=false;
  
  for(i=0;i<sz;i++){
    if(s.at(i) =='#'){mp[i]=1;}
    else{mp[i]=0;}
  }
  
  lint h = max(pa,pb);
  lint v = min(pa,pb);
  
  for(i=a;i<h+1;i++){
    if(mp[i]==1){rrnz++;}
    else{rrnz=0;}
    if(rrnz>1){rock=true;/*impossible*/}
  }
  
  for(i=b-1;i<v+2;i++){
    if(mp[i]==1){mrnz=0;}
    else{mrnz++;}
    if(mrnz>2){vag=true;/*3マス以上の空きアリ*/}
  }
    
  if(rock){cout<<"No"<<endl;return 0;}
  
  if(vag){
    bool su=true;bool fu=true;
    //b先にゴール
    rrnz=0;
    mp[pb]=1;
    for(i=a;i<pa+1;i++){
      if(mp[i]==1){rrnz++;}
      else{rrnz=0;}
      if(rrnz>1){su=false;/*impossible*/}
    }
    mp[pb]=0;
    //a先にゴール
    rrnz=0;
    mp[pa]=1;
    for(i=b;i<pb+1;i++){
      if(mp[i]==1){rrnz++;}
      else{rrnz=0;}
      if(rrnz>1){fu=false;/*impossible*/}
    }
    mp[pa]=0;
    
    if(su||fu){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
  }else{
    bool su=true;
    rrnz=0;
    mp[pb]=1;
    for(i=a;i<pa+1;i++){
      if(mp[i]==1){rrnz++;}
      else{rrnz=0;}
      if(rrnz>1){su=false;/*impossible*/}
    }
    mp[pb]=0;
    
    if(su){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
  }
  
}

Measured memory_bytes: 1284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define int long long
using namespace std;
const int maxn=500086;
const int mod=998244353;
int qpow(int a,int b,int p)
{
	int res=1,base=a%p;
	while(b) 
	{
		if(b&1) res=res*base%p;
		b>>=1,base=base*base%p;
	}
	return res;
}
int jc[maxn],inv[maxn];
int n,m;
int C(int n,int m)
{
	if(n<m) return 0;
	return jc[n]*inv[m]%mod*inv[n-m]%mod;
}
int F(int i)
{
	int fir=C(n,i)*C(m,i)%mod;
	int sec=qpow(m+1,n-i,mod)*qpow(n+1,m-i,mod)%mod;
	return fir*sec%mod*jc[i]%mod;
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	jc[0]=1; for(int i=1;i<maxn;++i) jc[i]=jc[i-1]*i%mod;
	inv[0]=inv[1]=1; for(int i=2;i<maxn;++i) inv[i]=mod-(mod/i)*inv[mod%i]%mod;
	for(int i=2;i<maxn;++i) inv[i]=inv[i]*inv[i-1]%mod;
	int ans=0; 
	for(int i=0,type=1;i<=n&&i<=m;++i,type=mod-type) ans=(ans+type*F(i))%mod;
	printf("%lld\n",ans);
}






Measured memory_bytes: 11028
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	string s;
	int n;
	cin >> n;
	cin >> s;
	int cnt[26] = {};
	rep(i, n) {
		cnt[s[i] - 'a']++;
	}
	llint ans = 1;
	rep(i, 26) {
		ans *= cnt[i] + 1;
		ans %= 1000000007;
	}
	ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    int tn = 2*1e5+1;
    int ans = 0;
    rep(i, N) {
        if (P[i] <= tn) {
            ans += 1;
            tn = P[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
string a,b;
cin>>a>>b;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
if(a<b)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    ll a,b,n; cin >> a >> b >> n;
    if(n == 1) cout << 0 << "\n";
    else{
        ll x;
        if(b <= n) x = n-(n%b)-1;
        else x = n;
        ll c = a*x/b;
        ll d = x/b;
        cout << c - a*d << "\n";
    }
}

Measured memory_bytes: 3584
h, w = map(int, input().split())
li = [".." + "." * w]
for i in range(h):
  li.append("." + input() + ".")
li.append(".." + "." * w)

for i in range(1, h+1):
  for j in range(1, w+1):
    if li[i][j] == "#":
      flag = False
      if li[i][j+1] == "#" or li[i][j-1] == "#" or li[i+1][j] == "#" or li[i-1][j] == "#":
        flag = True
      if not flag:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
N, M = map(int,input().split())
lst = [[] for i in range(N+1)]
for i in range(M):
    p,s = map(str,input().split())
    lst[int(p)].append(s)


ac = 0
wa = 0
for i in range(1,N+1):
    flg = 0
    tmp_wa = 0
    for submit in lst[i]:
        if submit == 'WA':
            tmp_wa += 1
        else:
            ac += 1
            wa += tmp_wa
            break
print(ac,wa)



Measured memory_bytes: 25432
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>

using namespace std;
typedef long long ll;

int main(){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(0, min(b,d) -  max(a, c) )<< endl;


}

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

const ll INF = 1LL<<62;
ll dp[105][100001];

int main(){
	ll n , W;
	cin >> n >> W;

	vector<ll> v(n) , w(n);
	for(ll i = 0 ; i < n ; i++){
		cin >> w[i] >> v[i];
	}

	for(ll i = 0 ; i < 105 ; i++){
		for(ll j = 0 ; j < 100001 ; j++){
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	dp[0][v[0]] = w[0];

	for(ll i = 1 ; i < n ; i++){
		dp[i][0] = 0;
		for(ll j = 1 ; j < 100001 ; j++){
			dp[i][j] = dp[i-1][j];
			if (j >= v[i]){
				dp[i][j] = min(dp[i][j] , dp[i-1][j-v[i]] + w[i]);
			}
		}
	}

	ll ans;

	for(ll v = 100000 ; v >= 0 ; v--){
		if (dp[n-1][v] <= W){
			ans = v;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 85656
//csjosh

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required
// using namespace __gnu_pbds; //required 
using namespace std;

#define ll long long 
#define loop(x) for(int i=0;i<x;i++)

#define llu unsigned long long 
#define pb push_back
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mt make_tuple //use tie
#define eb emplace_back
typedef tuple<int,int,int> State;//use in dijkstra
ll mod=1e9+7;
ll power(ll x,ll y,ll mod){
 ll ans=1;
 while(y>0){
  if(y&1){
    ans=(ans*x)%mod;
  }
  x=(x*x)%mod;
  y=y/2;
 }
 return ans%mod;
}

// typedef tree<
// pair<int, int>,
// null_type,
// less<pair<int, int>>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
ll ff[300005],ii[300005];
ll solve(int m,int n){
  //to do (m+n)!/m!*n!;
ll ans=ff[m+n]%mod;
ll hh=1;
hh=(hh*ii[m])%mod;
hh=(hh*ii[n])%mod;
return (ans*hh)%mod;
}
ll add(ll x,ll y){
	ll ans=(x+y+mod)%mod;
	return ans;
}
ll mul(ll x,ll y){
	return (x*y)%mod;
}
int main(){
    IOS;  
    // need to precalculate the values for all the factorials.
    int h,w,n;
    cin>>h>>w>>n;
    vector<pair<int,int> >v;
    int x,y;
    ff[0]=1;
    ii[0]=1;
    for(int i=1;i<=200009;i++){
      ff[i]=(i*ff[i-1])%mod;
      ii[i]=power(ff[i],(mod-2),mod)%mod;
    }
    loop(n)
    {
      cin>>x>>y;
      v.pb({x,y});
    }
    ll dp[n+4];
    v.pb({h,w});
    sort(v.begin(),v.end());
    for(int i=0;i<=n;i++){
     dp[i]=solve(v[i].first-1,v[i].second-1)%mod;
      for(int j=0;j<i;j++){
    if((v[i].first>=v[j].first) && (v[i].second>=v[j].second))
    	dp[i]=add(dp[i],-mul(dp[j],solve(v[i].first-v[j].first,v[i].second-v[j].second)));
      }
    }
  cout<<dp[n]<<endl;
     
}
 

// https://codeforces.com/contest/1132/problem/C
// https://codeforces.com/contest/1132/problem/F
// https://codeforces.com/problemset/problem/371/D
// https://www.codechef.com/problems/ABROADS
// https://codeforces.com/contest/913/problem/B
// https://codeforces.com/problemset/problem/580/C


// https://atcoder.jp/contests/dp/tasks/dp_v
// https://atcoder.jp/contests/dp/tasks/dp_w
// https://atcoder.jp/contests/dp/tasks/dp_x
// https://atcoder.jp/contests/dp/tasks/dp_z

Measured memory_bytes: 3968
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

int N, A, B, C, D;
string S;

vector<bool> Go(int X) {
    vector<bool> can(N);
    can[X] = true;

    for (int i = X + 1; i < N; i++) {
        if (S[i] == '.') {
            if ((i - 1 >= 0 && can[i - 1]) || (i - 2 >= 0 && can[i - 2])) {
                can[i] = true;
            }
        }
    }

    return can;
}

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

    cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;
    cin >> S;

    auto canA = Go(A);
    auto canB = Go(B);

    if (!canA[C] || !canB[D]) {
        cout << "No\n";
        return 0;
    } else {
        // A -> C; B -> D
        if (C < D) {
            cout << "Yes\n";
        } else {
            bool can_swap = false;
            for (int i = B - 1; i < D; i++) {
                if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') {
                    can_swap = true;
                }
            }
            if (can_swap) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 592
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n,d;
    std::cin >> n>>d;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll x,y;
        std::cin >> x>>y;
        if(x*x+y*y<=d*d){
            ans++;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3620
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int cnt=0;
    for(auto ch:s)if(ch=='x') cnt++;
    if(cnt>7) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int a, b;
		String sum;
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			String num[] = scan.nextLine().split(" ", 0);
			a = Integer.parseInt(num[0]);
			b = Integer.parseInt(num[1]);
			sum = String.valueOf(a+b);
			System.out.println(sum.length());
		}
	}
}

Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


vint ans(100005, INF);
vpair from[100005];

void dfs(int u) {
    if (ans[u] == INF) return;
    for (auto x : from[u]) {
        if (ans[x.fi] != INF) continue;
        if (x.se%2 == 0) ans[x.fi] = ans[u];
        else ans[x.fi] = 1 - ans[u];
        dfs(x.fi);
    }
}

int main() {
    int n;
    cin >> n;
    ans.resize(n);
    rep(i, n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        from[u].emplace_back(v, w);
        from[v].emplace_back(u, w);
    }
    
    ans[0] = 0;
    rep(i, n) dfs(i);

    out_ary(ans);

    return 0;
}

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

for i in range(1,n-1):
  num = []
  num.append(p[i-1])
  num.append(p[i])
  num.append(p[i+1])
  num.sort()
  
  if p[i]==num[1]:
    cnt+=1

print(cnt)

Measured memory_bytes: 3064
dice=gets.chomp.split(" ").map(&:to_i)
gets.chomp.split("").each do |command|
    if command == "N"
        tmp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = tmp
    elsif command == "E"
        tmp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = tmp
    elsif command == "W"
        tmp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = tmp
    else
        tmp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = tmp
    end
end
puts dice[0]


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

int main(){
    string s; 
    cin >> s;
    int q; 
    scanf("%d", &q);
    bool rev = false;

    for(int i = 0; i < q; i++){
        int t; 
        scanf("%d", &t);
        if(t == 1){
            rev = !rev;
        }else{
            int f; 
            string c;
            scanf("%d", &f);
            cin >> c;
            if(rev){
                if(f == 1) f = 2;
                else f = 1;
            }

            if(f == 1){
                // s = c+s;
                s.insert(0,c);
            }else{
                // s = s+c;
                s.push_back(c[0]);
            }
        }
    }
    int len = s.size();
    if(rev) {
        for(int i = len-1; i >= 0; i--)cout << s[i];
        cout << endl;
    }else cout << s << endl;
    return 0;
}


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

using namespace std;

int const N = 5e5+5;
int const M = 5e5+5;

int n, m;
int a[N];

pair<int, pair<int, int>> q[M];

bool sort_queries(pair<int, pair<int, int>> const& a, pair<int, pair<int, int>> const& b) {
  return a.second.second < b.second.second;
}

int bit[N];

void update(int idx, int v) {
  while(idx < N)
    bit[idx] += v, idx += (idx&-idx);
}

int query(int idx) {
  int sum = 0;
  while(idx > 0)
    sum += bit[idx], idx -= (idx&-idx);
  return sum;
}

int ans[M];

int main() {
  scanf("%d",&n);
    scanf("%d",&m);

  for(int i = 1; i <= n; ++i)
    scanf("%d",a+i);

  for(int i = 0; i < m; ++i)
    scanf("%d%d",&q[i].second.first,&q[i].second.second), q[i].first = i;

  sort(q,q+m,sort_queries);

  map<int,int> last;

  int R = 1;
  for(int i = 0; i < m; ++i) {
    int idx = q[i].first;
    int l = q[i].second.first;
    int r = q[i].second.second;

    while(R <= r) {
      int x = a[R];

      auto f = last.find(x);

      if(f == last.end())
        last[x] = R;
      else
        update(f->second, -1), f->second = R;

      update(R++, 1);
    }

    ans[idx] = query(r) - query(l-1);
  }

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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> A(n), B(n), C(n);
  for (int i = 0; i < n; i++)
    cin >> A[i];
  for (int i = 0; i < n; i++)
    cin >> B[i];
  for (int i = 0; i < n; i++)
    cin >> C[i];
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  ll cnt = 0;
  for (int b = 0; b < n; b++) {
    auto i = lower_bound(A.begin(), A.end(), B[b]);
    ll a   = i - A.begin();

    // auto i2 = upper_bound(C.begin(), C.end(), B[b]);
    // ll c    = C.end() - i2;
    auto i2 = upper_bound(C.begin(), C.end(), B[b]);
    ll c    = n - (i2 - C.begin());

    cnt += a * c;
  }
  cout << cnt << endl;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;

    // 冪剰余 a^n mod MOD
    const auto& modpow = [](unsigned long a, unsigned long n, unsigned long b = 1) -> unsigned long {
        unsigned long r{b % MOD};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    
    // オイラーのトーシェント関数 φ(n)
    const auto& totient = [](unsigned long n) -> unsigned long {
        unsigned long v{n}, k{n};
        for(unsigned long j{2}; j * j <= k; ++j)if(k % j == 0){
                v = v / j * (j - 1);
                while(k % j == 0)k /= j;
            }
        if(k > 1)v = v / k * (k - 1);
        return v;
    };
    
    unsigned long N, K;
    cin >> N >> K;
    
    // ans = Σφ(n) floor(K/i)^N
    unsigned long ans{0};
    for(unsigned long i{1}; i <= K; ++i)ans += modpow(K / i, N, totient(i));
    cout << ans % MOD << endl;
    
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();

		String[] strs = str.split("");
		int cnt = 0;

		for(int i=0; i<strs.length; i++) {

			if(strs[i].equals("2")) {
				cnt++;

			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22868
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

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

  int32_t A, B;
  cin >> A >> B;
  if((B-1) % (A-1) == 0) {
    cout << (B-1)/(A-1) << endl;
  } else {
    cout << (B-1)/(A-1) + 1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		int MOD = 1000000007;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		sc.close();

		long ans = 0;
		if(n%2 == 0){
			int[] count = new int[n];
			for(int i = 0; i <= n-1; i++) count[i] = 0;
			for(int i = 0; i < n; i++){
				count[a[i]]++;
			}
			boolean f = true;
			for(int i = 0; i <= n-1; i++){
				if(i%2 == 1 && count[i] != 2) f = false;
			}
			if(f){
				ans = 1;
				for(int i = 0; i < n/2; i++){
					ans *= 2;
					ans %= MOD;
				}
			}
		}else{
			int[] count = new int[n];
			for(int i = 0; i <= n-1; i++) count[i] = 0;
			for(int i = 0; i < n; i++){
				count[a[i]]++;
			}
			boolean f = true;
			if(count[0] != 1) f = false;
			for(int i = 2; i <= n-1; i++){
				if(i%2 == 0 && count[i] != 2) f = false; 
			}
			if(f){
				ans = 1;
				for(int i = 0; i < n/2; i++){
					ans *= 2;
					ans %= MOD;
				}
			}
		}

		System.out.println(ans);
	}
}

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

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int n, u, v;
ll val[N], LIS[N], len, ans[N];
vector<int> grid[N];

void dfs(int c, int p) {
    int idx = lower_bound(LIS + 1, LIS + n + 1, val[c]) - LIS;
    int temp = LIS[idx];
    LIS[idx] = val[c];
    ans[c] = max(ans[p], (ll)idx);
    for(auto next : grid[c]) {
        if(next != p) {
            dfs(next, c);
        }
    }
    LIS[idx] = temp;
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> val[i];
        LIS[i] = INF;
    }
    for(int i=1;i<n;i++) {
        cin >> u >> v;
        grid[u].push_back(v);
        grid[v].push_back(u);
    }
    dfs(1, 0);
    for(int i=1;i<=n;i++) cout << ans[i] << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, t;
	cin >> n >> t;
	vector<P> keiro(n);
	rep(i, n)
		cin >> keiro[i].first >> keiro[i].second;

	int min = INF;
	int ans = NIL;
	rep(i, n)
	{
		if(keiro[i].second <= t)
		{
			if(chmin(min, keiro[i].first))
				ans = keiro[i].first;
		}
	}

	cout << (ans != NIL ? to_string(ans) : "TLE") << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
height = list(map(int,input().split()))
lst = [0]*n
for j in range(m):
    x,y = map(int,input().split())
    if height[x-1] >= height[y-1]:
        lst[y-1] = 1
    if height[x-1] <= height[y-1]:
        lst[x-1] = 1
print(lst.count(0))

Measured memory_bytes: 20036