akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
struct P{
	int p,q,r;
	P(int p,int q,int r):p(p),q(q),r(r){
	}
};
int main(){
	int i,j;
	int n,m;
	while(scanf("%d%d",&n,&m),n||m){
		vector<int> a[15];
		for(i=0;i<m;++i){
			int p,q;
			scanf("%d%d",&p,&q);
			--p;
			--q;
			a[p].push_back(q);
			a[q].push_back(p);
		}
		int b=0;
		for(i=0;i<n;++i){
			int p;
			scanf("%d",&p);
			if(p)
				b|=1<<i;
		}
		vector<int> c[15];
		for(i=0;i<n;++i){
			int l;
			scanf("%d",&l);
			for(j=0;j<l;++j){
				int p;
				scanf("%d",&p);
				--p;
				c[i].push_back(p);
			}
			sort(c[i].begin(),c[i].end());
		}
		vector<P> d;
		bool e[15][1<<15]={};
		e[0][b]=true;
		queue<P> f;
		f.push(P(0,b,-1));
		bool g=false;
		while(!f.empty()){
			d.push_back(f.front());
			if(d.back().p==n-1)
				g=true;
			if(d.back().p==n-1&&d.back().q==1<<(n-1))
				break;
			f.pop();
			for(i=0;i<(int)c[d.back().p].size();++i){
				if(c[d.back().p][i]==d.back().p||e[d.back().p][d.back().q^1<<c[d.back().p][i]])
					continue;
				e[d.back().p][d.back().q^1<<c[d.back().p][i]]=true;
				f.push(P(d.back().p,d.back().q^1<<c[d.back().p][i],d.size()-1));
			}
			for(i=0;i<(int)a[d.back().p].size();++i){
				if(!(d.back().q>>a[d.back().p][i]&1)||e[a[d.back().p][i]][d.back().q])
					continue;
				e[a[d.back().p][i]][d.back().q]=true;
				f.push(P(a[d.back().p][i],d.back().q,d.size()-1));
			}
		}
		if(false){
		}else if(!f.empty()){
			vector<int> h;
			for(i=d.size()-1;i>=0;i=d[i].r)
				h.push_back(i);
			printf("You can go home in %d steps.\n",h.size()-1);
			for(i=h.size()-1;i;--i){
				if(d[h[i]].p==d[h[i-1]].p)
					printf("Switch %s room %d.\n",(d[h[i]].q^d[h[i-1]].q)&d[h[i-1]].q?"on":"off",(int)(log((double)(d[h[i]].q^d[h[i-1]].q))/log(2.))+1);
				else
					printf("Move to room %d.\n",d[h[i-1]].p+1);
			}
		}else if(g){
			puts("You can not switch off all lights.");
		}else{
			puts("Help me!");
		}
	}
	return 0;
}

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

using namespace std;

int x[1111], y[1111], r[1111];
double d[1111];
vector<pair<int, double> > g[1111];
int n;

long long sqr(int x){
	return 1ll * x * x;
}

double dist(int a, int b, int c, int d){
	return sqrt(sqr(a - c) + sqr(b - d));
}

int main(){
//	freopen("input.inp", "r", stdin);
	int xx, yy;
	scanf("%d%d%d%d",&x[0],&y[0],&xx,&yy);
	scanf("%d",&n);
	++n;
	x[n] = xx;
	y[n] = yy;
	for(int i = 1; i < n; ++i) scanf("%d%d%d",&x[i],&y[i],&r[i]);
	for(int i = 0; i <= n; ++i){
		for(int j = i + 1; j <= n; ++j){
			double d = dist(x[i], y[i], x[j], y[j]) - r[i] - r[j];
			if (d < 0) d = 0;
			g[i].push_back(make_pair(j, d));
			g[j].push_back(make_pair(i, d));
		}
	}
	set<pair<double, int> > s;
	s.insert(make_pair(0, 0));
	for(int i = 1; i <= n; ++i) d[i] = 1e20;
	while (!s.empty()){
		pair<double, int> cur = *s.begin();
		s.erase(s.begin());
		int u = cur.second;
		if (abs(d[u] - cur.first) > 1e-7) continue;
		for(int i = 0; i < g[u].size(); ++i){
			int v = g[u][i].first;
			double c = g[u][i].second;
			if (d[v] > d[u] + c){
				d[v] = d[u] + c;
				s.insert(make_pair(d[v], v));
			}
		}
	}
	printf("%.15lf",d[n]);
	return 0;
}

