akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int field[6][6]={0};
  string s;
  for(int i=0; i<5; i++){
    cin >>s;
    for(int j=0; j<s.size(); j++){
      if(s[j] == '1'){
	field[i][j+1]+=4;
	field[i+1][j+1]+=1;
      }
    }
    cin >>s;
    if(i!=4){
      for(int j=0; j<s.size(); j++){
	if(s[j] == '1'){
	  field[i+1][j]+=2;
	  field[i+1][j+1]+=8;
	}
      }
    }
  }
  int d = 2,x = 0,y = 1;
  for(;;){
    if(d == 1){
      if(field[x][y]&2){
	cout <<"U";
	if(field[x][y]&1)d = 8;
	else x--; 
      }
      else{d = 2;y++;}
    }
    else if(d == 2){
      if(field[x][y]&4){
	cout <<"R";
	if(field[x][y]&2) d = 1;
	else y++;
      }
      else{d = 4;x++;}
    }
    else if(d == 4){
      if(field[x][y]&8){
	cout <<"D";
	if(field[x][y]&4) d = 2;
	else x++;
      }
      else{d = 8;y--;}
    }
    else if(d == 8){
      if(field[x][y]&1){
	cout <<"L";
	if(field[x][y]&8) d = 4;
	else y--;
      }
      else{d = 1;x--;}
    }
    if(x == 0 && y == 1) break;
  }
  cout <<endl;
  return 0;
}

Measured memory_bytes: 1176
<?php
fscanf(STDIN, "%d", $n);

$sum = 0;
for ($i=1; $i <= $n; $i++) {
  for ($j=1; $j <= $n; $j++) {
    $ij = gcd($i, $j);
    for ($k=1; $k <= $n; $k++) {
      $sum += gcd($ij, $k);
    }
  }
}

echo $sum;

function gcd($m, $n)
{
  if($n > $m) list($m, $n) = array($n, $m);

  while($n !== 0){
    $tmp_n = $n;
    $n = $m % $n;
    $m = $tmp_n;
  }
  return $m;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	int n;
	cin>>n;
	vector<int> A(n);
	rep(i,n){
		cin>>A[i];
	  }
	  SORT(A);
	  cout<<A[n-1]-A[0];
		  }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        System.out.println((int)Math.pow(n, 3));
    }

}


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

#define      ll     long long int

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 17, M = (1 << 16), mod = 1e9 + 7;
int jc[M], ny[M];

int add(int x, int y) {
  return (x += y) > mod ? x - mod : x;
}

void Add(int &x, int y) {
  x = add(x, y);
}

int sub(int x, int y) {
  return (x -= y) < 0 ? x + mod : x;
}

void Sub(int &x, int y) {
  x = sub(x, y);
}

int mul(int x, int y) {
  return 1ll * x * y % mod;
}

void Mul(int &x, int y) {
  x = mul(x, y);
}

int q_pow(int x, int y) {
  int ans = 1;
  for(; y; y >>= 1) {
    if(y & 1) Mul(ans, x);
    Mul(x, x);
  }
  return ans;
}

int nm[M];
void init() {
  jc[0] = 1;
  for(int i = 1; i < M; ++i) jc[i] = mul(jc[i - 1], i);
  for(int i = 1; i < M; ++i)
    nm[i] = nm[i >> 1] + (i & 1);
  ny[M - 1] = q_pow(jc[M - 1], mod - 2);
  for(int i = M - 2; i >= 0; --i)
    ny[i] = mul(ny[i + 1], i + 1);
}

int C(int x, int y) {
  if(x < y) return 0;
  return mul(jc[x], mul(ny[y], ny[x - y]));
}

int f[N][M], a[N];
int main() { 
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= m; ++i) scanf("%d", &a[i]);  
  sort(a + 1, a + m + 1);
  reverse(a + 1, a + m + 1);
  f[0][0] = 1;
  int tot = 1 << n;
  for(int j = 0; j < tot; ++j)
    for(int i = 1; i <= m; ++i) {
      Add(f[i][j], f[i - 1][j]);
      for(int k = 0; k < n; ++k) {
        if((j >> k) & 1) continue;
        int last = tot - j - a[i], sum = (1 << k);
        Add(f[i][j | (1 << k)], mul(mul(f[i - 1][j], C(last, sum - 1)), jc[sum]));
     }
  }
  int ans = 0;
