akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define M 1000005
#define FI first
#define SE second
#define MP std::make_pair
#define PB push_back
#define mod 1000000007
#define base 233
#define INF 1000000000
typedef long long ll;
ll n, F[M];
ll read() {
	ll ans = 0; char c = getchar(); bool flag = 1;
	while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return flag ? ans : -ans;
}
void Write(ll x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
	return;
}
ll max(ll x, ll y) {return x > y ? x : y;}
ll power(ll x, ll y, ll ans = 1) {
	for (; y; y >>= 1, x = x * x % mod)
		if (y & 1) ans = ans * x % mod;
	return ans;
}
int main() {
	n = read(); F[0] = 1;
	for (ll i = 0; i < n; i++)
		for (ll j = 3; i + j <= n; j++) F[i + j] = (F[i + j] + F[i]) % mod;
	Write(F[n]);
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		char chairs[101];
		for(int i = 0; i < n; i++){ chairs[i] = '#'; }
		chairs[n] = '\0';
		for(int i = 0; i < m; i++){
			string s;
			cin >> s;
			bool flag = false;
			if(s[0] == 'A'){
				for(int j = 0; j < n; j++){
					if(chairs[j] == '#'){ chairs[j] = 'A'; break; }
				}
			}else if(s[0] == 'B'){
				bool flag = false;
				for(int j = n - 1; j >= 0; j--){
					if(chairs[j] != '#'){ continue; }
					if((j < 1 || chairs[j - 1] != 'A') && chairs[j + 1] != 'A'){
						chairs[j] = 'B';
						flag = true;
						break;
					}
				}
				if(!flag){
					for(int j = 0; j < n; j++){
						if(chairs[j] == '#'){ chairs[j] = 'B'; break; }
					}
				}
			}else if(s[0] == 'C'){
				if(i == 0){
					chairs[n / 2] = 'C';
				}else{
					int j = 0;
					for(; j < n; j++){
						if(chairs[j] != '#'){ break; }
					}
					if(chairs[j + 1] == '#'){
						chairs[j + 1] = 'C';
					}else if(j > 0 && chairs[j - 1] == '#'){
						chairs[j - 1] = 'C';
					}else{
						for(; j < n; j++){
							if(chairs[j] == '#'){ break; }
						}
						chairs[j] = 'C';
					}
				}
			}else if(s[0] == 'D'){
				if(i == 0){
					chairs[0] = 'D';
				}else{
					int dist = 0, idx = 0;
					for(int j = 0; j < n; j++){
						if(chairs[j] != '#'){ continue; }
						int d = 100;
						for(int k = j - 1; k >= 0; k--){
							if(chairs[k] != '#'){ d = min(d, j - k); break; }
						}
						for(int k = j + 1; k < n; k++){
							if(chairs[k] != '#'){ d = min(d, k - j); break; }
						}
						if(d > dist){ idx = j; dist = d; }
					}
					chairs[idx] = 'D';
				}
			}
		}
		cout << chairs << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>

int main(){
	int n,h,i,ioi,joi;
	char str[10001];
	while(scanf("%s",str)!=EOF){
		h=strlen(str);
		ioi=0;
		joi=0;
		for(i=0;i<h-2;i++){
			if(str[i]=='J' && str[i+1]=='O' && str[i+2]=='I'){
				joi++;
			}else if(str[i]=='I' && str[i+1]=='O' && str[i+2]=='I'){
				ioi++;
			}
		}
		printf("%d\n%d\n",joi,ioi);
	}
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if ((N % 10) == 9 or (N / 10) == 9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

constexpr int inf = numeric_limits<int>::max() / 2;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  vector<vector<char>> g(n + 1, vector<char>(m + 1));
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= m; ++j) {
      cin >> g[i][j];
    }
  }
  vector<vector<int>> dist(n + 1, vector<int>(m + 1, inf));
  dist[x1][y1] = 0;
  deque<pair<int, int>> q {{x1, y1}};
  auto in = [&] (int i, int j) {
    return i >= 1 && i <= n && j >= 1 && j <= m;
  };
  while(q.size()) {
    auto [r, c] = q.front();
    q.pop_front();
    for(int d = 0; d < 4; ++d) {
      int x = r + (d == 0) - (d == 1);
      int y = c + (d == 2) - (d == 3);
      if(in(x, y) && g[x][y] != '#' && dist[x][y] > dist[r][c]) {
        dist[x][y] = dist[r][c]; 
        q.push_front({x, y});
      }
    }
    for(int i = r - 2; i <= r + 2; ++i) {
      for(int j = c - 2; j <= c + 2; ++j) if(in(i, j)) {
        if(g[i][j] != '#' && dist[i][j] > dist[r][c] + 1) {
          dist[i][j] = dist[r][c] + 1;
          q.push_back({i, j});
        }
      }
    }
  }
  cout << (dist[x2][y2] == inf ? -1 : dist[x2][y2]) << '\n';
}

