akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  ll a,b,n;
  cin >> a >> b >> n;
  // REP(i,n+1){
  //   cout << i << " " << a*i/b << " " << a*(i/b) << endl;
  // }

  ll ans = 0;
  if(n%b == 0){
    ans = a*(n-1)/b - a*((n-1)/b);
  }else{
    ll nn = (n/b)*b-1;
    ans = a*(n)/b - a*((n)/b);
    chmax(ans, a*(nn)/b - a*((nn)/b));
  }
  cout << ans << endl;

}



Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  long int n,sum = 0;
  scanf("%d",&n);
  for(int i =1;i <=n;i++){
   if(i%3 != 0 && i%5 != 0){ 
  
    sum += i;
   }
  }
    printf("%ld",sum);
}
 

Measured memory_bytes: 2088
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
#include <cassert>
using namespace std;
 
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
 
#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)
 
typedef long long ll;
typedef pair<int, int> pii;

const int INF = 1<<29;

string brd[8];

char r(char c) { return c=='o'?'x':'o'; }

int dx[] = { 0, 0, -1, -1, -1, 1, 1, 1 };
int dy[] = { -1, 1, -1, 0, 1, -1, 0, 1 };

class node {
public:
	char t;
	int n, x, y;
	node(char t, int n, int x, int y):t(t), n(n), x(x), y(y) {}

	bool operator>(const node &r) const {
		if (t == 'o')
			return n>r.n 
				|| (n == r.n && y < r.y)
				|| (n == r.n && y == r.y && x < r.x);
		else
			return n>r.n 
				|| (n == r.n && y > r.y)
				|| (n == r.n && y == r.y && x > r.x);
	}
};

int num(char t, int x, int y, int d, int n)
{
	int nx = x + (n+1)*dx[d];
	int ny = y + (n+1)*dy[d];
	if (!(0 <= nx && nx < 8)) return 0;
	if (!(0 <= ny && ny < 8)) return 0;
	if (brd[ny][nx] == '.') return 0;
	if (brd[ny][nx] == t) return n;
	return num(t, x, y, d, n+1);
}

bool can_put(char t)
{
	rep(y, 8)
		rep(x, 8)
			if (brd[y][x] == '.')
				rep(d, 8)
					if (num(t, x, y, d, 0) > 0)
						return true;
	return false;
}

void paint(char t, int x, int y, int d, int n)
{
	int nx = x + (n+1)*dx[d];
	int ny = y + (n+1)*dy[d];
	if (!(0 <= nx && nx < 8)) return;
	if (!(0 <= ny && ny < 8)) return;
	if (brd[ny][nx] == '.') return;
	if (brd[ny][nx] == t) return;
	if (brd[ny][nx] == r(t)) {
		brd[ny][nx] = t;
		return paint(t, x, y, d, n+1);
	}
}

void change(char t, int x, int y)
{
	brd[y][x] = t;
	rep(d, 8)
		if (num(t, x, y, d, 0) > 0)
			paint(t, x, y, d, 0);
}

