akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const int MOD=1e9+7;

int main(){
  ll n,k;
  cin>>n>>k;
  
  ll ans=1,x;
  if(n==k){
    rep(i,n){
      cin>>x;
      ans=ans*x%MOD;
    }
    cout<<(MOD+ans)%MOD<<endl;
    return 0;
  }    
  
  vector<ll> A,B;
  rep(i,n){
    cin>>x;
    if(x>=0) A.push_back(x);
    else B.push_back(-x);
  }
  
  ll a=A.size();
  ll b=B.size();
  ll i=0,j=0;
  
  sort(ALL(A));
  sort(ALL(B));
  reverse(ALL(A));
  reverse(ALL(B));
  
  if(a==0 && k%2==1){
    for(int l=b-1;l>b-1-k;l--){
      ans=ans*B[l]%MOD;
    }
    cout<<(MOD-ans)%MOD<<endl;
    return 0;
  }
  if(a==0 && k%2==0){
    for(int l=0;l<k;l++){
      ans=ans*B[l]%MOD;
    }
    cout<<ans<<endl;
    return 0;
  }
  
  if(k%2==1){
    ans=A[0];
    i++;
    k--;
  }
  
  while(k>1){
    if(a-i<2){
      ans=(ans*B[j]%MOD)*B[j+1]%MOD;
      j+=2;
    }
    else if(b-j<2){
      ans=(ans*A[i]%MOD)*A[i+1]%MOD;
      i+=2;
    }
    else{
      if(A[i]*A[i+1]>B[j]*B[j+1]){
        ans=(ans*A[i]%MOD)*A[i+1]%MOD;
        i+=2;
      }
      else{
        ans=(ans*B[j]%MOD)*B[j+1]%MOD;
        j+=2;
      }
    }
    k-=2;
  }
  
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 5600
#include <iostream>
#include <string.h>

using namespace std;
long long int as[300006];
long long int memo0[300006];

int main() {
	// your code goes here
	int n;
	cin>>n;
	long long int sum=0;
	long long int sum0=0;
	long long int sum1=0;
	memset(memo0,0,sizeof(memo0));
	for(int i=0;i<n;i++){
		cin>>as[i];
		as[n+i]=as[i];
		as[2*n+i]=as[i];
		sum+=as[i];
	}
	int n2=(n/2-1)*2;
	for(int i=0;i<2*n;i++){
		if(i%2==0){
			sum0+=as[i];
			if(i-n2>=0){
				sum0-=as[i-n2];
			}
			memo0[i]=sum0;
		}else{
			sum1+=as[i];
			if(i-n2>=0){
				sum1-=as[i-n2];
			}
			memo0[i]=sum1;
		}
		
	}

	
	if(n==3){
		cout<<as[2]+as[0]-as[1]<<" "<<as[0]+as[1]-as[2]<<" "<<as[1]+as[2]-as[0];
		cout<<"\n";
	}else{
		for(int i=0;i<n;i++){
			int p=(i+n-1)%n;
			int p2=(p+(n/2-1)*2+1);
			long long int d=as[p]+as[(p+1)%n];
			//long long int d2=as[(p+n-1)%n]+as[(p+2)%n];
			long long int t=sum-2*d;
			if(i>0)cout<<" ";
			cout<<memo0[p2]*2-t;
		}
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 6016
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main
{
	static void merge(int arr[], int l, int m, int r) 
    { 
        int n1 = m - l + 1; 
        int n2 = r - m; 
        int L[] = new int [n1]; 
        int R[] = new int [n2]; 
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
        int i = 0, j = 0; 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
    static void sort(int arr[], int l, int r) 
    { 
        if (l < r) 
        { 
            int m = (l+r)/2; 
            sort(arr, l, m); 
            sort(arr , m+1, r); 
            merge(arr, l, m, r); 
        } 
    } 
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
    static long power(long n,long m)
    {
    	if(m==0)
    		return 1;
    	long ans=1;
    	while(m>0)
    	{
    		ans=ans*n;
    		m--;
    	}
    	return ans;
    }
	static int binarySearch(ArrayList<Integer> arr, int x) 
    { 
        int l = 0, r = arr.size() - 1,m=l + (r - l) / 2; 
        while (l <= r) { 
            m = l + (r - l) / 2; 
            if (arr.get(m) == x) 
                return m; 
            if (arr.get(m) < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return (int)Math.max(l, m); 
    } 
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=1;//Integer.parseInt(br.readLine());
	    outer:for(int i=1;i<=t;i++)
	    {
	        int n;
	        n=Integer.parseInt(br.readLine());
	        String s=br.readLine();
	        String str[]=s.split(" ");
	        int ans[]=new int[n];
	        for(int j=0;j<n-1;j++)
	        {
	        	int temp=Integer.parseInt(str[j]);
	        	ans[temp-1]++;
	        }
	        for(int j=0;j<n;j++)
	        System.out.println(ans[j]);
	    }
	}
}


Measured memory_bytes: 64636
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

int d[N][2];
string a;
int main()
{
	int i;
	cin >> a;
	a = '.' + a;
	d[1][0] = 1;
	for (i = 2; i < a.size(); i++) {
		d[i][0] = d[i - 1][1] + 1;
		d[i][1] = d[i - 2][0] + 1;
		if (a[i] != a[i - 1]) d[i][0] = max(d[i][0], d[i - 1][0] + 1);
	}
	cout << max(d[a.size() - 1][0], d[a.size() - 1][1]);
    return 0;
}

Measured memory_bytes: 2112
import fractions

A, B, C, D = map(int, input().split())

b = B//C + B//D - B//((C*D)//fractions.gcd(C, D))

A -= 1
a = A//C + A//D - A//((C*D)//fractions.gcd(C, D))
# print (a, b)
print ((B-b) - (A - a))

Measured memory_bytes: 5560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int N, M, Q;
vector<vector<int>>abcd;
ll ans = 0;
void dfs(vector<int>v, int x, int _v = 0) {
	if (_v == N) {
		ll cnt = 0;
		rep(i, 0, Q) {
			int a = abcd[i][0], b = abcd[i][1], c = abcd[i][2];
			if (v[b - 1] - v[a - 1] == c) {
				cnt += abcd[i][3];
			}
		}
		chmax(ans, cnt);
		return;
	}
	else {
		rep(i, x, M + 1) {
			vector<int>vec = v;
			vec.push_back(i);
			dfs(vec, i, _v + 1);
		}
	}
	return;
}
int main() {
	init();

	cin >> N >> M >> Q;
	abcd.resize(Q, vector<int>(4));
	rep(i, 0, Q) rep(j, 0, 4)cin >> abcd[i][j];
	vector<int>v;
	dfs(v, 1);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
 
int N, K;
int vals[5005];
 
int DPT[405][405];
 
int howclose(int i, int K, int nope) {
	if (K <= 0)
		return 1e9+10;
	if (i == N) {
		return K;
	}
	if (DPT[i][K] != -1) {
		return DPT[i][K];
	}
	if (i == nope) {
		return howclose(i+1, K, nope);
	}
	int ans = min(howclose(i+1, K-vals[i], nope), howclose(i+1, K, nope));
	return DPT[i][K] = ans;
}

vector<vector<bool>> dp_possl(5005, vector<bool>(5005)), isset = dp_possl;
bool possl(int i, int K) {
	if (K == 0)
		return 1;
	if (i < 0 || K < 0)
		return 0;
	if (isset[i][K])
		return dp_possl[i][K];
	isset[i][K] = 1;
	return dp_possl[i][K] = possl(i-1, K) || possl(i-1, K-vals[i]);
}

vector<vector<int>> dp_minr(5005, vector<int>(5005, -1));

int minr(int i, int K) {
	if (K <= 0)
		return 1e9+10;
	if (i == N)
		return K;
	if (dp_minr[i][K] != -1)
		return dp_minr[i][K];
	return dp_minr[i][K] = min(minr(i+1, K), minr(i+1, K-vals[i]));
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> vals[i];
	}
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		// for (int i = 0; i < N; ++i) {
		// 	for (int j = 0; j <= K; ++j) {
		// 		DPT[i][j] = -1;
		// 	}
		// }
		int close = 1e9+10;
		for (int p = 0; p <= K; ++p) {
			if (possl(i-1, p)) {
				close = min(close, minr(i+1, K-p));
			}
		}
		// cout << i << " " << close << " " << howclose(0, K, i) << endl;
		if (vals[i] >= close) {
			++cnt;
		}
	}
	cout << N-cnt << endl;
}

Measured memory_bytes: 105216
#include<stdio.h>

typedef long long ll;

int main() {
	char s[4];
	scanf("%s",s);
	ll ans = 0,max=0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'R') {
			ans++;
		}
		else {
			max = (max > ans) ? max : ans;
			ans = 0;
		}
	}
	max = (max>ans)?max:ans;
	printf("%lld",max );
	return 0;
}

Measured memory_bytes: 2152
import java.util.Scanner;

public class Main {

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

		int x = sc.nextInt();
		int res = 0;

		//400<=X<=1999
		res = 10 - x / 200;


		System.out.printf("%d", res);
	}
}


Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n,cnt=0;
  cin>>n;

  int a[101];

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


  for(int i=0;i<n;i++){
    for(int j=0;j<n-i-1;j++){
      if(a[j]>a[j+1]){
	cnt++;
	int temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
      }
    }
  }

  for(int i=0;i<n;i++){
    if(i==n-1){
      cout<<a[i]<<endl;
    }else{
      cout<<a[i]<<" ";
    }
  }

  cout<<cnt<<endl;
  return 0;

}



Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int n;
    bool yn = false;
    cin >> n;
    vector<char> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2; i++) {
            if ( s.at(i) == s.at(i + n / 2)) {
                yn = true;
            }
            else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else {
        cout << "No" << endl;
        return 0;
    }
    if (yn == true) cout << "Yes" << endl;
}