/*  for(int i = 1; i <= m; ++i) 
    for(int j = 0; j < tot; ++j) {
    if(f[i][j]) printf("f[%d][%d] = %d\n", i, j, f[i][j]);
  }*/
  for(int i = 0; i <= tot; ++i) {
    if(nm[i] & 1) Sub(ans, mul(jc[tot - 1 - i], f[m][i]));
    else Add(ans, mul(jc[tot - 1 - i], f[m][i]));
  }
  printf("%d\n", mul(ans, tot));
  return 0;
}

/*
2 1
3

8
*/

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
 
  int N,K; cin >> N >> K;
  int num = 0;
  double p = 0.0;
  for(int i=1;i<N+1;i++){
    int a = i;
    num = 0;
    while(a<K){
      a *= 2;
      num++;
    }
    p += 1/(pow(2.0,num)*N);
  }
  
  cout << fixed << setprecision(12);
  cout << p << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18L+5;
const int nax= 2e5+30;
vector<ll> dp(nax,inf);
vector<ll> tree(4*nax);
vector<ll> lazy(4*nax);
void build(int v,int tl,int tr) 
{
    if(tl>tr) return;
    if(tl==tr)
    {
        tree[v]=dp[tl];
        return;
    }
    int tm=(tl+tr)/2;
    build(2*v,tl,tm);
    build(2*v+1,tm+1,tr);
    tree[v]=min(tree[2*v],tree[2*v+1]);
}
void push(int v)
{
    tree[2*v]+=lazy[v];
    tree[2*v+1]+=lazy[v];
    lazy[2*v]+=lazy[v];
    lazy[2*v+1]+=lazy[v];
    lazy[v]=0;
}
void add(int v,int tl,int tr,int l,int r,ll sum)
{
    int tm=(tl+tr)/2;
    if(l>r) return;
    if(tl>=l&&tr<=r)
    {
        lazy[v]+=sum;
        tree[v]+=sum;
        return;

    }
    else
    {
        push(v);
        add(2*v,tl,tm,l,min(tm,r),sum);
        add(2*v+1,tm+1,tr,max(l,tm+1),r,sum);
        tree[v]=min(tree[2*v],tree[2*v+1]);
    }
    

}
ll get_min(int v,int tl,int tr,int l,int r)
{
    if(l>r) return inf;
    if(tl>=l&&tr<=r)
    {
        return tree[v];
    }
    else
    {
        push(v);
        int tm=(tl+tr)/2;
        return(min(get_min(2*v,tl,tm,l,min(tm,r)),get_min(2*v+1,tm+1,tr,max(l,tm+1),r)));
    }
    
}
void update(int v,int tl,int tr,int pos,int val)
{
    if(tl==tr)
    {
        tree[v]=val;
       // dp[tl]=val;
        return;
    }
    int tm=(tl+tr)/2;
     push(v);
    if(pos<=tm)
    {
       
        update(2*v,tl,tm,pos,val);
    }
    else update(2*v+1,tm+1,tr,pos,val);
    tree[v]=min(tree[2*v],tree[2*v+1]);
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<pair<int,ll>  > > vec(n+1);
    ll sum=0;
    for(int i=0;i<m;i++)
    {
        int l,r;ll a;
        cin>>l>>r>>a;
        sum+=a;
        vec[r].push_back({l,a});
    }
    dp[0]=0;
    build(1,0,n+1);
    for(int i=1;i<=n+1;i++)
    {
        for(auto it:vec[i-1])
        {
           // if(it.first>=1)
        //    if(it.first==1)
        //    {
        //        update(1,0,n+1,0,)
        //    }
            add(1,0,n+1,0,it.first-1,it.second);
            // for(int j=1;j<it.first;j++)
            // {
            //     dp[j]+=it.second;
            //     //dp[i]=max(dp[i],dp[j]+)
            // }
        }
        dp[i]=get_min(1,0,n+1,0,i-1);
        add(1,0,n+1,i,i,(ll)(dp[i]-inf));
       // update(1,0,n+1,i,dp[i]);



    }
    ll ans=sum-dp[n+1];
   // cout<<tree[0]<<endl;
   // for(auto it=0;it<=n+1;it++) cout<<dp[it]<<" ";
 //   cout<<endl;
    // for(int i=1;i<=n+1;i++)
    // {
    //     ans=min(ans,dp[i]);

    // }

    cout<<ans<<endl;

}