int main()
{
	rep(i, 8)
		getline(cin, brd[i]);

	for (char turn = 'o'; ; turn=r(turn)) {
		if (!can_put(turn)) {
			if (!can_put(r(turn)))
				break;
			continue;
		}
		node p = node(turn, -INF, -INF, -INF);
		rep(y, 8)
			rep(x, 8)
				if (brd[y][x] == '.') {
					int n = 0;
					rep(d, 8)
						n += num(turn, x, y, d, 0);
					if (n > 0) {
						node buf = node(turn, n, x, y);
						if (buf > p)
							p = buf;
					}
				}
		change(turn, p.x, p.y);
	}
	rep(i, 8)
		cout << brd[i] << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
vvpll G;
vl visited;
vl d;
bool ok = true;
 
void dfs(ll v, ll dist) {
    if(visited[v]) {
        if(d[v] != dist) {
            ok = false;
        }
        return;
    }
    visited[v] = 1;
    d[v] = dist;
    for(auto p : G[v]) {
        ll u = p.first;
        ll cost = p.second;
        dfs(u, d[v] + cost);
    }
}
 
int main() {
    ll n, m;
    cin >> n >> m;    
 
    G.resize(n);
    rep(i, m) {
        ll L, R, D;
        cin >> L >> R >> D;
        L--;  R--;
        G[L].pb(make_pair(R, D));
        G[R].pb(make_pair(L, -D));
    }
 
    visited.resize(n);
    d.resize(n);
    rep(v, n) {
        if(!visited[v]) {
            dfs(v, 0);
        }
    }
 
    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 16384
local n=io.read("*n","*l")
local d={}
for i=1,n do
    local x=io.read("*n")
    if not d[x] then
        d[x]=1
    else
        d[x]=d[x]+1
    end
end
local m=io.read("*n","*l")
local t={}
for i=1,m do
    local y=io.read("*n")
    if not t[y] then
        t[y]=1
    else
        t[y]=t[y]+1
    end
end

checker=true
for i,_ in pairs(t) do
    if d[i] then
        if t[i]>d[i] then
            checker=false
        end
    else
        checker=false
    end
end
print(checker and "YES" or "NO")

Measured memory_bytes: 24804
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var ab=(Arr.shift()).split(" ");;
   if(ab[0]==0 && ab[1]==0)break;
   var m=ab[1]-ab[0];
   var arr=[0,0,0];
   while(m>=1000){
      m-=1000;
      arr[2]++;
   }
   while(m>=500){
      m-=500;
      arr[1]++;
   }
   while(m>=100){
      m-=100;
      arr[0]++;
   }
   console.log(arr.join(" "));
}

Measured memory_bytes: 10748
#include <iostream>

int main()
{

  while(true)
{
  int n, x;
  std::cin>>n>>x;
if(n==0&& x==0)break;
 long long count = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = i+1; j <= n; j++)
    {
      for(int k = j+1;k<=n; k++)
      {
        if(i+j+k==x)
        {
          count++;
        }
      }
    }
  }
  std::cout << count << std::endl;
}
}



Measured memory_bytes: 3120
sx, sy, tx, ty = gets.split(' ').map(&:to_i)
dx = (sx - tx).abs
dy = (sy - ty).abs
puts 'U' * dy + 'R' * dx + 
    'D' * dy + 'L' * dx +
    'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D' +
    'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

ll aI, aO, aT, aJ, aL, aS, aZ, ans;

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

	cin >> aI >> aO >> aT >> aJ >> aL >> aS >> aZ;
	ll cntI = (aI / 2) * 4, cntJ = (aJ / 2) * 4, cntL = (aL / 2) * 4;
	ans = cntI + cntJ + cntL;
	//cerr << '#' << ans << endl;
	if (aI && aJ && aL)
	{
		aI--, aJ--, aL--;
		cntI = (aI / 2) * 4, cntJ = (aJ / 2) * 4, cntL = (aL / 2) * 4;
		ans = max(ans, cntI + cntJ + cntL + 6);
	}
	cout << (ans + aO * 2) / 2 << endl;
}



Measured memory_bytes: 256
ar = sorted(map(int, input().strip().split()))

diff = []
for i in range(0,2):
    diff.append(abs(ar[i + 1] - ar[i]))

diff = sorted(diff)


#for i in range(0,1):
 #   su += abs(diff[i + 1] - diff[i])

print(sum(diff))



Measured memory_bytes: 2940
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,1,1
for _ in range(N):
  b = int(input())
  for i in range(3):
    if b in A[i]:
      m[i][A[i].index(b)]=1
                
for i in range(3):
  l *= m[i][i]
  t,y = 1,1
  for j in range(3):
    y *= m[j][i]
    t *= m[i][j]
    if i+j == 2:
      r *= m[i][j]
  if t or y:
    ans=1

