akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    H = list(map(int, input().split()))[::-1]

    ans = 0
    now = 0
    for i in range(1, N):
        if H[i - 1] <= H[i]:
            now += 1
        else:
            ans = max(ans, now)
            now = 0
    ans = max(ans, now)

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
    int t,n,m,c=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n-1;i++)
    {
        if(s[i+1]!=s[i])
            c++;
    }
    cout<<c+1<<endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 100000

struct UnionFind{
    vector<int> par;
    vector<int> siz;

    UnionFind(int n){
        init(n);
    }
    
    void init(int n){
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }
};

signed main(){
    int n;
    cin >> n;
    UnionFind uf(2 * MAX);
    int x[n],y[n];
    REP(i,n){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        uf.unite(x[i], y[i] + MAX);
    }
    ll cntx[2 * MAX] = {}, cnty[2 * MAX] = {};
    for(int i = 0; i < MAX; i++){
        cntx[uf.root(i)]++;
        cnty[uf.root(i + MAX)]++;
    }
    ll ans = 0;
    for(int i = 0; i < 2 * MAX; i++){
        ans += cntx[i] * cnty[i];
    }
    cout << ans - n << endl;
    return 0;
}

Measured memory_bytes: 5760
import sys

class Area:
    def __init__(self, start, end, area):
        self.start = start
        self.end = end
        self.area = area
    def addArea(self, area):
        self.area += area

if __name__ == "__main__":
    line = sys.stdin.readline().strip()
    
    area_stack = []
    field_stack = []
    
    for i in range(0, len(line)):
        c = line[i]
        if (c == "\\"):
            field_stack.append((c, i))
        elif (c == "/"):
            if len(field_stack) == 0:
                continue
            cc = field_stack.pop()
            current_area = Area(cc[1], i, (i - cc[1]))
            if len(area_stack) == 0:
                area_stack.append(current_area)
                continue
            prev_area = area_stack.pop()
            flag = True
            while (prev_area.start > current_area.start) and (prev_area.end < current_area.end):
                current_area.addArea(prev_area.area)
                if len(area_stack) == 0:
                    flag = False
                    break
                prev_area = area_stack.pop()
            if flag:
                area_stack.append(prev_area)
            area_stack.append(current_area)
    print str(reduce(lambda x, y: x + y, map(lambda x: x.area, area_stack), 0))
    s = ""
    s += str(len(area_stack)) + " "
    for item in area_stack:
        s += str(item.area) + " "
    s = s.strip()
    print s

Measured memory_bytes: 8348
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	long long n,k,i,ans=0,x,r;
	scanf("%lld%lld",&n,&k);
	for(i=k+1;i<=n;i++)//i==b
	{
		x=n/i;r=n%i;
		if(r>=k)	ans+=x*(i-k)+r-k+1;
		else	ans+=x*(i-k);
	}
	if(k==0)	printf("%lld",n*n);
	else printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

long long int f[200001] = {}, a[200001], k, i, n, p;

int main() {
    scanf("%lld %lld", &n, &k);
    for (int j = 1; j <= n; j++) scanf("%lld", &a[j]);
    for (p = i = 1; i <= k; p = a[p], i++)
        if (f[p]) k = i + (k - i) % (i - f[p]);
        else f[p] = i;
    printf("%lld", p);
    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  double kotae=0;
  if(n%2==0){
    kotae=0.5;
  }else if(n==1){
    kotae=1;
  }else{
    kotae=((double)n+1)/2/(double)n;
  }
  cout<<fixed<<setprecision(12)<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	string S;
	cin >> S;

	int ans = 0;

	for (int i = 0;i < 3;i++) {
		if (S[i] == 'o') {
			ans++;
		}
	}

	cout << 700 + ans * 100 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int main(void){
    int i,m,n;
    cin>>m>>n;
    pair<int,int> kyori[m*n];
    int stu[m][2];
    int po[n][2];
    for(i=0;i<m;i++){
        cin>>stu[i][0]>>stu[i][1];
    }
    for(i=0;i<n;i++){
        cin>>po[i][0]>>po[i][1];
    }
    
    for(i=0;i<n*m;i++){
        kyori[i].first=abs(stu[i/n][0]-po[i%n][0])+abs(stu[i/n][1]-po[i%n][1]);
        kyori[i].second=i%n;
    }
    
    for(i=0;i<m*n;i+=n){
        stable_sort(kyori+i,kyori+i+n);
        cout<<kyori[i].second+1<<"\n";
    }
}


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

int main()
{  
	long long K,A,B;
	cin >>K >> A >> B ;
	bool YesFlag=false;

	for(long long i=A;i<=B;i++){
		if(i%K==0){
		YesFlag=true;
		}
	}

	if(YesFlag)	cout<<"OK" <<endl;
	else cout <<"NG"<<endl;
	
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

const long MOD = 1000000007;

int N;
int g[21][21];
long dp[22][1<<21];
vector<int> v[22];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> g[i][j];
        }
    }
    for(int i = 0; i < (1<<N); i++){
        int cnt = 0;
        for(int j = 0; j < N; j++){
            int m = 1<<j;
            if(i&m) cnt++;
        }
        v[cnt].push_back(i);
    }
    dp[0][0] = 1;
    for(int i = 0; i < N; i++){
        //cout << i << endl;
        for(int j_ = 0; j_ < v[i].size(); j_++){
            int j = v[i][j_];
            for(int k = 0; k < N; k++){
                int m = (1<<k);
                if(!g[i][k]) continue;
                if(!(j&m)){
                    dp[i+1][j|m] += dp[i][j];
                    dp[i+1][j|m] %= MOD;
                }
            }
        }
    }
    cout << dp[N][(1<<N)-1] << endl;
}