Measured memory_bytes: 25216
def solve():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  ans = ['Yes']*(N-K)
  for i in range(N-K):
    if A[i]>=A[i+K]:
      ans[i] = 'No'
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 31748
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	ll ans = 0;
	ll sum = 0;
	ll Xor = 0;
	int j = 0;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
		Xor ^= A[i];
		cnt++;
		while (sum != Xor) {
			sum -= A[j];
			Xor ^= A[j];
			j++;
			cnt--;
		}
		ans += cnt;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4416
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	int a=0,b=0;
	for(int i=0;i<4;i++)
	{
		int k;
		cin >> k;
		a+=k;
	}
	for(int i=0;i<4;i++)
	{
		int k;
		cin >> k;
		b+=k;
	}
	printf("%d\n",a>b ? a:b);
	return 0;
}

Measured memory_bytes: 1144
import java.util.*;

public class  Main{
	public static void main(String args[]){
	    Scanner sc = new Scanner(System.in);
	    int k = sc.nextInt();
      	int n = sc.nextInt();
      	int tmp=0,x1=sc.nextInt(),x=x1,y=sc.nextInt();
      	int max = y-x;
      
      	for(int i=0;i<n-2;i++){
        	x = y;
          	y = sc.nextInt();
          	tmp = y-x;
        	if(tmp>max) max = tmp;
      	}
      
		tmp = k+x1-y;
      	if(tmp>max) max = tmp;

      	System.out.println(k-max);
	}
}

Measured memory_bytes: 63688
#include <iostream>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <list>
#include <stack>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#define m7 1000000007
#define m9 1000000009
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second

using namespace std;
ll n, k, m;
vector<vector<ll> > X,Y;
vector<vector<ll>> mul(vector<vector<ll> > &X, vector<vector<ll>> &Y) {
	vector<vector<ll>> Z = vector<vector<ll>>(n, vector<ll>(n,0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				Z[i][j] = (Z[i][j] + X[i][k] * Y[k][j] ) % m7;
			}
		}
	}
	return Z;
}

void print(vector<vector<ll>>& X) {
	for (int i = 0; i < n; i++) {
		cout << '\n';
		for (int j = 0; j < n; j++) {
			cout << X[i][j] << ' ';
		}
	}
}
void pow( ll exp) {
	Y = X;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			Y[i][j] = 0;
		Y[i][i] = 1;
	}
	
	while (exp) {
		if (exp & 1) {
			Y = mul(Y, X);
		}
		X = mul(X, X);
		
		exp = exp >> 1;
	}
}
int main()
{
	cin >> n >> k;
	X.resize(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> X[i][j];
		}
	}
	ll cnt = 0;
	pow(k);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cnt = (cnt + Y[i][j]) % m7;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var inputs = input.split("\n");
  var n = parseInt(inputs[0], 10);
  var a = inputs[1].split(" ").map(e => parseInt(e, 10)).sort((x, y) => y - x);
  var sum = 0;
  var i = 1
  var c = 0
  while (c < n) {
    sum += a[i];
    i += 2;
    c++;
  }
  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37704
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[108];

int main(){
	cin >> n;
	double sum = 0;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		sum += a[i];
	}
	double mean = sum/n;
	int center = (mean-int(mean) < 0.5)? int(mean) : int(mean)+1;
	
	ll ans = 0;
	for(ll i = 1; i <= n; i++){ans += (a[i]-center)*(a[i]-center);}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    long L,R;
    long i,j;
    long result1,result2,result3;
    long min;
    
    scanf("%ld %ld\n",&L,&R);
    min = 2020;
    for(i=L;R>=i;i++){
        for(j=i+1;R>=j;j++){
            result1 = i;
            result2 = j;
            result1 = result1%2019;
            result2 = result2%2019;
            result3 = (result1*result2)%2019;
            if(min>result3) min = result3;
            if(min==0){
                j=R; i=R;
            }
        }
    }
    
    printf("%ld\n",min);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a_li = list(map(int,input().split()))
ans = a_li[0]
if 0 in a_li :
    print(0)
    exit()
for i in range(1, n) :
    ans *= a_li[i]
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)

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

#define MAX 316 // 316^2 = 99856, 317^2 = 100489より