Measured memory_bytes: 8652
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}


Measured memory_bytes: 3188
use std::io::stdin;

fn main() {
    let mut s: Vec<u64> = read().split(" ").map(|n| n.parse().unwrap()).collect();
    let mut n = 0;
    for _ in 0..2 {
        if s[0] < s[1] {
            n = n + s[1];
            s[1] = s[1] - 1;
        } else {
            n = n + s[0];
            s[0] = s[0] - 1;
        }
    }
    println!("{}", n);
}

fn read() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

int main() {
  int n;
  double sum = 0;
  cin >> n;
  vector<int>x(n);
  vector<int>y(n);
  for(int i = 0;i < n;i++) cin >> x[i] >> y[i];
  for(int i = 0;i < n-1;i++){
    for(int j = i+1;j < n;j++){
      sum += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(7) << 2*sum/n << endl;;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int p, q, r;
    cin>>p>>q>>r;
    cout<<min(p + q, min(q + r, p + r))<<endl;;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int A,B,T,n,i;
	scanf("%d %d %d", &A, &B, &T);
	i=1;
	while((i*A)<=(T+0.5))
	{
	i++;
	}
	i=i-1;
	n=i*B;
	printf("%d",n);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	
	int a,b,ans = -1 * INF;
	cin >> a >> b;
	ans = max(ans, a+b);
	ans = max(ans, a-b);
	ans = max(ans, a*b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int K, A, B;
  cin >> K >> A >> B;

  if(B%K<=B-A){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
  
return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; int a,n;
  cin >> n>>a;
  cin >> s;
  if(s.at(a-1)=='A')
    s.at(a-1)='a';
  if(s.at(a-1)=='B')
    s.at(a-1)='b';
  if(s.at(a-1)=='C')
    s.at(a-1)='c';
  cout << s << endl;

}

Measured memory_bytes: 256
n = int(input())

cc = [[0 for i in range(10)] for j in range(10)]

for i in range(n+1):
    hn = int(str(i)[0])
    tn = i % 10
    cc[hn][tn] = cc[hn][tn]+1
#    print("{} {}".format(hn, tn))
    
c = 0

for h in range(1,10):
    for t in range(1, 10):
        c = c + (cc[h][t]*cc[t][h])
#        print("{}".format(cc[h][t]))
        
print(c)

Measured memory_bytes: 3060
from itertools import permutations as p
n, *d = map(int, open(0).read().split())
h = []
k = 0
for i in list(p(range(n))):
    for j in range(n - 1): # i[j], i[j+1]
        k += ((d[i[j] * 2] - d[i[j+1] * 2])**2 + (d[i[j] * 2 + 1] - d[i[j+1] * 2 + 1])**2)**.5
    h += [k]
    k = 0
print(sum(h) / len(h))

Measured memory_bytes: 9332
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()

if 8 <= S.count("o")+ 15-len(S):
	print("YES")
else:
	print("NO")

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

int check(int k, int a, int b) {
	return (abs(a - k) == abs(b - k));
}

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

  int n;

  cin >> n;

  vector<int> arr(n), s(n);

  for(int &x: arr) {
  	cin >> x;

  }

  s = arr;

  sort(s.begin(), s.end());

  for(int i = 0; i < n; i++) {
  	for(int j = i + 1; j < n; j++) {

		swap(arr[i], arr[j]);  		
		if(arr == s) {
			cout << "YES" << endl;
			return 0;
		}
		swap(arr[i], arr[j]);  		
  	}
  }

  if(arr == s) {
			cout << "YES" << endl;
			return 0;
		}

  cout << "NO" << endl;
}

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

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  
  int sum;//最終出力
  sum=a*x+b*y;
  
  int p;
  p=max(x,y);
  
  int high;//??
  high=max(a,b);
  
  int i,t;
  for(i=0;i<=p;i++){
   
    if(x-i<0){
      if(i>=p){
        t=c*i*2;
    sum=min(sum,t);
      continue;
              }
        
      t=b*(y-i)+c*i*2;
    sum=min(sum,t);
      continue;
    }
    
    else if(y-i<0){
      if(i>=p){
        t=c*i*2;
    sum=min(sum,t);
      continue;
              }
      
      t=a*(x-i)+c*i*2;
    sum=min(sum,t);
      continue;
    }
    
    else{
      
      if(i>=p){
        t=c*i*2;
    sum=min(sum,t);
      continue;
              }
    
    t=a*(x-i)+b*(y-i)+c*i*2;
    sum=min(sum,t);
      
    }
    
    
    
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int bubbleSort(int A[],int N){
  int i,j,temp,count=0;
  for(i=0;i<N;i++){
    //  printf("a\n");
  for(j = N-1;j>i;j--){
    // printf("a\n");
    if(A[j] < A[j-1]){
      temp=A[j];
      A[j]=A[j-1];
      A[j-1]=temp;
      // A[j] ??¨ A[j-1] ?????????
      count++;
    }
  }
}
    return count;
    }
int main(){
  int N,i,flag;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
 flag=bubbleSort(A,N);
 for(i=0;i<N;i++){
   if(i>0) printf(" ");
   printf("%d",A[i]);
 }
   printf("\n");
   // printf(" ");
 printf("%d\n",flag);
 return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string n;
  cin >> n;
  ll ans = 0;
  for(auto &v: n) {
    ans += v - '0';
    ans %= 9;
  }
  if (ans == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

auto keta(ll n) {
    ll res;
    for(ll i = 0; i < 100; i++) {
        n = n / 10;

        if(n == 0) {
            res = i + 1;
            break;
        }
    }
    return res;
}


int main() {
    ll a;
    cin>>a;
    cout<<3*a*a<<endl;
}


Measured memory_bytes: 256
from sys import stdin, stdout
N = int(stdin.readline())
brick = list(map(int, stdin.readline().split()))

cont = 0
for i in range(N):
    if brick[i] == cont+1:
        cont = cont+1

if cont == 0:
    stdout.write("-1\n")
else:
    stdout.write("%d\n" % (N-cont))

Measured memory_bytes: 25912
/**
 * @author: pr4shan7 (प्रशांत)
 */
// #define _DEBUG

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

// #define int long long
// #define double long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_set;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define cai static_cast<int>
#define cal static_cast<long long>
#define cad static_cast<long double>
#define deb(z) cout << "// " << #z << " = " << z << endl;
const int N = 1e5 + 5;
const int INF = 1e9;
const int MV = 1e9 + 7;



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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, k; cin >> n >>k;
	double ar[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> ar[i];
		ar[i]++;
		ar[i]/=2;
	}

	double ans{};
	for (int i = 0; i < k; ++i)
	{
		ans+=ar[i];
	}
	// for(auto &&i: ar) {cout << i<<' ';}
	// 	cout  << endl;
	double fans=ans;
	for (int i = k; i < n; ++i)
	{
		ans=ans-ar[i-k]+ar[i];
		fans=max(fans,ans);
	}
	cout <<fixed<< fans <<setprecision(8)<< endl;

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int N;
int W[128];

int mikisinn[128];

int main(void) {
	int i;
	int asumikana = 999999999;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &W[i]) != 1) return 1;
		mikisinn[i] = mikisinn[i - 1] + W[i];
	}
	for (i = 1; i < N; i++) {
		int mizuhasu = abs((mikisinn[i] - mikisinn[0]) - (mikisinn[N] - mikisinn[i]));
		if (mizuhasu < asumikana) asumikana = mizuhasu;
	}
	printf("%d\n", asumikana);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	//三角形の外心を求める
	//外心：三角形各辺の垂直二等分線が交わる点
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double a,b,c,sin2a,sin2b,sin2c,px,py,r;
		a = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3);
		b = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1);
		c = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
		sin2a = a*(-a+b+c);
		sin2b = b*(a-b+c);
		sin2c = c*(a+b-c);
		px = (x1*sin2a + x2*sin2b + x3*sin2c) / (sin2a + sin2b + sin2c);
		py = (y1*sin2a + y2*sin2b +y3*sin2c) / (sin2a + sin2b + sin2c);
		double ra,rb,rc;
		ra = sqrt(a);
		rb = sqrt(b);
		rc = sqrt(c);
		r = sqrt(a*b*c/((ra+rb+rc)*(-ra+rb+rc)*(ra-rb+rc)*(ra+rb-rc)));
		printf("%.3f %.3f %.3f\n",px,py,r);
	}
	return 0;
}

