akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T& x, const T& y) { return x > y ? y : x; }
template<class T> inline T max(T& x, const T& y) { return x < y ? y : x; }
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read() {
    ll c = getchar(), Nig = 1, x = 0; while (!isdigit(c) && c != '-')c = getchar();
    if (c == '-')Nig = -1, c = getchar();
    while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
    return Nig * x;
}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
#define N 1005
///int num[maxn];
///int sum[maxn];
map<ll, ll>mp;
int n;
ll m;
start{
    n = read,m = read;
    ll num,sum = 0,ans = 0;
        mp.clear();
        mp[0]++;
        for (int i = 1; i <= n; i++) {
            num = read;
            sum += num;
            sum %= m;
            ans += mp[sum];
            mp[sum]++;
        }
        printf("%lld\n",ans);
    end;
}

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int n;

void Pisz(string s, char c, int ile)
{
    s += c;
    if (s.size() == n)
    {
        cout << s << endl;
        s.erase(s.size() - 1, 1);
        return;
    }
    for (int i = 0; i < ile; ++i)
        Pisz(s, 'a' + i, ile);
    Pisz(s, 'a' + ile, ile + 1);
    s.erase(s.size() - 1, 1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    string s = "";
    Pisz(s, 'a', 1);
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int ans=(1900*M+100*(N-M))*int(pow(2,M));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import math
A,B,N= map(int,input().split())

if B<=N:
    lista=(math.floor((A*(B-1))/B)-A*(math.floor((B-1)/B)))
    print(lista)
else:
    list=(math.floor((A*N)/B)-A*(math.floor(N/B)))
    print(list)


Measured memory_bytes: 9028
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int ans = 0;
    char op;
    REP(i, 4) {
        cin >> op;
        if (op == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!
//解説カンニング

ll gcd(ll A, ll B){
    ll w;
    if(A<B) swap(A,B);
    while(B){
        w = A%B;
        A = B;
        B = w;
    }
    return A;
}

int main(void){
    ll N, A[100100], R[100100], L[100100], ans=0;
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", A+i);
    L[0]=0; R[N+1]=0;
    for(ll i=0; i<=N-2; i++) L[i+1] = gcd(L[i], A[i]);
    for(ll i=N-1; i>=1; i--) R[i+1] = gcd(R[i+2], A[i]);
    for(ll i=1; i<=N; i++) chmax(ans, gcd(L[i-1], R[i+1]));
    printf("%lld\n", ans);
    return 0;
}


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

int main(void){
        int a, b, i = 1, ans;
        cin >> a >> b;
        while(true){
                if(floor((double)i*2.0/25.0)==a and floor((double)i*1.0/10.0)==b){
                        ans = i;
                        break;
                }
                if(floor((double)i*2.0/25.0)>a or floor((double)i*1.0/10.0)>b){
                        ans = -1;
                        break;
                }
                i++;
        }
        cout << ans << endl;
        return 0;
}


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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N;
	cin >> N;
	int k;
	bool frag = false;
	
	for(int i = 1; i < sqrt(2*N); i++) {
		if(i*(i+1) == 2*N) {
			k = i;
			frag = true;
			cout << "Yes" << endl;
			break;
		}
	}
	
	vector<vector<int>> S(k+1, vector<int>());
	int l = 1;
	
	if (frag) {
		cout << k+1 << endl;
		for (int i = 0; i < k; i++) {
			for (int j = i+1; j < k+1; j++) {
				if (i != j) {
					S[i].push_back(l);
					S[j].push_back(l);
					l++;
				}
			}
		}
		for (int i = 0; i < k+1; i++) {
			int size = S[i].size();
			cout << size;
			for (int j = 0; j < size; j++) cout << " " << S[i][j];
			cout << endl;
		}  			
	}
	if (!frag) cout << "No" << endl;
}


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

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

  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  cout << accumulate(p.begin(), p.end(), 0) - p[n-1] / 2 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
   
using namespace std;

int main()
{
    int n;
    cin >> n;
    int result[100003] = {};
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        result[l - 1]++;
        result[r]--;
    }
    int ans = 0;
    for(int i = 1; i < n + 1; i++){
        result[i] += result[i - 1];
        // cout << result[i] << endl;
        if(result[i] >= i) ans = max(i, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1560
S = [s for s in input()]

ans = 0
for i in range(2**(len(S)-1)):
    plus = [""]*(len(S))
    fomula = ""
    for j in range(len(S)-1):
        if(i>>j & 1):
            plus[j] = "+"
    
    for i in range(len(S)):
        fomula += S[i] + plus[i]
    ans += eval(fomula)
    
print(ans)

Measured memory_bytes: 39536
xy = list(map(int, input().split()))

#1番座標の原点平行移動
xy1dash = [-1 * xy[0], -1 * xy[1]]

xy2dash = [xy[2] + xy1dash[0], xy[3] + xy1dash[1]]

#pi/4回転後
xy4dash = [-1 * xy2dash[1], xy2dash[0]]
#平行移動戻す
xy4 = [xy4dash[0] - xy1dash[0], xy4dash[1] - xy1dash[1]]

xy3 = [xy4[0] + xy[2] - xy[0], xy4[1] + xy[3] - xy[1]]

print(xy3[0], xy3[1], xy4[0], xy4[1])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int b[1000][1000];
ll dp[1000][1000];

int main(){
	int h,w; cin>>h>>w;
	
	FOR(i,0,h) FOR(j,0,w){
		char c; cin>>c;
		b[i][j]=(c=='.'?1:0);
	}
	dp[0][0]=1;
	int i=0,j=0;
	FOR(i,0,h) FOR(j,0,w){
		if(i<h-1&&b[i+1][j]) (dp[i+1][j]+=dp[i][j])%=MOD;
		if(j<w-1&&b[i][j+1]) (dp[i][j+1]+=dp[i][j])%=MOD;
	}
	co(dp[h-1][w-1]);
}


Measured memory_bytes: 11904
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	long long int S,c;
	cin >> S >> c;

	long long int ans;
	ans = 0;
	if(S*2 >= c){
		ans = c/2;
	}else{
		ans += S;
		c -=  2*S;
		ans += c/4;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import kotlin.Long as Num

const val mod=1000000007

fun modpow(n:Num,p:Num=mod-2L):Num=when {
	p==0L->1L
	p%2==1L->n*modpow(n,p-1)%mod
	else-> {
		val d=modpow(n,p/2)
		d*d%mod
	}
}

fun nCr(n:Num,r:Num):Num=((n-r+1L..n)+(2..r).map {modpow(it)}).fold(1L) {a,b-> a*b%mod}

fun main(args:Array<String>) {
	val (n,a,b)=readLine()!!.split(" ").map {it.toLong()}
	println((modpow(2,n)+mod*2-1-nCr(n,a)-nCr(n,b))%mod)
}


Measured memory_bytes: 75756
# 英小文字からなる文字列 sが与えられます
# 前から数えて奇数文字目だけ抜き出して作った文字列を出力してください。
# ただし、文字列の先頭の文字を1文字目とします。

# s（文字列）：標準入力
s = str(input())
print(s[::2])

Measured memory_bytes: 8988
a=[1e4]*51
for i,j in[(2,380),(3,550),(5,850),(10,1520),(12,1870),(15,2244)]:
 a[i]=j
 for k in range(51-i):a[k+i]=min(a[k+i],a[k]+j)
for n in iter(input,'0'):print(a[int(n)//100])


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100, mod = 1e9 + 7, maxa = 1e6 + 100, maxb = 23;
const long long inf = 2e18 + 13;
int max(int x, int y){return (x > y ? x : y);}
int min(int x, int y){return (x < y ? x : y);}

long long dp[maxn];
long long pm[maxn];
long long x[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, e, t;
    cin >> n >> e >> t;
    fill(dp, dp + maxn, inf);
    t *= 2;
    e *= 2;
    int p1 = 0;
    for(int i = 1; i <= n; i++){cin >> x[i]; x[i] *= 2;}
    dp[0] = 0;

    for(int i = 1; i <= n; i++)
    {
        while(p1 + 1 < i && x[p1 + 1] <= x[i] - t / 2){p1++;}
        if(!p1){dp[i] = t;}
        else{dp[i] = min(dp[p1] + t, pm[p1] + x[i] * 2);}
        pm[i] = min(pm[i - 1], dp[i - 1] - 2 * x[i]);
       // cout << p1<<" "<< i << ' ' << dp[i] << ' ' << pm[i] << endl;
    }

    cout << (dp[n] + e) / 2 << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                //ios_base::sync_with_stdio(false);
                //cin.tie(NULL);
                lli t,n,i,j,b,a,q,m;
                cin>>n;
                cin>>a>>b;
                repp(i,1,10000){
                    if(n*i>=a&&n*i<=b){
                        cout<<"OK"<<endl;
                        return 0;
                    }
                }
                cout<<"NG"<<endl;


            }



Measured memory_bytes: 3636
a, b, c, d = map(int, input().split())

def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y)

def f(b, c, d):
  return b - ((b // c) + (b // d)) + b // ((c * d) // gcd(c,d))

print(f(b, c, d) - f(a-1, c, d))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}

int main(void){
    int n; cin >> n; ll ans = 0;
    for(int i = 0;i < n;i++){
        int a; cin >> a; ans += a-1;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
class Dice:
    def __init__(self):
        self.top = 1
        self.dside = 2
        self.rside = 3
        self.lside = 4
        self.uside = 5
        self.bottom = 6
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)
    def west(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.rside,
            self.top, self.lside, self.bottom)

num, dice = list(map(int, input().split())), Dice()
label = {i+1:num[i] for i in range(6)}
com = [i for i in input()]
for i in com:
    if i=="N":
        dice.north()
    elif i=="E":
        dice.east()
    elif i=="S":
        dice.south()
    else:
        dice.west()
print(label[dice.top])



Measured memory_bytes: 5612
#coding:utf-8
import math
a,b,c = map(int, input().split())
x = c - a - b
#(c-a-b)^2  > 4abする時が答え
#ただし(c-b-a) < 0になるものは対象外

if x < 0:
    print('No')
elif x**2 > 4*a*b:
    print('Yes')
else:
    print('No')


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

#define EPS 1e-9
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=(m);i<(n);i++)
#define sz(x) ((x).size())

typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A, const vec& b){
	int n=sz(A);
	mat B(n, vec(n+1));
	rep(i,n)rep(j,n) B[i][j]=A[i][j];
	rep(i,n) B[i][n] = b[i];
	
	rep(i,n){
		int piv=i;
		rep2(j,i,n){
			if(abs(B[j][i]) > abs(B[piv][i])) piv=j;
		}
		swap(B[i], B[piv]);
		
		if(abs(B[i][i]) < EPS) return vec();
		
		rep2(j,i+1,n+1) B[i][j] /= B[i][i];
		rep(j,n) if(i!=j){
			rep2(k,i+1,n+1) B[j][k] -= B[j][i] * B[i][k];
		}
	}
	
	vec x(n);
	rep(i,n) x[i] = B[i][n];
	return x;
}

int d;
double x[9];

int main2(){
	rep(i1,d+3)rep2(i2,i1+1,d+3){
		vector<int> ind;
		rep(i,d+3)if(i!=i1 && i!=i2)ind.push_back(i);
		mat A(d+1,vec(d+1));
		vec b(d+1);
		rep(i,d+1){
			rep(j,d+1)A[i][j]=pow(ind[i],j);
			b[i]=x[ind[i]];
		}
		vec c=gauss_jordan(A,b);
		double v1=0,v2=0;
		rep(i,d+1){
			v1 += pow(i1,i)*c[i];
			v2 += pow(i2,i)*c[i];
		}
		if(abs(v1-x[i1])<1e-5){
			cout<<i2<<endl;
			return 0;
		}
		if(abs(v2-x[i2])<1e-5){
			cout<<i1<<endl;
			return 0;
		}
	}
}

int main(){
	while(cin>>d && d){
		rep(i,d+3)cin>>x[i];
		main2();
	}
}

Measured memory_bytes: 1316
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right

N,M=map(int, sys.stdin.readline().split())
P=[ [] for _ in range(N+1) ]  #Prefecture 県
Q=[]    #クエリー

for _ in range(M):
    p,y=map(int, sys.stdin.readline().split())
    P[p].append(y)
    Q.append((p,y))

for i in range(1,N+1):
    P[i].sort()

for i,y in Q:
    print str(i).zfill(6)+str(bisect_left(P[i],y)+1).zfill(6)

Measured memory_bytes: 53148
program AGC43_A
  integer::H,W
  character(100)::S
  integer,allocatable::maze(:,:),dp(:,:)
  integer::i,j,k,dx(2)=[-1,0],dy(2)=[0,-1]
  read(*,*)H,W
  allocate(maze(H,W),dp(H,W))
  maze=0
  do i=1,H
     read(*,*)S
     do j=1,W
        if(S(j:j)=='#') maze(i,j)=1
     end do
  end do
  dp=huge(i)/2
  dp(1,1)=maze(1,1)
  do i=1,H
     do j=1,W
        do k=1,2
           dp(i,j)=min(dp(i,j),dp(max(1,i+dx(k)),max(1,j+dy(k)))&
           +merge(1,0,maze(max(1,i+dx(k)),max(1,j+dy(k)))==0 .and. maze(i,j)==1))
           !merge(a,b,c)はcが真ならa，偽ならb
        end do
     end do
  end do
  write(*,*)dp(H,W)
end program AGC43_A

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long dp1[502][513],dp2[502][513],mod = 998244353;
int main(){
    long long i,j,k,n,x,y = 1;
    cin >> n >> x;
    while(y<=x) y *= 2;
    y--;
    dp1[0][0] = 1;
    for(i=0;i<=x;i++){
        for(j=0;j<=n;j++){
            for(k=0;k<=y;k++){
                dp2[j][k] = dp1[j][k];
            }
        }
        for(j=0;j<=n;j++){
            for(k=0;k<=y;k++){
                (dp2[j + 1][(k^i)] += dp2[j][k]) %= mod;
            }
        }
        for(j=0;j<=n;j++){
            for(k=0;k<=y;k++){
                dp1[j][k] = dp2[j][k];
                dp2[j][k] = 0;
            }
        }
    }
    cout << dp1[n][x] << endl;
}


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

void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto& it: a) cin >> it;
	sort(a.rbegin(), a.rend());
	queue<int> s;
	long long ans = a[0];
	s.push(a[1]);
	int i = 2;
	while(i < n){
		int x = s.front();
		s.pop();
		ans += x;
		s.push(a[i]);
		i++;
		if(i < n){
			ans += x;
			s.push(a[i]);
			i++;
		}
	}
	cout << ans << '\n';
}

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

	int t = 1;
	while(t--) solve();
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {

    int64_t N,K,tmp=0;
  int64_t maximum=0;
    cin>>N>>K;
  
     vector<int> A(N);


     for(int i=0; i<N; i++){cin>>A[i];}
     for(int j=0; j<K; j++){tmp+=(A[j]+1);}
       maximum=tmp;
//cout<<tmp<<endl;
     for(int i=K; i<N; i++){
       tmp-=(A[i-K]+1);
       tmp+=(A[i]+1);
      // cout<<tmp<<endl;
       maximum = max(maximum , tmp);
       
     }
  if(maximum%2==0)cout<<maximum/2<<endl;
  else cout<<(maximum/2)<<".5"<<endl;
   
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] ss = br.readLine().split(" ");
			for(int i=0; i<ss.length; i++) {
				if(ss[i].equals("0")) {
					System.out.print(i+1);
				}
			}
		} catch(Exception e) {}
	}
}

Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;

int n,m,Q;
int f[maxn][maxn];

int main(){
	scanf("%d%d%d",&n,&m,&Q);
	for (int i = 1; i <= m; i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		if (v < u) swap(u,v);
		for (int i = v; i <= n; i++) {
			f[u][i]++;
		}
	}
	//cout << "ah" << endl;
	int ret = 0;
	for (int j = 0; j < Q; j++){
		int p,q;
		scanf("%d%d",&p,&q);
		int ret = 0;
		for (int i = p; i <= q; i++) {
			ret += f[i][q];
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 4720
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}

int main(void) {
  int N, d[110];
  cin >> N;
  REP(i,N) cin >> d[i];
  int sum = 0;
  REP(i,N) {
    for(int j=i+1;j<N;++j) {
      sum+=d[i]*d[j];
    }
  }
  pr(sum);
  return 0;
}



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

using namespace std;

#define PI 3.1415926535897932

int main(){
    char a[1];
    for (int i=0;i<19;i++) {
        scanf("%c",&a);
        printf("%c",a[0]==','?' ':a[0]);
    }
    printf("\n");
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
      }
      if(k<u->key){
	return treeSearch(u->left,k);
      }
  else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  Node a = root;
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root = x;
  }
  else{
    if(y == y->parent->left){
      y->parent->left=x;
    }
    else{
      y->parent->right=x;
    }
  }
  if(y!=z){
    z->key=y->key;
  }
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20468
A , B , C , D = map(int,input().split())
if A > C:
    C ,A = A ,C
    B ,D = D, B

if B <= C:
    print(0)
elif A<=C and C <=B and D<=B:
    print(D-C)
elif A<=C and C <=B and B <= D:
    print(B-C)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int n, a[102], b[102];

int main() {
  int i, j;
  while (cin >> n, n) {
    string in;
    cin >> in;
    rep (i,n) cin >> a[i] >> b[i];
    rep (i,n) {
      a[i]--; b[i]--;
    }
    
    for (i = n - 1; i >= 0; i--) {
      int ai = a[i], bi = b[i];
      int d = abs(ai - bi);
      for (j = 0; j < d; j++) {
        in[ai]++;
        in[bi]++;
        if (in[ai] > 'z') in[ai] = 'a';
        if (in[bi] > 'z') in[bi] = 'a';
      }
      swap(in[ai], in[bi]);
    }
    
    cout << in << endl;
  }
  return 0;
}

Measured memory_bytes: 0
<?php

$arr = explode(' ', trim(fgets(STDIN)));

$a = $arr[0];
$b = $arr[1];
$H = $arr[2];
$M = $arr[3];

$hk = (($H * 60 + $M) / 720) * 360;
$mk = ($M / 60) * 360;

// echo $hk . PHP_EOL;
// echo $mk . PHP_EOL;

$k = deg2rad(abs($hk - $mk));

$ret = sqrt( ($a * $a) + ($b * $b) - (2 * $a * $b * cos($k)));

echo $ret;

return;

?>


Measured memory_bytes: 16556
#include <stdio.h>
 
int main(){
    long long int banyakAnjing;
    scanf("%lld",&banyakAnjing);
 
    char name[100];
    int a=0;
    
    while(banyakAnjing!=0){
        banyakAnjing--;
        int b = banyakAnjing%26;
        name[a] ='a'+ b;
        banyakAnjing/=26;
        a++;
    }
    for(int j=a-1;j>=0;j--)	{
        printf("%c",name[j]);
    }
    return 0;
}

Measured memory_bytes: 1644
/*
 * created   : 2019-07-24 23:33:09
 * accepted  : 2019-07-24 23:35:20
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n, d;
  cin >> n >> d;
  int ans = (n + 2 * d) / (2 * d + 1);
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int x, a, b;
  cin >> x >> a >> b;
  if (b > x + a) {
    cout << "dangerous" << endl;
  } else if (b > a) {
    cout << "safe" << endl;
  } else {
    cout << "delicious" << endl;
  }

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int inf = 1<<29;

int d1[4] = {1,0,-1,0};
int d2[4] = {0,1,0,-1};
vector<vector<int>> d(55, vector<int>(55, inf));
vector<vector<char>> fi(55, vector<char>(55, '#'));

void bfs(){
    queue<pair<int, int>> q;
    q.push(make_pair(1,1));
    d[1][1] = 1;

    while(!q.empty()){
        pair<int, int> now = q.front(); q.pop();
        for(int i=0; i<4; i++){
            int nx = now.first+d1[i];
            int ny = now.second+d2[i];
            if(fi[nx][ny] == '.' && d[nx][ny] > d[now.first][now.second]+1){
                d[nx][ny] = d[now.first][now.second]+1;
                q.push(make_pair(nx, ny));
            } 
        }
    }
}

int main(){
    int H, W; cin >> H >> W;
    int white = 0;

    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) {
        cin >> fi[i][j];
        if(fi[i][j] == '.') white++;
    }

    bfs();

    if(d[H][W] == inf) cout << -1 << endl;
    else cout << white - d[H][W] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M;
ll MOD = 1000000007;
int ans = 0;
int S[10][10];
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<ll, ll> firstElof, pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}
//////////////

void BitSearch(int depth) {

}
int main()
{
	cin >> N;
	vector<string> S;
	vector<string> PtoS(101);
	vector<int> P;
	vector<int> PtoNumber(101);
	for (i = 0; i < N; i++) {
		string s;
		int p;
		cin >> s >> p;
		S.push_back(s);
		PtoS[p] = s;
		PtoNumber[p] = i+1;
	}
	sort(S.begin(), S.end());
	vector<int> Plist;
	for (i = 0; i < N; i++) {
		for (j = 0; j <= 100; j++) {
			if (PtoS[j] == S[i]) {
				Plist.push_back(j);
			}
		}
		sort(Plist.begin(), Plist.end());
		reverse(Plist.begin(), Plist.end());
		for (k = 0; k < Plist.size(); k++) {
			cout << PtoNumber[Plist[k]] << endl;
		}
		i += Plist.size() - 1;
		Plist.clear();
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>

using namespace std;

int main(){

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

    if(a == b){ cout << c;}
    else if(a == c){ cout << b;}
    else cout << a;

    return 0;
}

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

int main(void) {
    int H,W;
    cin >> H >> W;

    vector<string> a(H);
    for(int i=0;i<H;i++) {
        cin >> a[i];
    }

    vector<int> h(H,0);
    vector<int> w(W,0);
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(a[i][j] == '#') {
                h[i] = 1;
                w[j] = 1;
            }
        }
    }

    for(int i=0;i<H;i++) {
        if(h[i] == 0) continue;
        for(int j=0;j<W;j++) {
            if(w[j] == 0) continue;
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
int n,k;
int h[N],dp[N];
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  scanf("%d%d", &n,&k);
  for(int i=0;i<n;++i)
    scanf("%d",&h[i]);
  dp[0]=0;
  for(int i=1;i<n;++i)
  {
    dp[i]=1e9;
    for(int j=0;j<=min(i,k);++j)
    {
      dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j]);
    }
  }
  printf("%d",dp[n-1]);


}






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

int main(){
  int N,M,cnt=0,ans=0;
  cin>>N;
  ll D[N];
  for(int i=0;i<N;i++) cin>>D[i];
  cin>>M;
  ll T[M];
  for(int i=0;i<M;i++) cin>>T[i];
  
  map<int,int> mpa,mpb;
  for(int i=0;i<N;i++) mpa[D[i]]++;
  for(int i=0;i<M;i++) mpb[T[i]]++;
  for(int i=0;i<M;i++){
    int x=T[i];
    if(mpa[x]<mpb[x]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n;
  cin >> n;
  string ans = "";

  while (n > 0) {
    int a = n % 26;
    --a;
    if (a < 0) a = 25;
    ans += (char)(a + 'a');
    if (a == 25) --n;
    n /= 26;
  }

  rv(ans);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <math.h>

using namespace std;

int main()
{
    const int d = 753;
    string s;
    int ans = 1000000;
    cin >> s;
    int l = s.length();
    int tmp;
    for(int i=0; i<l-2; ++i){
        tmp = 100 * (s[i] - '0') + 10 * (s[i+1] - '0') + (s[i+2] - '0');
        ans = min(ans, abs(d - tmp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
x,k,d=map(int,input().split())

if x==0:
  if k&1:
    print(d)
  else:
    print(0)
  exit()

if x<0 and x+k*d<0:
    print(-x-k*d)
    exit()
if x>0 and x-k*d>0:
    print(x-k*d)
    exit()
    
x=x%(2*d)
if k&1:
  print(min(abs(x-d),abs(x+d)))
  exit()
else:
  print(min(abs(x-2*d),x))
  exit()


Measured memory_bytes: 61936
#include<stdio.h>
int main(){
  int i;
  char a[3];
  for(i=0; i<3; i++){
    scanf("%c",&a[i]);
  }
  if(a[1]=='R'){
    printf("ABC");
  }else if(a[1]=='B'){
    printf("ARC");
  }
return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int k,s; cin>>k>>s;
	int ans=0;
	for(int x=0;x<=k;++x){
		for(int y=0;y<=k;++y){
			int z=s-x-y;
			if(z>=0&&z<=k)++ans;
		}
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3636
X, K, D = map(int, input().split())
DK = D * K

ans = 0
if DK <= abs(X):
    ans = abs(X) - DK
else:
    q = X // D
    r = X % D
    if (K - q) % 2 == 0:
        ans = r
    else:
        ans = D - r
print(ans)


Measured memory_bytes: 61832
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll calc(ll n) {

	ll ret = 0;

	for (int i = 0; (n >> i) > 0; i++) {
		ll T = pow(2, i + 1);

		// iビット目について１の個数を求める
		ll bit = (n / T) * (T / 2);
		bit += n % T >= T / 2 - 1 ? n % T - (T / 2 - 1) : 0;

		ret += (bit % 2) << i;

	}

	return ret;

}

void solve() {

	ll A, B;
	cin >> A >> B;

	cout << (calc(B) ^ calc(A - 1)) << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll d;
ll dfs(ll a, ll t, ll first) {
    if(t == 0) return a==0?1:0;
    ll v = (a%10+10)%10;
    return (10-v-first)*dfs((a-t*v)/10, t/100, 0) + (v-first)*dfs((a+(10-v)*t)/10, t/100, 0);
}

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

    cin >> d;

    if(d%9) {
        cout << 0 << endl;
        return 0;
    }
    d /= 9;

    ll p10[20] = {};
    p10[0] = 1;
    FOR(i, 1, 20) p10[i] = p10[i-1] * 10;

    ll all = 0;
    FOR(i, 2, 19) all += ((i%2)?10:1) * dfs(d, p10[i]/10/9, 1);
    cout << all << endl;

    return 0;
}


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

typedef pair <string, int> p;

int main() {
	p pair,a;
	queue <p> qu;
	int q, i, n, time=0;
	cin >> n >> q;
	for (i = 0; i < n; i++) {
		cin >> pair.first >> pair.second;
		qu.push(pair);
	}
	while (!qu.empty()) {
		a = qu.front();
		qu.pop();
		if (a.second > q) {
			a.second -= q;
			qu.push(a);
			time += q;
		}
		else {
			cout << a.first << " " << time + a.second << endl;
			time += a.second;
		}
	}
}


Measured memory_bytes: 6224
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	int temp = 1;
	for(int i = 0;i<a;i++)
	{
		if(temp < b) temp *= 2	;
		else{
			temp+=b;
		}
	}
	printf("%d\n",temp);
}

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

using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef long long LL;
typedef vector<int> VI;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (to_string(i).length() % 2 == 1) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[100010],b[100010];
int main(){
    int n;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    ll cnt=0,ans=0;
    for (int i = 0; i < n; i++)
    {
        cnt+=a[i];
        if(a[i]==0){
            ans+=cnt/2;
            cnt=0;
        }
    }
    ans+=cnt/2;
    cout<<ans<<endl;
    
    return 0;
}
                  

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,X;
ll ans;
void func(ll a, ll b){
    if(a<=b){
        if(b%a==0){
            ans+=((b/a)*2-1)*a;
            return;
        }
        ans+=(b/a)*2*a;
        b=b%a;
        func(a,b);
    }
    else func(b,a);
}
int main(){
    cin>>N>>X;
    ans=N;
    func(X,N-X);
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
int n,m;
int calc(vector<int> const& num,int s,int t,int r){
    int res=0;
    int sub=s-t;
    sub/=2;
    int buf=r;
    while(buf<=100000&&sub>0){
        int tmp=num[buf];
        if(tmp/2<sub){
            sub-=tmp/2;
            res+=tmp/2;
        }
        else{
            res+=sub;
            sub=0;
            break;
        }
        buf+=m;
    }
    return res;
}

signed main(){
    cin>>n>>m;
    vector<int> x(n);
    vector<int> rest(m+1,0);
    vector<int> num(100001,0);
    int res=0;
    rep(i,n){
        cin>>x[i];
        rest[x[i]%m]++;
        num[x[i]]++;
    }
    //sort(ALL(rest));
    res+=rest[0]/2;
    int hulf=m/2;
    rep1(i,hulf){
        int flag=3;
        //cout<<res<<endl;
        if(rest[i]==rest[m-i]){
            if(m%2==0&&i==hulf){
                res+=rest[i]/2;
            }
            else{
                flag=2;
                res+=rest[i];
            }
        }
        else if(rest[i]<=rest[m-i]){
            flag=1;
            res+=rest[i];
            res+=calc(num,rest[m-i],rest[i],m-i);
        }
        else{
            res+=rest[m-i];
            res+=calc(num,rest[i],rest[m-i],i);
        }
        //cout<<flag<<endl;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1408
n = gets.chomp.to_i

x=1;y=1;z=1;
arr = Array.new(n, 0)
rt = Math.sqrt(n).ceil
x.upto(rt) do |a|
	y.upto(rt) do |b|
		z.upto(rt) do |c|
			ngo = a*a+b*b+c*c+a*b+b*c+c*a
			if ngo <= n
				arr[ngo - 1] += 1
			end
		end
	end
end

arr.each do |a|
	puts a 
end


Measured memory_bytes: 14308
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;cin>>n>>k;
	ll v[n+1];
	ll i;
	for(i=1;i<=n;i++)
		cin>>v[i];
	ll c=0;
	ll a=1;
	bool vis[n+1]={};
	//vis[1]=true;
	vector<ll> v1;

	while(!vis[a]){
		vis[a]=true;
		a=v[a];
		c++;
	}
	//cout<<a<<endl;
	ll c1=0;
	i=1;
	//cout<<a<<endl;
	ll prev=a; 
	//while(i!=a)
		//prev=i,i=v[i];

	bool vis1[n+1]={};
	while(!vis1[a]){
		vis1[a]=true;
		a=v[a];
		c1++;
	}
	//j=a;
	
	
	//cout<<c1<<endl;
	//cout<<c<<endl;
	ll s=c-c1;
	if(k>s)
	k-=s,
	k=k%c1;
	else prev=1;

	//cout<<prev<<endl;
	ll ans=prev;
	for(i=0;i<k;i++)
		ans=v[ans];

	cout<<ans;
	
	return 0;
} 

Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll n,m;cin>>n>>m;
    if(m%2==1){
        cout<<-1<<endl;return 0;
    }
    vector<ll>v[n];
    rep(i,1,m){
        ll a,b;cin>>a>>b;a--;b--;
        v[a].pb(b);v[b].pb(a);
    }
    queue<ll>q;
    stack<ll>s;
    bool used[n];memset(used,false,sizeof(used));
    ll par[n];
    q.push(0);used[0]=true;
    while(!q.empty()){
        ll t=q.front();q.pop();s.push(t);
        for(auto x:v[t]){
            if(!used[x]){
                q.push(x);
                used[x]=true;
                par[x]=t;
            }
        }
    }
    ll c[n];memset(c,0,sizeof(c));
    vector<l_l>ans;
    memset(used,false,sizeof(used));
    while(!s.empty()){
        ll t=s.top();s.pop();
        if(t==0)break;
        used[t]=true;
        for(auto x:v[t]){
            if(used[x])continue;
            if(c[t]%2==1){
                ans.pb(l_l(t,x));
                c[t]++;
            }else{
                ans.pb(l_l(x,t));
                c[x]++;
            }
        }
    }
    for(auto x:ans){
        cout<<x.first+1<<" "<<x.second+1<<endl;
    }
    return 0;
}



Measured memory_bytes: 11636
import sys 
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
    
mod = 10**9 + 7
def P(x,y):
    # x = k - 2
    # y = n - 1
    cnt = 0
    ans = 1
    waru = 1
    while cnt < y:
        ans *= (x-cnt)
        ans %= mod
        cnt += 1
    return ans%mod


ans = 1
def dfs(v,p):
    global ans
    us = edges[v]
    for u in us:
        if u == p: continue
        if len(edges[u]) == 1: ans *= 1
        ans *= P(k-2, len(edges[u])-1)   
        ans %= mod
        dfs(u,v)

dfs(0,-1)
n0 = len(edges[0])
a = P(k,n0+1)
# print(n0,a)
ans *= a
ans %= mod
print(ans)

Measured memory_bytes: 87344