akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
ll sum(ll x) {
	return x * (x + 1) / 2;
}
int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	REP(i, k, n + 2) {
		ll I = i;
		ll mini = sum(I - 1);
		ll maxi = sum(n) - sum(n - I) + 1;
		ll tmp = (maxi - mini) % MOD;
		ans += tmp;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,ans=0;
    cin>>n;
    ans += (n/500) * 1000;
    n = n%500;
    ans += (n / 5) * 5;
    //n = n%5;
    //ans += n;
    cout<<ans;

}

Measured memory_bytes: 256
from math import *
n = int(input())
ps = set(range(2, 55556))
for i in range(2, floor(sqrt(55555) + 1)):
    if i in ps:
        k = 2
        while(i*k <= 55555):
            if i*k in ps:
                ps.remove(i*k)
            k += 1
ans = []
i = 2
while len(ans) < n and i <= 55555:
    if i in ps:
        ans.append(i)
    i += 5
print(*ans)

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<vector<vector<ll>>> dp(51, vector<vector<ll>>(51, vector<ll>(101, 0)));

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> V(N);
    rep(i, N) cin >> V.at(i);
    ll ans = 0;
    rep(l, min(N, K)+1){
        rep(r, min(N, K)+1){
            rep(d, l+r+1){
                if(l+r+d > K){
                    continue;
                }
                if(l+r > N){
                    continue;
                }
                vector<ll> get(0);
                rep(i, l){
                    get.push_back(V.at(i));
                }
                rep(i, r){
                    get.push_back(V.at(N-1-i));
                }
                sort(all(get));
                get.erase(get.begin(), get.begin()+d);
                ll tmp = 0;
                rep(i, sz(get)){
                    tmp += get.at(i);
                }
                chmax(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll h1, m1, h2, m2, k;
/******* define variable end *******/
int solve() {
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	if(m2 - m1 < 0){
		cout << (h2-h1-1)*60 + (m2-m1+60) - k << endl;
	}else{
		cout << ((h2-h1) * 60 + (m2 - m1)) - k << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3652
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for (auto c : s) {
        if (c == 'R') {
            cnt++;
        }
    }
    if (cnt * 2 > n) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
string s;

signed main() {
    cin >> N >> s;
    int l = 0, r = 0;
    int cur = 0;
    rep(i,0,N) {
        if(s[i] == '(') cur++;
        else cur--;
        if(cur == -1) {
            l++;
            cur = 0;
        }
    }
    if(cur > 0) r = cur;
    cout << string(l, '(') + s + string(r, ')') << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x[1005],y[1005],p[36],len;
bool f[2];
inline int abs(int a1)
{
	return a1>0?a1:-a1;
}
inline void print(int x1,int y1)
{
	for(int i=1;i<=len;i++)
		if(abs(x1)>abs(y1))
		{
			if(x1>0)
				putchar('R'),x1-=p[i];
			else
				putchar('L'),x1+=p[i];
		}
		else
		{
			if(y1>0)
				putchar('U'),y1-=p[i];
			else
				putchar('D'),y1+=p[i];
		}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		f[(x[i]+y[i])%2]=1;
	}
	if(f[1]&&f[0])
	{
		printf("-1\n");
		return 0;
	}
	for(int i=30;i>=0;i--)
		p[++len]=(1<<i);
	if(f[0])
		p[++len]=1;
	printf("%d\n",len);
	for(int i=1;i<len;i++)
		printf("%d ",p[i]);
	printf("%d\n",p[len]);
	for(int i=1;i<=n;i++)
	{
		print(x[i],y[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
let z = 1000000007

let pow (x, n) =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x mod z) (n / 2) acc
    else doit (x * x mod z) (n / 2) (acc * x mod z) in
  doit x n 1

let () =
  Scanf.scanf "%d %d\n" (fun m n -> (m, n)) |> pow |> Printf.printf "%d\n"

Measured memory_bytes: 2420
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        double theta ;

        if (x > Math.pow(a, 2) * b / 2) {
        	theta = Math.toDegrees(Math.atan(2 * ( Math.pow(a, 2) * b - x) / Math.pow(a, 3)));
        }else {
        	theta = Math.toDegrees(Math.atan((Math.pow(b, 2) * a) / (2 * x )));
        }


        System.out.println(theta);

    }
}

Measured memory_bytes: 22996
from itertools import accumulate
from sys import stdin
input = stdin.readline

def calctime(string):
    h,m,s = map(int, string.split(':'))
    time = h*60*60 + m*60 + s
    return time

maxtime = 24*60*60
while True:
    n = int(input())
    if n == 0:
        break
    trainlist = [0]*(maxtime)
    for _ in range(n):
        start, end = input().split()
        start = calctime(start)
        end = calctime(end)
        trainlist[start] += 1
        trainlist[end] -= 1
    trainlist = accumulate(trainlist)
    print(max(trainlist))


Measured memory_bytes: 6336
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=max(b)
if b.count(c)>1:
    for i in range(a):
        print(c)
elif b.count(c)==1:
    d=sorted(b)
    d=d[a-2]
    e=b.index(c)
    for i in range(a):
        if i==e:
            print(d)
        else:
            print(c)

Measured memory_bytes: 18996
//recurive code hai 0/1 knapsack ka
#include<bits/stdc++.h>
#include <cstdlib>

using namespace std;
#define int long long
#define fastIO  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ip(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define op(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define MAX 100001

void start(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

}

int dp[101][MAX];
int *wt,*val;

int solve(int capacity,int n,int profit){
    

    for(int i=0;i<=n;i++){
    	for(int j=0;j<=profit;j++){
    		if(i == 0 && j == 0) dp[i][j] = 0;
    		else if(i == 0) dp[i][j] = 1e11;
    		else if(j >= val[i-1]){
    			dp[i][j] = min(wt[i-1] + dp[i-1][j-val[i-1]],dp[i-1][j]);
    		}
    		else dp[i][j] = dp[i-1][j];
    	}
    }

    int ans = 0;

    for(int i=0;i<=profit;i++){
    	if(dp[n][i] <= capacity) ans = i;
    }

    return ans;

} 


int32_t main(){
// start();
fastIO 

int n,capacity;
cin>>n>>capacity;

wt = new int[n];
val = new int[n];
int profit = 0;

for(int i=0;i<n;i++){
    cin>>wt[i];
    cin>>val[i];
    profit += val[i];
}
// memset(dp,-1,sizeof(dp));
// cout<<knapsack(wt,val,capacity,n)<<endl;
// cout<<memoization(wt,val,capacity,n)<<endl;
memset(dp,0,sizeof(dp));
cout<<solve(capacity,n,profit)<<endl;


}

Measured memory_bytes: 79232
n,a,b=[int(j) for j in input().split()]
s=a-b
h=[]
for i in range(n):
    p=int(input())
    h.append(p)
h.sort()
import bisect
import math
def f(m):
    n=bisect.bisect_right(h,m*b)
    l=h[n:]
    c=0
    for i in range(len(l)):
        if l[i]-m*b/s>0:
            c+=math.ceil((l[i]-m*b)/s)
    if c<=m:
        return True
    else:
        return False
        


left=0
right=10**15
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid   #ここがleftならansもleft。
    else:
        left=mid
print(right)


Measured memory_bytes: 67160
/*
Keep clam  Believe youself
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<cmath>
#define Xiaobo main
using namespace std;
const int maxn=2e5+7;
const int mod=1e9+7;
const double eps=1e-15;
const double pi=acos(-1);
const int INF=0x3f3f3f;
typedef long long ll;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
int Xiaobo()
{
	int h,a; 
	scanf("%d%d",&h,&a);
	int ans=h/a;
	if(h%a) ans++;
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, X, M) = readLine()!!.split(' ').map { it.toLong() }
    var x = X
    var cnt = 1L
    var ans = 0L
    val f = mutableSetOf<Long>()
    val loopArr = LongArray(M.toInt()+1)
    var loopTop = -1L
    var loopIn = false
    var loopSum = 0L
    var loopLen = 0L

    while(cnt <= N && !loopIn) {
        val next = x*x
        if (f.contains(x)) {
            loopIn = true
            loopTop = x
            loopArr[loopLen.toInt()] = x
            loopSum += x
            loopLen++
        }
        f.add(x)
        ans += x
        x = next % M
        cnt++
    }
    if (x == 0L) {
        println(ans)
        return
    }

    while (cnt <= N && x != loopTop) {
        ans += x
        loopArr[loopLen.toInt()] = x
        loopSum += x
        loopLen++
        x = (x * x) % M
        cnt++
    }
    if (loopLen > 0) {
        val loops = (N - cnt) / loopLen
        ans += loopSum * loops
        cnt += loopLen * loops

        var cnt2 = 0
        while (cnt <= N) {
            ans += loopArr[cnt2]
            cnt++
            cnt2++
        }
    }

    println(ans)
}


Measured memory_bytes: 44412
//解説見ました.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

ll dp[105][4][2];

int main(){
  string s;
  cin >>s;
  ll n = s.size();
  ll hi;
  cin >> hi;
  dp[0][0][0]=1;
  for(int i=0; i<n; i++){
   for(int j=0; j<4; j++){
    for(int k=0; k<2; k++){
      ll nd = s[i]-'0';
      for(int d=0; d<10; d++){
        int ni=i+1,nj=j,nk=k;
        if(d!=0)nj++;
        if(nj>hi)continue;
        if(k==0){
          if(d>nd)continue;
          if(d<nd)nk=1;
        }
        dp[ni][nj][nk] += dp[i][j][k];
      }
    }
   }
  }
  
  ll ans = dp[n][hi][0] + dp[n][hi][1];
  cout << ans << endl;
  return 0;
}
  
  
  


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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int mx = N;
  int mn = 1, pre = -1;
  for (int i = 0; i < N; i++) {
    if (pre >= A[i]) {
      mn++;
    }
    pre = A[i];
  }

  cout << mn << endl << mx << endl;
  return 0;
}


Measured memory_bytes: 3632
class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]

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

uf1 = UnionFind(N)
for _ in range(K):
    p, q = [int(i) - 1 for i in input().split()]
    uf1.union(p, q)

uf2 = UnionFind(N)
for _ in range(L):
    r, s = [int(i) - 1 for i in input().split()]
    uf2.union(r, s)

from collections import Counter
C = Counter((uf1.find(i), uf2.find(i)) for i in range(N))
print(*[C[(uf1.find(i), uf2.find(i))] for i in range(N)])


Measured memory_bytes: 41508
N = int(input())
S = [input() for i in range(N)]

from collections import Counter
c = Counter(S)

max = None
ans = []
for k, v in sorted(c.items(), key=lambda x: -x[1]):
    if max is None:
        max = v
    if v == max:
        ans.append(k)
    else:
        break

ans.sort()
print(*ans, sep="\n")

Measured memory_bytes: 123600
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = input()
    sm = 0
    for i in n:
        sm += int(i)
        sm %= 9

    if sm == 0:
        print("Yes")
    else:
        print("No")

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 70408
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

 //< "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

enum R_Way {
	R_Left,
	R_Front,
	R_Right,
	R_Back,

	R_Dummy,
};
struct Dice {
	int tp;
	int bo;
	int no;
	int so;
	int ea;
	int we;
	Dice(int tp_, int bo_, int no_, int so_, int ea_, int we_) :
		tp(tp_), bo(bo_), no(no_), so(so_), ea(ea_), we(we_) {

	}
	Dice(vector<int>pips_) {

	}

	Dice() {
		tp = 1;
		/*bo = 6;
		no = 2;
		so = 5;
		ea = 3;
		we = 4;*/
	}
	
	int rotate(const R_Way way) {
		switch (way) {
		case R_Right: {
			int c = tp;
			tp = we;
			we = bo;
			bo = ea;
			ea = c;
		}
					  break;
		case R_Back: {
			int c = tp;
			tp = so;
			so = bo;
			bo = no;
			no = c;
		}
					 break;
		case R_Left: {
			int c = tp;
			tp = ea;
			ea = bo;
			bo = we;
			we = c;
		}
					 break;
		case R_Front: {
			int c = tp;
			tp = no;
			no = bo;
			bo = so;
			so = c;
		}
					  break;
		default:
			assert(false);
		}
		return tp;
	}
	int rotate(const int way) {
		return rotate(static_cast<R_Way>(way));
	}
	void spin(const int  clockwise) {
		if (!clockwise) {

			rotate(R_Way::R_Left);
			rotate(R_Way::R_Back);
			rotate(R_Way::R_Right);
		}
		else {

			rotate(R_Way::R_Left);
			rotate(R_Way::R_Front);
			rotate(R_Way::R_Right);
		}
	}
	int hash()const {
		return tp + we * 6 + no * 36;
	}
};

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<string, int>mp;
		mp["West"] = 0;
		mp["South"] = 1;
		mp["East"] = 2;
		mp["North"] = 3;
		mp["Right"] = 4;
		mp["Left"] = 5;
		Dice di(1, 6, 5, 2, 3, 4);
		int ans = 0;
		while (N--) {
			string st; cin >> st;
			int type = mp[st];
			if (type < 4) {
				di.rotate(type);
			}
			else {
				di.spin(!(type - 4));
			}
			ans += di.tp;


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

Measured memory_bytes: 3172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) {

        try{
            BufferedReader br=new  BufferedReader(new InputStreamReader(System.in));
            int[] rc=new int[26];
            String[] a={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
            int sw;
            String dat,str;
              
            while((dat=br.readLine())!=null){
                dat=dat.toLowerCase();
                int i=0;
                while(i<dat.length()){
                    str = dat.substring(i,i+1);
                    int j=0;
                    sw=0;
                    while(sw==0 && j<26){
                        if(str.equals(a[j])){
                            rc[j] ++;
                            sw=1;
                        }else{
                            j++;
                        }
                    }
                    i++;
                } 
            }
            for(int i=0;i<a.length;i++){
                System.out.println(a[i] + " : "+ rc[i]);
            }
        }catch(IOException e){
                e.printStackTrace();
        }
             
}
}

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

int main(){
    int N; cin >> N;
    int n = N, w=0;

    while(n>0) {
        w += n%10;
        n /= 10;
    }

    cout << (N%w==0 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3604
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
			Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
       int k=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++){
    a[i]=sc.nextInt();
    }
    int dp[]=new int[n];
   
    dp[0]=0;
    dp[1]=Math.abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
         //dp[i]=Integer.MAX_VALUE;
         dp[i] = Integer.MAX_VALUE;
      for(int j=0;j<=k;j++){
          if(i>=j)
    dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
      }
    }
  System.out.println(dp[n-1]);
	}
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int N; cin >> N;
    int a[N+1], b[N+1];
    int q[N+1];
    for(int i=1;i<=N;i++){
        int p; cin >> p;
        q[p] = i;
    }
    for(int i=1;i<=N;i++){
        a[i] = 30000 * i;
        b[i] = 30000 * (N - i) + q[i];
    }
    for(int i=1;i<=N;i++) cout << a[i] << " ";
    cout << endl;
    for(int i=1;i<=N;i++) cout << b[i] << " ";
    cout << endl;
}

Measured memory_bytes: 896
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let i, j, X, Y, xlen, ylen, maxlen;
  let c;
  let str = '';
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    c = Array.from(Array(xlen + 1), () => []);

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1||1;
        else c[i][j] = Math.max(c[i - 1][j]||0, c[i][j - 1]||0);
      }
    }
    console.log(c[xlen][ylen]);
  }
  process.stdout.write(str);
})();