Measured memory_bytes: 1244
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];
ll dp[MAXN][3];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    int sp = 1 + n % 2;
    FOR(i,0,n) FOR(j,0,sp) dp[i][j] = -1e18;
    dp[0][0] = 0;
    FOR(i,0,n)
        FOR(j,0,sp)
            if (dp[i][j] != -1000000000000000000LL) {
                if (i == 0) {
                    // not choose space
                    dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[i+1]);
                    int remainSp = sp - j;
                    // choose space
                    FOR(k,1,remainSp) dp[i+k+1][j+k] = max(dp[i+k+1][j+k], dp[i][j] + a[i+k+1]);
                }
                else {
                    // not choose space
                    dp[i+2][j] = max(dp[i+2][j], dp[i][j] + a[i+2]);
                    int remainSp = sp - j;
                    // choose space
                    FOR(k,1,remainSp) dp[i+k+2][j+k] = max(dp[i+k+2][j+k], dp[i][j] + a[i+k+2]);
                }
            }
    ll res = -1e18;
    if (sp == 2) {
        res = max(res, dp[n-2][0]);
        res = max(res, dp[n-1][1]);
        res = max(res, dp[n][2]);
    }
    else {
        res = max(res, dp[n][1]);
        res = max(res, dp[n-1][0]);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int dicNum(int N, vector<int> &P, vector<int> &fact) {
	vector<bool> used(N, false);
	int res = 0;
	rep(i, N) {
		int lesser = 0;
		rep(j, P[i]-1) {
			if(!used[j]) lesser++;
		}
		//cout <<"P[i] " << P[i] << "  lesser :" << lesser << endl;
		res += (lesser * fact[N-i-1]);
		used[P[i]-1] = true;
	}
	
	return res;
}

int main() {
	int N;
	cin >> N;
	vector<int> P(N), Q(N);
	rep(i, N) cin >> P[i];
	rep(i, N) cin >> Q[i];

	vector<int> fact; // N!
	fact.push_back(1); // 0! = 1;
	rep(i, N+1) {
		fact.push_back(fact[i] * (i+1));
	}

	int ans = abs(dicNum(N, P, fact) - dicNum(N, Q, fact));
	//cout << "test: " << dicNum(N, P, fact) << ' ' << dicNum(N, Q, fact) << endl;
	cout << ans << endl;

	return 0;
}

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


// vector
#define MAX_ELE(vec) *max_element(vec.begin(), vec.end())
#define SORT(vec) sort(vec.begin(), vec.end());


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

// string
#define TO_UP(str) transform(str.cbegin(), str.cend(), str.begin(), ::toupper)

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



using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

    string S;
    cin >> S;

    SORT(S);
    // cerr << S << "\n";

    if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    

}