int connect(int a, int b) { // aとbを繋げる関数
	int ret = a, tmp = b; // このtmpを使う
	while (tmp > 0) {
		ret *= 10;
		tmp /= 10;
	} // これにより、tmp==bの桁数だけ、retの位を上げることにより解説のa*10^dができている
	return ret + b; // 最後にbを足す
}
int main() {
	int a, b;
	cin >> a >> b;
	int c = connect(a, b);
	for (int i = 1;i < MAX;i ++) {
		if (c == i * i) {
			cout << "Yes"; // 平方数だった
			return 0;
		}
	} // 平方数ではなかった
	cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

cをaとbを繋げた整数とする
c<=100100より、sqrt(c)<=316なので、総当たりが有効
次に、cが幾つか求める
bの桁数が分かっていれば、その桁数をdとすると、c=a*10^d+bが成り立つ
後は8-10行目を参照、オーダーはO(log(ab))かな
*/

Measured memory_bytes: 256
t = input()
if t == 'P':
    print('P')
elif t == 'D' or t == '?':
    print('D')
else:
    t = list(t)
    if t[0] == '?':
        if t[1] == 'D' or t[1] == '?':
                    t[0] = 'P'
        else:
            t[0] = 'D'

    for i in range(1, len(t)-1):
        if t[i] == '?':
            if t[i-1] == 'P':
                t[i] = 'D'
            else:
                if t[i+1] == 'D' or t[i+1] == '?':
                    t[i] = 'P'
                else:
                    t[i] = 'D'
    if t[-1] == '?':
        t[-1] = 'D' 
    print("".join(t))

Measured memory_bytes: 73968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}
// multimap
// mmap.emplace(key,value);
// auto ngw = list.equal_range("");
// for(auto e = ngw.first; it != ngw.second ; ++e)

int N, M;
vector<bool> canUse(9);
vector<int> w = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> r = {0, 6, 3, 4, 2, 1, 8, 5, 7};
bool compVector(vector<int> &a, vector<int> &b){
    int me = 0, aw = 0;
    rep(i, 9){
        me += a[i];
        aw += b[i];
    }
    if (me > aw){
        return true;
    }else if (me < aw){
        return false;
    }else
    {
        for(int i = 8; 0 <= i; i--){
            if (a[i] > b[i]){
                return true;
            }else if (a[i] < b[i]){
                return false;
            }
        }
    }
    return true;
}

// void vectorAdd(vector<int> &a, vector<int> &b){
//     return;
// }

void puts(vector<int> &vc){
    rep(i, 9){
        rep(j, vc[8 - i]){
            cout << (9 - i);
        }
    }
    cout << endl;
    return;
}


int main(){
    cin >> N >> M;
    rep(i, M){
        int a; cin >> a;
        canUse[a - 1] = true;
    }

    vector<vector<vector<int>>> dp(10, vector<vector<int>>(N + 1 , vector<int>(9, -99999999)));
    rep(i, 9) dp[0][0][i] = 0;
    rep(i, 9){
        rep(j, N + 1){
            rep(k, 9) dp[i + 1][j][k] = dp[i][j][k];
            if(canUse[r[i]] && 0 <= j - w[r[i]]){
                vector<int> fcomp(9, 0);
                rep(k, 9) fcomp[k] = dp[i + 1][j - w[r[i]]][k];
                fcomp[r[i]]++;
                // debug(fcomp);
                if(!compVector(dp[i + 1][j], fcomp)){
                    rep(k, 9) dp[i + 1][j][k] = dp[i + 1][j - w[r[i]]][k];
                    dp[i + 1][j][r[i]] += 1;
                }
            }
        }
    }
    //debug2(dp[9]);
    puts(dp[9][N]);
    return 0;
}

Measured memory_bytes: 7936
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();

		Arrays.sort(a);

		int ans = a[2] - a[1];
		if((a[1] - a[0])%2 == 0){
			ans += (a[1] - a[0])/2;
		}else {
			ans += ((a[1] - a[0] + 1)/2) + 1;
		}

		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32788
#include <stdio.h>
int main(void) {
	int n, i, j;
	double v[50], temp, sum;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%lf", &v[i]);

	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (v[j] < v[j - 1]) {
				temp = v[j];
				v[j] = v[j - 1];
				v[j - 1] = temp;
			}
		}
	}
	sum = v[0];
	for (i = 1; i < n; i++)
		sum = (sum + v[i]) / 2;
	printf("%lf", sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};
Node *root, *NIL;

void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node*)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x != NIL) {
    y=x;
    if(z->key < x->key) {
      x=x->left;
    }else {
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL) {
    root=z;
  }else {
    if(z->key < y->key) {
      y->left=z;
    }else {
      y->right=z;
    }
  }
}

bool find(int u) {
  Node *s=root;
  while(s != NIL) {
    if(s->key == u) {return true;}
    if(u < s->key) {
      s = s->left;
    }else {
      s = s->right;
    }
  }
  return false;
}