Measured memory_bytes: 318908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    vector<string> red(h, string(w, '.')), blue(h, string(w, '.'));
    for(ll i=0; i<h; i+=2) {
        REP(j, w-1) red[i][j] = '#';
        blue[i][w-1] = '#';
    }
    for(ll i=1; i<h; i+=2) {
        red[i][0] = '#';
        FOR(j, 1, w) blue[i][j] = '#';
    }
    REP(i, h) REP(j, w) if(s[i][j]=='#') {
        red[i][j] = blue[i][j] = '#';
    }

    REP(i, h) cout << red[i] << "\n";
    cout << "\n";
    REP(i, h) cout << blue[i] << "\n";

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int inf=(1<<20);

struct excel{
    int value,weight;
};

excel hello[102];
int cnt[102][100002];
int main(void){
    int n,w;
    cin>>n>>w;
    for(int i=0;i<=n;i++){
           for(int j=0;j<=w;j++){
               cnt[i][j]=0;
           }
    }
    for(int i=1;i<=n;i++){
        int k,l;
        cin>>k>>l;
        hello[i].value=k;
        hello[i].weight=l;
    }
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            cnt[i][j]=cnt[i-1][j];
            if(hello[i].weight<=j){
                cnt[i][j]=max(hello[i].value+cnt[i-1][j-hello[i].weight],cnt[i-1][j]);
            }
        }
    }
   cout<<cnt[n][w]<<endl;
    return 0;
}



Measured memory_bytes: 7432
#include <iostream>
using namespace std;
int main()
{
	int a;
	int b;
	char s;
	int result;
	bool bLoop = true;
	
	while(bLoop)
	{
    	cin >> a >> s >> b;
    
    	if (s == '?')
    	{
    	    bLoop = false;
    	}
    	else
    	{
        	if (s == '*')
        	{
        		result = a * b;
        	}
        	else if (s == '-')
        	{
        		result = a - b;
        	}
        	else if (s == '+')
        	{
        		result = a + b;
        	}
        	else if (s == '/')
        	{
        		result = (int)(a / b);
        	}
        
        	cout << result << endl;
    	}
	}

	return 0;
}


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

using namespace std;

int main(){
	
	int n, m;
	
	long long int a[20] = {};
	for(int i = 1; i < 20; i++){
		a[i] = a[i - 1] * 3 + 2;
	}
	
	while(true){
		cin >> n >> m;
		if(n == 0){
			break;
		}
		int tile[20] = {};
		for(int loop = 0; loop < 3; loop++){
			int num;
			cin >> num;
			for(int i = 0; i < num; i++){
				int num2;
				cin >> num2;
				num2 = n - num2 + 1;
				tile[num2] = loop;
			}
		}
		tile[0] = 10000;
		tile[n + 1] = 0;
		long long int ans = 1000000000LL;
		
		long long int cnt = 0;
		for(int i = 1; i <= n; i++){
			if(abs(tile[i] - tile[i + 1]) == 1){
				if(tile[i] - tile[i + 1] != tile[i - 1] - tile[i] && tile[i + 1] != 1){
					cnt += a[i] / 2;
				}else{
					cnt *= -1;
					cnt += a[i] / 2;
				}
			}else if(abs(tile[i] - tile[i + 1]) == 2){
				cnt *= -1;
				cnt += a[i];
			}else if(tile[i] == 1){
				cnt *= -1;
			}
			//cout << cnt << " ";
		}
		//cout << cnt << endl;
		ans = min(ans, cnt);
		
		tile[n + 1] = 2;
		
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(abs(tile[i] - tile[i + 1]) == 1){
				if(tile[i] - tile[i + 1] != tile[i - 1] - tile[i] && tile[i + 1] != 1){
					cnt += a[i] / 2;
				}else{
					cnt *= -1;
					cnt += a[i] / 2;
				}
			}else if(abs(tile[i] - tile[i + 1]) == 2){
				cnt *= -1;
				cnt += a[i];
			}else if(tile[i] == 1){
				cnt *= -1;
			}
			//cout << cnt << " ";
		}
		//cout << cnt << endl;
		ans = min(ans, cnt);
		if(ans > m){
			cout << "-1" << endl;
		}else{
			cout << ans << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 2976
let readLocations n =
  List.init n (fun _ -> (Scanf.sscanf (read_line ()) "%d %d %d" (fun t x y -> (t, x, y))))


let dist (_, x1, y1) (_, x2, y2) =
  (abs (x2 - x1)) + (abs (y2 - y1))

let dt (t1, _, _) (t2, _, _) =
  t2 - t1

let test formmer latter =
  let distance = dist formmer latter in
  let diffT = dt formmer latter in
  (diffT >= distance) && (distance mod 2 = diffT mod 2)
    

let main () =
  let n = read_int () in
  let locationList = readLocations n in
  let (satisfy, _) = List.fold_left
                       (fun (b, formmer) latter ->
                         ((b && (test formmer latter)), latter))
                       (true, (0, 0, 0))
                       locationList in
  let ans = if satisfy
            then "Yes"
            else "No" in
  (
    Printf.printf "%s" ans;
    print_newline ()
  )

let _ = main ()


Measured memory_bytes: 12916
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = "*" + input()

dp = [[0] * 3 for _ in range(N+1)]
#dp[i][0,1,2] i回目にグーチョキパーを出したときの最大得点
def f(i,r):
    return K*i - r
for r in range(0, K):
    i = 1
    while f(i,r) <= N:
        if T[f(i,r)] == "r":
            if i==1:
                dp[f(i, r)][0] = 0
                dp[f(i, r)][1] = 0
                dp[f(i, r)][2] = P
            else:
                dp[f(i, r)][0] = max(dp[f(i-1, r)][1], dp[f(i-1, r)][2])
                dp[f(i, r)][1] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][2])
                dp[f(i, r)][2] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][1]) + P
        if T[f(i,r)] == "s":
            if i==1:
                dp[f(i, r)][0] = R
                dp[f(i, r)][1] = 0
                dp[f(i, r)][2] = 0
            else:
                dp[f(i, r)][0] = max(dp[f(i-1, r)][1], dp[f(i-1, r)][2]) + R
                dp[f(i, r)][1] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][2])
                dp[f(i, r)][2] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][1])
        if T[f(i,r)] == "p":
            if i==1:
                dp[f(i, r)][0] = 0
                dp[f(i, r)][1] = S
                dp[f(i, r)][2] = 0
            else:
                dp[f(i, r)][0] = max(dp[f(i-1, r)][1], dp[f(i-1, r)][2])
                dp[f(i, r)][1] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][2]) + S
                dp[f(i, r)][2] = max(dp[f(i-1, r)][0], dp[f(i-1, r)][1])
        i += 1