print('Yes' if ans or l or r else 'No')

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int n,m,g;
char ch[100][100];
int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			cin>>ch[i][j];
		}
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(ch[i][j]=='.')
			{
				if(ch[i-1][j]=='#' and i-1>=1)g++;
				if(ch[i+1][j]=='#' and i+1<=n)g++;
				if(ch[i-1][j-1]=='#' and i-1>=1 and j-1>=1)g++;
				if(ch[i-1][j+1]=='#' and i-1>=1 and j+1<=m)g++;
				if(ch[i+1][j-1]=='#' and i+1<=n and j-1>=1)g++;
				if(ch[i+1][j+1]=='#' and i+1<=n and j+1<=m)g++;
				if(ch[i][j-1]=='#' and j-1>=1)g++;
				if(ch[i][j+1]=='#' and j+1<=m)g++;
				cout<<g;
				g=0;
			}
			if(ch[i][j]=='#') cout<<'#';
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String[] str1 = scanner.nextLine().split(" ");
        for (String s : str1) {
            System.out.print(s.substring(0, 1));
        }

        scanner.close();
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int X,A,B;

	scanf("%d %d %d",&X,&A,&B);

	int num_query;
	scanf("%d",&num_query);

	char command[10];

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'n':

			X += A;
			break;

		case 't':

			X += B;
			break;

		case 'k':

			X = 0;
			break;
		}

		X = max(0,X);
	}

	printf("%d\n",X);

	return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int modPow(ll a, ll n, ll p) {
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	ll t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll n;
	cin >> n;
	ll a, b;
	cin >> a >> b;
	ll p = 1e9 + 7;
	ll temp = modPow((ll)2, n, p)-1;
	ll atemp = 1, atemp2 = 1;
	ll btemp = 1, btemp2 = 1;
	rep(i,a) {
		atemp = atemp * (n-i) % p;
	}
	for(int i=1; i<=a; i++) {
		atemp2 = atemp2 * i % p;
	}
	atemp2 = modPow(atemp2, p-2, p);
	atemp = atemp * atemp2 % p;
	rep(i,b) {
		btemp = btemp * (n-i) % p;
	}
	for(int i=1; i<=b; i++) {
		btemp2 *= i;
		btemp2 %= p;
	}
	btemp2 = modPow(btemp2, p-2, p);
	btemp = btemp * btemp2 % p;
	temp = temp - atemp - btemp;
	temp %= p;
	while(temp < 0) {
		temp += p;
	}
	cout << temp << endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[100010],to[100010],co[100010],nt[100010],it[100010],l[100010];
void mklsb(int v,int e,int *a,int *b,int *c){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];      
    co[ta[b[i]]=i+e]=0;
  }
}
int MF(int e,int s,int t,int min){
  if(s==t)return min;
  int i,r;
  for(;it[s]+1;it[s]=nt[it[s]]){
    if(co[it[s]]==0||l[s]>=l[to[it[s]]])continue;
    r=MF(e,to[it[s]],t,MIN(min,co[it[s]]));
    co[it[s]]-=r;
    co[(it[s]+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int v,int e,int s,int g){
  int i,a=0,q[100010],t,r,c=3;
  while(1){
    for(i=t=0;i<v;i++)l[i]=0;
    l[q[0]=s]=1;
    for(r=1;r-t;t++){
      for(i=ta[q[t]];i+1;i=nt[i]){
	if(co[i]&&l[to[i]]==0)l[q[r++]=to[i]]=l[q[t]]+1;
      }
    }
    if(l[g]==0)return a;
    for(i=0;i<v;i++)it[i]=ta[i];
    while(r=MF(e,s,g,1e9))a+=r;
  }
}
int main(){
  int n,m,i,a[100010],b[100010],c[1000010],m1,m2;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  mklsb(n,m,a,b,c);//prls(n);
  printf("%d\n",maxf (n,m,0,n-1));
  return 0;
}
  

Measured memory_bytes: 2700
a = list(input())
 
A = a[0]+a[1]
B = a[2]+a[3]
 
if A == "00" or int(A) > 12:
  if B == "00" or int(B) > 12:
    print("NA")
  else:
    print("YYMM")
else:
  if B == "00" or int(B) > 12:
    print("MMYY")
  else:
    print("AMBIGUOUS")

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll n, l, memo = 0, ans = inf, tr;
	cin >> n >> l;
	rep(i, n)memo += i + l;
	rep(i, n) {
		if (abs(i + l - 0) < ans) {
			ans = abs(i + l); tr = i + l;
		}
	}
	cout << memo - tr << endl;
	ggr
}



Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
//参考http://topcoder.g.hatena.ne.jp/isa_rentacs/20111114/1321278656 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

double dp[16][9];
int dir[4] = {1,-3,-1,3};
int main()
{
  int n;
  while(cin >>n&&n){
    FILL(dp,0);
    char tmp;
    int s,t,b,x,y;
    cin >> tmp; s = (int)(tmp - 'A');
    cin >> tmp; t = (int)(tmp - 'A');
    cin >> tmp; b = (int)(tmp - 'A');

    dp[0][s] = 1;
    for(int i = 0;i < n;i++){
      for(int j = 0;j < 9;j++){
	if(dp[i][j] ==0)
	  continue;
	x = j%3;
	y = j/3;
	for(int k = 0;k < 4;k++){
	  if(0 <= x+dx[k] && x+dx[k] < 3 &&
	     0 <= y+dy[k] && y+dy[k] < 3 &&
	     j+dir[k] != b){
	    dp[i+1][j+dir[k]] += (dp[i][j]*0.25);
	  }
	  else{
	    dp[i+1][j] +=(dp[i][j]*0.25);
	  }
	}
      }
    }
    printf("%.8f\n",dp[n][t]);
  }
  return 0;
}

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

using namespace std;

int n, m, a[15], stat[15], ans = 0;

bool valid (int mask) {
  for (int i = 0; i < m; i++) {
    if ((__builtin_popcount(a[i] & mask) & 1) != stat[i]) return false;
  }
  return true;
}

int solve (int p, int mask) {
  if (p > n) return (valid (mask) == 1);
  return solve (p + 1, mask) + solve (p + 1, mask | (1 << p));
}

int main () {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int mask = 0, k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int p;
      cin >> p;
      mask |= (1 << p);
    }
    a[i] = mask;
  }
  for (int i = 0; i < m; i++) {
    cin >> stat[i];
  }
  cout << solve (1, 0) << '\n';
  return 0;
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    string S;
    
    cin >> N;
    cin >> S;
    
    int x = 0;
    int xmax = 0;
    for(int i = 0; i < S.size(); i++)
    {
        if(S[i]=='I')
        {
            x++;
        }
        else
        {
            x--;
        }
        //cout << x << endl << endl;
        if(x > xmax) xmax = x;
    }
    
    cout << xmax << endl;
    
    return 0;
}