void inorder(Node *u) {
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u==NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n,i,x;
  string com;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> com;
    if(com=="insert") {
      cin >> x;
      insert(x);
    } else if(com=="print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else if(com=="find") {
      cin >> x;
      if(find(x)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 22008
include Math

a, b, h, m = gets.split.map(&:to_i)

a_angle = (2 * PI) * (60 * h + m) / (60 * 12)
b_angle = (2 * PI) * m / 60

a_x = a * cos(a_angle)
a_y = a * sin(a_angle)
b_x = b * cos(b_angle)
b_y = b * sin(b_angle)

length = sqrt((a_x - b_x)**2 + (a_y - b_y)**2)
puts length


Measured memory_bytes: 14764
n,k=map(int,input().split())
x=[int(i) for i in input().split()]

ans=float('inf')
for i in range(n-k+1):
    mini=x[i]
    maxi=x[i+k-1]
    if mini*maxi==0:
        a=max(abs(mini),abs(maxi))
        ans=min(ans,a)
    elif mini*maxi<0:
        a=abs(mini)*2+maxi
        b=abs(mini)+maxi*2
        ans=min(ans,a,b)
    else:
        a=max(abs(mini),abs(maxi))
        ans=min(ans,a)
print(ans)
    

Measured memory_bytes: 14660
n=gets.to_i
we=gets.chomp
w=[0,0]
e=[0,0]

(0...n).each do |i|
  w[i+1]=w[i]
  e[i+1]=e[i]
  w[i+1]+=1 if we[i]==?W
  e[i+1]+=1 if we[i]==?E
end
e.shift
e << e[-1]
ans = Float::INFINITY
(0..n).each do |i|
  ans = [ans,w[i]+e[-1]-e[i]].min
end
p ans


Measured memory_bytes: 20496
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;

void solve() {
    ll N, u, v; cin >> N;
    ll sum = 0;
    for(int i = 0; i < N-1; i++) {
        cin >> u >> v;
        if(u > v) swap(u, v);
        sum -= u * (N - v + 1);
    }
    for(int i = 1; i <= N; i++) {
        sum += i * (N - i + 1);
    }
    cout << sum <<"\n";
}

int main() {
    fast 
    // input output
    int t=1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

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

int countmatch = 0;

int main(){
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  int coins = A + B + C;
  
  for(int a = 0; a <= A; a++){
  	for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
      	int sumCoins = 500 * a + 100 * b + 50 * c;
        if(sumCoins == X)countmatch++;
      }
    }
  }
  
  
  cout << countmatch << endl;
}

Measured memory_bytes: 256
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;
void chadd(ll &a, const ll &b){a = (a + b) % MOD;}


ll dp[222][NUM];

int main(){

    ll N, X;
    cin >> N >> X;
    V v(N);
    rep(i, N)cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());
    dp[0][X] = 1;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= 100000; j++){
            chadd(dp[i + 1][j % v[i]], dp[i][j]);
            chadd(dp[i + 1][j], dp[i][j] * (N - i - 1));
        }
    }
    ll ans = 0;
    for(ll j = 0; j <= 100000; j++)chadd(ans, j * dp[N][j]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 159232
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

const ld pi = 3.141592653589793;

int n, l[102], ans;

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

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
          if (0 < l[i] + l[j] + l[k] - 2 * max(l[i], max(l[j], l[k]))) {
            ans++;
          }
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
def cal(n, i):
    numerator = 1
    denominator = 1
    for j in range(1, i+1):
        numerator *= (n-j+1) 
        denominator *= j
    x = numerator // denominator
    return x

N, K = map(int, input().split())
for i in range(1, K+1):
    if i > N-K+1:
        print(0)
    else:
        ans = cal(N-K+1, i)
        ans *= cal(K-1, i-1)
        ans = ans % 1000000007
        print(int(ans))

Measured memory_bytes: 3316
from heapq import heapify, heappush, heappop
class HeapQue(object):
    def __init__(self, iterable, max_heap=False):
        self.sign = -1 if max_heap else 1
        sequence = [self.sign * number for number in iterable]
        heapify(sequence)
        self.heapque = sequence

    def push(self, item):
        heappush(self.heapque, item * self.sign)

    def pop(self):
        try:
            return heappop(self.heapque) * self.sign
        except:
            return 0

N, M = map(int, input().split())
jobs = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0], reverse=True)
q = HeapQue([], max_heap=True)
total = 0
for i in range(1, M + 1):
    while jobs and jobs[-1][0] == i:
        q.push(jobs.pop()[1])
    total += q.pop()
print(total)

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

int main() {
  int64_t N, K, amari, ans;
  cin >> N >> K;
  amari = N%K;
  if(amari < K-amari) ans = amari;
  else ans = K-amari;
  
  cout << ans << endl;
    
}

Measured memory_bytes: 3628
N,A,B,C,D = (int(i) for i in input().split())
S = input()
S = list(S)

result = "Yes"
onon = True

