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

/*============================ DEBUGGING =============================*/

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*============================= DEFINES ==============================*/

#define eps 1e-9
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define set(x,k) memset(x,k,sizeof x)

/*============================== TYPEDEFS ============================*/

typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<bool> vb;
typedef queue<int> qi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
/*============================ START FROM HERE =======================*/

int main(){
	FIO
	
	int n;cin>>n;
	int a[n];rep(i,0,n)cin>>a[i];
	int b[n];rep(i,0,n)cin>>b[i];
	int c[n-1];rep(i,0,n-1)cin>>c[i];
	int ans=0;
	rep(i,0,n-1){
		ans+=b[a[i]-1];
		if(a[i]+1==a[i+1])ans+=c[a[i]-1];
	}
	ans+=b[a[n-1]-1];
	cout<<ans;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll result;
    if(abs(A-B) % 2 == 0)result = abs(A-B) /2;
    else{
        ll resa = ((N-A) + (N-B) + 1)/2;
        ll resb = (A+B-1)/2;
        result = min(resa, resb);
        /*
        //2つのあいだよりも端のほうが近い場合
        if((N+1/2) <= A) {
            result = ((N-A) + (N-B) + 1)/2;
        }
        else if((N/2+1) >= B){
            result = (A+B-1)/2;
        }
        else {
            if(((N/2) - A) < (B-(N/2))){
                result = ((N-A) + (N-B) + 1)/2;
            }
            else{
                result = (A+B-1)/2;
            }
        }
         */
    }

    cout << result << endl;

    return 0;
}


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

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

    int N;
    string S;
    cin >> N >> S;

    int ans = 0;

    for(int i=2; i<S.size(); i++)
        ans += (S[i-2] == 'A' && S[i-1] == 'B' && S[i] == 'C');

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


Measured memory_bytes: 256
using System;