Measured memory_bytes: 256
n=int(input())
d={2:0}
while n%2<1:  n//=2;  d[2]+=1
for i in range(3,int(n**0.5)+1,2):
  while n%i<1:  n//=i;  d[i]=d.get(i,0)+1
  if n<2: break
if n>1: d[n]=1
a=0
for i in d.values():
  t=c=0
  while t+c<i: c+=1; t+=c
  a+=c
print(a)

Measured memory_bytes: 9416
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    S = input().strip()
    if "RRR" in S:
        print(3)
    elif "RR" in S:
        print(2)
    elif "R" in S:
        print(1)
    else:
        print(0)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61680
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
   int n,m,v;
   char s[20];
   while(scanf("%d %d",&m,&n)==2){
      if(m==0 && n==0)break;
      int dr=1,dc=0;
      int r=0,c=0;
      while(scanf("%s",s)==1){
         if(s[0]=='S')break;
         if(s[0]=='F'){
            scanf("%d",&v);
            r=max(0,min(n-1,r+v*dr));
            c=max(0,min(m-1,c+v*dc)); 
         }
         else if(s[0]=='B'){
            scanf("%d",&v);
            r=max(0,min(n-1,r-v*dr));
            c=max(0,min(m-1,c-v*dc)); 
         }
         else if(s[0]=='R'){
            swap(dr,dc);
            dr=-dr;
         }
         else if(s[0]=='L'){
            swap(dr,dc);
            dc=-dc;
         }
      }
      printf("%d %d\n",c+1,r+1);
   }
   return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};