Measured memory_bytes: 146608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  int c;
  int d;
  int e;
  cin >> a >> b >> c >>d;
  if(a + b == c + d){
    cout << "Balanced" << endl;
  }
  else if(a + b > c + d){
    cout << "Left" << endl;
  }
  else{
    cout << "Right" << endl;
  }
  
  }


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

using namespace std;


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

	int n, k, i, j, ct = 0;
	cin >> n >> k;
	while (n > 0) {
		ct++;
		n /= k;
	}
	cout << ct << "\n";
	return 0;
}



Measured memory_bytes: 888
h, w, k = list(map(int, input().split()))

grid = [input() for _ in range(h)]
ans = [[0]*w for _ in range(h)]

cnt = 0

for j in range(h):
    for i in range(w):
        if grid[j][i] == "#":
            cnt += 1
            l = i
            r = i
            u = j
            d = j

            moving = True
            while moving and l > 0:
                moving = False
                if ans[j][l-1] == 0 and grid[j][l-1] == ".":
                    moving = True
                    l -= 1

            moving = True
            while moving and r < w-1:
                moving = False
                if ans[j][r+1] == 0 and grid[j][r+1] == ".":
                    moving = True
                    r += 1

            moving = True
            while moving and u > 0:
                moving = False
                canMove = True

                for x in range(l, r+1):
                    if not (ans[u-1][x] == 0 and grid[u-1][x] == "."):
                        canMove = False
                        break

                if canMove:
                    moving = True
                    u -= 1

            moving = True
            while moving and d < h-1:
                moving = False
                canMove = True

                for x in range(l, r+1):
                    if not (ans[d+1][x] == 0 and grid[d+1][x] == "."):
                        canMove = False
                        break

                if canMove:
                    moving = True
                    d += 1

            for y in range(u, d+1):
                for x in range(l, r+1):
                    ans[y][x] = cnt