Measured memory_bytes: 256
// but in the end its me & I

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

#define s second
#define f first
#define pb push_back
//#define int ll

using namespace std;

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

const long long MAX=1010,INF=1e9+7,mod=998244353;

int dx[2]={0,1};
int dy[2]={1,0};
int n,m,k,dp[MAX][MAX];
string s[MAX];
vector <int> v;
bool mark[MAX];
set <pii> st;
queue <pii> q;

bool is_valid(int x, int y)
{
    if(y==1 && x > n-1) return 0;
    if(y==2 && x > m-1) return 0;
    return 1;
}
void solve()
{
    // paye dp
    for(int i=0;i<n;i++)
    {
        if(s[i][0]=='#') break;
        dp[i][0]=1;
    }
    for(int i=0;i<m;i++)
    {
        if(s[0][i]=='#') break;
        dp[0][i]=1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(s[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            if(dp[i][j]>=INF) dp[i][j]-=INF;
        }
    }

}
main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        cin >> s[i];
    }
    solve();
    cout << dp[n-1][m-1];
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
using namespace std;
string tmp;
int main(){
  string s;cin>>s;
  vector<string> ans;
  
  for(int i = 0; s.size() > i; i++){
    tmp.push_back(s[i]);
    if(ans.empty()){
      ans.push_back(tmp);
    }else{
      if(ans[ans.size()-1] == tmp)continue;
      ans.push_back(tmp);
    }
    tmp = "";
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 10996
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[60][60], f[120], g[101000], h[10100], counto = 0, ans = 0, x[100] = {}, y, z;
int64_t ab[10000] = {}, abc = 0, abcd = 0;
pair<int, int>manji[101] = {};
char rikka, toka[150][150] = {};
vector<int> train,code;
vector<char>aka,ao;
string saya, homu, kyok, mami[108], mado[100];
bool gg;
bool exist[1000];
int main() {
	cin >> a;
	unsigned long long kk[90];
	kk[0] = 2;
	kk[1] = 1;
	for (int i = 2; i <= a; i++) {
		kk[i] = kk[i - 1] + kk[i - 2];
		
	}
	cout << kk[a] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 2007;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n;
int col[maxN], pre[maxN];
vector<int> adj[maxN];
bool fix[maxN];
bool is[maxN];
int leaf[maxN], las[maxN];
bool hav[maxN];
bool use[maxN];
vector<int> ans;

void rot(int x) {
	ans.push_back(x);
	int t = col[0];
	do { swap(col[x], t); x = pre[x]; } while (x);
	swap(col[0], t);
}

void solve() {
	while (1) {
		int cccc = 0;
		per (i, n, 0) if (!fix[i]) {
			if (adj[i].size() == 0) {
				is[i] = true;
				leaf[i] = las[i] = i;
				++cccc;
			}
			else if (adj[i].size() == 1 && is[adj[i][0]]) {
				is[i] = true;
				leaf[i] = leaf[adj[i][0]];
				++cccc;
			}
		}
		cerr << cccc << endl;
		rep (i, 0, n) if (!fix[i] && adj[i].size() > 1) {
			vector<int> tmp;
			for (vector<int>::iterator it = adj[i].begin(); it != adj[i].end(); ++it)
				if (!leaf[*it]) tmp.push_back(*it);
			adj[i] = tmp;
		}
		memset(use, 0, sizeof use);
		while (1) {
			if (is[col[0]]) {
				int v = leaf[col[0]], &u = las[v];
				while (v != u && col[0] < col[v]) v = pre[v];
				rot(v);
				fix[u] = true;
				if (u == 0) return;
				u = pre[u];
			}
			else {
				hav[0] = false;
				rep (i, 1, n) if (!fix[i]) 
					hav[i] = hav[pre[i]] | is[col[i]];
				bool flag = false;
				per (i, n, 1) if (!fix[i] && !use[i] && hav[i]) {
					rot(i);
					use[i] = true;
					flag = true;
					break;
				}
				if (!flag) break;
			}
		}
		rep (i, 0, n) if (is[i]) assert(fix[i]);
	}
}

int main() {

	n = ri()-1;
	rep (i, 1, n) adj[pre[i] = ri()].push_back(i);
	rep (i, 0, n) col[i] = ri();
	solve();

	rep (i, 0, n) assert(col[i] == i);
	printf("%d\n", ans.size());
	for (vector<int>::iterator it = ans.begin(); it != ans.end(); ++it)
		printf("%d\n", *it);

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    if(n == 3 || n == 5 || n == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
        }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 300005

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
///////////////////////////////////////////
    fastio;
///////////////////////////////////////////

    lli n,k;
    cin>>n>>k;
    string s;
    cin>>s;


    loopl(i,1,n+1)
    {
        char a = s[i-1];
        if(i == k)
            cout<<char(a+32);
        else cout<<a;
    }


}

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

int main() {
  string s,ans;
  set<ll>a;
  cin >> s;
  rep(i,sz(s)) a.insert((ll)s.at(i));
  ans = a.size()==2 ? "Yes" : "No";
  cout<< ans << endl;
}


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

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

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

    int ans = 100000;

    REP(i, N)
    {
        int c,t;
        cin >> c >> t;
        if(t <= T)
        {
            ans = min(ans, c);
        }
    }

    if(ans == 100000)
    {
        cout << "TLE" << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,k,i;
    scanf("%d %d",&n,&k);
    int a[n];
    //int be=0;
    //int af=0;
    //int o=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        //if(a[i]==1)
         //   o=1;
        //else if(o=0)
         //   be++;
       // else if(o=1)
         //   af++;
    }
    int ans;
    float tmp;
    if(n==1)
    {
        ans=1;
        return;
    }
    ans = 1 + ((n- 1 - 1) / (k-1));
    printf("%d",ans);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define cl CLOCKS_PER_SEC
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
    int n;
    cin>>n;
    cout<<((((n+999)/1000)*1000)-n)<<"\n";
    return 0;
}


Measured memory_bytes: 3624
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    x = 0
    for i in range(N):
        x ^= a[i]

    x ^= a[0]
    xors = [x]
    for i in range(1, N):
        x ^= a[i-1]
        x ^= a[i]
        xors.append(x)

    print(' '.join(str(x) for x in xors))


main()


Measured memory_bytes: 41712
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 510000;
const int MOD = pow(10, 9) + 7;
//fac[i] i!, finv[i] (i)^(-1)!, inv[i] i^(-1)
long long fac[MAX], finv[MAX], inv[MAX];
 
// 各階乗を計算しておく
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main() {
  COMinit();
  long long H, W, Hdis, Wdis;
  cin >> H >> W >> Hdis >> Wdis;
  long long Hdiff = H - Hdis;
  long long Wdiff = W - Wdis;
  long long pattern1[Hdiff];
  long long pattern2[Hdiff];
  long long ans = 0;
  for(int i = 0; i < Hdiff; i++){
    pattern1[i] = COM(Wdis + i - 1, i);
  }
  for(int j = 0; j < Hdiff; j++){
    long long Hcanmove = H - j - 1;
    long long Wcanmove = Wdiff - 1;
    pattern2[j] = COM(Hcanmove + Wcanmove, Hcanmove);
  }
  for(int k = 0; k < Hdiff; k++){
    long long patt = (pattern1[k] * pattern2[k]) % MOD;
    ans += patt % MOD;
    ans %= MOD; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

ll N, K;
ll a[200005];
ll f[200005];

ll getMinK(ll s) {
    ll total = 0;
    for (ll i = 0; i < N; ++i) {
        ll need = s / f[i];
        total += max(0LL, a[i] - need);
    }
    return total;
}

int main() {
    scanf("%lld %lld", &N, &K);
    for (int i = 0; i < N; ++i) {
        scanf("%lld", &a[i]);
    }

    for (int i = 0; i < N; ++i) {
        scanf("%lld", &f[i]);
    }

    sort(a, a + N);
    sort(f, f + N);
    ll m = N / 2;
    for (ll i = 0; i < m; ++i) {
        swap(f[i], f[N - i - 1]);
    }

    ll left = 0, right = 1000000000005LL;
    while (left <= right) {
        ll mid = (left + right) / 2;
        ll minK = getMinK(mid);
        //cout << left << " " << right << " " << mid << " " << minK << endl;
        if (minK <= K) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    printf("%lld\n", left);
    return 0;
}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
struct BinTree
{
	char data;
	BinTree *left,*right;
};
ll n,k,v[1001];
ll solve(ll l,ll r)
{
	vector<ll> t;
	for(int i=0;i<=l;i++) t.push_back(v[i]);
	for(int i=r;i<n;i++) t.push_back(v[i]);
	sort(t.begin(),t.end());
	ll lim=k-t.size();
	if(lim<0) return 0;
	ll sum=0;
	for(int i=0;i<t.size();i++)
	{
		if(t[i]<0&&lim>0) lim--;
		else sum+=t[i];
	}
	return sum;
}
//#define read io.read
int main()
{
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> v[i];
	ll ans=0;
	for(int i=-1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans=max(ans,solve(i,j));
		}
	}
	cout << ans;
	return 0;
}


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<long long> ab(n);
    long long ans = 0;
    for(i = 0;i < n;i++){
        int a,b;
        cin >> a >> b;
        ab[i] = a+b;
        ans += a-b;
    }
    sort(ab.begin(),ab.end());
    for(i = 0;i < n;i++){
        if(i%2) ans -= ab[n-i-1];
        else ans += ab[n-i-1];
    }
    cout << ans/2 << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1152
#include<stdio.h>
int main(void)
{
	int N,i,k[10001],flg,a;
	scanf("%d",&N);
	while(!(N==0)){
		flg=0;
		a=0;
		for(i=1;i<=N;i++){
			scanf("%d",&k[i]);
			if(k[i]>=2){
				flg=1;
				a++;
			}
			else if(k[i]>=1){
				a++;
			}
		}
		if(flg==1){
			a=a+1;
			printf("%d\n",a);
		}
		else{
			printf("NA\n");
		}
		scanf("%d",&N);
	}
	return 0;
}

		

Measured memory_bytes: 1080
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>
#include <list>

#define MOD (1000000000 + 7)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 

vector<ll> divisor;
void list_divisor(ll n) {
    divisor.clear();
    for(int i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            divisor.push_back(i);
            if(i*i != n) divisor.push_back(n/i);
        }
    }
    sort(divisor.begin(), divisor.end());
}

vector<bool> Eratosthenes(ll N) {
    vector<bool> primes(N, true);
    vector<ll> ret;
    primes[0] = false;
    primes[1] = false;
    for (ll i=2; pow(i,2)<=N; i++) {
        if (primes[i]) {
            for(int j=2; i*j<=N; j++) primes[i*j] = false;
            ret.push_back(primes[i]);
        }
    }
    return primes;//ret;
}


int main() {
    ll N;
    cin >> N;

    vector<ll> x(N, 0), y(N, 0);
    for(ll i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    map<pair<ll, ll>, ll> m;
    ll count_max = 0;
    pair<ll, ll> max_pair;
    for(ll i = 0; i < N; i++) {
        for(ll j = 0; j < N; j++ ) {
            if(i==j) continue;
            pair<ll, ll> p = make_pair<ll, ll>(x[j]-x[i], y[j]-y[i]);
            m[p]++;
            if(count_max < m[p]) {
                count_max = m[p];
                max_pair = p;
            }
        }
    }

    // for(auto itr = m.begin(); itr != m.end(); itr++) {
    //     cout << itr->first.first <<"," << itr->first.second << ":" << itr->second<<endl;
    
    // }

    cout << N - count_max << endl;



}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int N,W,H;
int x,y,w;
int superx[400005];
int supery[400005];

int main(void)
{
  memset(superx,0,sizeof(superx));
  memset(supery,0,sizeof(supery));
  cin >> N >> W >> H;
  bool clear=true;
  for(int i=0;i<N;i++)
    {
      cin >> x >> y >> w;
      x+=200000;
      y+=200000;
      superx[x-w]++;
      superx[x+w]--;
      supery[y-w]++;
      supery[y+w]--;
    }
      for(int i=1;i<=400000;i++)
	{
	  superx[i]+=superx[i-1];
	  supery[i]+=supery[i-1];
	}
      for(int i=200000;i<200000+W;i++)
	{
	  if(superx[i]<=0) clear=false;
	}
      if(clear)
	{
	  cout << "Yes" << endl;
	  return 0;
	}
      else
	{
	  clear=true;
	  for(int i=200000;i<200000+H;i++)
	    {
	      if(supery[i]<=0) clear=false;
	    }
	}
      if(clear)
	{
	  cout << "Yes" << endl;
	}
      else
	{
	  cout << "No" << endl;
	}

  return 0;
}



Measured memory_bytes: 6228
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int X;
    cin >> X;
    for(int i = 0; i < 10; i++){
        if(400 + i*200 <= X && X <= 599 + i*200){
            cout << 8-i << endl;
            break;
        }
    }
}


Measured memory_bytes: 3632
public class Main{
	public static void main(String[] args){
		//
		String input = new java.util.Scanner(System.in).nextLine();
		int sec = Integer.parseInt(input);
		int h = sec / 3600;
		int m = (sec % 3600) / 60; 
		int s = (sec % 3600) % 60; 
		System.out.println( h + ":" + m + ":" + s );
		//
	}
}

Measured memory_bytes: 26228
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;



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

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
    ll n;
    cin >> n;
    ll ans = n/2 + n%2;
    cout << ans << endl;
}   

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define endl '\n'

using namespace std;

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

const int mod = 1e9+7;

ll poww(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)
			res = (res*a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int n;
	cin>>n;
	vector<ll> v(n);
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	int ans=0;
	for(ll i=0;i<60;++i){
		int cnt=0;
		for(int j=0;j<n;++j){
			if((v[j]&(1LL<<i))!=0)
				cnt++;
		}
		ll bit_0 = n-cnt;
		ll tot_bit_1_at_i = (cnt*bit_0)%mod;
		ll dec_val = ((poww(2LL,i)%mod)*tot_bit_1_at_i)%mod;
		ans = (ans+dec_val)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
 
// vector<vector<int>> data(3, vector<int>(4));
 
struct Edge {
	ll to, id;
	Edge(ll to, ll id): to(to), id(id) {}
};
 
vector<Edge> G[55];
 
vector<ll> es;
 
bool dfs(ll v, ll tv, ll p = -1) {
	if (p == -1) es = vector<ll>();
	if (v == tv) return true;
	for (Edge e : G[v]) {
		if (e.to == p) continue;
		if (dfs(e.to, tv, v)) {
			es.emplace_back(e.id);
			return true;
		}
	}
	return false;
}
 
int main(){	
	long long M;
	long long N;
	scanf("%lld",&N);
 
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		ll a, b;
		scanf("%lld",&a);
		scanf("%lld",&b);
		a--; b--;
 
		G[a].emplace_back(b, i);
		G[b].emplace_back(a, i);
	}
 
	scanf("%lld",&M);
	vector<ll> eset(M);
	rep(i, M) {
		ll u, v;
		cin >> u >> v;
		u--; v--;
		dfs(u, v);
		for (ll e : es) {
			eset[i] |= 1LL<<e;
		}
	}
 
	ll res = 0;
 
	rep(i, 1<<M) {
		ll mask = 0;
		rep(j, M) {
			if (i>>j&1) mask |= eset[j];
		}
		ll white = __builtin_popcountll(mask);
		ll now = 1LL<<(N-1-white);
		if (__builtin_popcountll(i)%2 == 0) res += now; else res -= now;
 	}
	cout << res << endl;
	return 0;
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

using pii = pair<int, int>;

inline void Main() {
  // code
  int n,a[(int)1e5+1],b[(int)1e5];
  long long r=0;
  cin>>n;
  rep(i,n+1) cin>>a[i];
  rep(i,n) cin>>b[i];

  rep(i, n) {
    if(a[i]>=b[i]) {
      a[i] -= b[i];
      r+= b[i];
      b[i] = 0;
    } else {
      b[i] -= a[i];
      r+= a[i];
      a[i] = 0;
      if(a[i+1] >= b[i]) {
        a[i+1] -= b[i];
        r+= b[i];
        b[i] = 0;
      } else {
        b[i] -= a[i+1];
        r+= a[i+1];
        a[i+1] = 0;
      }
    }
  }

  cout << r << endl;
}

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


Measured memory_bytes: 1024
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()

Measured memory_bytes: 36932
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

root = None
def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z[2] < x[2]:
            x = x[0]
        else:
            x = x[1]
    z[3] = y

    if y is None:
        root = z
    elif z[2] < y[2]:
        y[0] = z
    else:
        y[1] = z

def debug():
    s0 = [""]
    s1 = [""]

    def dfs(nd):
        v = str(nd[2])
        s0.append(v)
        if nd[0] is not None:
            dfs(nd[0])
        s1.append(v)
        if nd[1] is not None:
            dfs(nd[1])
    dfs(root)
    return " ".join(s1), " ".join(s0)


M = int(readline())
ans = []
for m in range(M):
    cmd, *V, = readline().split()
    if cmd == "print":
        ans.extend(debug())
    else:
        insert([None, None, int(V[0]), None])
write("\n".join(ans))
write("\n")




Measured memory_bytes: 124872
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int n,b[110],st=0,fi;
pair<string,int> a[110];
signed main()
{
	cin>>n;
	rep(i,n){
		cin>>a[i].first>>a[i].second;
		b[a[i].second]=i+1;
	}
	sort(a,a+n);
	rep(i,n){
		if(a[i].first!=a[i+1].first){
			fi=i;
			for(int j=fi;j>st-1;j--){
				cout<<b[a[j].second]<<endl;
			}
			st=fi+1;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    constexpr int64_t mod = 1000000000 + 7;

    int n, m; cin >> n >> m;
    if (1 < abs(n - m)) {
        cout << 0 << endl;
        return 0;
    }

    int64_t ans = 1 + (n == m);
    while (n) {
        ans = (ans * n--) % mod;
    }
    while (m) {
        ans = (ans * m--) % mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  int s,t = 0;
  rep(i,0,n) {
    cin >> s;
    t += s-1;
  }
  cout << t << endl;
}


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

using namespace std;
long long ans=1,N,k;
int main()
{
 cin>>N>>k;
 for(int i=0;i<N;i++)
 {
    if(ans<k)ans*=2;
    else ans+=k;
 }
 
 cout<<ans<<endl;
 return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int now=0;
    int cnt=0;
    while(cnt<100){
        now+=a;
        if(c<=now){
            cout<<c<<endl;
            return 0;
        }
        now+=b;
        if(now>=c) c+=60;
        cnt++;
    }
    cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds; 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=2e5+5;
const int mod=1e9+7;	
const ll oo=1e18+5;

//~ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

vector<int> d;
int k;

void solve(){
	int n,x,m;
	cin>>n>>x>>m;
	vector<int> rem(k);
	for(int i=0;i<k;++i){
		rem[i]=d[i]%m;
	}
	int tot=n-1;
	int num=(n-1)/k;
	int add=(n-1)%k;
	int equal=0;
	// count equal
	for(int i=0;i<k;++i){
		if(!rem[i]) ++equal;
	}
	equal*=num;
	for(int i=0;i<add;++i){
		if(!rem[i]) ++equal;
	}
	//~ cout<<equal<<endl;
	ll sum=0;
	for(int i=0;i<k;++i){
		sum+=rem[i];
	}
	sum*=num;
	for(int i=0;i<add;++i){
		sum+=rem[i];
	}	
	sum+=x;
	int greater=(sum/m)-(x/m);
	tot-=(greater+equal);
	cout<<tot<<endl;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int q;
	cin>>k>>q;
	d.resize(k);
	for(int& x:d) cin>>x;
	while(q--){
		solve();
	}
	return 0;	
}


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


   int X,Y;cin >> X >> Y;
   int x,y;cin >> x >> y;

   int ans = (X*Y) - (x*Y + (X*y - x*y));

   cout << ans << endl;





}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		System.out.println(String.valueOf(s.charAt(0)) + (s.length() - 2) + String.valueOf(s.charAt(s.length()-1)));
	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    string ret = "No";
    if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) ret = "Yes";
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256