ll a[N];
ll n, k;
ll f(ll x)
{
	ll s = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(a[i] > x)
			s += (a[i] / x) - (a[i] % x == 0);
	}
	return (s <= k);
}
int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	ll l = 1, r=  10000000000ll;
	ll ans = 1;
	for(int i = 1; i <= 50 ; i ++)
	{
		ll m = (l + r) >> 1ll;
		if(!f(m))
		{
			ans = m+1;
			l = m + 1;
		}
		else
			r = m;
	}
	cout << ans;




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 5116
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                boolean[] list = primeList(999999);
                while(sc.hasNext()){
                        int n = sc.nextInt();
                        System.out.println(primeNumber(n, list));
                }   
                sc.close();
        }   
        static boolean[] primeList(int n){
                boolean[] notprime = new boolean[n+1];
                for(int i = 2; i <= n; i++){
                        if(!notprime[i]){
                                for(int j = 2; j*i <= n; j++){
                                        notprime[j*i] = true;
                                }   
                        }   
                }   
                return notprime;
        }   
        static int primeNumber(int n, boolean[] list){
                int sum = 0;
                for(int i = 2; i <= n; i++){
                        if(!list[i]){
                                sum++;
                        }   
                }   
                return sum;
        }   
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
 
using namespace std;
 
char calc(char x,char y,char z,bool &C){
  int a = x - '0',b = y - '0',c = z - '0';
  int d = a + b + c;
 
  if(d >= 10){
    C = true;
    d -= 10;
  }
 
  return d + '0';
}
 
string sum(string a,string b){
  string res = "";
 
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
 
  int length;
  if((int)a.size() > (int)b.size()){
    length = (int)a.size();
     
    for(int i = (int)b.size() ; i < length ; i++){
      b += '0';
    }
 
  }
  else{
    length = (int)b.size();
 
    for(int i = (int)a.size() ; i < length ; i++){
      a += '0';
    }
 
  }
 
  for(int i = 0 ; i <= length ; i++)
    res += '0';
 
  for(int i = 0 ; i < length ; i++){
    bool C = false;
    res[i] = calc(a[i],b[i],res[i],C);
    if(C) res[i+1] = ((res[i+1]-'0') + 1) + '0';
  }

  for(int i = length ; i > 0; i--){
     
    if(res[i] == '0'){
      res.erase(res.begin()+i);
    }
    else{
      break;
    }
     
  }
 
  reverse(res.begin(),res.end()); 
 
  return res;
}