for row in ans:
    print(" ".join(map(str, row)))

Measured memory_bytes: 12620
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, s, x[MAXN];
ll ans, p[MAXN];
int main() {
	read(n), read(s);
	for (int i = 1; i <= n; i++)
		read(x[i]), read(p[i]);
	int l = 1, r = n, last = -1;
	while (l <= r) {
		if (x[r] < s || (x[l] < s && p[l] < p[r])) {
			if (last != -1) ans += abs(x[l] - last);
			last = x[l], p[r] += p[l++];
		} else {
			if (last != -1) ans += abs(x[r] - last);
			last = x[r], p[l] += p[r--];
		}
	}
	ans += abs(s - last);
	writeln(ans);
	return 0;
}

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

foods = {}
for i, b in zip(range(1, N + 1), B):
    if i != N:
        foods[i] = {
            "point": b,
            "bonus": C[i - 1],
            "bonus_food": i + 1
        }
    else:
        foods[i] = {
            "point": b,
            "bonus": 0,
            "bonus_food": -1
        }

point = 0
before = {
    "point": 0,
    "bonus": 0,
    "bonus_food": 0
}
for a in A:
    point += foods[a]["point"]

    if before["bonus_food"] == a:
        point += before["bonus"]

    before = foods[a]

print(point)

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, b[55][55], c[30];
char a[55][55];
int main(){
	scanf("%d", &n);
	for(int i = 0; i < 26; i++)
		c[i] = 100000;
	for(int i = 1; i <= n; i++){
		getchar();
		scanf("%s", a[i]);
	}
	for(int i = 1; i <= n; i++)
		for(int j = 0; j < strlen(a[i]); j++){
			b[i][a[i][j] - 'a']++;
		}
	for(int j = 0; j < 26; j++)
		for(int i = 1; i <= n; i++)
			c[j] = min(c[j], b[i][j]);
	for(int i = 0; i < 26; i++)
		for(int j = c[i]; j > 0; j--)
			printf("%c", (i + 'a'));
	printf("\n");
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := 0
	for i := 0; i < n; i++ {
		ans += -iScan() + iScan() + 1
	}
	fmt.Println(ans)
}


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