Measured memory_bytes: 33408
from functools import reduce

def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    mod_mul = lambda a, b: a * b % mod
    numer = reduce(mod_mul, range(n - k + 1, n + 1), 1)
    denom = reduce(mod_mul, range(1, k + 1), 1)
    return numer * pow(denom, mod - 2, mod) % mod

X, Y = map(int, input().split())

b = (2 * X - Y) // 3
a = (-X + 2 * Y) // 3

if (X + Y) % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    print(nCk(a + b, a))


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

int main(){ 
int n;
cin>>n;
vector<int> b(n);
for(int i=0; i<n-1; i++){
cin>>b[i];
}
int a=b[0]+b[n-2];
for(int i=0; i<n-2; i++){
a+= min(b[i],b[i+1]);
}
cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

Measured memory_bytes: 3632
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
using namespace std;
#pragma endregion
signed main() {
	int A,B,C;
	cin >>A >> B >>C;
	if (B - A == C - B)
		cout << "YES";
	else
		cout << "NO";
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

vector<llong> divisors(llong n) { // 約数列挙
    vector<llong> ret;
    for(llong i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if((i * i) != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));

    return ret;
}

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    llong n;
    cin >> n;

    vector<llong> divs1 = divisors(n), divs2 = divisors(n - 1);
    int ans = (int)divs2.size(); // 割らない場合の答え
    rep(i, (int)divs1.size()) { // 割る場合の答え
        llong N = n, K = divs1[i];
        if (K == 1) continue;
        while (true) {
            if (N % K == 0) N /= K;
            else break;
        }
        if (N % K == 1) ++ans;
    }

    cout << ans - 1 << endl;

    return 0;
}

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

long long dp[60][60][3000];
int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i, 0, n) {
        cin >> x[i];
    }
    dp[0][0][0] = 1;
    rep(i, 0, n) {
        rep(j, 0, n) {
            rep(k, 0, 2500) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
            }
        }
    }
    long long ans = 0;
    rep(i, 1, n + 1) {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {

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




		while(true){
			int n = sc.nextInt();
			if (n==0){
				break;
			}

			int count = 0;
			String rightFoot = "d"; // d?????¨????????????
			String leftFoot = "d";
			String command = "x";
			String nextFoot = "x";
			String nextMove = "x";
			String beforeStat = "d"; // false???????????°??????
			
			for(int i=0;i<n;i++){
				command=sc.next();

				nextFoot=command.toString().substring(0,1);
				nextMove=command.toString().substring(1,2);

				if(nextFoot.equals("r") && nextMove.equals("u")){
					rightFoot = "u";
				}
				else if(nextFoot.equals("r") && nextMove.equals("d")){
					rightFoot = "d";
				}
				else if(nextFoot.equals("l") && nextMove.equals("u")){
					leftFoot = "u";
				}
				else if(nextFoot.equals("l") && nextMove.equals("d")){
					leftFoot ="d";
				}

				if(rightFoot==leftFoot&&(!rightFoot.equals(beforeStat))){
					// ????¶???¨????¶????????????????????????????????????¶?????¨??°????????´???
					count ++;
					if(beforeStat=="d"){
						beforeStat="u";
					}
					else{
						beforeStat="d";
					}
				}
			}
			System.out.println(count);

		}
	}

}

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

N = INT()
C = [INT() for _ in range(N)]

dp = [0]*(N+1)
dp[0] = 1
dp2 = [-1]*(max(C)+1) #前に色iが出てきたインデックスの保存

for i in range(1, N+1):
	p = dp2[C[i-1]]  # 色C[i-1]が前に出てきたインデックス
	if 1 < i-p and p != -1:
		dp[i] += dp[p]
	dp2[C[i-1]] = i
	dp[i] += dp[i-1]
	dp[i] %= mod

print(dp[N])