ans = 0
for j in range(1, K+1):
    ans += max(dp[-j])
print(ans)
    

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

int main()
{
	
	int n = 1;
	std::cin >> n;


	while (n)
	{
		std::vector<int32_t> num_list{};

		while (n--)
		{
			int tmp = 0;
			std::cin >> tmp;
			num_list.push_back(tmp);
		}

		std::vector<int32_t> comfarm_list{};
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				if (num < 0)
				{
					comfarm_list.push_back(sum);
				}
				sum += num;
			}
			sum_list.push_back(num);
		}

		for (auto sum : sum_list)
		{
			comfarm_list.push_back(sum);
		}

		int32_t max_sum = *( std::max_element(comfarm_list.begin(),comfarm_list.end()) );
		std::cout << max_sum << std::endl;
	
		std::cin >> n;
	}

	return 0;
}

Measured memory_bytes: 19316
import itertools

def main():
    atgc = ["A", "T", "G", "C"]
    mod = 10 ** 9 + 7
    n = int(input())

    dp = [[[[0 for i3 in range(4)] for i2 in range(4)] for i1 in range(4)] for i0 in range(n)]

    for i, j, k in itertools.product(range(4), range(4), range(4)):
        dp[0][i][j][k] = 1
    dp[0][0][2][3] = 0 #AGC
    dp[0][0][3][2] = 0 #ACG
    dp[0][2][0][3] = 0 #GAC

    for t in range(n-3):
        for i, j, k in itertools.product(range(4), range(4), range(4)):
            dp[t+1][i][j][k] = dp[t][0][i][j] + dp[t][1][i][j] + dp[t][2][i][j] + dp[t][3][i][j]

        for i in range(4):
            dp[t+1][i][2][3] -= dp[t][0][i][2] #(A)*GC
        for i in range(4):
            dp[t+1][2][i][3] -= dp[t][0][2][i] #(A)G*C
        #(A)GGCが重複しているので
        dp[t+1][2][2][3] += dp[t][0][2][2]

        dp[t+1][0][2][3] = 0 #AGC
        dp[t+1][0][3][2] = 0 #ACG
        dp[t+1][2][0][3] = 0 #GAC

    ans = 0
    for i, j, k in itertools.product(range(4), range(4), range(4)):
        ans += dp[n-3][i][j][k]
    print(ans%mod)
main()

Measured memory_bytes: 3440
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    int n ;
    cin >> n ;
    cout << 3*n*n ; 

























return 0 ;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

vvl cart_product (const vvl& v) {
  vvl s = {{}};
  for (auto& u : v) {
    vvl r;
    for (auto& x : s) {
      for (auto y : u) {
        r.push_back(x);
        r.back().push_back(y);
      }
    }
    s.swap(r);
  }
  return s;
}