string strs,strt;
int arys[100010],aryt[100010];
int main(){
	cin>>strs>>strt;
	int Q;
	cin>>Q;
	int num;
	arys[0]=0;
	for(int i=1;i<=strs.length();i++){
		if(strs[i-1]=='A') num=1;
		else num=2;
		arys[i]=(arys[i-1]+num)%3;
	}
	aryt[0]=0;
	for(int i=1;i<=strt.length();i++){
		if(strt[i-1]=='A') num=1;
		else num=2;
		aryt[i]=(aryt[i-1]+num)%3;
	}

	int a,b,c,d,b_a,d_c;
	for(int i=1;i<=Q;i++){
		cin>>a>>b>>c>>d;
		b_a=(arys[b]-arys[a-1]+3)%3;
		d_c=(aryt[d]-aryt[c-1]+3)%3;
		if(b_a!=d_c) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}

	return 0;
}



Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

int main(void){
    long long int N,A,B;
    long long int X[100002];
    long long int ans=0;
    scanf("%lld %lld %lld",&N,&A,&B);
    rep(i,N)scanf("%lld",&X[i]);
    rep(i,N-1){
        ans+=min(A*(X[i+1]-X[i]),B);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String s1 = "snuke";
		sc.nextLine();
		boolean b=false;
		int i=0;
		int j = 0;
		String[][] s = new String[H][W];
		for (i=0;i<H;i++){
			for (j=0;j<W;j++){
				s[i][j] = sc.next();
			}
			sc.nextLine();
		}
		for (i=0;i<H;i++){
			for (j=0;j<W;j++){
				if (s1.equals(s[i][j])){
					b=true;
					break;
				}
			}
			if(b==true){
				break;
			}
		}
		System.out.println((char)(j+1+64)+String.valueOf(i+1));
	}

}