Measured memory_bytes: 256
//A Payment


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int n;
		cin>>n;
		if (n%1000 == 0)
		{
			cout<<n%1000;
		}
		else if (n%1000 != 0)
		{
			int sum = n%1000;
			int sum_1 = 1000-sum;
			cout<<sum_1<<endl;
		}
		return 0;
	}


Measured memory_bytes: 3620
def main():
    n =int(input())

    ans = ''
    if n == 0:
        print(0)
    while n!=0:
        if n%2 != 0:
            n -= 1
            ans = '1' + ans
        else:
            ans = '0' + ans
        n /= -2
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N, K = map(int, input().split())

if N == 1 and K == 1 :
    print(1)
else :

    MOD = 10 ** 9 + 7

    M = max(K-1, N-K+1)

    fac = [0] * (M + 1)
    inv = [0] * (M + 1)
    fac[0] = 1
    inv[0] = 1

    for i in range(1, M + 1) :
        fac[i] = fac[i-1] * i
        inv[i] = pow(fac[i], MOD - 2, MOD)
        
    def comb(n, r) :
        if n <= 0 :
            return 0
        if r > n :
            return 0
            
        return fac[n]*inv[n-r]*inv[r]%MOD
        
    for i in range(1, K + 1) :
        print(comb(K-1, i-1) * comb(N-K+1, i) % MOD)

Measured memory_bytes: 45040
import sys 
import math
a = list(map(int,input().split()))
A = a[0]
B = a[1]
H = a[2]
M = a[3]

short_needle_angle = (360*(M/60))
if H >= 12:
    H = H -12
long_needle_angle = (360*(H/12)) + (30*(M/60))
angle = abs(long_needle_angle - short_needle_angle)

if angle > 180:
    angle = 360 - angle
red = math.radians(angle)
a = (A ** 2) + (B ** 2) - (2* A *B * math.cos(red))
print(math.sqrt(a))

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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)           fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741
ll n;
ll arr[3005];
ll dp[3005][3005][2];
ll pre[3005];

ll fin(ll st, ll l, ll ch){
	if (l<1)return 0;
	if (l==1)return arr[st];
	if (dp[st][l][ch]!=-1)return dp[st][l][ch];
	dp[st][l][ch]=max(arr[st]+(pre[st+l]-pre[st+1])-fin(st+1,l-1,!ch),arr[st+l-1]+(pre[st+l-1]-pre[st])-fin(st,l-1,!ch));
	return dp[st][l][ch];
}