if C < D:
    for i in range(A-1,D):
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(A-1,C):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B -2,D-1):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)

Measured memory_bytes: 4916
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,A;
int nums[59];
ll dp[59][2509];

void init(){
    mem(dp,0);
    dp[0][0]=1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>A;
    rep(i,N) cin>>nums[i];
    
    ll total=0;
    rep1(n,N){
        init();
        int tgt=A*n;
        rep(i,N){
            int x=nums[i];
            for(int k=n;k>0;k--){
                for(int j=0;j+x<=tgt;j++){
                    dp[k][j+x]+=dp[k-1][j];
                }
            }
        }
        total+=dp[n][tgt];
    }
    cout1(total)
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var abc = ReadLine().Split().Select(int.Parse).ToArray();
        int a = abc[0], b = abc[1], c = abc[2];
        int cnt = b / a;
        WriteLine(Min(cnt,c));
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,L;
string S[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	FOR(i,N) cin>>S[i];
	sort(S,S+N);
	FOR(i,N) cout<<S[i];
	cout<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=31;
typedef pair<int,int> P;
int main()
{
  int n,c,cc,i,j,k,res=3e8;
  int d[N_MAX][N_MAX],s[3][N_MAX];
  P dd[3][N_MAX];
  cin >> n >> c;
  for(i=0;i<3;i++)
    fill(s[i]+1,s[i]+c+1,0);
  for(i=0;i<3;i++)
    for(j=1;j<=c;j++){
      dd[i][j].first=0;
      dd[i][j].second=j;
    }
  for(i=1;i<=c;i++)
    for(j=1;j<=c;j++)
      cin >> d[i][j];
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++){
      cin >> cc;
      s[(i+j)%3][cc]++;
    }
  for(i=0;i<3;i++)
    for(j=1;j<=c;j++)
      for(k=1;k<=c;k++)
        dd[i][j].first+=s[i][k]*d[k][j];
  for(i=0;i<3;i++)
    sort(dd[i]+1,dd[i]+c+1);
  for(i=1;i<=3;i++)
    for(j=1;j<=3;j++)
      for(k=1;k<=3;k++)
        if(dd[0][i].second!=dd[1][j].second
           && dd[1][j].second!=dd[2][k].second
           && dd[2][k].second!=dd[0][i].second)
          res=min(res,dd[0][i].first+dd[1][j].first+dd[2][k].first);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair> > 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,m,s;
  cin>>n>>m>>s;

  vector<vector<int>> p(n);
  map<pair<int,int>,pair<int,ll>> rail;
  vector<int> mai(n);
  vector<ll> hun(n);

  int u,v,a;
  ll b;
  rep(i,m){
    cin>>u>>v>>a>>b;
    u--;v--;
    p[u].pb(v);
    p[v].pb(u);
    rail[{u,v}]=mp(a,b);
    rail[{v,u}]=mp(a,b);
  }

  rep(i,n){
    cin>>mai[i]>>hun[i];
  }

  vector<vector<ll>> ans(n,vector<ll>(2600,INF));
  if(s>2500) s=2500;
  ans[0][s]=0;

  pq que;
  que.push({0,{0,s}});

  while(!que.empty()){
    auto z=que.top();
    ll t=z.fi;
    int x = z.se.fi;
    int y = z.se.se;
    que.pop();

    for(int nv : p[x]) {
      auto ne = rail.at({nv,x});
      a = ne.fi;
      b = ne.se;
      if(y-a>=0){
        if(chmin(ans[nv][y-a],t+b)){
          que.push({t+b,{nv,y-a}});
        }
      }
    }

    if(y+mai[x]>2500) continue;
    if(chmin(ans[x][y+mai[x]],t+hun[x])){
      que.push({t+hun[x],{x,y+mai[x]}});
    }
  }

  repo(i,n){
    ll x=INF;
    rep(j,2501){
      chmin(x,ans[i][j]);
    }
    cout << x << endl;
  }

}


Measured memory_bytes: 6244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int res = 0;
		int[] V = new int[N];
		int[] C = new int[N];

		for(int i = 0;i<N;i++) {
			V[i]=sc.nextInt();
		}
		for(int i = 0;i<N;i++) {
			C[i]=sc.nextInt();
		}
		for(int i = 0;i<N;i++) {
			if(V[i]-C[i]>0) {
				res += V[i]-C[i];
			}
		}


		System.out.println(res);


	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;

int main()
{
	long long  n, a, b;
	cin >> n >> a >> b;

	long long ans = n / (a + b) * a;

	if (n % (a + b) < a) ans += n % (a + b);
	else ans += a;
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
	
	@Raghul
*/
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
ll ans[100005];
ll fastpow(ll a,ll b){
	if(b==0)
		return 1LL;
	ll temp=fastpow(a,b/2);
	temp=temp*temp;
	if(b%2==1)
		temp=temp*a;
	return temp;
}	
void solve(){
	ll n;
	cin>>n;
	ll a[n], sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll maxi = *max_element(a,a+n);
	sum-=maxi;
	maxi/=2;
	sum+=maxi;
	cout<<sum;
	return;
}
int main(){ 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T;
    T = 1;
    while(T--){
    	solve();
    }
    return 0;
} 

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

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define reP(i, x, n) for(int i=x; i<n; i++)
#define aLL(x) x.begin(), x.end()
#define pB push_back
#define eB emplace_back
#define tRav(a, x) for(auto& a: x)
#define fI first
#define sE second
#define lB lower_bound
#define uB upper_bound
#define MOD 1000000007

typedef vector<int> vec;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+5;
int m[N];
ll ans=0;


int main(){
    fast_cin();
    int n;cin>>n;
    vec v(n);
    reP(i, 0, n){
    	cin>>v[i];
    	ans+=m[v[i]];
    	m[v[i]]++;
    }
    for(int i=0;i<n;i++){
    	ans-=m[v[i]]-1;
    	cout<<ans<<endl;
    	ans+=m[v[i]] - 1;
    }
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define maxn 200001

int n, m, x, y, H, W, cnt;
int a[maxn];
int c[3];

void solve(){
	cin >> n;
	rep(i, n){
		cin >> x;
		//cout << x << endl;
		cnt = 0;
		while (x % 2 == 0) x /= 2, cnt++;
		cnt = min(cnt, 2);
		c[cnt]++;
		//cout << cnt << endl;
	}
	//cout << c[0] << ' ' << c[1] << ' ' << c[2] << endl;
	if (c[0] + min(1, c[1]) - c[2] > 1){
		puts("No");
	}
	else{
		puts("Yes");
	}
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
	solve();	
}

Measured memory_bytes: 256
#include<stdio.h>

int check(int i, int m, int n, int a[])
{
	int c;
	if( m == 0 ){
		c = 1;
	}else if( i >= n ){
		c = 0;
	}else{
		c = check(i+1, m, n, a) + check(i+1, m-a[i], n, a);
	}
	
	return c;
}

int main(void)
{
	int n, q, i, m, c;
	scanf( "%d", &n );
	int a[n];
	for( i = 0; i < n; i++ ){
		scanf( "%d", &a[i] );
	}
	scanf( "%d", &q );
	
	for( i = 0; i < q; i++ ){
		scanf( "%d", &m );
		c = check(0, m, n, a);
		if( c == 0 ){
			printf( "no\n" );
		}else{
			printf( "yes\n" );
		}
	}
	
	return 0;
}


Measured memory_bytes: 2108
inp = [input() for i in range(2)]
k = int(inp[0])
inlist = inp[1].split()
low = int(inlist[0])
high = int(inlist[1])

mod = low % k
dist = k - mod
if (mod == 0):
  print("OK")
elif (low + dist <= high) :
  print("OK")
else:
  print("NG")

Measured memory_bytes: 9196
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back


const ll MOD=1000000007;
ll dp[100000][2];
vector<ll> v[100000];

ll dfs(ll x,ll bk,ll p)
{
    if(v[x].size()==0)
        return dp[x][bk]=1;

    if(dp[x][bk]!=-1)
        return dp[x][bk];

    ll sm=1;
    for(ll i=0;i<v[x].size();i++)
    {
        ll num=v[x][i];
        if(num==p)
            continue;
        if(bk==0)
            sm=(sm*(dfs(num,0,x)+dfs(num,1,x))%MOD)%MOD;
        else
            sm=(sm*dfs(num,0,x))%MOD;
    }
    return dp[x][bk]=sm;
}

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

    
    ll i,n;
    cin>>n;
    for(ll i=1;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;y--;
        v[x].PB(y);
        v[y].PB(x);
    }
    memset(dp,-1,sizeof dp);
    ll ans1=dfs(0,0,-1);
    ll ans2=dfs(0,1,-1);

    cout << (ans1+ans2)%MOD;
 
    return 0;
}


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

typedef long long ll;
typedef vector < int > vi;
typedef pair <int , int > pi;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fr(i,a,b) for(int i=a;i<b;i++)


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int ac=0,re=0,tle=0,wa=0;
    string s;
    while(n--)
    {
        
        cin>>s;
        if(s=="AC")
        {
            ac++;
        }
        if(s=="TLE")
        {
            tle++;
        }
        if(s=="WA")
        {
            wa++;
        }
        else if(s=="RE")
        {
            re++;
        }
        
    }

    cout<<"AC x "<<ac<<"\n";
    cout<<"WA x "<<wa<<"\n";
    cout<<"TLE x "<<tle<<"\n";
    cout<<"RE x "<<re<<"\n";

    
    
    return 0;
}


Measured memory_bytes: 3652
#include <vector>
#include <algorithm>
#include <iostream>
#include <chrono>
#include<bitset>
#include<deque>
//#include<pair>
#define vint vector<int>
#define vint2 vector<vint>
#define vchar vector<char>
#define vchar2 vector<vchar> 
#define vchar3 vector<vchar2> 
#define pr pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;




int main(){
	int N, M;
	
	cin >> N >> M;
	vint ar(N);
	REP(i, M){
		REP(j, 2){
			int a;
			cin >> a;
			ar[a - 1]++;
		}

	}
	REP(i, N){
		cout << ar[i] << endl;
	}
	
	

	return 0;


}



Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N;
    cin >> N;
    vi buka(N);
    for (int i = 1; i < N; i++)
    {
        int joushi;
        cin >> joushi;
        --joushi;
        ++buka[joushi];
    }
    
    for (int i = 0; i < N; i++)
    {
        cout << buka[i] << endl;
    }
}