Measured memory_bytes: 10700
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, K;
    cin >> N >> K;

    int res = 0;
    rep(i, N) {
        int x;
        cin >> x;
        res += min(x*2, abs(x-K)*2);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
int n,m;
string s;
vector<string> vec;
 
int main(){
	cin >> n >> m;
	REP(i,0,n) cin >> s,vec.push_back(s);
	sort(vec.begin(),vec.end());
	REP(i,0,vec.size()) cout << vec[i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#define N 100099
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define LL long long
using namespace std;
int n;
struct DOT
{
    int v, id;
    bool operator<(const DOT y) const
    {
        return v < y.v;
    }
} p[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &p[i].v);
        p[i].id = i;
    }
    sort(p + 1, p + 1 + n);
    for (int i = 1; i <= n; i++)
        printf("%d ", p[i].id);
    cout << endl;
    return 0;
}


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

int main(){
	string s;cin>>s;
  	int a,b;
  	for(int i=0;i<s.size();i++){
    	if(s[i]=='A'){a=i;break;}
    }
  	for(int i=s.size()-1;i>=0;i--){
    	if(s[i]=='Z'){b=i;break;}
    }
	cout<<b-a+1<<endl;
}

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

int main()
{
    size_t N, M;
    cin >> N >> M;

    vector<int> H(N);
    for (int &h : H)
    {
        cin >> h;
    }

    vector<bool> flag(N, true);
    int A, B;
    for (size_t i = 0; i < M; i++)
    {
        cin >> A >> B;
        A--;
        B--;
        if (H[A] <= H[B])
        {
            flag[A] = false;
        }
        if (H[A] >= H[B])
        {
            flag[B] = false;
        }
    }
    int ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (flag[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3788
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       int k,x;cin>>k>>x;
       int mn = x-k+1;
       int mx = x+k-1;
       while(mx>=mn){
           cout<<mn<<" ";
           mn++;
       }
    }
    


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

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n,d;
  cin >> n >> d;

  vector<int> x(n), y(n);
  rep(i,n) {
    cin >> x[i] >> y[i];
  }

  int answer = 0;
  rep(i,n) {
    int dist = x[i] * x[i] + y[i] * y[i];
    if(dist <= d * d) {
      answer++;
    }
  }
  cout << answer << endl;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
struct query { int i,v,ans; } Q[maxn];

bool cmp1(const query& a, const query& b)
{ return a.v < b.v; }

bool cmp2(const query& a, const query& b)
{ return a.i < b.i; }

int main()
{
/* #ifdef foo_ */
/*     freopen("foo", "rt", stdin); */
/* #endif */
/*     ios::sync_with_stdio(false); */
    int n,k;
    while (cin >> n >> k) {
        VI A(n);
        FOR(i,0,n) {
            cin >> A[i];
        }
        sort(ALL(A));
        while (A.size() && k)
            A.pop_back(), k--;
        LL ans = 0;
        FOR(i,0,A.size())
            ans += A[i];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
//https://codeforces.com/gym/102465/problem/E
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int main(){
	int n;
	cin >> n;
	int flag = 0;
	while (n){
		int x = n % 10;
		n /= 10;
		if (x == 7){
			flag = 1;
			break;
		}
	}
	if (flag) cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
int main(){
    //char str[21], tmp[21];
    char *str = NULL;
    int i;
    size_t n = 0;
    ssize_t len;
    len = getline(&str, &n, stdin);
    for (i=len-2; i>=0; i--)
        printf("%c", str[i]);
        //str[j] = tmp[i];
    //printf("%s\n", str);
    puts("");
    free(str);
    return 0;
}

Measured memory_bytes: 532
s = list(input())
t = list(input())
lens = len(s)
lent = len(t)
dp = [[0]*(lens+1) for _ in range(lent+1)]

for i in range(1,lent+1):
    x = t[i-1]
    for j in range(1,lens+1):
        y = s[j-1]
        dp[i][j] = max(dp[i-1][j],dp[i][j-1])
        if x == y:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1)

m = lent
n = lens
ans = ""
while m>0 and n>0:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
        continue
    if dp[m][n] == dp[m][n-1]:
        n -= 1
        continue
    m -= 1
    n -= 1
    ans = t[m]+ans

print(ans)

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

using namespace std;

template< typename Data, typename T >
struct ReRooting {

  struct Node {
    int to, rev;
    Data data;
  };

  using F1 = function< T(T, T) >;
  using F2 = function< T(T, int, int, Data) >; // ret, src, to, data


  vector< vector< Node > > g;
  vector< vector< T > > ldp, rdp;
  vector< int > lptr, rptr;
  const F1 f1;
  const F2 f2;
  const T ident;

  ReRooting(int n, const F1 &f1, const F2 &f2, const T &ident) :
      g(n), ldp(n), rdp(n), lptr(n), rptr(n), f1(f1), f2(f2), ident(ident) {}

  void add_edge(int u, int v, const Data &d) {
    g[u].emplace_back((Node) {v, (int) g[v].size(), d});
    g[v].emplace_back((Node) {u, (int) g[u].size() - 1, d});
  }

  T dfs(int idx, int par) {

    while(lptr[idx] != par && lptr[idx] < g[idx].size()) {
      auto &e = g[idx][lptr[idx]];
      ldp[idx][lptr[idx] + 1] = f1(ldp[idx][lptr[idx]], f2(dfs(e.to, e.rev), idx, e.to, e.data));
      ++lptr[idx];
    }
    while(rptr[idx] != par && rptr[idx] >= 0) {
      auto &e = g[idx][rptr[idx]];
      rdp[idx][rptr[idx]] = f1(rdp[idx][rptr[idx] + 1], f2(dfs(e.to, e.rev), idx, e.to, e.data));
      --rptr[idx];
    }
    if(par < 0) return rdp[idx][0];
    return f1(ldp[idx][par], rdp[idx][par + 1]);
  }

  vector< T > solve() {
    for(int i = 0; i < g.size(); i++) {
      ldp[i].assign(g[i].size() + 1, ident);
      rdp[i].assign(g[i].size() + 1, ident);
      lptr[i] = 0;
      rptr[i] = (int) g[i].size() - 1;
    }
    vector< T > ret;
    for(int i = 0; i < g.size(); i++) {
      ret.push_back(dfs(i, -1));
    }
    return ret;
  }
};

const int INF = 1 << 30;
using pi = pair< double, int >;

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

  auto f1 = [](pi a, pi b) {
    return pi(a.first + b.first, a.second + b.second);
  };

  auto f2 = [](pi a, int src, int to, int data) {
    return pi((a.second == 0 ? 0.0 : a.first / a.second) + 1.0, 1);
  };

  ReRooting< int, pi > g(N, f1, f2, {0.0, 0});
  for(int i = 1; i < N; i++) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    g.add_edge(s, t, 0);
  }

  for(auto &p : g.solve()) {
    cout << fixed << setprecision(10) << (p.second == 0 ? 0.0 : p.first / p.second) << endl;
  }
}

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

def dfs(sign):
    cnt=0
    tmp=0
    for a in A:
        tmp+=a
        if tmp*sign>=0:
            cnt+=abs(tmp)+1
            tmp=-sign
        sign*=-1
    return cnt

print(min(dfs(1),dfs(-1)))

# copy

Measured memory_bytes: 14332
import math
n = int(input())
m = int(math.sqrt(8 * n + 1))

if m * m != 8 * n + 1:
  print("No")
else:
  k = int((m + 1) / 2)
  S = [[] for h in range(k)]
  l = 1
  for i in range(k - 1):
    for j in range(i + 1, k):
      S[i].append(l)
      S[j].append(l)
      l += 1
  print("Yes")
  print(k)
  s = "{} " * k
  t = s.rstrip(" ")
  for p in range(k):
    print(t.format(k - 1, *S[p]))

Measured memory_bytes: 9076
s=int(input())
s1=int(s/100)
s2=s%100
if 0<s1<=12 and 0<s2<=12:
    print("AMBIGUOUS")
elif 0<s1<=12:
    print("MMYY")
elif 0<s2<=12:
    print("YYMM")
else:
    print("NA")

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

using namespace std;

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

    vector<int> cnt(M, 0);
    for(int i = 0; i < N; ++i){
        int K; cin >> K;
        for(int j = 0; j < K; ++j){
            int A; cin >> A; --A;
            ++cnt[A];
        }
    }

    int ans = 0;
    for(int i = 0; i < M; ++i){
        if(cnt[i] == N){
            ++ans;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;

    vector<int> a(26);
    REP(i, s.size()) { a[s[i] - 'a']++; }

    REP(i, a.size()) {
        if (a[i] % 2 != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>

using namespace std;

#define ll long long
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

static int i, j, q;

int main() {
    IO;
    //ifstream cin("In.txt");
    ll n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll mi = A * (N - 1) + B;
  ll ma = B * (N - 1) + A;

  cout << max(0LL, ma - mi + 1) << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        long k = sc.nextLong();
        Integer[][] a = new Integer[62][n + 1];
        int t = 1;
        for (int i = 1; i <= n; i++) a[0][i] = sc.nextInt();
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + 1][j] = a[i][a[i][j]];
            }
            if ((k >> i & 1) == 1) t = a[i][t];
        }
        out.println(t);
        out.flush();
    }
}

Measured memory_bytes: 125416
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){

    vector <ll> A(3);
    ll cnt = 0; 

    cin >> A[0] >> A[1] >> A[2];

    sort(A.begin(),A.end());
    while(A[1] < A[2])
    {
        A[0]++;
        A[1]++;
        cnt++;;
    }

        while(A[0] < A[2])
    {
        A[0] += 2;
        cnt++;
    }

    if(A[0] > A[2])cnt++;

    cout << cnt << endl;

    return 0;
}

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

int n;
int x[maxn],y[maxn];
int d[maxn],xx[maxn];
double kq;

double dist(int i,int j){
    long long tmp=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
    return sqrt(tmp);
}

void process(){
    double tmp=0;
    for(int i=1;i<=n-1;i++)
        tmp=tmp+dist(xx[i],xx[i+1]);
    kq=kq+tmp;
}

void back(int i){
    for(int j=1;j<=n;j++)
        if (d[j]==0){
            d[j]=1;xx[i]=j;
            if (i==n) process();
            else back(i+1);
            d[j]=0;
        }
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    int gt=1;for(int i=1;i<=n;i++) gt=gt*i;
    kq=0;back(1);
    kq=kq/gt;
    printf("%.10f",kq);
}


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

using namespace std;

#define int 	long long
#define endl	"\n"
#define mod		1000000007
#define IOS		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int32_t main(){

	IOS
	int a, b, c, d, x = 0;
	cin >> a >> b >> c >> d;

	do {

		if(x++ % 2) {
			a -= d;
		}

		else {
			c -= b;
		}

	} while(a > 0 && c > 0);

	if(a > 0)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

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

using namespace std;

int main(){
  int N;

  while(cin >> N, N){
    int cnt = 0;
    string s;
    bool l = false, r = false, a = true, b = false;
    for(int i = 0 ; i < N ; i++){
      cin >> s;
      if(s == "lu"){
        if(r && a) cnt++, a = false, b = true;
        l = true;
      }else if(s == "ru"){
        if(l && a) cnt++, a = false, b = true;
        r = true;
      }else if(s == "ld"){
        if(!r && b) cnt++, a = true, b = false;
        l = false;
      }else{
        if(!l && b) cnt++, a = true, b = false;
        r = false;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1208