akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	ll n;
	cin >> n;

	for (ll h = 1; h <= 3500; h++){
		for (ll w = 1; w <= 3500; w++){
			if ((4 * h * w - n * h - w * n) < 1) continue;
			if ((n * h * w) % (4LL * h * w - n * h - w * n) != 0){
				continue;
			}
			ll tmp = (n * h * w) / (4LL * h * w - n * h - w * n);
			if (tmp < 1) continue;
			cout << w << " " << h << " " << tmp << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <tuple>
#include <utility>
using namespace std;

struct UnionFind {
    vector<int> node;
    int components;
    UnionFind(int n) : node(n, -1), components(n) {}
    void reset() {
        fill(node.begin(), node.end(), -1);
        components = node.size();
    }
    int find(int x) { return node[x] < 0 ? x : node[x] = find(node[x]); }
    int size(int x) { return -node[find(x)]; }
    int size() { return components; }

    // x が必ず親側
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        // if(size(x) > size(y)) swap(x, y);
        node[x] += node[y];
        node[y] = x;
        components--;
        return true;
    }
};

void dfs(const vector<vector<int>> &G, int v, const vector<int> &marked, UnionFind &uf){
    for(auto v_ : G[v]){
        if(!marked[v_]) uf.unite(v,v_);
        dfs(G,v_,marked,uf);
    }
}

int main() {
    int n, q;
    while(cin >> n >> q, n){
        vector<int> P(n,-1);
        vector<vector<int>> G(n);
        for(int i = 1; i < n; ++i){
            cin >> P[i];
            --P[i];
            G[P[i]].push_back(i);
        }
        vector<pair<char,int>> Q;
        vector<int> marked(n,0);
        marked[0] = 1;
        for(int i = 0; i < q; ++i){
            char t;
            int v;
            cin >> t >> v;
            --v;
            Q.emplace_back(t,v);
            if(t == 'M') marked[v]++;
        }
        UnionFind uf(n);
        dfs(G,0,marked,uf);
/*
        for(int i = 0; i < n; ++i){
            cerr <<"! : " <<  i << " " << uf.find(i) << endl;
        }
*/
        long long ans = 0;
        reverse(Q.begin(),Q.end());
        for(auto q : Q){
            int v = q.second;
            if(q.first == 'M'){
                if(--marked[v] == 0) {
                    uf.unite(P[v],v);
                }
            }else{
                //cerr << v << " " << uf.find(v) << endl;
                ans += uf.find(v)+1;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 28236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int x;
  cin >> x;
  int cur = 0;
  int ans = 0;
  int i;
  for(i = 1; ; ++i){
    cur += i;
    ans++;
    if(cur >= x) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.split(" ");
  input[0] = parseInt(input[0]);
  input[1] = parseInt(input[1]);
  input[2] = parseInt(input[2]);
  input[3] = parseInt(input[3]);
  let a;
  let b;
  if (input[1] > input[3]) {
    a = input[3];
  } else {
    a = input[1];
  }
  if (input[0] > input[2]) {
    b = input[0];
  } else {
    b = input[2];
  }
  if (a > b) {
    console.log(String(Math.abs(b - a)));
  } else {
    console.log("0");
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define double long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define repii(i,a,b) for(ll i=a;i<=b;i++)
#define pb push_back
#define in insert
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
int main()
{
    fastIO;
    string a,b;
    cin>>a>>b;
    int c=0;
    rep(i,3)
    {
        if(a[i]==b[i])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import numpy as np

N,M = map(int,input().split())
MOD = 998244353

def cumprod_mod(arr):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    arr = arr.ravel()[:L]
    return arr

U = 5*10**6
x = np.arange(U,dtype=np.int64)
x[0] = 1
fact = cumprod_mod(x)

x = np.arange(U,0,-1,dtype=np.int64)
x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod_mod(x)[::-1]

def comb(n,k):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

x = comb(3*M+N-1,N-1) # 何でもいいから作る
y = N * comb(M+N-2,N-1) # どれかが 2M+1 以上

# 奇数がM+1個以上あるものを除く
odd_cnt = np.arange(M+2,3*M+1,2)
S = (3*M - odd_cnt)//2
bl = (odd_cnt <= N)&(S>=0)
odd_cnt = odd_cnt[bl]
S = S[bl]
arr = fact[N] * fact_inv[odd_cnt] % MOD * fact_inv[N-odd_cnt] % MOD
# SをN個で作る -> S+N-1 C N-1
arr *= fact[S+N-1] * fact_inv[N-1] % MOD * fact_inv[S] % MOD
arr %= MOD
z = arr.sum() % MOD

answer = x-y-z
answer %= MOD
print(answer)



Measured memory_bytes: 207736
#include <cstdio>

int ls[299999];
int main() {
	int N;
	scanf("%d",&N);
	int ret=0;
	for(int i=1;i<=N;i++) scanf("%d",&ls[i]);
	for(int i=1;i<=N;i++) if(ls[ls[i]]==i) ret++;
	printf("%d\n",ret/2);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#define ri register int
#define pi acos(-1.0)

using namespace std;

inline char gch()
{
    static char buf[100010], *h = buf, *t = buf;
    return h == t && (t = (h = buf) + fread(buf, 1, 100000, stdin), h == t) ? EOF : *h ++;
}

typedef long long lo;

typedef unsigned int uint;

template<typename inp_typ>

inline void re(inp_typ &x)
{
    x = 0;
    char a; bool b = 0;
    while(!isdigit(a = getchar()))
        b = a == '-';
    while(isdigit(a))
        x = x * 10 + a - '0', a = getchar();
    if(b == 1)
        x = - x;
}

int  A[1010], n;

bool flag[100000100];

int main()
{
    re(n);
    for(ri i = 1; i <= n; i ++)
        re(A[i]);
    for(ri i = 1; i <= n; i ++)
    {
        int x = 0;
        for(ri j = i; j <= min(i + 7, n); j ++)
            x = x * 10 + A[j], flag[x] = 1;
    }
    for(ri i = 0; i <= 100000000; i ++)
        if(!flag[i])
        {
            printf("%d\n", i); break;
        }
}


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

using namespace std;
#define int long long
#define N 666666
struct str{
	int num;
	int sum;
};
map<int,int> vis;
deque<str> q;
signed main(){
	int k;
	cin>>k;
	q.push_back((str){1,1});
	while(!q.empty()){
		struct str t=q.front();
		q.pop_front();
		if(vis[t.num]) continue;
		vis[t.num]=1;
		if(t.num==0){
			cout<<t.sum;
			return 0;
		}
		q.push_front((str){(10*t.num)%k,t.sum});
		q.push_back((str){(t.num+1)%k,t.sum+1});
	}
	return 0;
}

Measured memory_bytes: 8192
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int n = sc.nextInt();
        int prevW = sc.nextInt();
        int prevH = sc.nextInt();
        long total = 0;
        for (int i = 1; i < n; i++) {
            int curW = sc.nextInt();
            int curH = sc.nextInt();
            if ((prevW < curW && prevH < curH) || (prevW > curW && prevH > curH)) {
                int max = Math.max(Math.abs(curW - prevW), Math.abs(curH - prevH));
                total += max;
            } else {
                total += Math.abs(curW - prevW) + Math.abs(curH - prevH);
            }
            prevW = curW;
            prevH = curH;
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 31924
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	let c = v[2];
	let d = v[3];
	if (c - a).abs() <= d || ((b - a).abs() <= d && (c - b).abs() <= d) {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int x,ans,f[200010],n;
int main() 
{
	scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
    	scanf("%d",&x);
    	f[x]=f[x-1]+1;
        ans=max(ans,f[x]);
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for ( int i = a; i < b; i++ )
#define rep(i, n) REP(i, 0, n)
#define INFTY (1<<21)
int m, n, k, d, C[7], G[110][110], N, D[110][64];
int getID(string str) {if (str == "H")return 0;
	if (str == "D")return N - 1;
	string num = str.substr(1, str.size() - 1);
	if (str[0] == 'C')return atoi(num.c_str());
	return atoi(num.c_str()) + m;
}
bool isC(int x) {
	return 1 <= x && x <= m;}
int bellman() {
	rep(i, N)
		rep(j, (1<<m))
			D[i][j] = INFTY;
	D[0][0] = 0;
	rep(o, N*(1<<m))
	{
		bool change = false;
		rep(u, N)
			rep(v, N)
			{
				if (u == v || G[u][v] == INFTY)
					continue;
				rep(b, (1<<m))
				{
					if (isC(v) && (b & (1 << (v - 1))) != 0)
						continue;
					if (isC(v)) {
						if (D[u][b] + G[u][v] - C[v]
								< D[v][b | (1 << (v - 1))]) {
							D[v][b | (1 << (v - 1))] = D[u][b] + G[u][v] - C[v];
							change = true;
						}
					} else {
						if (D[u][b] + G[u][v] < D[v][b]) {
							D[v][b] = D[u][b] + G[u][v];
							change = true;
						}
					}
				}
			}
		if (!change)
			break;
	}
	int minv = INFTY;
	rep(i, (1<<m))
		minv = min(minv, D[N - 1][i]);
	return minv;
}
int main() {
	string source, target;
	int cost;
	while (cin >> m >> n >> k >> d && m) {
		N = 2 + n + m;
		REP(i, 1, m+1)
			cin >> C[i];
		rep(i, N)
			rep(j, N)
				G[i][j] = INFTY;
		rep(i, d)
		{
			cin >> source >> target >> cost;
			int s = getID(source);
			int t = getID(target);
			G[t][s] = G[s][t] = min(G[s][t], cost * k);
		}
		cout << bellman() << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include <algorithm>
#include <iostream>

using namespace std;

const int M = 1e9+7;

long long kaijo[200005]; int inv[200005];

int mpow(long long a, int n)
{
  if (n % 2) return mpow(a, n-1) * a % M;
  if (n == 0) return 1;
  return mpow(a*a%M, n/2);
}

long long cmb(int n, int r)
{
  return kaijo[n] * inv[r] % M * inv[n-r] % M;
}

int main()
{
  int n, k; cin >> n >> k;
  k = min(k, n-1);
  
  kaijo[0] = 1;
  for (int i = 1; i <= n; ++i) kaijo[i] = kaijo[i-1] * i % M;
  for (int i = 0; i <= n; ++i) inv[i] = mpow(kaijo[i], M-2);
  
  long long sum = 0;
  for (int i = 0; i <= k; ++i) sum = (sum + cmb(n, i) * cmb(n-1, i))%M;
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2560
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  var q = o.a();
  var s = [-9e15].concat(o.r(a));
  var t = [-9e15].concat(o.r(b));
  var x = o.r(q);
  var x2 = Array(q);
  var xs = 0, xt = 0;
  var ans = Array(q);
  for(var i = 0; i < q; i++){
    x2[i] = [x[i], i];
  }
  x2.sort((a,b)=>a[0]-b[0]);
  for(i = 0; i < q; i++){
    var z = x2[i][0];
    var u = 9e99, v;
    while(xs <= a && s[xs] < z)xs++;
    while(xt <= b && t[xt] < z)xt++;
    if(xs > 1 && xt > 1){
      v = z - Math.min(s[xs-1], t[xt-1]);
      if(v < u)u = v;
    }
    if(xt > 1 && xs !== a+1){
      v = Math.min(z + s[xs] - 2 * t[xt-1], 2 * s[xs] - z - t[xt-1]);
      if(v < u)u = v;
    }
    if(xs !== a+1 && xt !== b+1){
      v = Math.max(s[xs], t[xt]) - z;
      if(v < u)u = v;  
    }
    if(xs > 1 && xt !== b+1){
      v = Math.min(z + t[xt] - 2 * s[xs-1], 2 * t[xt] - z - s[xs-1]);
      if(v < u)u = v;  
    }
    ans[x2[i][1]] = u;
  }
  return ans.join("\n");
}

Measured memory_bytes: 84944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int N;

    std::cin >> N;

    cout << 2.0 * M_PI * N << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 3796
#include <stdio.h>

long ll(long a){
if(a<0) a=0-a;
return a;
}

int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	int i,j;
	long sum=0;
	for(i=0;i<n;i++) {scanf("%d",&a[i]);sum+=a[i];}
	long minxy;
	long sumx=0;
	short flag=0;
	for(i=0;i<n-1;i++){
		sumx+=a[i];
		if(flag==1){
			if(ll(sum-sumx*2)<minxy) minxy=ll(sum-sumx*2);
		}else{minxy=ll(sum-sumx*2);}
		flag=1;
	}
	printf("%d", minxy);
	return 0;
} 

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
#define db double
#define mo 1000000007
using namespace std;
int n,m,a,b,x,y;
char ans[1005][1005];
void jdb(){
	puts("YES");
	for (int i=1;i<=n;i++)
		printf("%s\n",ans[i]+1);
	puts("");
}
void cogito(){
	if (n%2==0||m%2==0) return;
	if (n<3||m<3) return;
	int x=n-1,y=m-1;
	for (int i=x-1;i<=x+1;i++)
		for (int j=y-1;j<=y+1;j++)
			ans[i][j]='*';
	if (a>=2&&b>=2){
		int A=a-2,B=b-2;
		int y=1;
		for (;y+1<=m&&A;y+=2)
			if (ans[n][y]=='.'&&ans[n][y+1]=='.')
				ans[n][y]='<',ans[n][y+1]='>',A--;
		int x=1;
		for (;x+1<=n&&A;x+=2)
			if (ans[x][m]=='.'&&ans[x+1][m]=='.')
				ans[x][m]='^',ans[x+1][m]='v',B--;
		for (int i=1;i<=n&&A>=2;i++)
			for (int j=1;j<m&&A>=2;j++)
				if (ans[i+1][j+1]=='.'&&ans[i][j]=='.'
					&&ans[i+1][j]=='.'&&ans[i][j+1]=='.')
					ans[i][j]=ans[i+1][j]='<',
					ans[i][j+1]=ans[i+1][j+1]='>',A-=2;
		for (int i=1;i<n&&B>=2;i++)
			for (int j=1;j<=m&&B>=2;j++)	
				if (ans[i+1][j+1]=='.'&&ans[i][j]=='.'
					&&ans[i+1][j]=='.'&&ans[i][j+1]=='.')
					ans[i][j]=ans[i][j+1]='^',
					ans[i+1][j]=ans[i+1][j+1]='v',B-=2;
		for (int i=1;i<=n&&A;i++)
			for (int j=1;j<m&&A;j++)
				if (ans[i][j]=='.'&&ans[i][j+1]=='.')
					ans[i][j]='<',
					ans[i][j+1]='>',A--;
		for (int i=1;i<n&&B;i++)
			for (int j=1;j<=m&&B;j++)	
				if (ans[i][j]=='.'&&ans[i+1][j]=='.')
					ans[i][j]='^',
					ans[i+1][j]='v',B--;
		if (A||B) return;
		x=n-1; y=m-1;
		ans[x-1][y-1]=ans[x+1][y]='<';
		ans[x-1][y]=ans[x+1][y+1]='>';
		ans[x][y-1]=ans[x-1][y+1]='^';
		ans[x+1][y-1]=ans[x][y+1]='v';
		ans[x][y]='.';
		jdb();
		exit(0);
	}
}
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if (2*(a+b)>n*m){
		puts("NO");
		return 0;
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			ans[i][j]='.';
	cogito(); 
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			ans[i][j]='.';
	if (n&1){
		int y=1;
		for (;y+1<m&&a;a--){
			ans[n][y]='<'; ans[n][y+1]='>'; y+=2;
		}
	}
	if (m&1){
		int x=1;
		for (;x+1<n&&b;b--){
			ans[x][m]='^'; ans[x+1][m]='v'; x+=2;
		}
	}
	x=1,y=1;
	for (;a>=2&&x+1<=n;a-=2){
		ans[x][y]=ans[x+1][y]='<';
		ans[x][y+1]=ans[x+1][y+1]='>';
		y+=2;
		for (;y+1>m&&x+1<=n;y=1,x+=2);
	}
	for (;b>=2&&x+1<=n;b-=2){
		ans[x][y]=ans[x][y+1]='^';
		ans[x+1][y]=ans[x+1][y+1]='v';
		y+=2;
		for (;y+1>m&&x+1<=n;y=1,x+=2);
	}
	for (int i=1;i<=n&&a;i++)
		for (int j=1;j<m&&a;j++)
			if (ans[i][j]=='.'&&ans[i][j+1]=='.')
				ans[i][j]='<',ans[i][j+1]='>',a--;
	for (int i=1;i<n&&b;i++)
		for (int j=1;j<=m&&b;j++)
			if (ans[i][j]=='.'&&ans[i+1][j]=='.')
				ans[i][j]='^',ans[i+1][j]='v',b--;
	if (a||b)
		puts("NO");
	else jdb();
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;

long long func(long long a, long long b) {
	if (a % b == 0) {
		return a / b - 1;
	}
	else {
		return a / b;
	}
}

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	//int N, L; std::cin >> N >> L;
	//std::vector<int> taste(N);
	//int absed_min = INT_MAX;
	//int index = 0;
	//int sum = 0;
	//rep(i, N) {
	//	taste[i] = L + i;
	//	if (abs(L + 1) < absed_min) {
	//		index = i;
	//		absed_min = abs(L + i);
	//	}
	//	sum += taste[i];
	//}
	//
	//std::cout << sum - taste[index];

	long long A, B, C, D; std::cin >> A >> B >> C >> D;
	int c = C;//
	int d = D;//kopi-
	if (C < D) {
		long long tmp = C;
		C = D;
		D = tmp;
	}
	
	long long x = C * D;
	long long r = C % D;
	while (r != 0) {
		C = D;
		D = r;
		r = C % D;
	}
	long long lcm = x / D;
	long long divide_withC = (B/c)-((A-1)/c);
	long long divide_withD = (B / d) - ((A -1)/ d);
	long long divide_withlcm = (B / lcm) - ((A-1) / lcm);
	long long ans = (B - A + 1) - (divide_withC + divide_withD - divide_withlcm);
	std::cout << ans;


	return 0;

}

Measured memory_bytes: 256
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

flag = False
cnt = 0

for i in range(len(D)):
    if D[i][0] == D[i][1]:
        cnt += 1
        if cnt == 3:
            flag = True
    else:
        cnt = 0

print('Yes' if flag else 'No')

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

#define MAX 302
int h;
int w;

char buf[MAX][MAX];


string x;
string y;
int dp[302][302];
int same[302][302];
int calc(){
	for (int i = 0; i <= x.size(); i++){
		for (int j = 0; j <= y.size(); j++){
			dp[i][j] = INT_MAX;
			same[i][j] = 0;
		}
	}
	for (int i = x.size() - 1; i >= 0; i--){
		for (int j = y.size() - 1; j >= 0; j--){
			same[i][j] = (x[i] == y[j]);
			same[i][j] += same[i + 1][j + 1];
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i <= x.size(); i++){
		for (int j = 0; j <= y.size(); j++){
			if (i < x.size()){
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + same[i][j]);
			}
			if (j < y.size()){
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + same[i][j]);
			}
		}
	}
	return dp[x.size()][y.size()];
}
int main(){
	cin >> h >> w;
	for (int i = 0; i < h; i++){
		scanf("%s", buf[i]);
	}
	int sum = 0;
	for (int i = 1; i < w; i++){
		x.clear();
		y.clear();
		for (int j = 0; j < h; j++){
			x.push_back(buf[j][i-1]);
			y.push_back(buf[j][i]);
		}
		reverse(x.begin(), x.end());
		reverse(y.begin(), y.end());
		sum += calc();
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18
 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#include <deque>
#define repi(i,x,n) for(int i = x; i < n; i++)
#define rep(i,n) repi(i,0,n)
#define int long long
using namespace std;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int n;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int time;
    deque<pair<int,int> > ans;
    while(1){
        cin>>n;
        if(n==0) break;
        rep(i,n*2){
            string s;
            cin>>s;
            time=0;
            int check= 1;
            if(i%2==1) check=-1;
            time+=stoi(s.substr(0,2)) * 10000;
            time+=stoi(s.substr(3,2)) * 100;
            time+=stoi(s.substr(6));
            ans.push_back(make_pair(time,check) );
        }
        sort(ans.begin(),ans.end() );
        int cnt=0;
        int num=0;
        rep(i,n*2){
            cnt+=ans[0].second;
            ans.pop_front();
            num=max(num,cnt);
        }
        cout<<num<<endl;
    }
            
    return 0;
}


       



Measured memory_bytes: 3248
//
// Created by sark2 on 14-01-2020.
//

#include "bits/stdc++.h"

using namespace std;
#define pb push_back
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASES int t;cin>>t;while(t--)

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

const int mod = 1e9 + 7;

int main() {
    IOS

    ll n; cin>>n;
    if(n&1){
        cout<<0<<"\n";
    }else{
        ll f = 5;
        ll ans = 0;
        n /= 2;
        while(n/f){
            ans += n/f;
            f *= 5;
        }
        cout<<ans<<"\n";
    }

}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int h[100010],nex[200010],to[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int d[100010],f[100010];
void dfs(int fa,int x){
	int i,c;
	c=0;
	for(i=h[x];i;i=nex[i]){
		if(to[i]!=fa){
			dfs(x,to[i]);
			f[x]+=f[to[i]];
			c+=!f[to[i]];
		}
	}
	if(c>1)f[x]+=c-1;
}
int main(){
	int n,i,x,y;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		x++;
		y++;
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	for(i=1;i<=n;i++){
		if(d[i]>2)break;
	}
	if(i>n){
		putchar('1');
		return 0;
	}
	dfs(0,i);
	printf("%d",f[i]);
}

Measured memory_bytes: 5376
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    ls = [[0] * 10 for i in range(10)]
    for i in range(1, n + 1):
        val = list(str(i))
        ls[int(val[-1])][int(val[0])] += 1
    
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += ls[i][j] * ls[j][i]

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

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

int main() {
  int n;
  cin >> n;
  
  int ans = n % 10;
  if(ans == 3) cout << "bon" << endl;
  else if ((ans == 0) || (ans == 1) || (ans == 6) || (ans == 8)) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3556
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1000000, A = 1000000;

int aa[N], kk[1 + A];

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	int d = 0;
	for (int i = 0; i < n; i++)
		d = gcd(d, aa[i]);
	if (d != 1) {
		cout << "not coprime\n";
		return 0;
	}
	for (int i = 0; i < n; i++) {
		int x = aa[i];
		for (int a = 2; a <= x / a; a++) {
			if (x % a == 0)
				kk[a]++;
			while (x % a == 0)
				x /= a;
		}
		if (x > 1)
			kk[x]++;
	}
	for (int a = 2; a <= A; a++)
		if (kk[a] > 1) {
			cout << "setwise coprime\n";
			return 0;
		}
	cout << "pairwise coprime\n";
	return 0;
}


Measured memory_bytes: 11292
/*
  "I knew I shouldn't have
   gotten out of bed today."
   - Squidward Tentacles
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>

#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#include<iomanip>
#include<fstream>
#include<chrono>
using namespace std;
using namespace __gnu_pbds;

#define int          long long
#define pii          pair<int,int>
#define vi           vector<int>
#define peque        priority_queue
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       x.begin(),x.end()
#define ball(x)      x.rbegin(),x.rend()
#define mem(x,y)     memset(x,y,sizeof(x))
#define oset         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main()
{
    VR46 ofstream out("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU THODE TEST CASE BNAKE TEST KRLE
    int t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        int n;
        string s;
        cin>>n>>s;

        if( n&1 ) return cout<<"No\n", 0;

        int x = n/2;

        string t = "";
        rep(i,0,x-1) t += s[i];
        rep(i,x,n-1)
        {
            if( s[i]!=t[i-x] ) return cout<<"No\n", 0;
        }
        cout<<"Yes\n";
    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<ll> A,B,ans;
ll par[MAX_N],size[MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		par[i] = i;
		size[i] = ll(1);
	}
}

ll find(int x)
{
	if (par[x] == x)
	{
		return x;
	}
	else
	{
		return par[x] = find(par[x]);
	}
}

ll unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return 0;
	}
	else
	{
		if (size[x] > size[y]) swap(x,y);
		par[x] = y;
		ll res = size[x] * size[y];
		size[y] += size[x];
		return res;
	}
}

int main()
{
	init();
	ll N,M;
	cin >> N >> M;
	rep(i,M)
	{
		ll a,b;
		cin >> a >> b;
		A.push_back(a); B.push_back(b);
	}
	reverse(A.begin(), A.end()); reverse(B.begin(), B.end());
	ll temp = N * (N-1) / 2;
	ans.push_back(temp);
	rep(i,M-1)
	{
		temp -= unite(A[i],B[i]);
		ans.push_back(temp);
	}
	reverse(ans.begin(), ans.end());
	rep(i,M)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5356
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long a[n],sum=0,mx=-1;
  for(int i=0;i<n;i++)
  {
   	cin>>a[i];
    if(i!=0 && a[i]<mx)
      sum+=mx-a[i];
    mx=max(a[i],mx);
  }
  cout<<sum;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}


int main()
{
    ll n;
    cin>>n;
    bool arr[1000001];
    fi(i,1000001)
    {
        arr[i] = true;
    }
    arr[0] = false;
    arr[1] = false;
    for(int i = 2; i<=sqrt(1000000); i++)
    {
        if(arr[i])
        {
            for(int j = i*i; j<=1000000; j += i)
            {
                arr[j] = false;
            }
        }
    }
    for(int i = 0;i<=1000000;i++)
    {
        if(i>=n && arr[i])
        {
            cout<<i;
            break;
        }
    }
}


Measured memory_bytes: 8972
#!/usr/bin/env ruby

n = gets.chomp.to_i
ary = gets.chomp.split(' ').map(&:to_i)

right_gcd = [ary.first]
ary.slice(1..-1).each { |num| right_gcd << right_gcd.last.gcd(num) }

left_gcd = [ary.last]
ary.reverse.slice(1..-1).each { |num| left_gcd << left_gcd.last.gcd(num) }
left_gcd = left_gcd.reverse

ans = 0

0.step(n - 1) do |i|
  if i ==  0
    left_gcd[i + 1]
  elsif i == n - 1
    right_gcd[i - 1]
  else
    right_gcd[i - 1].gcd(left_gcd[i + 1])
  end.tap { |gcd| ans = (gcd > ans ? gcd : ans) }
end

puts ans


Measured memory_bytes: 12940
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

A,B = II()

b = format(B,'b')
n = len(b)
a = format(A,'b').zfill(n)
num = B-A+1

ans = str()
for i in range(n):
    if i==0:
        q,m = divmod(num,2)
        if q%2==0:
            if m==1:
                ans += a[n-i-1]
            else:
                ans += '0'
        else:
            if m==1:
                if a[n-i-1]=='0':
                    ans += '1'
                else:
                    ans += '0'
            else:
                ans += '1'
        continue       
    if a[n-i-1]=='0':
        temp = (1<<i)-int(a[-i:],2)
        if temp >= num:
            ans += '0'
        else:
            val = num-temp
            q,m = divmod(val,2**i)
            if q%2==1:
                ans += '0'
            else:
                if m%2==1:
                    ans += '1'
                else:
                    ans += '0'
    else:
        temp = (1<<(i+1))-int(a[-(i+1):],2)
        if temp >= num:
            if num%2==0:
                ans += '0'
            else:
                ans += '1'
        else:
            val = num-temp
            q,m = divmod(val,2**i)
            if q%2==1:
                if m%2==1:
                    if temp%2==0:
                        ans += '1'
                    else:
                        ans += '0'
                else:
                    if temp%2==0:
                        ans += '0'
                    else:
                        ans += '1'
            else:
                if temp%2==0:
                    ans += '0'
                else:
                    ans += '1'

ans = ans[::-1]
print(int(ans,2))

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

int main()
{
	int a,b,c,k,max,pdt;
	cin>>a>>b>>c>>k;
	max=a;
	if(b>max)
		max=b;
	if(c>max)	
		max=c;
	pdt=max*pow(2,k);
	pdt=pdt+a+b+c-max;
	cout<<pdt;
}	

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,i,s=0;cin>>n;
    for(i=1;i<=n;i++){
        if((i%5)==0 || (i%3)==0){
            continue;
        }else s+=i;
    }
    cout<<s;
}


Measured memory_bytes: 3624
x,k,d=map(int,input().split())
if x<0:x=-x
if x-k*d>=0:
    print(x-k*d);exit()
# if d==1:
#     print(0);exit()
p=x%d
kai=(x-p)//d
if kai%2==k%2:
    print(p)
else:
    print(abs(d-p))


Measured memory_bytes: 61688
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    char a;
    cin >> a;
    if(a-'A' < 26 && 0<= a-'A') cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<numeric>
#include<queue>
#include<string>
#include<sstream>

using namespace std;

int main(void) {

  int m, nmin, nmax;
  while(cin >> m >> nmin >> nmax){
    if( m == 0 ) break;

    vector<int> p(m);
    for(int i=0; i<m; i++) cin >> p[i];

    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());

    int g = 0;
    int ans = nmin;
    for(int i=nmin-1; i<nmax; i++){
      if(g <= p[i] - p[i+1]){
        ans = i+1;
        g = p[i] - p[i+1];
      }

    }
    cout << ans << endl;
  }


  return 0;
}










//

Measured memory_bytes: 3152
from collections import Counter
n=int(input())
slis=[]
for i in range(n):
	s=sorted(list(input()))
	slis.append(s)
ctr=Counter()
ans=0
for s in slis:
	a="".join(s)
	if a in ctr:
		ans+=ctr[a]
	ctr[a] +=1
print(ans)


Measured memory_bytes: 39428
#include <iostream>

int main()
{
  int A, B;
  std::cin >> A >> B;

  int ret = B;
  if(A <= 5) {
    ret = 0;
  } else if(A <= 12) {
    ret = B/2;
  }

  std::cout << ret << std::endl;
  return 0;
}
	

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

#define int long long

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

signed main() {
    string S;
    int x, y;
    cin >> S >> x >> y;
    int ox = 0, oy = 0;
    for (; S[ox] != 'T' && ox < S.length(); ox++) ;
    int x_kosuu = 0, y_kosuu = 0;
    int x_table[8000] = {}, y_table[8000];
    bool cur_is_x = false;
    for (int i = ox + 1; i < S.length(); i++) {
        if (S[i] == 'T') {
            if (cur_is_x) {
                x_kosuu++;
            } else {
                y_kosuu++;
            }
            cur_is_x = !cur_is_x;
        } else {
            if (cur_is_x) {
                x_table[x_kosuu]++;
            } else {
                y_table[y_kosuu]++;
            }
        }
    }
    if (cur_is_x) {
        x_kosuu++;
    } else {
        y_kosuu++;
    }
    bool x_bef[S.length() * 2 + 1] = {};
    x_bef[ox + S.length()] = true;
    for (int i = 0; i < x_kosuu; i++) {
        bool x_cur[S.length() * 2 + 1] = {};
        for (int j = 0; j < S.length() * 2 + 1; j++) {
            if (x_bef[j]) {
                x_cur[j + x_table[i]] = true;
                x_cur[j - x_table[i]] = true;
            }
        }
        for (int j = 0; j < S.length() * 2 + 1; j++) {
            x_bef[j] = x_cur[j];
        }
    }
    bool x_flag = x_bef[x + S.length()];

    bool y_bef[S.length() * 2 + 1] = {};
    y_bef[oy + S.length()] = true;
    for (int i = 0; i < y_kosuu; i++) {
        bool y_cur[S.length() * 2 + 1] = {};
        for (int j = 0; j < S.length() * 2 + 1; j++) {
            if (y_bef[j]) {
                y_cur[j + y_table[i]] = true;
                y_cur[j - y_table[i]] = true;
            }
        }
        for (int j = 0; j < S.length() * 2 + 1; j++) {
            y_bef[j] = y_cur[j];
        }
    }
    bool y_flag = y_bef[y + S.length()];
    if (x_flag && y_flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import heapq
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

X, Y, Z, K = list(map(int, input().split()))
A = list(sorted(map(int, input().split()), reverse=True))
B = list(sorted(map(int, input().split()), reverse=True))
C = list(sorted(map(int, input().split()), reverse=True))

heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
history = {(0, 0, 0)}
for _ in range(K):
    d, a, b, c = heapq.heappop(heap)
    if a + 1 < X and (a + 1, b, c) not in history:
        history.add((a + 1, b, c))
        heapq.heappush(heap, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
    if b + 1 < Y and (a, b + 1, c) not in history:
        history.add((a, b + 1, c))
        heapq.heappush(heap, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
    if c + 1 < Z and (a, b, c + 1) not in history:
        history.add((a, b, c + 1))
        heapq.heappush(heap, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
    print(-d)


Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long long n, m, sum = 0;
    cin >> n >> m;
    vector<vector<long long>> v = vector<vector<long long>>(n, vector<long long>(2));
    for (int i = 0; i < n; i++) {
        cin >> v.at(i).at(0) >> v.at(i).at(1);
    }
    sort(v.begin(), v.end(), [](const vector<long long>& a, const vector<long long>& b) { return a[0] < b[0]; });
    int i = 0;
    while (i < n) {
        if (m < v.at(i).at(1)) {
            sum += m * v.at(i).at(0);
            break;
        }
        m -= v.at(i).at(1);
        sum += v.at(i).at(0) * v.at(i).at(1);
        i++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int w, d, res; cin >> w >> d, w; cout << res << endl){
        res = 0;

        vi hw(w), hd(d);
        rep(i, w) cin >> hw[i];
        rep(i, d) cin >> hd[i];

        sort(all(hw), greater<int>());
        sort(all(hd), greater<int>());

        int ww = 0, dd = 0;
        while(ww < w && dd < d){
            int chw = hw[ww];
            int cntw = 0, cntd = 0;
            while(dd < d && chw == hd[dd]){
                dd++;
                cntd++;
            }
            while(ww < w && chw == hw[ww]){
                ww++;
                cntw++;
            }
            res += chw * max(cntw, cntd);

            if(w <= ww) break;
            if(d <= dd) break;

            while(ww < w && hw[ww] > hd[dd]) res += hw[ww++];
            if(w <= ww) break;
            while(dd < d && hd[dd] > hw[ww]) res += hd[dd++];
            if(d <= dd) break;
        }
        while(dd < d) res += hd[dd++];
        while(ww < w) res += hw[ww++];
    }

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n;
    cin >> n;
    VI v(n);
    Int a;
    for (Int i = 2; i <= n; ++i) {
        cin >> a;
        a--;
        v[a]++;
    }
    for (Int i = 0; i < n; ++i) {
        cout << v[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	scanf("%c",&a);
	if(a=='A')
		printf("T");
	else if(a=='C')
		printf("G");
	else if(a=='G')
		printf("C");
	else if(a=='T')
		printf("A");	
	return 0;
}

Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
 int n;cin>>n;
  cout<<n/3<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <functional>
#include <map>
#include <cmath>
#include <deque>
#include <string>
#define SIZE 100005

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

int deg[SIZE];
set <int> st[SIZE];
set <int>::iterator it;

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b),a--,b--;
		deg[a]++,deg[b]++;
		st[a].insert(b);
		st[b].insert(a);
	}
	if(m<n+2)
	{
		puts("No");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		if(deg[i]%2==1)
		{
			puts("No");
			return 0;
		}
	}
	int cnt=0;
	queue <int> que;
	for(int i=0;i<n;i++) if(deg[i]==2) que.push(i);
	while(!que.empty())
	{
		int v=que.front();que.pop();
		if(st[v].empty()) continue;
		it=st[v].begin();
		int a=*it;
		it++;
		int b=*it;
		st[v].clear();
		st[a].erase(v);
		st[b].erase(v);
		if(deg[a]>deg[b]) swap(a,b);
		if(deg[a]==2&&st[a].count(b))
		{
			cnt++;
			st[a].clear();
			st[b].erase(a);
			if(st[b].size()==2) que.push(b);
		}
		else if(st[a].count(b))
		{
			st[a].erase(b);
			st[b].erase(a);
			cnt++;
			if(st[a].size()==2) que.push(a);
			if(st[b].size()==2) que.push(b);
		}
		else
		{
			st[a].insert(b);
			st[b].insert(a);
		}
	}
	int N=0,M=0;
	for(int i=0;i<n;i++)
	{
		M+=st[i].size();
		if(!st[i].empty()) N++;
	}
	//rintf("%d %d %d\n",N,M,cnt);
	if((M/2==N&&cnt==1)||(N==0&&cnt<=2))puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 15104
n, x, m = map(int, input().split())
di = {}
for i in range(m+1):
    di[i] = -1
li = []
for i in range(m+1):
    li.append(x)
    di[x] = i
    x = pow(x, 2, m)
    if di[x]  >= 0:
        break
#print(li)
#print(x)
ans = 0
#print(di[x])
for j in range(di[x]):
    ans += li[j]
loop_sum = 0
for j in range(di[x], i+1):
    loop_sum += li[j]
#print(loop_sum)
loop = i+1-di[x] #1ループ何個か
#print(loop)
n -= di[x]
k = n//loop # 何回ループするか
ans += loop_sum * k
#print(ans)
kk = n-k*loop #残り
#print(kk)
ans += sum(li[di[x]:di[x]+kk])
print(ans)

Measured memory_bytes: 85776
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back

typedef struct tree {
  ll to;
  ll cost;
} tree;

ll co[100010];
vector<tree> node[100010];

void dfs (ll v, ll p, ll c) {
  co[v] = c;
  for (auto itr : node[v]) {
    if (itr.to == p) continue;
    dfs(itr.to, v, c+itr.cost);
  }
}

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

  rep(i,n-1) {
    ll a,b,c;
    cin >> a >> b >> c;
    a--, b--;
    node[a].pb({b,c});
    node[b].pb({a,c});
  }

  ll q,k;
  cin >> q >> k;
  k--;

  rep(i,n) co[i] = 0;
  dfs(k,-1,0);

  rep(i,q) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    cout << co[x] + co[y] << endl;
  }
}


Measured memory_bytes: 14336