Measured memory_bytes: 4000
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def check(s):
        for i in range(n):
            if s>>i & 1:
                for j, y in to[i]:
                    if s >> j & 1 != y:
                        return False
        return True

    to = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = MI()
            to[i].append([x - 1, y])
    ans = 0
    for s in range(1 << n):
        if check(s):
            ans = max(ans, bin(s).count("1"))
    print(ans)

main()


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

eva_list = []

for i in range(N):
    key, value = input().split()
    eva_list.append([key,int(value),i+1])

eva_list.sort(key=lambda x:x[1], reverse=True)
eva_list.sort(key=lambda x:x[0])

for i in range(N):
    print(eva_list[i][2])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int a, b, c, d, e, k;
	bool ans = true;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a > k) ans = false;
	cout << (ans ? "Yay!" : ":(") << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC057CheckPoints
{
    class Program
    {
        static int[,] students;
        static int[,] checkPoints;


        static void Main(string[] args)
        {
            int N, M;
            string[] vals = Console.ReadLine().Split(' ');
            N = int.Parse(vals[0]);
            M = int.Parse(vals[1]);

            students = new int[N, 2];
            for(int i=0; i < N; i++)
            {
                vals = Console.ReadLine().Split(' ');
                students[i, 0] = int.Parse(vals[0]);
                students[i, 1] = int.Parse(vals[1]);
            }

            checkPoints = new int[M, 2];
            for(int i=0; i < M; i++)
            {
                vals = Console.ReadLine().Split(' ');
                checkPoints[i, 0] = int.Parse(vals[0]);
                checkPoints[i, 1] = int.Parse(vals[1]);

            }

            for(int i=0; i < N; i++)
            {
                int n = 0;
                int dn = dist(i, 0);
                for(int j=1; j < M; j++)
                {
                    int dj = dist(i, j);
                    if(dn > dj)
                    {
                        dn = dj;
                        n = j;
                    }
                    else if(dn == dj && n > j)
                    {
                        n = j;
                    }
                }
                Console.WriteLine(n + 1);
            }
        }


        static int dist(int s, int p)
        {
            return Math.Abs(checkPoints[p, 0] - students[s, 0]) + Math.Abs(checkPoints[p, 1] - students[s, 1]);
        }

    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  bool prime[100000];
  for(int i=0;i<100000;++i) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<100000;++i) {
    if(!prime[i]) continue;
    for(int j=2;i*j<100000;++j) prime[i*j] = false;
  }
  vector<int> primearr;
  for(int i=0;i<100000;++i) {
    if(prime[i] && i%5==1) primearr.push_back(i);
  }
  for(int i=0;i<N;++i) cout<<primearr[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 3724
#include <stdio.h>
#define INFTY 2000000000
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int L[250002],R[250002];
int count;

int main(){
  int A[500000],n;
  int i;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);

  for(i = 0; i < n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],count);
  return 0;
}

void merge(int* A, int left,int mid, int right){
  int n1,n2;
  int i,j,k;
  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0; 
  j = 0;
  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
  }
}

void mergeSort(int* A, int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

Measured memory_bytes: 4504