void solve() {
    cin>>n;
    pre[0]=0;
    rep(i,0,n){
    	cin>>arr[i];
    	pre[i+1]=arr[i]+pre[i];
    }
    
    memset(dp,-1,sizeof dp);
    cout<<fin((ll)0,n,(ll)0)-min(fin((ll)1,n-1,(ll)1),fin((ll)0,n-1,(ll)1))<<endl;
    // rep(i,0,n+1){
    // 	rep(j,0,n+1){
    // 		trace(i,j,dp[i][j][0],dp[i][j][1]);
    // 	}
    // }
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 141568
// Bitter Alchemy
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int N, X;
    int m[1010];
    int c = 0;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> m[i];
        X -= m[i];
        c++;
    }
    sort(m, m+N);
    for (int i = 0; i < N; i++) {
        while (X / m[i] != 0) {
            X -= m[i];
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    double a[1000],s=0;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        s+=(1/a[i]);
    cout<<1/s<<endl;
}


Measured memory_bytes: 3788
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, _x, _y] = input[0].split(" ").map((x: string): number => +x);
// 1-indexedを0-indexedに変換
const x = _x - 1;
const y = _y - 1;

function distance(i: number, j: number, { x, y }: { x: number, y: number }) {
	return Math.min(j - i, Math.abs(x - i) + Math.abs(y - j) + 1);
}

const result = new Array(n - 1).fill(0);
let cnt = 0;
for (let i = 0; i < n; i++) {
	for (let j = i + 1; j < n; j++) {
		result[distance(i, j, { x, y }) - 1]++;
		cnt++;
	}
}
console.log(result.join("\n"));


Measured memory_bytes: 10444
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a1,a2,a3;
	scanf("%d%d%d",&a1,&a2,&a3);
	if(a1+a2+a3>=22)
		printf("bust\n");
	else
		printf("win\n");
	return 0;
}

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

using namespace std;

#define rep(i, n) for(i = 0;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define pb push_back
#define mp make_pair

typedef int edge;
vector<edge> G[100];
bool use[100];
bool vst[100];

int dfs(int now, int d){
  vst[now] = true;
  int res = d, i, j;
  rep(i, G[now].size())if(!vst[G[now][i]])res = max(res, dfs(G[now][i], d + 1));
  vst[now] = false;
  return res;
}

signed main(void){
  int i, j, n, a, b;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(n == 0)break;
    rep(i, 100)use[i] = false;
    rep(i, n){
      scanf("%d%d", &a, &b);
      --a; --b;
      G[a].pb(b); G[b].pb(a);
      use[a] = true; use[b] = true;
    }

    int res = 0;
    rep(i, 100)if(use[i]){
      rep(j, 100)vst[j] = false;
      res = max(res, dfs(i, 1));
    }
    printf("%d\n", res);

    rep(i, 100)if(use[i])G[i].clear();


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3280
N=int(input())
S=input()
dr={}
dg={}
db={}
for i in range(N):
    if S[i]=="R":
        dr[i]=1
    elif S[i]=="G":
        dg[i]=1
    else:
        db[i]=1
lendb=len(db)
ans=0
for r in dr:
    for g in dg:
        ans+=lendb-(2*r-g in db)-(2*g-r in db)-((r+g)/2 in db)
print(ans)


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

using namespace std;

int main()
{
    int n,c=0;
    cin>>n;
    int a[n];
    map<int,int> vis;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
        vis[a[i]]=i;
    }
    sort (a,a+n);
    for (int i=0; i<n; i++)
        cout<<vis[a[i]]+1<<" ";
    return 0;
}


Measured memory_bytes: 5888
S = int(input())
mod = 10**9 + 7