int main(){
  int n;

  cin >> n;
  while(n--){
    string a,b;

    cin >> a >> b;

    string c = sum(a,b);    

    if((int)c.size() > 80) cout << "overflow" << endl;
    else cout << c << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
/*
Problem : https://atcoder.jp/contests/abc140/tasks/abc140_f
Algorithm : simulate
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 5;

int n,mx;
multiset<int> a;
vector<int> v,tmp;

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i = 0;i < (1 << n);i++){
		int x;
		scanf("%d",&x);
		a.insert(x);
		mx = max(mx,x);
	}
	v.push_back(mx);
	a.erase(a.find(mx));
	for(int i = 1;i <= n;i++){
		tmp.clear();
		for(auto x : v){
			auto it = a.lower_bound(x);
			//cout << *it << endl;
			if(it == a.begin()){
				puts("No");
				return 0;
			}
			it--;
			tmp.push_back(*it);
			a.erase(it);
		}
		for(auto x : tmp)
		    v.push_back(x);
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  vector <ll> v(26, 0);
  string s;
  ll C, c;
  while (cin >> s) {
    rep(i, s.size()) {
      C = s.at(i)-'A';
      c = s.at(i)-'a';
      if (0<=C && C<26) {
        v.at(C)++;
      } else if (0<=c && c<26) {
        v.at(c)++;
      }
    }
  }
  rep(i, 26) {
    char a = i+'a';
    cout << a << " : " << v.at(i) << endl;
  }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int N;
int f[105][10];
int p[105][15];

signed main(){
  cin>>N;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=10;j++){
      cin>>f[i][j];
    }
  }
  for(int i=1;i<=N;i++){
    for(int j=0;j<=10;j++){
      cin>>p[i][j];
    }
  }

  int ans=-INF;
  for(int bit=1;bit<(1<<10);bit++){
    int sum=0;
    for(int i=1;i<=N;i++){
      int cont=0;
      for(int j=1;j<=10;j++){
        if((bit&(1<<(j-1)))&&f[i][j]==1)cont++;
      }
      sum+=p[i][cont];
    }
    ans=max(ans,sum);
  }

  cout<<ans<<"\n";
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
#define print(x) cout<<'>'<<#x<<':'<<x<<endl;
#define F first
#define S second
const int mod=1000000007;

void solve(){
    char a,b,c,d,e,f,g,h,i;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
    cout<<a<<e<<i;

}

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

    solve();

    return 0;
}




Measured memory_bytes: 256
class Node:
    def __init__(self):
        self.parent=-1
        self.left=-1
        self.right=-1

nodeList=[]
depthList=[]
heightList=[]

def readinput():
    global nodeList

    n=int(input())
    nodeList = [Node() for _ in range(n)]
    for _ in range(n):
        id,left,right = list(map(int,input().split()))
        nodeList[id].left=left
        if(left!=-1):
            nodeList[left].parent=id
        nodeList[id].right=right
        if(right!=-1):
            nodeList[right].parent=id
        #print('[id,l,r]: ',end=''); print(id,left,right)
        #printNodeList()
    return

def printNodeList():
    global nodeList
    print('\n[printNodeList]')
    for i,node in enumerate(nodeList):
        print(i, node.parent, node.left, node.right)
    print('')

def findRoot():
    global nodeList

    for i, node in enumerate(nodeList):
        if node.parent==-1:
            return i

def getDepth(p,d):
    global depthList
    global nodeList

    depthList[p]=d
    l=nodeList[p].left
    if(l!=-1):
        getDepth(l,d+1)
    r=nodeList[p].right
    if(r!=-1):
        getDepth(r,d+1)

def getHeight(p):
    global heightList
    global nodeList

    pnode=nodeList[p]
    if(pnode.left==-1 and pnode.right==-1):
        heightList[p]=0
    elif(pnode.left==-1):
        heightList[p]=getHeight(pnode.right)+1
    elif(pnode.right==-1):
        heightList[p]=getHeight(pnode.left)+1
    else:
        heightList[p]=max(getHeight(pnode.left),getHeight(pnode.right))+1
    return heightList[p]

def nodeType(id):
    global nodeList

    node=nodeList[id]
    if(node.parent==-1):
        return 'root'
    elif(node.left==-1 and node.right==-1):
        return 'leaf'
    else:
        return 'internal node'

def getSibling(id):
    global nodeList

    node=nodeList[id]
    if(node.parent==-1):
        return -1
    parent=nodeList[node.parent]
    if(parent.left==id):
        return parent.right
    else:
        return parent.left

def getChild(id):
    global nodeList

    node=nodeList[id]
    if (node.left==-1 and node.right==-1):
        return 0
    elif (node.left==-1 or node.right==-1):
        return 1
    else:
        return 2

def main():
    global nodeList
    global depthList
    global heightList
    depthList = [0]*len(nodeList)
    heightList = [0]*len(nodeList)

    root=findRoot()
    getDepth(root,0)
    getHeight(root)

    for i,node in enumerate(nodeList):
        print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'\
            .format(i, node.parent, getSibling(i), getChild(i), depthList[i], heightList[i], nodeType(i) ))


    return

if __name__=='__main__':
    readinput()
    main()


Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	string s;
	cin >> s;
	for (int i = 0; i < 4; ++i) {
		int cnt = 0;
		for (int j = 0; j < 4; ++j) {
			if (s[i] == s[j])cnt++;
		}
		if (cnt != 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, d;
    cin >> n >> m >> d;
    double ans = 0;
    if (d == 0)
    {
        ans = (double)(m - 1) / n;
    }
    else
    {
        ans = (double)2 * (n - d) * (m - 1) / (n * n);
    }
    cout << fixed;
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i >=(b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;

ll binpow1(ll a,ll b){
    ll res=1;
    while (b>0){
        if (b&1)
        res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

ll binpow2(ll a,ll b,ll m){
    a%=m;
    ll res=1;
    while (b>0){
        if (b & 1)
        res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}

ll gcd(ll a,ll b){
    if (b==0)
        return a;
    else
        return gcd(b,a%b);
}

map<ll,ll> fact(ll n) {
    map<ll,ll> factorization;ll c=0;
    while (n % 2 == 0) {
        c++;
        n /= 2;
    }
    if(c>0)
    {
        factorization.insert({2,c});
    }c=0;
    for (ll d = 3; d * d <= n; d += 2) {
        while (n % d == 0) {
            c++;
            n /= d;
        }
        if(c>0)
    {
        factorization.insert({d,c});
    }c=0;
    }
    if (n > 1)
       {
           factorization.insert({n,1});
       }
    return factorization;
}

ll dp[1001][1001];
char a[1000][1000];

ll func(ll h,ll w,ll m,ll n)
{
    ll ans=0;
    if(dp[h][w]!=-1)
    {
        return dp[h][w];
    }
    if(h==m && w==n)
    {
        dp[h][w]=1;
        return dp[h][w];
    }
    if(h+1<=m && a[h][w-1]!='#')
    {
        ans=ans+func(h+1,w,m,n)%mod1;
        ans=ans%mod1;
    }
    if(w+1<=n && a[h-1][w]!='#')
    {
        ans=ans+func(h,w+1,m,n)%mod1;
        ans=ans%mod1;
    }
    dp[h][w]=ans%mod1;
    return dp[h][w];
}

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll h,w;
    cin>>h>>w;
    memset(dp,-1,sizeof(dp));
    FOR(i,0,h)
    {
        FOR(j,0,w)
        {
            cin>>a[i][j];
        }
    }
    cout<<func(1,1,h,w)<<'\n';





	return 0;
}













Measured memory_bytes: 12496
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ManyFormulas game = new ManyFormulas();
		game.run();
	}
}

class ManyFormulas {
	
	String S;
	String[] nums;
	
	ManyFormulas() {
		Scanner cin = new Scanner(System.in);
		this.S = cin.nextLine();
		this.nums = new String[S.length()];
		char[] tmp = S.toCharArray();
		for (int i = 0; i < S.length(); i++) {
			nums[i] = String.valueOf(tmp[i]);
		}
	}
	
	void run() {
		boolean[] contained = new boolean[nums.length];
		long allSum = dfs(0, contained);
		System.out.println(allSum);
	}
	
	long dfs(int depth, boolean[] contained) {
		if (depth == nums.length - 1) {
//			contained[contained.length - 1] = false;
			return calculateSum(contained);
		}
		return dfs(depth + 1, copyArray(contained)) + dfs(depth + 1, setFlagAtIndex(contained, depth)); 
	}
	
	long calculateSum(boolean[] contained) {
		long sum = 0;
		long tmpNum = 0;
		int digit = 1;
	
		for (int i = contained.length - 1; i >= 0; i--) {
			if (contained[i]) {
				sum += tmpNum;
				digit = 1;
				tmpNum = 0;
			} 
			tmpNum += Long.valueOf(nums[i]) * digit;
			digit *= 10;
		}
		sum += tmpNum;
		return sum;
	}
	
	boolean[] setFlagAtIndex(boolean[] arr, int index) {
		boolean[] newArr = copyArray(arr);
		newArr[index] = true;
		return newArr;
	}
	
	boolean[] copyArray(boolean[] arr) {
		boolean[] newArr = new boolean[arr.length];
		for (int i = 0; i < arr.length; i++) {
			newArr[i] = arr[i];
		}
		return newArr;
	}
	
	void printArray(boolean[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 9940
#include <cstdio>

const int MN = 200005;

char S[MN];
int N, K, A[MN * 2], p;

void Solve() {
	if (!A[p]) A[p] = 1;
	else A[p++ + N] = ~N & 1;
}

int main() {
	scanf("%d%d%s", &N, &K, S + 1), p = 1;
	for (int i = 1; i <= N; ++i) A[i] = (S[i] == 'B') ^ (~i & 1);
	while (K && p <= N) Solve(), --K;
	if (K & 1) Solve();
	for (int i = 1; i <= N; ++i) printf("%c", 'A' + (A[p + i - 1] ^ (~i & 1)));
	puts("");
	return 0;
}

Measured memory_bytes: 3420
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let q: usize = read();
    let ab: Vec<(usize, usize)> = (0..n - 1).map(|_| (read(), read())).collect();
    let px: Vec<(usize, usize)> = (0..q).map(|_| (read(), read())).collect();

    let mut tree = vec![vec![]; n];

    for &(a, b) in ab.iter() {
        tree[a - 1].push(b - 1);
        tree[b - 1].push(a - 1);
    }

    let mut ans = vec![0; n];
    for &(p, x) in px.iter() {
        ans[p - 1] += x;
    }

    let mut stack = vec![0];
    let mut used = vec![false; n];

    while let Some(v) = stack.pop() {
        used[v] = true;
        for &v_i in tree[v].iter() {
            if !used[v_i] {
                ans[v_i] += ans[v];
                stack.push(v_i);
            }
        }
    }

    for i in 0..ans.len() - 1 {
        print!("{} ", ans[i]);
    }
    println!("{}", ans[..].last().unwrap());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 32892
from math import gcd
MOD = 1000_000_007

N = int(input())

Fish = {}
zeros = 0

for i in range(N):
  A, B = map(int,input().split()) 
  if A == 0 and B == 0:
    zeros += 1
    continue
  
  G = gcd(abs(A), abs(B))
  A, B = A // G, B // G
  if A < 0:
    A *= -1
    B *= -1
  elif A == 0:
    B = 1
    
  if (A, B) not in Fish:
    Fish[(A, B)] = 1
  else:
    Fish[(A, B)] += 1

#print(Fish)
done_set = set()

ans = 1
for (a, b) in Fish.keys():
  #print(a,b)
  if b > 0:
    c = b
    d = -a
  elif b == 0:
    c = 0
    d = 1
  else: 
    c, d = -b, a
  
  #print(done_set)
  #print((a,b), (c,d), done_set)
  if (a, b) in done_set or (c, d) in done_set: 
    continue
  #print((a,b), Fish[(a,b)])
  #print((c,d), Fish[(c,d)])
  if (c, d) not in Fish.keys():
    
    ans *= pow(2, Fish[(a,b)], MOD)
  else:
    ans *= (1 + (pow(2, Fish[(a,b)], MOD)-1) + (pow(2, Fish[(c,d)], MOD)-1))  
    done_set.add((c,d))
  ans %= MOD
  
  #print(done_set, ans)
  done_set.add((a,b))
  
ans += zeros
ans -= 1
ans %= MOD
#print(zeros)
print(ans)

  
    

Measured memory_bytes: 75188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    while(true){
        int h,w;
        cin >> h >> w;
        if(h==0&&w==0) break;
        for(int i = 0; i < h; ++i){
            for(int j = 0; j < w; ++j){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3072
#include <stdio.h>
int main(){
  int n,p;
  int kouho[50],mame;
  int count;
  while(1){
    scanf("%d%d",&n,&p);
    if(n==0 && p==0)break;
    for(count=0;count<n;count++){
      kouho[count]=0;
    }
    count=0;
    mame=p;
    while(kouho[count]!=p){
      if(mame>0){
	kouho[count]++;
	mame--;
      }
      else if(mame==0){
	mame=kouho[count];
	kouho[count]=0;
      }
      count++;
      if(count==n){
	count=0;
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 600
from scipy.sparse.csgraph import shortest_path
import numpy as np
import itertools

N,M,R = map(int,input().split())
r = list(map(int, input().split()))

edge = np.zeros((N+1,N+1))
for _ in range(M):
  A,B,C = map(int,input().split())
  edge[A,B] = C  
dist = shortest_path(edge, directed = False).astype(int)

answer = 10**18
for visit in itertools.permutations(r):
  p = 0
  prev = visit[0]
  for x in visit[1:]:
    if prev != None:
      p += dist[prev,x]
    prev = x
  answer = min(answer,p)
  
print(answer)


Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,M;
    cin>>N>>M;
    vector<int> out(N+3);
    rep(i,M){
        int a;
        cin>>a;
        out.at(a)=1;
    }
    vector<ll> dp(N+3);
    dp.at(0)=1;
    rep(i,N){
        dp.at(i+1)+=dp.at(i);
        dp.at(i+2)+=dp.at(i);
        dp.at(i+1)%=MOD;
        dp.at(i+2)%=MOD;
        if(out.at(i+1)){dp.at(i+1)=0;}
        if(out.at(i+2)){dp.at(i+2)=0;}
    }
    cout<<dp.at(N)<<endl;
}

Measured memory_bytes: 1408
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(400000):
    d,q=random.randrange(1,D+1),random.randrange(1,27)
    old=T[d]
    T[d]=q
    new=point()
    if new>now:
        now=new
    else:
        T[d]=old

for i in T[1:]:
    print(i)

Measured memory_bytes: 79416
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
    mut a:i64,
    mut b:i64,
    mut c:i64,
    }
    if a + b + 1 >= c {
        println!("{}", b + c);
    } else {
        println!("{}", 2 * b + a + 1);
    }
}


Measured memory_bytes: 2080
S=input()

Nflag=False
Wflag=False
Sflag=False
Eflag=False

if "N" in S:
   Nflag=True
if "W" in S:
   Wflag=True
if "S" in S:
   Sflag=True
if "E" in S:
   Eflag=True

if Nflag and Wflag and Sflag and Eflag:
   print("Yes")
elif Nflag and Sflag and Wflag==False and Eflag==False:
   print("Yes")
elif Nflag==False and Sflag==False and Wflag and Eflag:
   print("Yes")
else:
   print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int r;
char d[10000][100];
void f(char *s){//printf("%s\n",s);
  int i;
  for(i=0;i<r;i++){
    if(strcmp(s,d[i])==0)return;
  }
  strcpy(d[r++],s);
}
int main(){
  int n,i,j,k;
  char e[100],s[100],a[4][100];
  scanf("%d",&n);
  while(n--){
    r=0;
    scanf("%s",s);
    for(i=1;s[i];i++){
      for(j=0;j<i ;j++)a[0][j  ]=s[j];
      for(k=0;k<j ;k++)a[1][k  ]=s[j-k-1];
      for(j=i;s[j];j++)a[2][j-i]=s[j];
      for(k=i;s[k];k++)a[3][k-i]=s[j-k+i-1];
      a[0][i]=a[1][i]=a[2][j-i]=a[3][j-i]=0;
      //for(j=0;j<4;j++)printf("%s\n",a[j]);printf("\n");
      for(j=0;j<8;j++){//printf("%d %d\n",j/2,2-(j/4)*2+j%2);
	strcpy(e,a[j/2]);
	strcat(e,a[2-(j/4)*2+j%2]);
	f(e);
      }
    }
    printf("%d\n",r);
  }
  return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>
int main(void){
    long long int i,n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a>n%(a+b)){
        i=n%(a+b);
    }else{
        i=a;
    }
    printf("%lld",(n/(a+b))*a+i);
    return 0;    
}


Measured memory_bytes: 128
# ダイクストラ法
# connections = [[[町ｘ, コスト], [町y, コスト]], ...]
import heapq as hq


def D_stra(N, connections, st):
    mxc = float("inf") #2 ** 29
    cost = [mxc for i in range(N)]
    route = [mxc for i in range(N)]
    visited = [False for i in range(N)]
    cost[st] = 0
    q = []

    hq.heappush(q, (0, st))

    while q:
        c, node = hq.heappop(q)
        if visited[node]:
            continue
        visited[node] = True

        for connection in connections[node]:
            target, mc = connection
            if cost[target] > c + mc:
                cost[target] = c + mc
                hq.heappush(q, (c + mc, target))
                route[target] = node


    return cost, route

n, m = map(int, input().split())
mp2 =[]

connections = [[] for _ in range(n)]
for _ in range(m):
    aa, bb = map(int, input().split())
    connections[aa-1].append([bb-1, 1])
    connections[bb-1].append([aa-1, 1])

dijkstra_result = []
_, result = D_stra(n, connections, 0)

if float("inf") in result[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(result[i]+1)


Measured memory_bytes: 139504
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(ll i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(ll i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

#define print(d, arr) REP(i, d) cout << arr[i] << " "; cout << endl;
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }

ll N;
vector<ll> A, B;


int main() {
    cin >> N;
    
    ll tmp;
    REP(i, N + 1) {
        cin >> tmp;
        A.emplace_back(tmp);
    }
    
    REP(i, N) {
        cin >> tmp;
        B.emplace_back(tmp);
    }
    
    ll count = 0;
    REP(i, N) {
        if (B[i] - A[i] > 0) {
            count += A[i];
            if(A[i + 1] - (B[i] - A[i]) >= 0) {
                A[i + 1] -= B[i] - A[i];
                count += B[i] - A[i];
            } else {
                count += A[i + 1];
                A[i + 1] = 0;
            }
        } else {
            count += B[i];
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int X,A,B;
    cin >> X >> A >> B;
    X -= A;
    while(true)
        if(X-B>=0)
            X-=B;
        else
            break;
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

dy = (1, 0, -1, 0)
dx = (0, 1, 0, -1)

h, w = map(int, input().split())
table = []
for _ in range(h):
    table.append(list(input()))
q = deque()
for y in range(h):
    for x in range(w):
        if table[y][x] == "#":
            q.append((y, x))
            table[y][x] = 0

while q:
    y, x = q.popleft()
    d = table[y][x]
    for k in range(4):
        ny, nx = y + dy[k], x + dx[k]
        if 0 <= ny < h and 0 <= nx < w:
            if table[ny][nx] == ".":
                table[ny][nx] = d + 1
                q.append((ny, nx))
print(max(list(map(lambda n: max(n), table))))


Measured memory_bytes: 135772
(defun join (list sep)
 (with-output-to-string (s)
   (labels ((fn (list)
              (cond ((null (cdr list)) (princ (car list) s))
                    (t (princ (car list) s)
                       (princ sep s)
                       (fn (cdr list))))))
     (fn list))))

(let ((len (length (read-line))))
     (format t "~A" (join (loop repeat len collect "x") "")))

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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n , k;
   cin >> n >> k;
   int r , s , p;
   cin >> r >> s >> p;
   vector<char> t(n + 1);
   for (int i = 1; i <= n; i++) {
      cin >> t[i];
   }
   auto getWinner = [&](char tp) {
      if (tp == 'r')
         return 'p';
      if (tp == 'p')
         return 's';
      if (tp == 's')
         return 'r';
   };
   int r_win = 0 , s_win = 0 , p_win = 0;
   auto winnerPlus = [&](char tp , int delta) {
      if (tp == 'r')
         r_win += delta;
      if (tp == 's')
         s_win += delta;
      if (tp == 'p')
         p_win += delta;
   };
   int ans = 0;
   vector<bool> dels(n + 1 , false);
   for (int i = 1; i <= n; i++) {
      char win = getWinner(t[i]);
      winnerPlus(win , 1);
      if (i - k >= 1) {
         if (win == getWinner(t[i - k]) && !dels[i - k]) {
            dels[i] = true;
            winnerPlus(win , -1);
         }
      }
   }
   cout << r * r_win + s * s_win + p * p_win << '\n';
   return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define each(e,v) for(auto&& e:(v))
#define DEBUG(x) cout<<#x<<": "<<x<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;

int main() {
    int n; cin >> n;
    vint t(n), a(n);
    rep(i, n) {
        cin >> t[i] >> a[i];
    }
    ll A = 1, B = 1;
    rep(i, n) {
        ll c1 = (A-1+t[i]) / t[i];
        ll c2 = (B-1+a[i]) / a[i];
        ll c = max(c1, c2);
        A = c * t[i];
        B = c * a[i];
    }
    cout << A + B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    cout << b << a << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.math;
import std.random;
import std.range;
import std.algorithm;
import std.functional;
import core.bitop;
import std.bigint;
import std.typecons;
import std.container;

void main()
{
    auto input = readln.split.to!(int[]);
    auto N = input[0], A = input[1], B = input[2];

    int result;
    foreach (e; 1 .. N + 1)
    {
        auto s = e.to!(string).map!(a => a.to!int - '0').sum;
        if (A <= s && s <= B)
            result += e;
    }
    result.writeln;
}


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

using namespace std;

void solve() {
    char X, Y;
    cin >> X >> Y;
    if (X < Y)
    {
        cout << "<" << endl;
    }
    else if (X > Y)
    {
        cout << ">" << endl;
    }
    else
    {
        cout << "=" << endl;
    }
}

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

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	cout<<6-n-m;
	
}


Measured memory_bytes: 3524
// ------------------------------------
// Date:2018/ 3/11
// Problem:ABC 090 . b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

bool check(int i) {
  string tmp = to_string(i);
  // cout << tmp << endl;
  REP(ti, tmp.size()) {
    if (tmp[ti] != tmp[tmp.size() - ti - 1]) return false;
  }
  return true;
}

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

  int a, b;
  int cnt = 0;
  cin >> a >> b;
  FOR(i, a, b + 1) {
    if (check(i)) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1400000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}
char* di = cn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = X + '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	fread(cn, 1, CM, stdin);
	int N = getint();
	rep(i, N - 1) A[getint()]++;

	rep1(i, N) putint(A[i]);

	fwrite(cn, 1, di - cn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 3528
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        ans ^=a;
    }
    if(ans==0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<int> v(N);
  for(auto &vi: v) cin >> vi;
  sort(v.begin(), v.end());
  double s=0.5*(v[0]+v[1]);
  for(int i=2; i<N; i++) s = (s+v[i])/2.0;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  std::string s;
  cin >> s;
  s = "." + s;

  if (c < d) {
    for (int i = a; i < d; i++) {
      if (s[i] == '#' && s[i + 1] == '#') {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  } else {
    for (int i = a; i < d; i++) {
      if (s[i] == '#' && s[i + 1] == '#') {
        cout << "No" << endl;
        return 0;
      }
    }

    for (int i = b - 1; i <= d - 1; i++) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 888