class Plogram
{
    static void Main()
    {

        var num = Console.ReadLine().Split();
        int A = int.Parse(num[0]);
        int B = int.Parse(num[1]);
        int K = int.Parse(num[2]);
        int count = 0;

        for(int i = A; i > 0; i--)
        {
            if(A % i == 0 && B % i == 0)
            {
                count++;
            }
            if(count == K)
            {
                Console.WriteLine(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 13140
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 100005;

int N, p[MN], c[MN], d[MN], k[MN], g[MN], Ans;
int q[MN], l, r;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &p[i]), ++d[p[i]];
	for (int i = 1; i <= N; ++i) if (d[i] > 2) return puts("0"), 0;
	for (int i = 1; i <= N; ++i) if (!d[i]) q[++r] = i;
	while (l < r) {
		int u = q[++l], x = p[u];
		k[x] = k[u] + 1;
		if (++c[x] == d[x]) q[++r] = x;
	}
	for (int i = 1; i <= N; ++i) if (c[i] > 1) return puts("0"), 0;
	Ans = 1;
	for (int i = 1; i <= N; ++i) if (c[i] < d[i]) {
		q[r = 1] = i;
		for (int x = p[i]; x != i; x = p[x]) q[++r] = x;
		int lst = 0;
		for (int j = 1; j <= r; ++j) if (c[q[j]]) lst = j;
		for (int j = 1; j <= r; ++j) c[q[j]] = d[q[j]];
		if (!lst) { ++g[r]; continue; }
		lst -= r;
		for (int j = 1; j <= r; ++j) if (k[q[j]]) {
			if (k[q[j]] > j - lst) return puts("0"), 0;
			if (k[q[j]] < j - lst) Ans = 2 * Ans % Mod;
			lst = j;
		}
	}
	for (int i = 1; i <= N; ++i) if (g[i]) {
		int x = 1, y = 1 + (i >= 3 && i & 1), z;
		for (int j = 2; j <= g[i]; ++j)
			z = ((1 + (i >= 3 && i & 1)) * y + (LL)x * (j - 1) * i) % Mod, x = y, y = z;
		Ans = (LL)Ans * y % Mod;
	}
	printf("%d\n", Ans);
	return 0;
}

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

using namespace std;

using ll = long long;

int main(){
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for(int a = 0; a < k; ++ a){
		int b = (k - a) % k;
		if((2 * b) % k == 0){
			ll cnt = n / k + (b && ((n % k) >= b));
			ans += cnt * cnt * cnt;
		}
	}
	cout << ans << '\n';
}


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



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

    if(n==1)
        cout<<1<<endl;

    else{
        long long int s=0;
        long long int f=1;

        while(n!=0){
            s+=f;
            f=f*2;

            n=n/2;
        }

        cout<<s<<endl;
    }


}


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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>

using namespace std;

int main(){
	int N=0;
	cin>>N;
	int c[100003]={0};
	for(int i=0;i<N;i++){
		cin>>c[i];
	}
	long long ans=0;
	for(int i=0;i<N;i++){
		if(i>0){
			if((c[i-1]==1) && (c[i]>0)){
				ans+=1LL;
				c[i]-=1;
			}
		}
		ans+=(long long)c[i]/2LL;
		c[i]=c[i]%2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
import fractions

def monsters_battle_royal(n, a):
    gcd = a[0]
    for i in range(1, n):
        gcd = fractions.gcd(gcd, a[i])
    return gcd

n = int(input())
a = list(map(int, input().split()))

ans = monsters_battle_royal(n, a)
print(ans)


Measured memory_bytes: 16240
import java.util.Scanner;

public class Main { //InsertionSort

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			int min = i;
			for(int j = i; j < n; j++) {
				if(arr[min] > arr[j]) {
					min = j;
				}
			}
			if(i != min) {
				count++;
			}
			int v = arr[min];
			arr[min] = arr[i];
			arr[i] = v;
		}
		for(int i = 0; i < n; i++) {
			if(i == n - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26424
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
    //Enter your code here Tanmay:)
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2!=0)
        cout<<"No";
    else 
    {
        for(char ch='a';ch<='z';ch++)
        {
            int cnt=0;
            for(int j=0;j<s.size();j++)
            {
                if(s.at(j)==ch)
                    cnt++;
            }
            if(cnt%2!=0)
                {cout<<"No";
            exit(0);}
        }
        cout<<"Yes";
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
using namespace std;

typedef long long ll;

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

    vector<int> vec(n);
    for(int i = 0; i < n; i++) scanf("%d", &vec.at(i));

    int minimum = vec.at(0);
    int ans = 0;

    for(int i = 0; i < n; i++)
    {
        if(minimum >= vec.at(i)) ans++;
        minimum = min(minimum, vec.at(i));
    }

    cout << ans << endl;


    
    
    
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

string s;
int n;

bool C(int x)
{
    if(x > n){
        return false;
    }
    int cnt = 0;
    string t = s;
    int rev[100005] = {0};
    for(int i = 0; i <= n - x; i++){
        if(i > 0){
            rev[i] += rev[i - 1];
        }
        if(t[i] == '0' && rev[i] % 2 == 1){
            rev[i]++;
            if(i + x < n){
                rev[i + x]--;
            }
        }
        else if(t[i] == '1' && rev[i] % 2 == 0){
            rev[i]++;
            if(i + x < n){
                rev[i + x]--;
            }
        }
    }
    for(int i = n - x + 1; i < n; i++){
        if(i > 0){
            rev[i] += rev[i - 1];
        }
        if((t[i] == '0' && rev[i] % 2 == 1) || (t[i] == '1' && rev[i] % 2 == 0)){
            if(i >= x){
                return true;
            }
            else{
                return false;
            }
        }
    }
    return true;
}

int bs(int lb, int ub)
{
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        if(C(mid)){
            lb = mid;
        }
        else{
            ub = mid;
        }
    }
    return lb;
}

signed main()
{
    cin >> s;
    n = s.size();
    cout << bs(1, n + 1) << endl;


    return 0;
}
/*


*/


Measured memory_bytes: 1280
#include <stdio.h>

int main(void) {
    long long int K, A, B, ans, R, S, coin;
    ans = 1;
    coin = 0;
    scanf("%lld%lld%lld", &K, &A, &B);
    if (A > B || A >= K) {
        printf("%lld", K + 1);
    } else {
        K -= A - 1;
        ans += A - 1;
        // printf("ans=%lld,K=%lld\n", ans, K);
        R = B - A;
        while (K > 1 && R > 1) {
            ans += R;
            K -= 2;
            //   printf("while:ans=%lld,K=%lld\n", ans, K);
        }
        ans += K;
        printf("%lld", ans);
    }
    return 0;
}


Measured memory_bytes: 128
#-*- coding: utf-8 _*_
import datetime
 
def is_leap(y):
    if y%400==0:   return True
    if y%100==0:   return False
    if y%4==0:     return True
    return False
 
def get_day(y,m,d):
    if m<=2:
        y-=1
        m+=12
    dy = 365*(y-1)
    c = y/100
    dl=(y>>2)-c+(c>>2)
    dm=(m*979-1033)>>5
    return dy+dl+dm+d-1
 
def solve(line):
    ipt = map(int, line.split("."))
#     print ipt
    if len(ipt) >3:
        n=0
        for i in range(5):  n+=ipt[i]*mm[i]
        date = datetime.date.fromordinal(offset+n+1)
        print str(date.year)+"."+str(date.month)+"."+str(date.day)
    else:
        n=get_day(*ipt)-offset
#         print n
        n%=1872000
        ret=""
        for i in range(4):
            ret+=str(n/mm[i])+"."
            n%=mm[i]
        ret+=str(n)
        print ret
 
if __name__=='__main__':
    # const
    mm=(144000,7200,360,20,1)
    w1=(0,0,31,59,90,120,151,181,212,243,273,304,334,365)
    w2=(0,0,31,60,91,121,152,182,213,244,274,305,335,366)
    offset = get_day(2012,12,21)
#     print datetime.MAXYEAR
     
    while True:
        line=raw_input()
        if line=="#":   exit()
        solve(line)

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


class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def size(self, x):
        return -self.parent[self.find(x)]

    def find(self, x):
        if (self.parent[x] < 0):
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if (x == y):
            return False
        if (self.size(x) < self.size(y)):
            self.parent[y] += self.parent[x]
            self.parent[x] = y
        else:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N = int(input())
    x_list = []
    y_list = []
    x_app = x_list.append
    y_app = y_list.append
    for i in range(N):
        x, y = (int(x) for x in input().split())
        x_app([x, i])
        y_app([y, i])

    x_list.sort()
    y_list.sort()
    adj = []
    adj_app = adj.append
    for i in range(N-1):
        adj_app((x_list[i + 1][0] - x_list[i][0], x_list[i + 1][1], x_list[i][1]))
        adj_app((y_list[i + 1][0] - y_list[i][0], y_list[i + 1][1], y_list[i][1]))

    adj.sort(key=lambda x: x[0])
    uf = UnionFind(N)
    ans = 0
    for edge in adj:
        if not uf.same(edge[1], edge[2]):
            ans += edge[0]
            uf.unite(edge[1], edge[2])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 133724
import java.util.*;
public class Main {
    static int[] v;
    static int[] dist;
    static int INF = 1000000000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        // List<Edge>[] g = new List[n + 1];
        List<List<Edge>> g = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            g.add(new ArrayList<>());
        }
        dist = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            dist[i] = INF;
        }
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int d = sc.nextInt();
            // g[l].add(new Edge(r, d));
            // g[r].add(new Edge(l, -d));
            g.get(l).add(new Edge(r, d));
            g.get(r).add(new Edge(l, -d));
        }
        if (bfs(g, n)) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

    public static boolean bfs(List<List<Edge>> g, int n) {
        for (int i = 1; i <= n; i++) {
            if (dist[i] != INF) {
                continue;
            }
            Queue<Integer> que = new LinkedList<>();
            que.offer(i);
            dist[i] = 0;
            while (!que.isEmpty()) {
                int v = que.poll();
                for (Edge e : g.get(v)) {
                    if (dist[e.to] == INF) {
                        dist[e.to] = dist[v] + e.cost;
                        que.offer(e.to);
                    } else if (dist[e.to] != dist[v] + e.cost) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
class Edge {
    int to;
    int cost;
    public Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}


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

int main(void){
    int n,x;
    cin >> n >> x;
    int l;
    int place = 0;
    int count = 1;
    for(int i = 0;i < n;i++){
        cin >> l;
        place += l;
        if(place <= x){
            count++;
        } else {
            break;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_4_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] target = ReadIntAr();
            int m = ReadInt();
            int[] searchKeys = ReadIntAr();

            int cnt = 0;
            for (int i = 0 ; i < searchKeys.Length ; i++)
            {
                if (Array.BinarySearch(target, searchKeys[i]) >= 0) cnt++;
            }
            Console.WriteLine(cnt.ToString());
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << " " << a * 2 + b * 2 << endl;
}


Measured memory_bytes: 3096
/* while(!cin.eof()) */

#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e18+100)
#define N 1000200 

int fre[N];

// Driver code to test above functions
int32_t main()
{
    
 
    

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

    a--;
    b--;
    cout << b/a + (b%a!=0);


    return 0;  
} 

Measured memory_bytes: 256
N,K = list(map(int, input().split()))
V = list(map(int, input().split()))

ans = -1e9
for leftops in range(min(N,K)+1):
  for rightops in range(min(N,K)-leftops+1):
    X = V[:leftops] if leftops > 0 else []
    X = X + V[-rightops:] if rightops > 0 else X
    work = sum(X)
    #print(leftops,rightops,work)
    #print(X)
    X.sort()
    
    if len(X) == 0:
      ans = max(ans,0)
      continue
      
    for k in range(min(K-leftops-rightops,len(X))):
      if X[k] < 0:
        work -= X[k]
      else:
        break
    ans = max(ans,work)
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,n,k,i,j, q, b, c;
    cin >> n;
    vector<ll> v(n + 5, INT_MAX);
    map<ll, ll> m;
    ll xr = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        xr ^= v[i];
    }
    for(int i = 0; i < n; i++){
        cout << (xr ^ v[i]) << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4748
#define LL long long
#include<iostream>
using namespace std;

int main(){
	LL a,b,c;
	cin>>a>>b>>c;
	a =b*10+c;
	if(a%4==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int n,a,b,t[10];  
string s;

int main() {
  rep(i,3){
    cin >> a >> b;
    t[a]++,t[b]++;
  }
  if(t[1]>2 || t[2]>2 || t[3]>2 || t[4]>2)
  cout << "NO" << endl;
  else 
  cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef double db;
ll a[1005];
int main(){
    ll n;cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    ll now=1000;
    for(ll i=1;i<n;i++){
        if(a[i]<a[i+1]){
            now=now/a[i]*a[i+1]+now%a[i];
        }
    }
    cout<<now<<endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double n, m, d;
    cin >> n >> m >> d;
    double ans;
    if(d == 0) ans = 1/n;
    else ans = 2*(n-d)/(n*n);
    ans *= (m-1);
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long dg(long long n,long long x){
	if(x>n) swap(n,x);
	if(n%x==0) return (n/x*2-1)*x;
	return dg(x,n%x)+n/x*2*x;
}
int main(){
	long long n,x;
	scanf("%lld%lld",&n,&x);
	printf("%lld",dg(x,n-x)+n);
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
    val scan = new java.util.Scanner(System.in)
    val n, t = scan.next().toInt
    val as = (1 to n).toArray.map(_ => scan.next().toInt)
    var mins = as.scan(as(0))((n, m) => math.min(n,m)).drop(1)
    val cost = (0 until n).map(i => as(i) - mins(i)).zip(0 until n).sorted.reverse
    val min = cost.filter(_._1 == cost(0)._1).map(_._2)
    println(min.length)
}

Measured memory_bytes: 59956
#include <stdio.h>

#define MAX 100000
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node T[MAX];

int n,H,D[MAX];

int getdepth(int u){
  int d = 0;
  while(T[u].p!=NIL){
    u = T[u].p;

    d++;
  }

  return d;
}

void print(int u){

  int i,C;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);

  if(T[u].p == NIL){
    printf("root, ");
  }

  else if(T[u].l == NIL){
    printf("leaf, ");
  }

  else{
    printf("internal node, ");
  }

  printf("[");

  for(i=0,C=T[u].l;C!=NIL;i++,C=T[C].r){
    if(i){
      printf(", ");
    }
    printf("%d",C);

  }
  printf("]\n");
}

int main(){
  int i,j,d,v,C,l;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&C);
      if(j == 0){
	T[v].l = C;
      }
      else{
	T[l].r = C;
      }
      l = C;
      T[C].p = v;
    }
  }

  H = 0;
  for(i=0;i<n;i++){
    D[i] = getdepth(i);
    if(D[i] > H){
      H = D[i];
    }
  }

  for(i=0;i<n;i++){
    print(i);
  }

  return 0;




}



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

int main(){
    long double a, b, c;
    cin >> a >> b >>c;
    long double ansA,ansB;
    ansA = sqrtl(a);
    ansB = sqrtl(b);

    if (a + b + 2*(ansA*ansB) < c) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}

signed main(){
	int n,m;cin>>n>>m;
	multiset<int,greater<int>> ms;
	rep(i,n){
		int a;cin>>a;
		ms.insert(a);
	}
	rep(i,m){
		int tar=*ms.begin();
		ms.erase(ms.begin());
		tar/=2;
		ms.insert(tar);
	}
	int ans=0;
	for(auto c:ms) ans+=c;
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var n = p[0];
		var k = p[1];
		
		var red = n-k;
		
		fac = new long[510000];
		finv = new long[510000];
		inv = new long[510000];
		COMinit();
		for(int i = 0; i < k; i++)
		{
			var pos = red + 1;
			long pattern = 1;
			long posk = 1;
			posk = COM(pos, i+1);
			pattern = COM(k-1, i);
			
			Console.WriteLine((posk * Math.Max(1, pattern)) % Giri);
		}
	}

	private static long[] fac;
	private static long[] finv;
	private static long[] inv;
	

	
	static void COMinit()
	{
		 fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    inv[1] = 1;
	    for (int i = 2; i < 510000; i++){
	        fac[i] = fac[i - 1] * i % Giri;
	        inv[i] = Giri - inv[Giri%i] * (Giri / i) % Giri;
	        finv[i] = finv[i - 1] * inv[i] % Giri;
	    }
	}
	
	static long COM(int n, int k)
	{
	    if (n < k) return 0;
	    if (n < 0 || k < 0) return 0;
	    return fac[n] * (finv[k] * finv[n - k] % Giri) % Giri;
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 23124
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>

int main() {
	int i, n, S[13], H[13], D[13], C[13], num;
	char suit[20];

	for (i = 0; i < 13; i++) {
		S[i] = 0;
		H[i] = 0;
		D[i] = 0;
		C[i] = 0;

	}
	scanf("%d", &n);

	for (i = 1; i <= n; i++)
	{
		scanf("%s %d", suit, &num);

		if (strcmp(suit, "S") == 0) {
			S[num - 1] = 1;
		} else	if (strcmp(suit, "H") == 0) {
			H[num - 1] = 1;
		} else	if (strcmp(suit, "C") == 0) {
			C[num - 1] = 1;
		} else	{
			D[num - 1] = 1;
		}

	}

	for (i = 0; i < 13; i++) {
		if (S[i] == 0) {
			printf("S %d\n", i +1);
		}
	}


	for (i = 0; i < 13; i++) {
		if (H[i] == 0) {
			printf("H %d\n", i +1);
		}
	}


	for (i = 0; i < 13; i++) {
		if (C[i] == 0) {
			printf("C %d\n", i +1);
		}
	}


	for (i = 0; i < 13; i++) {
		if (D[i] == 0) {
			printf("D %d\n", i+1);
		}
	}

	
	return 0;
}

Measured memory_bytes: 1840
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;


int main()
{
  int s, w;
  cin >> s >> w;

  string res;
  if(w >= s) res = "unsafe";
  else res = "safe";

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


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
	int n, m, c;
	cin >> n >> m >> c;
	int b[21];
	int a[21][21];
	int ans = 0;
	rep(i, 0, m)cin >> b[i];
	rep(i, 0, n)rep(j, 0, m)cin >> a[i][j];
	rep(i, 0, n) {
		int sum = c;
		rep(j, 0, m)sum += a[i][j]*b[j];
		if (sum > 0)ans++;
	}
	cout << ans << endl;
}

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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

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

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

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

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};



const int N = 100005;
vector<int> T[N];
int n;
vector<int> dists;

void dfs(int v, int d = 0, int p = -1) {
    dists[v] = d;
    for (auto c : T[v]) {
        if (c == p) continue;
        dfs(c, d+1, v);
    }
}
vector<int> calcDist(int v) {
    dists = vector<int>(n);
    dfs(v);
    return dists;
}


int main() {
    int u, v; cin >> n >> u >> v;
    u--;
    v--;
    rep(i,n-1) {
        int a, b; cin >> a >> b;
        a--;
        b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    
    vector<int> distT = calcDist(u);
    vector<int> distV = calcDist(v);
    
    int mx = 0;
    rep(i,n) {
        if (distT[i] < distV[i]) {
            mx = max(mx, distV[i]);
        }
    }
    
    cout << mx - 1 << endl;
}


Measured memory_bytes: 12536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.length();
	if(n&1)
	{cout<<"No";return 0;}
	
	for(int i=0;i<n-1;i+=2)
	{
		if(s[i]!='h' or s[i+1]!='i')
		{cout<<"No";return 0;}
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
import math

a = int(raw_input())

while a	> 0:
    a -= 1
    x1,y1,x2,y2,x3,y3 =	map(float,raw_input().split())

    a1 = 2*(x2-x1)
    b1 = 2*(y2-y1)
    c1 = x1*x1-x2*x2+y1*y1-y2*y2
    a2 = 2*(x3-x1)
    b2 = 2*(y3-y1)
    c2 = x1*x1-x3*x3+y1*y1-y3*y3

    X = (b1*c2-b2*c1)/(a1*b2-a2*b1)
    Y = (c1*a2-c2*a1)/(a1*b2-a2*b1)

    R = math.sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1))

    print "%.3f %.3f %.3f" % (X,Y,R)

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , p , a[55];
    long long gu=0 , ki=0 , ans=0 , allgu=0 , GN=1 , GR=1 ,KN=1 , KR=1;
    cin >> n >> p;
    for(int i=0 ;i<n ;i++ ){
        cin >> a[i];
        if(a[i]%2 == 1){
            ki++;
        } else {
            gu++;
        }
    }
    
    for(long long i=1 ;i<=gu ;i++ ){
        GN  *= gu-i+1 , GR *= i;
        if(GN%GR == 0){
            GN = GN/GR , GR = 1;
        }
        allgu += GN/GR;
    } 
    allgu++;
    
    if(p == 0){
        ans += allgu;
        for(long long i=2 ;i<=ki ;i+=2 ){
            KN *= (ki-i+1) * (ki-i+2) , KR *= (i-1) * i;
            if(KN%KR == 0){
                KN = KN/KR , KR = 1;
            }
            ans += allgu * (KN / KR);
        }
    } else {
        ans += allgu * ki;
        KN = ki;
        for(long long i=3 ;i<=ki ;i+=2 ){
            KN *= (ki-i+1) * (ki-i+2) , KR *= (i-1) * i;
            if(KN%KR == 0){
                KN = KN/KR , KR = 1;
            }
            ans += allgu * (KN / KR);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
N, M, Q = map(int, sys.stdin.readline().split())
students = deque(range(N))
rotate, popleft = students.rotate, students.popleft
for n in map(int, sys.stdin.readline().split()):
    rotate(-(n%N if n%2==0 else -n%N))
    popleft()
    N -= 1
students = set(students)
print("\n".join("1" if n in students else "0" for n in map(int, sys.stdin.readline().split())))


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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int N; cin>>N;
  int X[N]; for (int i=0; i<N; i++) cin>>X[i];
  int Y[N]; for (int i=0; i<N; i++) Y[i]=X[i];
  sort(Y,Y+N);
  for (int i=0; i<N; i++) cout<<(X[i]<Y[N/2]?Y[N/2]:Y[N/2-1])<<endl;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll x, k, d; cin >> x >> k >> d;
    // 0をまたげない
    if ((double)abs(x) / d > k) {
        cout << abs(x) - k * d << endl;
        return 0;
    }
    // 0をまたげる
    ll used_times = floor((double)abs(x) / d);
    ll close_zero;
    if (x < 0) close_zero = x + used_times * d;
    else close_zero = x - used_times * d;
    ll remain_times = k - used_times;
    // cout << used_times << " " << close_zero << " " << remain_times << endl;
    if (remain_times % 2 == 0) {
        cout << abs(close_zero) << endl;
    }
    else {
        if (close_zero < 0) 
            cout << abs(close_zero + d) << endl;
        else 
            cout << abs(close_zero - d) << endl;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
using namespace std;

#define pb push_back
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define sz size()

typedef complex<int> P;
typedef vector<P> V;

int n;

bool same(V a,V b){
	rep2(i,1,a.sz){
		if(a[i]-b[i]!=a[0]-b[0])return 0;
	}
	return 1;
}

int main(){
	while(cin>>n && n){
		V v;
		int m,x,y;
		cin>>m;
		rep(i,m){
			cin>>x>>y;
			v.pb(P(x,y));
		}
		rep(h,n){
			V w;
			cin>>m;
			rep(i,m){
				cin>>x>>y;
				w.pb(P(x,y));
			}
			if(m!=v.sz)continue;
			rep(i,2){
				rep(j,4){
					if(same(v,w)){
						cout<<h+1<<endl;
						goto out;
					}
					rep(k,m)w[k]=w[k]*P(0,1);
				}
				reverse(w.begin(),w.end());
			}
			out:;
		}
		cout<<"+++++\n";
	}
}

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

int main(){
  int m, nmin, nmax;
  while(cin >> m >> nmin >> nmax, m || nmin || nmax){
    nmin--;
    nmax--;
    vector<int> v(m);
    
    for(int i = 0; i < m; i++){
      cin >> v[i];
    }

    pair<int, int> ans = make_pair(0, 0);

    for(int i = nmin; i <= nmax; i++){
      if(v[i] - v[i + 1] >= ans.second){
        ans = make_pair(i + 1, v[i] - v[i + 1]);
      }  
    } 
    cout << ans.first << endl;
  }
}

Measured memory_bytes: 3124
#include<stdio.h>
int main(void){
    int a,b,c;
    scanf("%d",&c);
    scanf("%d %d",&a,&b);
    for(int i=a;i<=b;i++){
        if(i%c==0){
        printf("OK");
        return 0;
    }
    }
    printf("NG");
    return 0;
}

Measured memory_bytes: 1732
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int x[200],y[200],n,d,p;
  int xmn,xmx,ymn,ymx;
  while(cin>>n&&n){
    x[0]=y[0]=xmn=xmx=ymn=ymx=0;
    for(i=1;i<n;i++){
      cin>>d>>p;
      if(0){
      }else if(p==0){
	x[i]=x[d]-1;
	y[i]=y[d];
	if(xmn>x[i])
	  xmn=x[i];
      }else if(p==1){
	x[i]=x[d];
	y[i]=y[d]+1;
	if(ymx<y[i])
	  ymx=y[i];
      }else if(p==2){
	x[i]=x[d]+1;
	y[i]=y[d];
	if(xmx<x[i])
	  xmx=x[i];
      }else if(p==3){
	x[i]=x[d];
	y[i]=y[d]-1;
	if(ymn>y[i])
	  ymn=y[i];
      }
    }
    cout<<xmx-xmn+1<<" "<<ymx-ymn+1<<endl;
  }
  return 0;
}

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

int main(){
  
  int N;
  //vector<int> A(N);
  float F;
  cin >> N;
  float r=0;
  
  for(int i=0; i<N; i++){
    cin >> F;
    r = r + (1/F);
  }
  
  cout << 1/r << endl; 
  
  return 0;
}







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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

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

template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<ll>;
V(size_t) -> V<ll>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll W, H, x, y;
    cin >> W >> H >> x >> y;

    ld res = (ld)W * H / 2.0;

    ll huku;
    if(2*x==W and 2*y==H){
        huku = 1;
    }else{
        huku = 0;
    }

    cout << res spa huku << endl;

    return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <tuple>
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<pint> ab(N);
    for (int i = 0; i < N; ++i) cin >> ab[i].first >> ab[i].second;

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

    ll res = 0;
    ll sum = 0;
    for (auto&& _ab : ab) {
        sum += _ab.second;
        if (sum >= K) {
            res = _ab.first;
            break;
        }
    }
    cout << res << endl;
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

ll s;

int main() {
    scanf("%lld",&s);
    printf("0 0 1000000000 1 %lld %lld\n",1ll*inf*((s-1)/inf+1)-s,(s-1)/inf+1);
    return 0;
}


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

int main(){
        int n, x;
        int c = 0;
        int sum;
        while(1){
                cin >> n >> x;
                if(n ==0 && x== 0)break;
                for (int i = 1;i <=n-2 ; i++){
                        for(int j = i+1,sum = 0; j <= n -1; j++){
                                for(int k = j+1; k<= n; k++){
                                sum = i + j + k;
                        if(sum ==x){c++; break;}
                                }
                        }
                }
                cout << c <<endl;
                c = 0;
        }
}


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

#define ll long long
#define PI acos(-1.0)
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  int N;
  int K;
  cin >> N >> K;
  bool D[10];  //嫌な数字ならtrue
  FOR(i, 0, 10) D[i] = false;
  FOR(i, 0, K) {
    int d;
    cin >> d;
    D[d] = true;
  }
  //全探索
  FOR(i, 0, 10 * N) {
    if (N <= i) {
      int check = true;
      string s = to_string(i);
      FOR(j, 0, s.length()) {
        if (D[s[j] - '0']) check = false;
      }
      if (check) {
        cout << i << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3644
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto a = new int[][](3, 3);
  foreach (i; 0..3) {
    a[i] = readln.chomp.split.to!(int[]);
  }
  auto n = readln.chomp.to!int;
  foreach (_; 0..n) {
    auto b = readln.chomp.to!int;
    foreach (i; 0..3) {
      foreach (j; 0..3) {
        if (a[i][j] == b) {
          a[i][j] = -1;
        }
      }
    }
  }
  
  auto f = false;

  foreach (i; 0..3) {
    int sum1, sum2, sum3, sum4;
    foreach (j; 0..3) {
      sum1 += a[i][j];
      sum2 += a[j][i];
      sum3 += a[j][j];
      sum4 += a[j][2-j];
    }
    if (sum1 == -3 || sum2 == -3 || sum3 == -3 || sum4 == -3) {
      f = true;
    }
  }
  if (f) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b;cin >> a >> b;
    if(b == 1){
        cout << 0 << endl;
    }else{
        for(int i=1;;i++){
            int sum = (a-1)*(i-1) + a;
            if(sum >= b){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}


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

using namespace std;

class DICE {
public:
	int top;
	int bottom;
	int right;
	int left;
	int front;
	int back;
	void South();
	void North();
	void East();
	void West();
};

void DICE::South() {
	int kari = front;
	front = top;
	top = back;
	back = bottom;
	bottom = kari;
}

void DICE::North() {
	int kari = front;
	front = bottom;
	bottom = back;
	back = top;
	top = kari;
}

void DICE::West() {
	int kari = top;
	top = left;
	left = bottom;
	bottom = right;
	right = kari;
}

void DICE::East() {
	int kari = top;
	top = right;
	right = bottom;
	bottom = left;
	left = kari;
}

int main() {
	DICE d;
	cin >> d.top >> d.front >> d.left >> d.right >> d.back >> d.bottom;
	string a;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'S') {
			d.South();
		} else if (a[i] == 'N') {
			d.North();
		} else if (a[i] == 'E') {
			d.East();
		} else {
			d.West();
		}
	}
	cout << d.top << endl;
	return 0;
}

Measured memory_bytes: 1204
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;

const int mod = 998244353;

int add(int a, int b) {
	return ((ll)a + b + mod) % mod;
}

void solve() {
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> a(k);
	for (int i = 0; i < k; i++) {
		cin >> a[i].first >> a[i].second;
	}

	vector<int> dp(n + 1, 0);
	dp[1] = 1;
	int sum = 0;
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int l = i - a[j].second - 1;
			int r = i - a[j].first;
			if (l >= 0)
				sum = add(sum, -dp[l]);
			if (r >= 0)
				sum = add(sum, dp[r]);
		}
		dp[i] = sum;
	}

	cout << dp[n];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
using namespace std;

void next(vector<int>& v, int& len){
	int n = v.size();
	int pos = v.size()-1;
	for (int i=n-1; i>n-len; i--){
		if (v[i]==v[i-1]+1 || v[i]==9) pos--;
		else break;
	}
	if (v[pos]==9){
		pos--;
		len++;
	}
	v[pos]++;
	for (int i=pos+1; i<n; i++){
		v[i]=max(v[i-1]-1,0);
	}
}

void print(vector<int>& v, int& len){
	for (int i=v.size()-len; i<v.size(); i++){
    	cout << v[i];
    }
    cout << endl;
}

int main(){
    int k, len=1;
    vector<int> v(100,0);
    cin >> k;
    for (int i=0; i<k; i++){
    	next(v,len);
    	//print(v,len);
    }
    print(v,len);
    return 0;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc095/tasks/arc096_a */

#include <iostream>

int solve(const int A, const int B, const int C, const int X, const int Y)
{
  int min_price = 1e5 * 5000 * 2;

  int max_num = std::max(X, Y);
  min_price = std::min(min_price, C*2*max_num);

  min_price = std::min(min_price, A*X + B*Y);

  if (X > Y) {
    min_price = std::min(min_price, C*2*Y + A*(X-Y));
  } else {
    min_price = std::min(min_price, C*2*X + B*(Y-X));
  }

  return min_price;
}

int main(int argc, char *argv[])
{
  // Input
  int A, B, C, X, Y;

  std::cin >> A >> B >> C >> X >> Y;

  // Output
  std::cout << solve(A, B, C, X, Y) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n>>a;
  b=n/500;
  b*=500;
  n-=b;
  if(n<=a){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}

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

s = [input() for _ in range(n)]

cnt = sum(x.count("AB") for x in s)

cnt_a = sum(x[-1] == "A" for x in s)
cnt_b = sum(x[0] == "B" for x in s)

cnt_ab = sum(x[0] == "B" and x[-1] == "A" for x in s)

if cnt_a == cnt_b == cnt_ab > 0:
    print(cnt + cnt_a - 1)
else:
    print(cnt + min(cnt_a, cnt_b))

Measured memory_bytes: 3700
import sys

S = input()

flag = 0

for s in S:
    if s == "h":
        flag = flag + 1
        if flag >= 2:
            print("No")
            sys.exit()
    elif s == 'i':
        flag = flag - 1
        if flag < 0:
            print("No")
            sys.exit()
    else:
        print("No")
        sys.exit()

if s == "h":
    print("No")
    sys.exit()    

print("Yes")



Measured memory_bytes: 3060