memo = []
for i in range(S//3):
    for j in range(S-3*i-2):
        if j == 0:
            memo.append([1])
        else:
            if i == 0:
                x = 1
                memo[i].append(x)
            else:
                x = (memo[i][j-1]+memo[i-1][j])%mod
                memo[i].append(x)
ans = 0
for i in range(S//3):
    ans = (ans + memo[i][S-3*(i+1)])%mod
print(ans)


Measured memory_bytes: 72292
#include <iostream>
using namespace std;
#define mod 998244353
long long fact[300005],inv[300005];
long long pow_log(long long x,int y)
{
	if (!y)
	return 1;
	long long ret=pow_log(x,y/2);
	ret=(ret*ret)%mod;
	if (y%2)
	ret=(ret*x)%mod;
	return ret;
}
long long ncr(int n,long long r)
{
	if (r>n)
	return 0;
	return (((fact[n]*inv[r])%mod)*inv[n-r])%mod;
}
int main()
{
	int n,ans=0;
	long long k,a,b;
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	fact[0]=1;
	for (int i=1;i<=n;i++)
	fact[i]=(fact[i-1]*i)%mod;
	inv[n]=pow_log(fact[n],mod-2);
	for (int i=n-1;i>=0;i--)
	inv[i]=(inv[i+1]*(i+1))%mod;
	for (int i=0;i<=n;i++)
	{
		if (k>=i*a && (k-i*a)%b==0)
		ans=(ans+ncr(n,i)*ncr(n,(k-i*a)/b))%mod;
	}
	printf("%d",ans);
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long int arr[3005],n,dp[3005][3005][3],m;
long long int solve(long long int low,long long int high,long long int player)
{
    long long int pl=(player==1?2:1);
    if(low==high)
    {
        if(player==1)
          dp[low][high][player]=arr[low];
        else
          dp[low][high][player]=(-1)*arr[low];
      return dp[low][high][player];
    }
    if(dp[low][high][player]!=-1)
        return dp[low][high][player];
    long long int ans1,ans2;
    if(player==1)
    {
        ans1=arr[low]+solve(low+1,high,pl);
        ans2=arr[high]+solve(low,high-1,pl);
        dp[low][high][player]=max(ans1,ans2);
    }
    if(player==2)
    {
        ans1=solve(low+1,high,pl)-arr[low];
        ans2=solve(low,high-1,pl)-arr[high];
        dp[low][high][player]=min(ans1,ans2);
    }
    return dp[low][high][player];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long int i,j,k,a,b,ans=0,sum=0,cnt=0;
    cin >> n;
    //long long int arr[n];
    memset(dp,-1,sizeof(dp));
    /*for(i=0;i<n;i++)
        for(j=0;j<k;j++)
            cout << dp[i][j];*/
    //cout << k << endl;
    for(i=1;i<=n;i++)
    {
        cin >> arr[i];
    }
    /*for(i=1;i<=n;i++)
        cout << arr[i] << endl;*/
    cout << solve(1,n,1) << endl;
    return 0;
}

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

using namespace std;


int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    for(int i =0; i < s.size()-1; ++i){
        if(s[i+2] == s[i+3] && s[i+4] ==s[i+5]){
            cout << "Yes\n";
            break;
        }
        else{
            cout <<"No\n";
            break;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {

	public static void printArray(int[] a,int n){
    	for(int f=0;f<n;f++){
    		if(f<n-1)System.out.print(a[f]+" ");
    		else System.out.println(a[f]);
    	}
	}

	public static void scanArray(int[] a,int n, Scanner s){
    	for(int i=0;i<n;i++){
    		a[i] = s.nextInt();
    	}
	}

	public static void insertSort(int[] a,int n){
		int v,j;
    	for(int i=1;i<n;i++){
    		v=a[i];
    		j=i-1;
    		while(j>=0 && a[j]>v){
    			a[j+1]=a[j];
    			j--;
    		}
    		a[j+1]=v;

    		printArray(a,n);
    	}
	}

	public static void bubbleSort(int[] a,int n){
		int f = 1;
		int c = 0;
		int tmp;
		while(f==1){
			f=0;
			for(int j=n-1;j>=1;j--){
				if(a[j]<a[j-1]){
					c+=1;
					tmp=a[j];
					a[j]=a[j-1];
					a[j-1]=tmp;
					f=1;
				}
			}
		}
		printArray(a,n);
		System.out.println(c);
	}


	public static void main(String args[]) {
    	Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int a[] = new int[n];

    	scanArray(a,n,scan);
    	//printArray(a,n);
    	//insertSort(a,n);
    	bubbleSort(a,n);


    }
}

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

using namespace std; 

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	long double sum = 0.0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		long double x; 
		cin>>x ;
		sum += (1.00 / x) ;
	}
	return cout<<fixed<<setprecision(12)<<(1.00 / sum)<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>

#define POUND 0
#define DOT 1

void print_chess(int h, int w){
    int i, j, flag;
    for(j = 0; j < h; j++){
        if (j % 2 == 1)
            flag = DOT;
        else 
            flag = POUND;
        for(i = 0; i < w; i++){
            if(flag == POUND){
                printf("#");
                flag = DOT;
            }
            else if(flag == DOT){
                printf(".");
                flag = POUND;
            }
        }
        printf("\n");
    }
    printf("\n");
}

int main(void){
    int h, w;

    scanf("%d %d", &h, &w);
    while(h != 0 && w != 0){
        print_chess(h, w);
        scanf("%d %d", &h, &w);
    }

    return 0;
}



Measured memory_bytes: 2104
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println(lcm(a, b))

}

func lcm(i, j int) int {
	return i * j / gcd(i, j)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 512
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
//int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	long long s,c;
	cin>>s>>c;
	if(s>=c/2) cout<<c/2<<endl;
	else{
       long long t;
		t=(c/2-s)/2;
		cout<<s+t<<endl;
	}
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int a, b;
    cin >> a >> b;
    int d = b - a;
    int sum = d * (d + 1) / 2;
    cout << sum - b << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int N,dist[300][300], bad[300][300];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N;
	F0R(i,N) F0R(j,N) {
	    cin >> dist[i][j];
	} 
	// if equal, ignore it?
	F0R(i,N) F0R(j,N) F0R(k,N) {
	    if (dist[i][j] > dist[i][k]+dist[k][j]) {
	        cout << -1;
	        return 0;
	    } 
	    if (dist[i][j] == dist[i][k]+dist[k][j] && k != i && k != j) {
	        bad[i][j] = 1;
	    }
	}
	ll ans = 0;
	F0R(i,N) FOR(j,i+1,N) if (!bad[i][j]) ans += dist[i][j];
	cout << ans;
}

// read!
// ll vs. int!

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

int a,b,c,z;
cin >> a >> b >> c;
if(a<b){
a<b;
}else{
z=a,a=b,b=z;
}
if(b<c){
b<c;
}else{
z=b,b=c,c=z;
}
if(a<b){
a<b;
}else{
z=a,a=b,b=z;
}
cout << a << " " << b << " " << c << "\n";

return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	// input
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<vector<ll>> dp(N, vector<ll>(N));
	REP(i, N)cin >> a[i];

	// init
	REP(i, N)dp[i][i] = (N % 2 == 1 ? 1 : -1)*a[i];

	// dp
	REP(i, N)for(int j = i - 1; j >= 0; j--)
	{
		dp[i][j] = (N % 2 == (i + j + 1) % 2
			? max(dp[i - 1][j] + a[i], dp[i][j + 1] + a[j])
			: min(dp[i - 1][j] - a[i], dp[i][j + 1] - a[j]));
	}
	cout << dp.back().front() << endl;
	cin >> N;

	return 0;
}


Measured memory_bytes: 70784
using System;
using System.Collections.Generic;

namespace AtCoder_
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = {0, 0, 0, 0, 0};
            array[0] = int.Parse(Console.ReadLine());
            array[1] = int.Parse(Console.ReadLine());
            array[2] = int.Parse(Console.ReadLine());
            array[3] = int.Parse(Console.ReadLine());
            array[4] = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());

            int di = Math.Abs(array[0] - array[4]);
            if(di > k)
            {
                Console.WriteLine(":(");
            }
            else
            {
                Console.WriteLine("Yay!");
            }
        }
        static void MainStream()
        {

        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<stdlib.h>

long arl[200200];
long *ars[200200];
long ans[200200];

long queue[200200];
long qlen,qhead;

void enqueue(long n){
    queue[(qhead+qlen) % 200200] = n;
    qlen++;
}

long dequeue(void){
    long ret = queue[qhead];
    qlen--;
    qhead = (qhead+1) % 200200;
    return ret;
}

int main(void){
    register long i;
    long n,m;
    scanf("%ld%ld",&n,&m);
    for(i = 0;i < m;i++){
        long x,y;
        scanf("%ld%ld",&x,&y);
        x--; y--;
        ars[x] = realloc(ars[x],sizeof(long) * (arl[x]+1));//sizeof()!!!!!!!!!!!!!!
        ars[y] = realloc(ars[y],sizeof(long) * (arl[y]+1));//sizeof()!!!!!!!!!!!!!!
        ars[x][arl[x]] = y;
        ars[y][arl[y]] = x;
        arl[x]++;
        arl[y]++;
    }
    for(i = 0;i < n;i++)ans[i] = -1;
    enqueue(0);
    while(qlen){
        int cur = dequeue();
        for(i = 0;i < arl[cur];i++)if(ans[ars[cur][i]] == -1){
            ans[ars[cur][i]] = cur;
            enqueue(ars[cur][i]);
        }
    }
    puts("Yes");
    for(i = 1;i < n;i++)printf("%ld\n",ans[i]+1);
}

Measured memory_bytes: 10544
#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};

int main()
{
	ll n, m;
	cin >> n >> m;
	ll s = 0;
	for(int i = 1; i <= m; i ++)
	{
		ll x;
		cin >> x ;
		s += x;
	}
	ll ans = n  - s;
	if(ans < 0)
		ans = -1;
	cout << ans;



	





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

Measured memory_bytes: 3632
eval'N,A,B='+`dd`.split*?,
A*=t=(A+B).pow -2+M=10**9+7,M
B*=t
a=A.pow N,M
b=B.pow N,M
[g=1,*(1...N).map{g=g*_1%M}].map{$.=($.+_1.pow(M-2,M)*(a+b)*100*t=t*N%M)%M
N+=1
a=a*B%M
b=b*A%M}
p$.

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

int main(){

  int m,tmp;

  while(cin >> m, m){
    int f = 1,s = 2,e = 3,w = 4,n = 5,b = 6;
    int ans = 0;

    for(int i=0;i<m;i++){
      string str;
      cin >> str;

      if(str == "North"){
	tmp = f;
	f = s;
	s = b;
	b = n;
	n = tmp;
      }

      else if(str == "East"){
	tmp = f;
	f = w;
	w = b;
	b = e;
	e = tmp;
      }

      else if(str == "West"){
	tmp = f;
	f = e;
	e = b;
	b = w;
	w = tmp;
      }

      else if(str == "South"){
	tmp = f;
	f = n;
	n = b;
	b = s;
	s = tmp;
      }

      else if(str == "Right"){
	tmp = s;
	s = e;
	e = n;
	n = w;
	w = tmp;
      }

      else if(str == "Left"){
	tmp = s;
	s = w;
	w = n;
	n = e;
	e = tmp;
      }
      ans += f;    
    }

    cout << ans+1 << endl;

  }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int k,x;
  cin>>k>>x;
  Int MAX=1000000;
  for(Int i=-MAX;i<=MAX;i++)
    if(abs(i-x)+1<=k) cout<<i<<" ";
  cout<<endl;
  return 0;
}


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

int swap( int& a, int& b )
{
    int t = a;
    a = b;
    b = t;
}

void bubbleSort( int* a, int* b, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( b[j] < b[j-1] )
            {
                swap( b[j], b[j-1] );
                swap( a[j], a[j-1] );
            }
}

int main()
{
    int n;

    while( cin >> n, n )
    {
        int* a = new int[n];
        int* b = new int[n];

        for( int i = 0; i < n; i++ )
            cin >> a[i] >> b[i];
        
        bubbleSort( a, b, n );

        int w = 0;
        bool j = true;
        for( int i = 0; i < n; i++ )
        {
            if( w <= b[i] )
                w += a[i];
            else
            {
                j = false;
                break;
            }
            if( w > b[i] )
            {
                j = false;
                break;
            }
        }
        if( j )
            cout << "Yes" << endl;
        if( !j )
            cout << "No" << endl;

        delete a, b;
    }
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

ll N,Q; vi V[200010]; vpii P; vll ans;
void input(){
    cin>>N>>Q;
    rep(i,N-1){
        ll a,b; cin>>a>>b; V[a-1].emplace_back(b-1); V[b-1].emplace_back(a-1);
    }
    rep(i,Q){
        ll a,b; cin>>a>>b; P.emplace_back(make_pair(a-1,b));
    }
    return;
}

void dfs(ll p,ll parent){
    for(auto v: V[p]){
        if(v==parent) continue;
        ans[v]+=ans[p];
        dfs(v,p);
    }
}

void solve(){
    rep(i,N) ans.emplace_back(0);
    rep(i,Q) ans[P[i].first]+=P[i].second;
    dfs(0,-1);
    rep(i,N-1) cout<<ans[i]<<" ";
    cout<<ans[N-1]<<endl;
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 25972
#include <cstdio>
using namespace std;
const int MOD = 1000000007;
int N; long long A[300001], ans;
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; ++i) {
    scanf("%ld", &A[i]);
  }
  for(int i = 0; i < 60; ++i) {
    int cnt1 = 0;
    for(int j = 1; j <= N; ++j) {
      if(A[j]>>i & 1) ++cnt1;
    }
    ans += (1LL<<i)%MOD*cnt1%MOD*(N-cnt1)%MOD;
    ans %= MOD;
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF=1e3+5;
int n,a[INF],k;
signed main()
{
        // char ch;
        cin>>n>>k;
        for (int i=1; i<=n; i++) cin>>a[i];
        sort(a+1,a+1+n);
        int ans=0;
        for (int i=1; i<=k; i++) ans+=a[i];
        cout<<ans<<endl;
        return 0;
}


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

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
    
    int N,K;
    cin>>N>>K;
    cout<<N-K+1<<endl;
    
    
    }



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k=0;
string s, t;


int main()
{
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    int ans, g, p;
    cin >> s;

    ans = g = p = 0;
    REP(i, s.size())
    {
        if (g > p)
        {
            ans += (s[i] == 'g' ? 1 : 0);
            p++;
        }
        else
        {
            ans += (s[i] == 'g' ? 0 : -1);
            g++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512