int main() {
  //
  ll n,W;
  cin>>n>>W;
  vl w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  vvl mp(4), idx(4, vl(1, 0));
  rep(i, n) {
    rep(k, 4) {
      if (w[i] == w[0] + k) {
        mp[k].emplace_back(v[i]);
        idx[k].emplace_back(mp[k].size());
      }
    }
  }
  rep(k, 4) {
    sort(ALL(mp[k]), greater<ll>());
  }
  ll ans = 0;
  vvl a = cart_product(idx);
  for(auto& c: a) {
    ll curW = 0, curV = 0;
    rep(k, 4) {
      // cout << c[k] << " ";
      rep(i, c[k]) {
        curW += w[0] + k;
        curV += mp[k][i];
      }
    }
    // cout << endl;
    if (curW <= W) {
      ans = max(ans, curV);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vi b(m);
  vvi a(n,vector<int>(m));
  rep(i,m) cin >> b[i];
  rep(i,n)rep(j,m) cin >> a[i][j];
  int ans=0;
  rep(i,n){
    ll sum=c;
    rep(j,m){
      sum += a[i][j]*b[j];
    }
    if(sum>0) ans++;
  }
  cout << ans << endl; 
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<math.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int k;
    scanf("%d", &k);
    int max;
    if (a < b)
        max = b;
    else
        max = a;
    if (max < c)
        max = c;
    int ans = a + b + c - max;
    ans += max * pow(2, k);
    printf("%d\n", ans);
    return 0;
}

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

int main(void) {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> as(n);
  vector<int> bs(m);
  for (int &a : as) cin >> a;
  for (int &b : bs) cin >> b;

  vector<long long> aas(n + 1);
  vector<long long> bbs(m + 1);
  aas[0] = 0;
  bbs[0] = 0;
  int result = 0;
  for (int i = 1; i < n + 1; i++) aas[i] = as[i - 1] + aas[i - 1];
  for (int i = 1; i < m + 1; i++) bbs[i] = bs[i - 1] + bbs[i - 1];

  for (int i = 0; i < n + 1; i++) {
    if (k < aas[i]) break;

    vector<long long>::iterator it = upper_bound(bbs.begin(), bbs.end(), k - aas[i]);
    int idx = it == bbs.end()
      ? (bbs.size() - 1)
      : (distance(bbs.begin(), it) - 1);
    result = max(result, (int)(i + idx));
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 7996
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll cnt[55][26], ans[26];
int main() {
	ll n, now = 0, cnt = 1;
	cin >> n;
	while (1) {
		now += cnt;
		if (now >= n) {
			cout << cnt << endl;
			return 0;
		}
		cnt++;
	}
	return 0;
}

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


int main()
{
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	int ans=0;
	ans+=min(k,a);
	k-=ans;
	k-=min(k,b);
	if(k) ans-=k;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int ans=-1,cnt;
signed main(){
	ios_base::sync_with_stdio(0);
	string s;
	cin>>s;
	if(s=="RRS"||s=="SRR"){
		cout<<2;
		re 0;
	}
	if(s=="RRR"){
		cout<<3;
		re 0;
	}
	if(s=="SSS"){
		cout<<0;
		re 0;
	}
	cout<<1;
	re 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <map>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main()
{
  int N, M;
  map<string, int> mp;
  cin >> N;
  REP(i, N) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cin >> M;
  REP(i, M) {
    string s;
    cin >> s;
    mp[s]--;
  }
  int max = 0;
  for (auto it = mp.begin(); it != mp.end(); ++it)  {
    max = std::max(it->second, max);
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string S[] = {"SUSPICIOUS", "SAFE"};

int h, w;
string grid[50];
int sx[1 << 8], ex[1 << 8], sy[1 << 8], ey[1 << 8];
int g[26][26];

string solve()
{
	for (int i = 0; i < (1 << 8); i++){
		sx[i] = sy[i] = 50;
		ex[i] = ey[i] = 0;
	}
	fill_n(*g, 26 * 26, 1 << 28);
	for (int i = 0; i < 26; i++) g[i][i] = 0;
	
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			char c = grid[i][j];
			sx[c] = min(sx[c], i);
			sy[c] = min(sy[c], j);
			ex[c] = max(ex[c], i);
			ey[c] = max(ey[c], j);
		}
	}
	
	for (char c = 'A'; c <= 'Z'; c++){
		for (int x = sx[c]; x <= ex[c]; x++){
			for (int y = sy[c]; y <= ey[c]; y++){
				if (grid[x][y] == '.'){
					return S[0];
				}
				else if (grid[x][y] != c){
					g[c - 'A'][grid[x][y] - 'A'] = -1;
				}
			}
		}
	}
	
	for (int k = 0; k < 26; k++){
		for (int i = 0; i < 26; i++){
			for (int j = 0; j < 26; j++){
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}
	
	for (int i = 0; i < 26; i++){
		if (g[i][i] < 0){
			return S[0];
		}
	}
	return S[1];
}

int main()
{
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		scanf("%d %d", &h, &w);
		
		for (int i = 0; i < h; i++){
			cin >> grid[i];
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1252
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]
dp=[[0]*W for _ in range(N)]
for n in range(N):
    if n==0:
        for j in range(WV[0][0]-1,W):
          dp[n][j]=WV[0][1]
    else:
        for j in range(W):
            if (j-WV[n][0])>=0:
                dp[n][j]=max(dp[n-1][j-WV[n][0]]+WV[n][1],dp[n-1][j])
            else:
                dp[n][j]=dp[n-1][j]
print(dp[N-1][W-1])

Measured memory_bytes: 147564
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;
using PII = pair<int, int>;
int main() {
	int n;
	cin >> n;

	map<int, int> nums;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		nums[a]++;
	}

	vector<PII> v(nums.begin(), nums.end());
	sort(v.begin(), v.end(), greater<PII>());

	long long x = 0;
	long long y = 0;
	for (auto p: v) {
		if (p.second >= 4) {
			if (x == 0) {
				x = p.first;
				y = p.first;
				break;
			} else {
				y = p.first;
				break;
			}
		}
		if (p.second >= 2) {
			if (x == 0) {
				x = p.first;
			} else {
				y = p.first;
				break;
			}
		}
	}

	long long ans = x * y;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
n = gets.to_i
as = []
diff = []
gets.split(" ").each_with_index{|v, i|
  v = v.to_i
  as << v
  diff << (v - (i + 1))
}
diff.sort!
half = diff.length / 2
m = diff.length % 2 == 1 ? diff[half] : (diff[half - 1] + diff[half]) / 2
t = 0
as.each_with_index{|a, index|
  i = index + 1
  t += (a - (m + i)).abs
}
puts t


Measured memory_bytes: 19844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();
        if (k%2 == 0) {
            System.out.println(a-b);
        }
        else {
            System.out.println(b-a);
        }
        sc.close();
    }
}

Measured memory_bytes: 35576
package main

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

func main() {
	n := getInt()
	ruisekiwa := make([]int, n)
	ruisekiwa[0] = getInt()
	for i := 1; i < n; i++ {
		ruisekiwa[i] = ruisekiwa[i-1] + getInt()
	}

	ans := 1 << 60
	for i := 0; i < n-1; i++ {
		tmp := abs((ruisekiwa[n-1] - ruisekiwa[i]) - ruisekiwa[i])
		ans = min(ans, tmp)
	}

	fmt.Println(ans)
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

struct City
{
public:
    lin i;
    lin p;
    lin y;
    lin id;
};

lin n,m;
lin id[100001];

int main(void)
{
    cin >> n >> m;
    vector<City> c;
    rep(i,m)
    {
        City cc;
        lin p,y;
        cin >> p >> y;
        cc.i = i;
        cc.p = p;
        cc.y = y;

        c.push_back(cc);
    }

    sort(c.begin(), c.end(), [](const City &c1, const City &c2){ return c1.y < c2.y; });

    rep(i,m)
    {
        c[i].id = id[c[i].p];
        id[c[i].p]++;
        //cout << c[i].y << "," << c[i].p << "," << c[i].i << "," << c[i].id << endl;
    }

    sort(c.begin(), c.end(), [](const City &c1, const City &c2){ return c1.i < c2.i; });

    rep(i,m)
    {
        printf("%06d", c[i].p);
        printf("%06d", c[i].id + 1);
        printf("\n");
    }

    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(ll N, vector<pair<ll, ll>> A) {
    ll time = 0;
    sort(A.begin(), A.end());
    for (auto i : A) {
        time += i.second;
        if (time > i.first) {
            cout << NO << endl;
            return;
            ;
        }
    }
    cout << YES << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    vector<pair<ll, ll>> A(N);
    for (int i = 0; i < N; i++) {
        ll B, C;
        scanf("%lld", &B);
        scanf("%lld", &C);
        A[i].first = C;
        A[i].second = B;
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 3328
N=int(input())

def isSQ(x):
  for i in range(1,10**6+1):
    if i**2==x:
      return i
    elif i**2>x:
      return -1
  else:
    return -1

answer=0
root=isSQ(N)
if root==-1:
  for i in range(1,int(N**0.5)+1):
    if N%i==0:
      ni=N//i-1
      if N//ni==N%ni:
        answer+=ni
else:
  for i in range(1,root):
    if N%i==0:
      ni=N//i-1
      if N//ni==N%ni:
        answer+=ni

print(answer)

#answer2=0
#for i in range(1,N):
#  if N%i==N//i:
#    print(i,N%i,N//i)
#    answer2+=i
#print(answer2)

Measured memory_bytes: 9428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    ll X;
    cin >> X;
    ll n = 100;
    int i;
    for (i = 0; n < X; n *= 1.01, ++i)
        ;
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner


import scala.io.StdIn._

object Main extends App {

  val Array(n,m) = readLine().split(" ").map(_.toInt)


  def solve() = {
    val odd = if(m >= 2) m * (m-1) / 2 else 0
    val even = if(n >= 2) n * (n-1) / 2 else 0
    odd + even
  }

  println(solve())

}



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


def solve(K: int, S: str):
    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + "...")
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
n=int(input())
s=list(input())
t=list(input())
ans=0
if s==t:
    ans=n
else:
    for i in range(n-1):
        if s[1+i:]==t[:n-1-i]:
            ans=n+(i+1)
            break
if ans==0:
    ans=n*2
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int maxn = 1e5 + 10;
ll n , freq[maxn] , frq[maxn] , ans = 1 , mod = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin >> x;
		freq[x]++;
	}	
	for(int i=0;i<n;i++)
	{
		int left = n - 1 - i;
		int right = i;
		frq[abs(left - right)]++;
	}
	for(int i=0;i<maxn;i++)
	{
		if(frq[i] != freq[i]){ cout << 0; return 0; }
		if(!frq[i]) continue;
		ans = ans * frq[i];
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int A, B;

  cin >> A >> B;

  int ans_candidate_from_A = ceil(A / 0.08);

  if (B / 0.1 <= ans_candidate_from_A && ans_candidate_from_A < (B + 1) / 0.1) {
    cout << ans_candidate_from_A << endl;
    return 0;
  }

  int ans_candidate_from_B = ceil(B / 0.1);
  if (A / 0.08 <= ans_candidate_from_B && ans_candidate_from_B < (A + 1) / 0.08) {
    cout << ans_candidate_from_B << endl;
    return 0;
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        Dictionary<int, int> date = new Dictionary<int, int>();
        int ind = 0;

        for (int y = 1; y < 1000; y++)
        {
            var isLeap = y % 3 == 0;
            for (int m = 1; m <= 10; m++)
            {
                var max = isLeap || m % 2 == 1 ? 20 : 19;
                for (int d = 1; d <= max; d++)
                {
                    date.Add(Encode(y, m, d), ind++);
                }
            }
        }


        for (int i = 0; i < t; i++)
        {
            var ymd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var y = ymd[0];
            var m = ymd[1];
            var d = ymd[2];
            Console.WriteLine(ind - date[Encode(y, m, d)]);
        }
    }
    static int Encode(int y, int m, int d) => (y * 11 + m) * 21 + d;
}


Measured memory_bytes: 26804
#include "bits/stdc++.h"

using namespace std;

void Main() {
    string C1, C2;
    cin >> C1;
    cin >> C2;

    if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		@SuppressWarnings("resource")
		Scanner ab = new Scanner(System.in);
		
		while(ab.hasNext())
		{
		
		double a = ab.nextDouble();
		
		double b = ab.nextDouble();
		
		double c = ab.nextDouble();
		
		double d = ab.nextDouble();
		
		double e = ab.nextDouble();
		
		double f = ab.nextDouble();
		
		double x = (c*e - f*b)/ (a*e - b*d);
		
		double y = (c - a*x)/b;
		
		if( x == 0 || x == -0 ) x = 0;
		if( y == 0 || y == -0 ) y = 0;
		
		System.out.printf("%.3f %.3f\n",x,y);
		
		
		
		}
	}

}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N; cin >> N;
    vector<int> A(N), B(N);
    vector<pair<ll, ll>> p(N);
    REP(i, N) {
        cin >> A[i] >> B[i];
        p[i] = make_pair(B[i], A[i]);
    }

    sort(all(p), greater<pair<int,int>>());
    ll sum_num = accumulate(all(A), 0);

    string res = "No";
    for(int i = 0; i < N; ++i) {
        if(i == 0) {
            if(p[i].first < sum_num) {
                break;
            }
        } else {
            sum_num = sum_num - p[i - 1].second;
            if(p[i].first < sum_num) {
                break;
            }
        }

        if(i == N - 1) {
            res = "Yes";
        }
    }

    cout << res << endl;
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    stack<char> st;

    int ans = 0;
    for(char c : s) {
        if(st.empty() || st.top() == c)
            st.push(c);
        else
            st.pop(), ans += 2;
    }
    cout << ans << endl;
}

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


int main(){
	int n;
	cin >> n;
	vector<int> b(n);
	for(int i = 0; i < n; i++){
		cin >> b[i];
		b[i]--;
	}
	vector<int> ans;
	while(b.size() > 0){
		int z = -1;
		for(int i = 0; i < b.size(); i++){
			if(b[i] == i) z = i;
		}
		if(z == -1){
			cout << -1 << endl;
			exit(0);
		}
		ans.push_back(z);
		b.erase(b.begin() + z);
	}
	reverse(ans.begin(), ans.end());
	for(int x : ans){
		cout << x + 1 << '\n';
	}
}

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

using namespace std;
const int N = 4e3 + 77 , Mod = 1e9 + 7;
int n , m;
bool M[N];
vector < int > p;
char c;
int main(){
	cin >> n >> m;
	if(m - n >= 0)return cout << "Impossible" << endl, 0;
	for(int i = 0;i < n + m;i++){
		if(p.empty()){p.push_back(i);continue;}
		cout << '?' << ' ' << p.back() << ' ' << i << endl;
		cin >> c;
		if(c == 'N'){p.pop_back();continue;}
		p.push_back(i);
	}
	int pol = p.back();
	M[pol] = true;
	for(int i = 0;i < n + m;i++){
		if(pol == i)continue;
		cout << '?' << ' ' << pol << ' ' << i << endl;
		cin >> c;
		if(c == 'Y')M[i] = true;
	}
	cout << '!' << ' ';
	for(int i = 0;i < n + m ;i++)cout << M[i];
	cout << endl;
	return (0);
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string o,e;
  cin >> o >> e;
  REP(i,o.size()){
    cout << o[i];
    if(i < e.size())cout << e[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc123/tasks/abc123_a

import itertools
li = []
for _ in range(5):
    li.append(int(input()))
di = int(input())
for a, b in itertools.combinations(li, 2):
    if abs(a - b) > di:
        print(":(")
        exit()
print("Yay!")


Measured memory_bytes: 3060
S = input()
lens = len(S)
ans = 0
if lens % 2:
    #abcde
    mid = (lens//2)+1
    ans = 0
    for i in range(mid):
        if S[i] != S[lens-i-1]:
            ans += 1
    print(ans)
else:
    mid = lens //2
    #abcdef
    for i in range(mid):
        if S[i] != S[lens-1-i]:
            ans += 1
    print(ans)

Measured memory_bytes: 3064
def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
def yes():print("Yes")
def no():print("No")

from collections import deque, Counter
from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np
x,y=LI()

for a in range(0,x+1):
    b=x-a
    if b>=0 and 2*a+4*b==y:
        yes()
        exit()
no()
        




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

int main(){
    map<long long,long long> mp;
    long long a,n;
    bool ans = true;
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> a;
        if (mp[a] == -1) {
            ans = false;
        }
        mp[a] = -1;
    }

    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

vector<vector<int>> v(100010);
int path[111111];
bool isPath[111111];
int tyokkei;

bool dfs(int now,int depth,int prev,int goal){
	//cout << now << ' ' << depth << ' ' << prev << ' ' << goal << endl;
	tyokkei = max(tyokkei,depth+1);
	path[depth] = now;
	if(now == goal)return true;
	for(int i = 0;i < v[now].size();i++){
		if(v[now][i] == prev)continue;
		if(dfs(v[now][i],depth+1,now,goal))return true;
	}
	return false;
}

int f(int num){
	int ret;
	queue<pair<int,int>> q;
	q.push(MP(num,-1));
	while(!q.empty()){
		auto now = q.front();q.pop();
		for(int	i = 0;i < v[now.FI].size();i++){
			if(v[now.FI][i] == now.SE)continue;
			ret = v[now.FI][i];
			q.push(MP(v[now.FI][i],now.FI));
		}
	}
	return ret;
}

void makePath(){
	int A = f(0);
	int B = f(A);
	dfs(A,0,-1,B);
}

bool check(int depth){
	REP(i,tyokkei)isPath[path[i]] = true;
	for(int i = 0;i < tyokkei;i++){
		for(int j = 0;j < v[path[i]].size();j++){
			if(!isPath[v[path[i]][j]] && v[v[path[i]][j]].size() != 1){
				return false;
			}
		}
	}
	return true;
}

int main()
{
	int n;cin >> n;
	REP(i,n-1){
		int a,b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}
	makePath();
	//SHOW1d(path,tyokkei);
	if(!check(0)){
		cout << -1 << endl;
		return 0;
	}
	vector<int> ans;
	vector<int> ans2;
	ans.PB(1);
	int cou = 2;
	for(int i = 1;i < tyokkei-1;i++){
		int tmp = cou;
		for(int j = 0;j < v[path[i]].size()-2;j++){
			tmp++;
			ans.PB(tmp);
		}
		ans.PB(cou);
		cou = tmp+1;
	}ans.PB(cou);
	ans2.PB(1);
	cou = 2;
	for(int i = tyokkei-2;i > 0;i--){
		int tmp = cou;
		for(int j = 0;j < v[path[i]].size()-2;j++){
			tmp++;
			ans2.PB(tmp);
		}
		ans2.PB(cou);
		cou = tmp+1;
	}ans2.PB(cou);
	
	if(ans < ans2){
		REP(i,n){
			cout << ans[i];
			if(i != n-1)cout << ' ';
		}cout << endl;
	}
	else{
		REP(i,n){
			cout << ans2[i];
			if(i != n-1)cout << ' ';
		}cout << endl;
	}
	return 0;
}

Measured memory_bytes: 13944
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

use rand::prelude::*;

const CN: usize = 26;

fn calc(cv: &[isize], sv: &[Vec<isize>], tv: &[usize]) -> isize {
    let mut last = vec![0; CN];
    let mut res = 0;
    for i in 0..sv.len() {
        let t = tv[i];
        res += sv[i][t];
        last[t] = i + 1;
        for j in 0..CN {
            res -= cv[j] * (i + 1 - last[j]) as isize;
        }
    }
    res
}

fn gen_tv(rng: &mut rand::rngs::ThreadRng, d: usize) -> Vec<usize> {
    (0..d)
        .into_iter()
        .map(|_| rng.gen::<usize>() % CN)
        .collect::<Vec<_>>()
}

fn main() {
    input! {
        d: usize,
        cv: [isize; CN],
        sv: [[isize; CN]; d],
    };

    let mut rng = rand::thread_rng();
    let mut tv = gen_tv(&mut rng, d);
    let mut res = calc(&cv, &sv, &tv);
    for _ in 0..20000 {
        let tv2 = gen_tv(&mut rng, d);
        let p = calc(&cv, &sv, &tv2);
        if p > res {
            tv = tv2;
            res = p;
        }
    }
    for _ in 0..370000 {
        let di = rng.gen::<usize>() % d;
        let q = rng.gen::<usize>() % CN;
        let old = tv[di];
        tv[di] = q;
        let p = calc(&cv, &sv, &tv);
        if p > res {
            res = p;
        } else {
            tv[di] = old;
        }
    }
    println!("{}", tv.into_iter().map(|x| x + 1).join("\n"));
}


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

int main() {
    long long N,D;
    cin >> N >> D;
    vector<long long> X(N);
    vector<long long> Y(N);
    for(int i=0; i<N; i++){
        cin >> X.at(i) >> Y.at(i); 
    }
    int count=0;
    for(int i=0; i<N; i++){
        if(X.at(i)*X.at(i)+Y.at(i)*Y.at(i) <= D*D){
            count++;
        }
    }
    cout << count << endl;

  }


Measured memory_bytes: 6412
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string = chunk;
    const lines = input_string;
    const c = []
    c.push(lines.split(' ').map(value => parseInt(value)));

    // console.log("c:", c);
    var A = c[0][0];
    var B = c[0][1];
    var C = c[0][2];
    var A_ = A;
    var B_ = B;
    var C_ = C;
    A = B_;
    B = A_;
    C = A;
    A = C_;
    console.log(A + " " + B + " " + C);

});




Measured memory_bytes: 21192
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using static System.Console;

namespace ABC119A
{
    static class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine()?.Split('/').Select(int.Parse).ToList();

            WriteLine(CheckDate(line) ? "TBD" : "Heisei");
        }

        private static bool CheckDate(IReadOnlyList<int> list)
        {

            if (list[0] < 2019) return false;
            if (list[0] == 2019 && list[1] <= 4 && list[2] <= 30) return false;
            return true;
        }

        public static T TryParse<T>(this string input)
        {
            try
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                return (T)converter.ConvertFromString(input);
            }
            catch
            {
                throw new InvalidCastException(typeof(T) + " is not supported.");
            }
        }

        public static List<T> SplitTryParseToList<T>(this String input)
        {
            return input.Split().Select(n => n.TryParse<T>()).ToList();
        }

        public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2)
        {
            var t = list[index1];
            list[index1] = list[index2];
            list[index2] = t;
            return list;
        }

        public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list)
        {
            return list
                .GroupBy(i => i)
                .Where(g => g.Any())
                .Select(g => Tuple.Create(g.Key, g.Count()))
                .ToList();
        }
        public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list)
        {
            return list.OrderByDescending((x) => x.Item2).ToList();
        }
        public static List<T> ReadLineOne<T>(int n)
        {
            var list = new List<T>();
            foreach (var i in Enumerable.Range(1, n))
            {
                list.Add(Console.ReadLine().TryParse<T>());
            }
            return list;
        }
        public static void PrintAll<T>(this IEnumerable<T> list)
        {
            foreach (var i in list)
            {
                Console.Write($"{i} ");
            }

            Console.WriteLine();
        }
    }
}


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

U = [[0]*M for i in range(N)]

for i in range(N):
    A = list(map(int, input().split()))
    K = A[0]
    A = A[1:]
    for j in range(K):
        t = A[j] - 1
        U[i][t] = 1

cnt = 0
for i in range(M):
    cnt2 = 0
    for j in range(N):
       cnt2 += U[j][i]
       if cnt2 == N:
           cnt +=1

print(cnt)

Measured memory_bytes: 3064
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
const int N=600;
int n,d1,d2,col[2][N*N];
std::vector<std::pair<int,int>> v[2];
inline int id(const int &x,const int &y) {
	return x*N+y;
}
inline bool check(const int &x) {
	return 0<=x&&x<n*2;
}
void dfs(const int &x,const int &t) {
	const int i=x/N,j=x%N;
	for(auto &d:v[t]) {
		const int nx=i+d.first,ny=j+d.second;
		if(!check(nx)||!check(ny)) continue;
		const int y=id(i+d.first,j+d.second);
		if(!col[t][y]) {
			col[t][y]=col[t][x]==1?2:1;
			dfs(y,t);
		}
	}
}
int main() {
	n=getint(),d1=getint(),d2=getint();
	for(register int i=0;i<=d1;i++) {
		const int j=sqrt(d1-i*i);
		if(i*i+j*j!=d1) continue;
		v[0].emplace_back(std::make_pair(i,j));
		v[0].emplace_back(std::make_pair(-i,j));
		v[0].emplace_back(std::make_pair(i,-j));
		v[0].emplace_back(std::make_pair(-i,-j));
	}
	for(register int i=0;i<=d2;i++) {
		const int j=sqrt(d2-i*i);
		if(i*i+j*j!=d2) continue;
		v[1].emplace_back(std::make_pair(i,j));
		v[1].emplace_back(std::make_pair(-i,j));
		v[1].emplace_back(std::make_pair(i,-j));
		v[1].emplace_back(std::make_pair(-i,-j));
	}
	for(register int i=0;i<n*2;i++) {
		for(register int j=0;j<n*2;j++) {
			if(!col[0][id(i,j)]) {
				col[0][id(i,j)]=1;
				dfs(id(i,j),0);
			}
			if(!col[1][id(i,j)]) {
				col[1][id(i,j)]=1;
				dfs(id(i,j),1);
			}
		}
	}
	for(register int i=0,cnt=0;i<n*2;i++) {
		for(register int j=0;j<n*2;j++) {
			if(col[0][id(i,j)]==1&&col[1][id(i,j)]==1) {
				printf("%d %d\n",i,j);
				if(++cnt==n*n) return 0;
			}
		}
	}
}

Measured memory_bytes: 31872