Measured memory_bytes: 31112
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
#define int long long
	int n, m;
	cin >> n >> m;
	long long ans = 0;
	for (long long i = 1; i <= sqrt(m); ++i) {
		if (m % i == 0) {
			if (m / i >= n) {
				ans = max(ans, i);
			}
			long long geko = m / i;
			if (m / geko >= n) {
				ans = max(ans, geko);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 888
package main

import (
  "fmt"
)

func check_fact(i int, j int) uint{ //i*2**k がjを初めて超えるkを求める
  var k uint
  k = 0
  // fmt.Println(i,j)
  for {
    // fmt.Println(k)
    if i*(2<<k) >= j{
      // fmt.Println(i*(2<<k),j)
      // fmt.Println(k)
      return k+1
    }
    k++

  }
}

func main(){
  var N, K int
  fmt.Scan(&N, &K)

  // fmt.Println(check_fact(1,17))
  var result float64
  if N < K{
    for i:=1; i<=N; i++{
      k := check_fact(i, K)
      // fmt.Println(i,k)
      // fmt.Println(1/float64((2<<(k-1))*N))
      result += 1/float64((2<<(k-1))*N)
    }
    fmt.Println(result)
  }else{
    for i:=1; i<K; i++{
      k := check_fact(i, K)
      // fmt.Println(i,k)
      // fmt.Println(1/float64((2<<(k-1))*N))
      result += 1/float64((2<<(k-1))*N)
    }
    result += float64(N-K+1)/float64(N)
    fmt.Println(result)
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,P;
    cin>>N>>P;
    string S;
    cin>>S;
    map<int,int> m;
    int x=S[N-1]-'0';
    x%=P;
    m[0]++;
    m[x]++;
    int cou=10%P;
    for(int i=N-2;i>=0;i--){
        int y=S[i]-'0';
        y*=cou;
        y%=P;
        x=x+y;
        x%=P;
        m[x]++;
        cou*=10;
        cou%=P;
    }
    int ans=0;
    for(auto p:m){
        ans+=(p.second*(p.second-1))/2;
    }
    if(P!=2&&P!=5){
        cout << ans << endl;
    }else{
        int a=0;
        rep(i,N){
            int z=S[i]-'0';
            if(z%P==0){
                a+=i+1;
            }

        }
        cout << a << endl;
    }
    



}


Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 61;
#define ll long long
ll n,sum=0,k;
int arr[1000000];
ll dp[1000000];
ll finds(int next)
{
    if(next>n)
        {return  inf;}
    if(next==(n-1))
        {return 0;}

    if(dp[next]!= -1)
        {return dp[next];}

    for(int i=1;i<=k;i++)
    {
        if(dp[next]!=-1)
            {dp[next]=min(dp[next],finds(next+i)+abs(arr[next+i]-arr[next]));}
        else
            {dp[next]=finds(next+i)+abs(arr[next+i]-arr[next]);}

    }
    return dp[next];

}
int main()
{
    ll i,j,l,m;
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(i=0;i<n;i++)
        cin>>arr[i];
    cout<<finds(0);

}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int k;
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>k;
  cout<<a[k-1]<<"\n";
}

Measured memory_bytes: 256
n  = int(input())
A = list(map(int,input().split()))
l = []
from collections import Counter
counter = Counter(A)
total = 0
def choose2(n):
    return n*(n-1)/2
for i in counter.most_common():
    c = choose2(i[1])
    total += c

for i in A:
    print(int(total-choose2(counter[i])+choose2(counter[i]-1)))

Measured memory_bytes: 97228
import sys
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1
first = [-1] * N


if K < 2 * N:
    now = 0
    for i in range(K):
        now = A[now]
    print(now + 1)
    sys.exit()

first[0] = 0
now = 0
while True:
    next = A[now]
    if first[next] == -1:
        first[next] = first[now] + 1
        now = next
    else:
        K -= first[next]
        loop = first[now] + 1 - first[next]
        K %= loop
        now = next
        for i in range(K):
            now = A[now]
        print(now + 1)
        sys.exit()


Measured memory_bytes: 92136
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//解説AC
//qiita.com/drken/items/fd4e5e3630d0f5859067
//Thank you.
int main(){
string s;
cin>>s;
vector <string> words{"dream","dreamer","erase","eraser"};
reverse(s.begin(),s.end());
rep(i,4)
{reverse(words[i].begin(),words[i].end());}

string can_ans = "YES";

int i=0;
while(i<s.size())//全文字チェックするまでrep 複数文字チェックしたら、まとめてi多そう
{
//n番目以降の文字列をm文字だけ取り出す場合は[string].substr(n, m)
  /*cout << s.substr(i,5)<< " : "<<words[0]<<endl;
  cout << s.substr(i,7)<< " : "<<words[1]<<endl;
  cout << s.substr(i,5)<< " : "<<words[2]<<endl;
  cout << s.substr(i,6)<< " : "<<words[3]<<endl;*/

  if(s.substr(i,5)==words[0])
  {
    i+=5;
  }
  else if(s.substr(i,7)==words[1])
  {
     i+=7;
  }
  else if(s.substr(i,5)==words[2])
  {
    i+=5;
  }
  else if(s.substr(i,6)==words[3])
  { 
    i+=6;
  }
  else
  {
    can_ans="NO";
    break;
  }
}

cout << can_ans <<endl;
return 0;




}


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

using namespace std;

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

    pair<pair<string,int>,int> s[n];
    for(int i=0; i<n; i++){
        string str;
        int num;
        cin >> str >> num;
        s[i] = make_pair(make_pair(str, num * (-1)),i+1);
    }

   sort(s, s+n);
    for(int i=0;i<n;i++){
        cout << s[i].second << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 2e9
#define ALL(v) v.begin(), v.end()
 
using namespace std;
typedef long long ll;

int main(){
  int x;
  float temp1,temp2,temp;
  bool ans=false;
  cin >> x;
  if(x<100){
      cout << 0 << endl;
      return 0;
  }
  if(x%100==0) ans=true;

  temp1 = x%100;
  temp2 = x/100;
  temp = temp1/temp2;

  if(temp<=5.0){
      ans = true;
  }
  cout << (ans? 1:0) << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

bool is_power_of_2(const LL x)  /* x >= 1 */
{ return (x & (x-1)) == 0; }    /* could be x == lowbit(x) */

const LL inf = 1e16;
const int maxn = 16;
int n,A[maxn][maxn]; LL dp[1<<maxn];

LL dfs(const int mask)
{
    if (is_power_of_2(mask))
        return 0;
    LL& ans = dp[mask];
    if (-1 == ans) {
        ans = 0;
        FOR(i,0,n) FOR(j,i+1,n) if ((mask&(1<<i)) && (mask&(1<<j)))
            ans += A[i][j];
        for (int s = mask; s > 0; s = (s-1)&mask) {
            if (s < mask) {
                const LL res = dfs(s) + dfs(mask-s);
                ans = max(ans,res);
            }
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n) {
        FOR(i,0,n) FOR(j,0,n)
            cin >> A[i][j];
        memset(dp,-1,sizeof(dp));
        cout << dfs((1<<n)-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 768
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int r, c, n; readV(r, c, n);

  struct P { int s, i; }
  P[] p;

  auto score(int x, int y)
  {
    if (y == 0) return x;
    else if (x == r) return r+y;
    else if (y == c) return r+c+(r-x);
    else if (x == 0) return r+c+r+(c-y);
    return -1;
  }

  foreach (i; 0..n) {
    int x1, y1, x2, y2; readV(x1, y1, x2, y2);
    
    auto s1 = score(x1, y1);
    auto s2 = score(x2, y2);
    if (s1 >= 0 && s2 >= 0) p ~= [P(s1, i), P(s2, i)];
  }

  p.sort!"a.s < b.s";

  auto s = SList!int();
  foreach (pi; p)
    if (!s.empty && s.front == pi.i)
      s.removeFront();
    else
      s.insertFront(pi.i);

  writeln(s.empty ? "YES" : "NO");
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> fact;
    for(unsigned long i{2}; i * i <= N; ++i)if(N % i == 0){
        unsigned long cnt{0};
        while(N % i == 0){
            ++cnt;
            N /= i;
        }
        fact.emplace_back(cnt);
    }
    if(N != 1)fact.emplace_back(1);
    unsigned long ans{0};
    for(const auto& e : fact){
        unsigned long i{0};
        while((i + 1) * (i + 2) <= e * 2)++i;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int n;
    double ret=0;
    cin>>n;
    double arr[n+1]={0,};
    string type[n+1];
    for(int i=0;i<n;i++){
        cin>>arr[i]>>type[i];
    }
    
    //1BTC = 380000yen
    for(int i=0;i<n;i++){
        if(type[i] == "JPY"){
            ret+=arr[i];
        }
        if(type[i] == "BTC"){
            ret+=(380000*arr[i]);
        }
    }
    cout<<fixed;
    cout.precision(4);
    cout<<ret<<"\n";

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> p_int;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

int main() {
	int n,t,a;
	cin >> n >> t >> a;
	double h[n];
	int ans = 0;
	double tmp = 114514191;
	for (int i = 0;i < n;i++) {
		cin >> h[i];
		if (tmp > abs((t - h[i] * 0.006) - a)) {
			ans = i;
			tmp = abs((t - h[i] * 0.006)-a);
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
#define H 1001
#define W 1001
int h, w;
int sx, sy;
int gx, gy;
char c[H][W];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n;
vector<vector<int> > d(H, vector<int>(W, INF));
int bfs(void)
{
    rep(i, h)
    {
        rep(j, w)
        {
            d[i][j] = INF;
        }
    }
    queue<P> q;
    q.push(P(sy, sx));
    d[sy][sx] = 0;
    while (q.size())
    {
        P p = q.front();
        q.pop();
        rep(i, 4)
        {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] != 'X' && d[ny][nx] == INF)
            {
                q.push(P(ny, nx));
                d[ny][nx] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gy][gx];
}
int main()
{
    cin >> h >> w >> n;
    rep(i, h)
    {
        rep(j, w)
        {
            cin >> c[i][j];
            if (c[i][j] == 'S')
            {
                sy = i;
                sx = j;
            }
        }
    }
    int ans = 0;
    trep(i, 1, n + 1)
    {
        rep(j, h)
        {
            rep(k, w)
            {
                if (c[j][k] == (i + '0'))
                {
                    gy = j;
                    gx = k;
                }
            }
        }
        ans += bfs();
        sy = gy;
        sx = gx;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7688
N, A, B = map(int, input().split())
if (B - A) & 1:
    res = (B - A - 1) // 2 + A
    A, B = N - B + 1, N - A + 1
    res = min(res, (B - A - 1) // 2 + A)
    print(res)
else:
    print((B - A) // 2)

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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  
  int count = 0;
  for(int i = l; i < r+1; i++){
    if(i % d == 0) count++;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3596
n = int(input())
d = [list( map( int, input().split() ) ) for i in range(n)]

for i in range(n-2):
  if d[i][0] == d[i][1]:
    if d[i+1][0] ==d[i+1][1]:
      if d[i+2][0] == d[i+2][1]:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 62360
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define rep(i,a,b) for(int i=a;i<=int(b);i++)
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
const ll M  = 1e9+7 ;
const int N = 100100;
const int inf = INT_MAX;
const double eps = 1e-7;
const ll iinf = -1e18 ;
//////////////////////    Hi    ^_^  hack me if you can :P

int a[200];
int n;
int main()
{
    speed;
    cin >> n;
    lop(i,n) cin >> a[i];
    sort(a,a+n);
    cout << a[n-1]-a[0]<<endl;

}


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

int main(){

    int a, b;
    cin >> a >> b;

    if ((a<=0) && (b>=0)){
        cout << "Zero" << endl;
    } 
    else if((a>0) && (b>0)){
        cout << "Positive" << endl;
    }
    else{
        long long diff;
        diff = abs(a-b);
        if (diff%2 == 0){
            cout << "Negative" << endl;
        }
        else{
            cout << "Positive" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
n =gets.to_i
a = gets.split.map(&:to_i)
min_count = 0
min_value = a.min
max_value = a.max 

n.times do |i|
	min_count += 1 if a[i] == min_value
end
result = false

if (max_value - min_value) == 0
	result =  (a[0] * 2 <= n || a[0] == (n-1) ) ? true : false
elsif (max_value - min_value) > 1
	result = false
else
	if min_count <= min_value && max_value <= (min_count + (n - min_count) / 2)
		result = true
	else
		result = false
	end
end
ans = result ? "Yes" : "No"
puts ans


Measured memory_bytes: 8076
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

ll modpow(ll x, ll y){
    if(y == 0) return 1;
    if(y == 1) return x;
    return x * modpow(x, y-1) % MOD;
}

signed main(){ INIT;
    VAR(int, n, x);
    VEC(int, a, n);
    ll ans = 0;
    if(a[0] > x) ans += a[0] - x, a[0] = x;
    REP(i, n - 1){
        if(a[i] + a[i + 1] > x){
            int t = a[i] + a[i + 1] - x;
            ans += t;
            a[i + 1] -= t;
        }
    }
    OUTL(ans);
RET;}

Measured memory_bytes: 640
from collections import Counter
input()
A=list(map(int,input().split()))
A.sort(reverse=True)
C=Counter(A)
ans=0
for a in A:
    if not C[a]:
        continue
    C[a]-=1
    t=2**a.bit_length()-a
    if C[t]:
        C[t]-=1
        ans+=1
print(ans)

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

int main() {

  string A,B;
  cin >> A >> B;
  
  if((A.at(0)==B.at(2))&&(A.at(1)==B.at(1))&&(A.at(2)==B.at(0))){
  cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A<B){
    if(A<C && C<B) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else{
    if(B<C && C<A) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	int N;long long int  ans = 0; cin >> N;
	vector<ll>A(N + 1), B(N);
	rep(i, N + 1) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
	}
	for (int i = N - 1; i >= 0; i--) {
		if (B[i] <= A[i + 1]) {
			ans += B[i];
		}
		else {
			if (B[i] - A[i + 1] <= A[i]) {
				ans += B[i];
				A[i] -= (B[i] - A[i + 1]);
			}
			else {
				ans += A[i] + A[i + 1];
				A[i] = 0;
			}
		}
	}
	cout << ans << endl;
}












	


	 



































    





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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

ll n,m,q;
ll a[60],b[60],c[60],d[60];
ll ans=0;
ll aa[20];
void getans(ll pos,ll p)
{
	if(pos==n)
	{
		ll val=0;
		for(ll i=0;i<q;++i)
		{
			if(aa[b[i]-1]-aa[a[i]-1]==c[i])
				val+=d[i];
		}
		amax(ans,val);
		return ;
	}
	for(ll i=p;i<=m;++i)
	{
		aa[pos]=i;
		getans(pos+1,i);
	}
}
int _runtimeTerror_()
{
	cin>>n>>m>>q;
	for(ll i=0;i<q;++i)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	getans(0,1);
	cout<<ans;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	int M1, M2, D1, D2;
	cin >> M1 >> D1;
	cin >> M2 >> D2;

	if(M1==M2){
		cout << 0 << "\n";
	}
	else{
		cout << 1 << "\n";
	}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

int inf = std::numeric_limits<int>().max();

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define ll long long
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

int main() {
	int n;
	cin >> n;
	vector<double> v(n+1, 0); 
	for(int i=1; i<=n; i++) {
		cin >> v[i];
	}
	vector<vector<double>> dp(n+1, vector<double>(n+1, 0)); 
	dp[0][0] = 1;
	for(int i=0; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			if (i>0)	dp[i][j] = dp[i-1][j-1] * v[j] + dp[i][j-1] * (1-v[j]); 	
			else dp[i][j] = dp[i][j-1] * (1-v[j]); 	
		}
	}
	/*cout << "---" << endl;
	for(int i=0; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cout << dp[i][j] << "\t";
		}
		cout << endl;
	}*/

	cout.precision(10);
	double ans = 0;
	for(int i=1+n/2; i<=n; i++) {
		ans += dp[i][n]; 
	}
	cout << ans << endl;
}


Measured memory_bytes: 70784
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[i + n / 2]) {
            cout << "No" << endl;
            return 0;
        }
    }


    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

long long power(long long a,long long b,long long mod) {

    long long res=1;

    while(b>0) {

        if(b&1)

            res=(res*a)%mod;

        a=(a*a)%mod;

        b>>=1;

    }

    return res;

}

long long nC2(long long n) {

    return (n*(n-1));

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    if(n<2) {

        cout << 0 << '\n';

    } else {

        long long res = power(10,n,1000000007) -power(9,n,1000000007) - power(9,n,1000000007) + power(8,n,1000000007)+1000000007 +1000000007;

        res%=1000000007;

        cout << res << '\n';

    }

    return 0;

}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9;
void solve(){
    int h,w,k;
    cin>>h>>w>>k;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    //int rw[h],col[w],total=0;
    int ans=0;
    for(int i=0;i<(1ll<<h);i++){
        vector<bitset<6>> used(h);
        for(int j=0;j<h;j++){
            if(i&(1ll<<j)){
                for(int k=0;k<w;k++){
                    used[j][k]=1;
                }
            }
        }
        for(int j=0;j<(1ll<<w);j++){
            int sum=0;
            vector<bitset<6>> us(6);
            for(int k=0;k<w;k++){
                if(j&(1ll<<k)){
                    for(int x=0;x<h;x++){
                        us[x][k]=1;
                    }
                }
            } 
            for(int k=0;k<h;k++){
                for(int x=0;x<w;x++){
                    if(used[k][x]||us[k][x]) continue;
                    if(s[k][x]=='#') sum++;
                }
            }
            if(sum==k) ans++;
        }
    }
    cout<<ans;
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) 
	    solve();
	return 0; 
	
}


Measured memory_bytes: 3644
H,W =map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
M = []
for i in range(N):
    for j in range(a[i]):
        M.append(i+1)
ans = [M[i*W:(i+1)*W] for i in range(H)]
for i in range(1,H,2):
    ans[i].reverse()
for i in ans:
    for j in i:
        print(j,end = " ")
    print()
 

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n, m);
    Rep(n){
        Cin(string, s);
        Cout(s);
        Cout(s);
    }
}


Measured memory_bytes: 256
n=int(input())
l=[[0]*9 for i in range(9)]
for i in range(1,n+1):
  if i%10!=0:
    l[i%10-1][int(str(i)[0])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=l[i][j]*l[j][i]
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
string s,t,temp;
int main(){
	cin>>s>>t;
	int len=s.length();
	for(int i=0;i<len;i++){
		temp=s.substr(i)+s.substr(0,i);
		if(temp==t){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  long long k;
  string s;
  cin >> s >> k;
  for(long long i=0;i<k-1;i++){
    if(s[0]=='1'&&s[1]=='\0')
      break;
    if(s[0]=='1'){
      s.erase(s.begin());
    }else
      break;
  }
  cout << s[0] << endl;
  return 0;
}

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

char n[30];

void print_square() {
    int i ;

    printf("%d", n[0]);

    for (i=1;i<30;i++) {
        if (!n[i]) break;
        printf(" %d", n[i]);
    }

    puts("");
    return ;
}

void format(int p) {
    int i, sum = 0;
    int save = n[p];

    for (i=p+1;i < 30;i++) {
        sum += n[i];
        n[i] = 0;
    }

    if (sum == 0) return ;

    for (i=p+1;i < 30;i++) {
        if (sum <= save) {
            n[i] = sum;
            return ;
        } else {
            n[i] = save;
            sum -= save;
        }
    }

    return ;
}

int move() {
    int i = 29;
    char from;
    char zero_start;

    while (1) {
        if (i < 0) { 
            return 0;
        }

        if (n[i] > 1) {
            from = i;
            break;
        }
        i--;
    }


    i = 0;
    while (1) {
        if (i > 29) {
            return 0;
        }

        if (n[from] > n[i] + 1) {
            zero_start = i;
            break;
        }

        i++;
    }

    n[zero_start] += 1;
    n[from] -= 1;


    format(from);

    return 1;
}

int main() {
    while (1) {
        memset(n, 0, 30);
        scanf("%d", &n[0]);

        if (!n[0]) {
            return 0;
        }

        do {
            print_square();
        } while (move());
    }
}

Measured memory_bytes: 1040
# -*- coding: utf-8 -*-
# ALDS1_3_D_Areas on the Cross-Section Diagram

from collections import deque

def make_h_list(slope):
    """
    入力データから高さのリストを作る
    """
    h_list =deque([0])
    for s in slope:
        d = 0
        if s == "\\":
            d = -1
        elif s == "/":
            d = 1
        h_list.append(h_list[-1] + d)
    return h_list

def trim_edge(h_list, left=True):
    """
    水溜りの境界を探す
    """
    if left:
        while h_list:
            h = h_list.popleft()
            if h not in h_list:
                continue
            if h_list[0] - h < 0:
                h_list.appendleft(h)
                return h_list
    else:
        while h_list:
            h = h_list.pop()
            if h not in h_list:
                continue
            if h_list[-1] - h < 0:
                h_list.append(h)
                return h_list
            
def make_w_list(h_list):
    """
    水たまりのリストを作る
    """
    w_list = []
    water = []
    h_list = trim_edge(h_list)
    while h_list:
        h = h_list.popleft()
        if not water:
            water.append(h)
        elif water[0] == h:
            water.append(h)
            w_list.append(water)
            water = []
            h_list.appendleft(h)
            h_list = trim_edge(h_list)
        else:
            water.append(h)
            if water[0] < water[-1]:
                water.pop(0)
    return w_list
                
def calc_area(water):
    """
    面積計算
    """
    h = water[0]
    s = 0
    for i in range(len(water) - 1):
        s += (water[i+1] - h) + (water[i+1] - water[i]) / 2
    return abs(int(s))


in_data = str(input())

h_list = make_h_list(in_data)
h_list = trim_edge(h_list, left=False)

if type(h_list) != None:
    w_list = make_w_list(h_list)
    a_list = [calc_area(water) for water in w_list]
else:
    a_list = []

print(sum(a_list))
print(len(a_list), *a_list)


Measured memory_bytes: 7376
#include <iostream>
#define prim 1000000007
using namespace std;

int N,a[100010],p[100010];

int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++){
        cin >> a[i];
        if ((N+1-a[i])%2){
            cout << 0 << "\n";
            return 0;
        }

        p[(N+1-a[i])/2]++;
    }

    if (N%2 && p[(N+1)/2]!=1){
        cout << 0 << "\n";
        return 0;
    }

    for (i=1; i<=N; i++){
        if (p[i]>2){
            cout << 0 << "\n";
            return 0;
        }
    }

    int p=N/2,res=1;
    for (i=1; i<=p; i++) res=(res*2)%prim;

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


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

int main(){
  int N,sum_A;
  cin>>N;
  vector<int> vec(N,0);
  sum_A=0;

  for(int i=0;i<N-1;i++){
  int A;
  cin>>A;
  vec.at(A-1)++;
  }
  for(int x:vec){
  cout<<x<<endl;
  }
}

Measured memory_bytes: 4000
// [AT2554 Choose Integers] https://www.luogu.org/problem/AT2554
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    for (int i = 1; i <= 1000; i++)
    {
        if (a*i % b == c)
        {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;cin>>k;
    string s;cin>>s;
    int n = s.size();
    if(n<=k){
        cout<<s<<endl;
        return 0;
    }
    else{
        for(int i=0; i<k; i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;

ll x[11][11];
set<ll> sqlist;

int main(){_;
  ll n,d;cin>>n>>d;
  REP(i,n){
    REP(j,d){
      cin>>x[i][j];
    }
  }
  for(ll i=1;i*i<=16000;i++){
    sqlist.insert(i*i);
  }
  int count=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ll dist = 0;
      for(int y=0;y<d;y++) dist+=(x[i][y]-x[j][y])*(x[i][y]-x[j][y]);
      if(sqlist.find(dist)!=sqlist.end()){
        count++;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

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

  ll S = 0;
  ll NUM = N;
  while(1){
    S += NUM % 10;
    NUM = ll(NUM / 10);
    if(NUM == 0) break;
  }

  if(N % S == 0) print("Yes");
  else print("No");

  return 0;
}




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

int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    if(n%2==1) cout<<0<<endl;
    else{
    n/=2;
    while(n>=5){
        n/=5;
        ans+=n;
    }
    cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#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;
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

int main()
{
    int K;
    cin >> K;

    ll s = 0;
    for (int i = 1; i <= K; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            for (int k = 1; k <= K; k++)
            {
                s += gcd(i, gcd(j, k));
            }
        }
    }
    OP(s);
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll s[100010], t[100010], c[35];

ll ch[35][100010];

int main(){
    int n, C;
    cin >> n >> C;
    rep(i, n){
        cin >> s[i] >> t[i] >> c[i];
        ch[c[i]][s[i]]++;
        ch[c[i]][t[i]]--;
    }
    rep(i, 35) rep(j, 100009){
        ch[i][j+1] += ch[i][j];
    }

    rep(i, 35) rep(j, 100009){
        if (ch[i][j] == 0 && ch[i][j+1] == 1) ch[i][j]++;
    }

    int ans = 0;
    rep(j, 100009) {
        int tmp = 0;
        rep(i, 35) tmp += ch[i][j];
        ans = max(ans, tmp);
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 29184