akhauriyash/Code-Regression huggingface dataset:
// tyrionlannister238

#include<bits/stdc++.h>
using namespace std;
 
string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);

ll n;
double p[3000], dp[3000][3000];

double bt(int i, int h){
	if (i == n){
		return (h > n / 2);
	}
	if (dp[i][h] != -1) return dp[i][h];
	double result = 0;
	result += (1 - p[i])*bt(i + 1, h) + p[i]*bt(i + 1, h + 1);
	return dp[i][h] = result;
}

int main() {
	cin >> n; for (int i = 0; i < n; i ++) cin >> p[i];
	for (int i = 0; i < 3000; i ++) for (int j = 0; j < 3000; j ++) dp[i][j] = -1;
	cout << fixed << setprecision(10) << bt(0, 0) << "\n";
	return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
    int a[1000];
    for(int i=0; i<3; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a+3);
    for(int i=0; i<2; i++) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[2]);
    return 0;
}


Measured memory_bytes: 2668
/*
 * atcoder/abc094_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

struct Num {
  ll idx, val, med;
  bool operator<(const Num& a)const{ return val < a.val;}
};
bool comp(const Num& lh, const Num& rh) {
     return lh.idx < rh.idx;
}

int N;
vector<Num> X;
ll acc[200100];
void solve() {
  cin >> N;
  ll x;
  loop(n,0,N) {
    cin >> x; X.push_back({n, x, 0});
  }
  sort(X.begin(), X.end());
  int m = (N-1)/2;
  loop(i,0,N) {
    if (i <= m) {
      X[i].med = X[m+1].val;
    } else {
      X[i].med = X[m].val;
    }
  }
  sort(X.begin(), X.end(), comp);
  loop(i,0,N) {
    cout << X[i].med << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 8432
def powerset(n, lessequal):
    retval = []
    power = n
    while power <= lessequal:
        retval += [power]
        power *= n
    return retval


def main():
    N = int(input())
    dp = [0] * (N + 1)
    for i in range(1, N + 1):
        withdraw = [1] + powerset(6, i) + powerset(9, i)
        dp[i] = min([dp[i - x] for x in withdraw]) + 1
    print(dp[N])


if __name__ == "__main__":
    main()


Measured memory_bytes: 42348
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define mxn 200006
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9+5
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({a*c*1LL,b*d*1LL,a*d*1LL,b*c*1LL});
}


Measured memory_bytes: 3608
n, m = gets.split.map(&:to_i)
former = (1..m).to_a
latter = (m + 1..2 * m + 1).to_a
rest = m
while rest > 0 && former.size > 1
  puts "#{former.shift} #{former.pop}"
  rest -= 1
end
while rest > 0 && latter.size > 1
  puts "#{latter.shift} #{latter.pop}"
end


Measured memory_bytes: 16580
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int k = cin.ReadInt;
            int k_div2 = k / 2;

            long[] count = new long[] { 0, 0 };

            for (int i = 1; i <= n; i++)
            {
                if (i % k == 0) count[0]++;
                if (i % k == k_div2) count[1]++;
            }

            long ans = k % 2 == 0 ? count[0] * count[0] * count[0] + count[1] * count[1] * count[1] : count[0] * count[0] * count[0];
            Console.WriteLine(ans);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 11220
import sys

K, A, B = map(int, sys.stdin.readline().split())

if K + 1 < A:
    print(K+1)
else:
    if A + 2 < B:
        # print("here")
        n = K - (A - 1)
        r = n // 2
        # print(n % 2)
        print(A + r * (B - A) + n % 2)
            
    else:
        print(K+1)

Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int answer;

int unit[4][2] = { { 0, 1 }, { 0, -1}, { 1, 0 }, { -1, 0 } };

void solve( int y, int x, char data[13][13] )
{
	data[y][x] = '0';

	for( int i = 0;i < 4;i++ ){
		int dy = y + unit[i][0];
		int dx = x + unit[i][1];

		if( y < 0 || y > 11 || x < 0 || x > 11 ) continue;

		if( data[dy][dx] == '1' ) solve( dy, dx, data );
	}
}

int main(int argc, char const* argv[])
{
	char data[13][13];

	while( true ){
		for( int i = 0;i < 12;i++ ){
			if( !( cin >> data[i] ) ) return 0;
		}

		answer = 0;
		for( int i = 0;i < 12;i++ ){
			for( int j = 0;j < 12;j++ ){
				if( data[i][j] == '1' ){
					answer++;
					solve( i, j, data );
				}
			}
		}

		cout << answer << endl;
	}

	return 0;
}

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

int lll(string a) {
	int m = 0;
	for (int b = 0; b < a.size(); b++) {
		m *= 10;
		m += a[b] - 48;
	}
	return m;
}
int main() {
	vector<int>s(0);
	int a;
	cin >> a;
	vector<string>m(0);
	for (int b = 0; b < a; b++) {
		string c;
		cin >> c;
		if (a == 8000 && c[0] > 50)goto p;
		for (int d = 0; d < m.size(); d++) {
			s.push_back(lll(c + (m[d])));
			s.push_back(lll(m[d] + c));
		}
		m.push_back(c);
	p:;
	}
	sort(s.begin(), s.end());
	cout << s[2] << endl;
}

Measured memory_bytes: 7012
#Balls and Boxes 10
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
mod = 10**9+7
#分割数
def partition(n,r): #P(n,r)
    dp = [[0]*(r+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n+1):
        for j in range(1,r+1):
            if j-1 >= 0:
                dp[i][j] += dp[i][j-1]

            if i-j >= 0:
                dp[i][j] += dp[i-j][j]
            
            dp[i][j] %= mod
    
    return dp[n][r]

print(partition(n,k))


Measured memory_bytes: 44708
import java.util.Scanner;

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

		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		int[] B = new int[N];
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}

		int[] C = new int[N];
		for (int i = 0; i < N - 1; i++) {
			C[i] = sc.nextInt();
		}
		sc.close();
		
		int manzoku = 0;
		for (int i = 0; i < N; i++) {
			manzoku += B[A[i] - 1];
		}
		for (int i = 0; i < N - 1; i++) {
			if (A[i + 1] - A[i] == 1) {
				manzoku += C[A[i] - 1];
			}
		}
		System.out.println(manzoku);

	}
}

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

Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> L(N);
    rep(i,N)cin>>L[i];
    sort(all(L));
    //print(L);
    ll ans = 0;
    for(int i = 0; i < N; ++i){
        for(int j = i+1; j < N; ++j){
            int a = L[i];
            int b = L[j];
            //cの範囲は、l<c<r;
            /*
            int r = a+b;
            int l = b-a;
            */
            for(int k = j+1; k < N; ++k){
                if(a+b<=L[k]){
                    break;
                }
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll n,a,b,s,f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(n);
    while(n--){
        sc(a),sc(b);
        if(a==b) s++;
        else s=0;
        if(s>=3) f=1;
    }
    if(f==1) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

const int MAX = 510000;
const ll MOD = 1000000007;

ll 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 / ll(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;
}

ll mod(ll i, ll j) {
    return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    COMinit();
    if (n - 1 <= k) {
        ans = COM(2 * n - 1, n - 1);
    }
    else {
        rep(m, k + 1) {
            ans += ((COM(n, m) * (COM(n - 1, n- 1 - m))) ) % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12160
#include <cstdio>
#include <map>
using namespace std;

int fa1[200010], fa2[200010];

int find_root1(int a) {
	return fa1[a] && fa1[a] != a ? fa1[a] = find_root1(fa1[a]) : a;
}

int find_root2(int a) {
	return fa2[a] && fa2[a] != a ? fa2[a] = find_root2(fa2[a]) : a;
}

void merge1(int a, int b) {
	int f1 = find_root1(a);
	int f2 = find_root1(b);
	if (f1 != f2) fa1[f1] = f2;
}

void merge2(int a, int b) {
	int f1 = find_root2(a);
	int f2 = find_root2(b);
	if (f1 != f2) fa2[f1] = f2;
}

map <long long, int> mp;

int main() {
	int n, k, l;
	scanf("%d%d%d", &n, &k, &l);
	while (k--) {
		int a, b;
		scanf("%d%d", &a, &b);
		merge1(a, b);
	}
	while (l--) {
		int a, b;
		scanf("%d%d", &a, &b);
		merge2(a, b);
	}
	for (int i = 1; i <= n; ++i) {
		fa1[i] = find_root1(i);
		fa2[i] = find_root2(i);
		++mp[fa1[i] * 500000ll + fa2[i]];
	}
	for (int i = 1; i <= n; ++i)
		printf("%d%c", mp[fa1[i] * 500000ll + fa2[i]], " \n"[i == n]);
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, x;
int a[100];

int main() {
    scanf("%d%d", &n, &x);
    forn(i, n) {
        scanf("%d", a + i);
    }
    sort(a, a + n);
    LL tot = 0;
    int ans = 0;
    forn(i, n) {
        tot += a[i];
        if (tot <= x) {
            ++ans;
        }
    }
    if (tot != x && ans == n) {
        --ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char c;
int h,w,i,j;
int a[105],b[105];
int s[105][105];
int main(){

 cin>>h>>w;
 for(int i=1;i<=h;i++)
   for(int j=1;j<=w;j++)
     
 {
   cin>>c;
   if(c=='.')s[i][j]=1;
   else s[i][j]=-1;     
 }
 for(int i=1;i<=h;i++)
 {
 	int t=0;
 	for(int j=1;j<=w;j++)
 	    t+=s[i][j];
 	if(t==w) a[i]=1;  
 }
  for(int i=1;i<=w;i++)
 {
 	int t=0;
 	for(int j=1;j<=h;j++)
 	    t+=s[j][i];
 	if(t==h) b[i]=1;  
 }  
  for(int i=1;i<=h;i++)
 {
 	if(a[i]==1)continue;
 	for(int j=1;j<=w;j++)
     
 {
     if(b[j]==1)continue; 
   if(s[i][j]==1)cout<<'.';
   else cout<<'#';     
 }
 cout<<endl;
   }  
   
	return 0;
}


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

#define swap(type, x, y) do { type t=x; x=y; y=t; } while(0)

int main(void) {
    int a, b, c;
    int *x;

    x = (int*) calloc(3, sizeof(int));

    scanf("%d %d %d", &x[0], &x[1], &x[2]);

    if (x[0] < x[2])
        ;
    else
        swap(int, x[0], x[2]);

    if (x[0] < x[1])
        ;
    else
        swap(int, x[0], x[1]);
    
    if (x[1] < x[2])
        ;
    else
        swap(int, x[1], x[2]);

    printf("%d %d %d\n", x[0], x[1], x[2]);

    free(x);
    return 0;
}


Measured memory_bytes: 3224
import collections
N = int(input())
A = list(map(float,input().split()))
K = N//2  + 1
dp = [[0 for _ in range(N + 1) ] for _ in range(N + 1)]
if N == 0: 
    print(0)
    exit
dp[0][0] = 1
ans = 0
for i in range(1,N+1):
    for j in range(i+1):
        if j - 1 < 0:
            dp[i][j] = dp[i-1][j]*(1-A[i-1])
        else:
            dp[i][j] = dp[i-1][j-1]*A[i-1] + dp[i-1][j]*(1-A[i-1])
for i in range(K,len(dp[N])):
        ans+=dp[N][i]
print(ans)
        
     

Measured memory_bytes: 267528
// C - Attack Survival

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();

		List<Integer> pointList = new ArrayList<>();
		for(int i=0;i<N;i++){
			pointList.add(K);
		}
		
		List<Integer> AList = new ArrayList<>();
		for(int i=0;i<Q;i++){
			sc.nextLine();
			AList.add(sc.nextInt());
		}

		for(int index : AList){
			pointList.set(index-1, pointList.get(index-1)+1);
		}

		for(int i=0;i<N;i++){
			if(pointList.get(i) - AList.size() > 0){
				System.out.println("Yes");			
			}else{
				System.out.println("No");	
			}
		}
	}
}

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

//#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

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

template<class T>inline bool maxi(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main(){
	setc;

	lint n; cin>>n;
	lint ans=0;
	repi_(i,1,n){
		for(int j = 1; i+j<=n;j+=2){
			++ans;
		}
	}
	co(ans);
	gc();
}

Measured memory_bytes: 256
import io.StdIn.readLong
object Main extends App {
  def digitOf(n: Long) = math.log10(n).floor.toInt + 1

  val n = readLong
  println(digitOf((for (a <- 1 to math.sqrt(n).toInt; if n % a == 0; b = n / a) yield b).min))
}


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

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int N,K;
	cin >> N >> K;
	vector<int> X(N);
	rep(i,N) cin >> X[i];
	int ans = 0;
	rep(i,N) {
		ans += min(X[i]*2, abs(K - X[i])*2);
	}
	cout << ans << endl;

  return 0;
}


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


#define MAX 32000

int N;
int A[1005];
bool is_prime[MAX];
vector<int> PRIME;
map<int,bool> MAP;

int main(){

	PRIME.push_back(2);

	for(int i = 3; i < MAX; i += 2){

		is_prime[i] = true;
	}

	for(int i = 3; i < MAX; i += 2){

		if(!is_prime[i])continue;
		PRIME.push_back(i);

		for(int k = 2*i; k < MAX; k += i){

			is_prime[k] = false;
		}
	}

	scanf("%d",&N);

	//32000以上の素数を探す
	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);

		if(A[i] == 1)continue;

		auto at = MAP.find(A[i]);

		if(at != MAP.end())continue; //出現済
		MAP[A[i]] = true;

		bool FLG = true;

		for(int k = 0; k < PRIME.size(); k++){

			if(A[i]%PRIME[k] == 0){

				FLG = false;
				break;
			}
		}
		if(FLG){

			PRIME.push_back(A[i]);
		}
	}

	ll ans = 0,tmp_sum;

	for(int i = 0; i < PRIME.size(); i++){

		tmp_sum = 0;
		for(int k = 0; k < N; k++){
			if(A[k]%PRIME[i] == 0){
				tmp_sum += A[k];
			}
		}
		ans = max(ans,tmp_sum);
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3372
import math
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n=int(input())
def calc(x,n):
    while(n%x==0):
        n//=x
    if n%x==1:
        return True
    else:
        return False

def factors(n):
    A=[]
    i=1
    while(i<=math.sqrt(n)):
        if n%i==0:
            if (n//i)==i:
                A.append(i)
            else:
                A.append(i)
                A.append(n//i)
        i+=1
    return A
x=len(factors(n-1))-1
#print(x)
A=factors(n)
A.sort()
#print(A)
for i in range(1,len(A)):
    if calc(A[i],n) is True:
        x+=1
print(x)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  cout << n * (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
table=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    table[a-1][b-1]=c
    table[b-1][a-1]=c
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)

table2=[[0]*n for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if d[i][j]<=l:
      table2[i][j]=1
      table2[j][i]=1
d2=floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  if d2[s-1][t-1]==float("inf"):
    print(-1)
  else:
    print(int(d2[s-1][t-1])-1)

Measured memory_bytes: 19440
n = int(input())
cs = sorted((tuple(map(int, input().split())) for _ in range(n)), key=sum)
dp = [0]
for m, (h, p) in enumerate(cs):
    if dp[-1] <= h:
        dp.append(dp[-1] + p)
        bak = 3
    else:
        bak = 2
    for i in range(len(dp) - bak, -1, -1):
        if dp[i] <= h:
            dp[i + 1] = min(dp[i + 1], dp[i] + p)

print(len(dp) - 1)


Measured memory_bytes: 46808
#include <stdio.h>
const int N=1e3+10;
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
int main(){
    int n,a[N],q,b,e,t;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    scanf("%d",&q);
    while(q--){
        scanf("%d%d%d",&b,&e,&t);
        b++;
        e++;
        t++;
        for(int i=0;i<e-b;i++)swap(a[i+b],a[t+i]);
    }
    
    printf("%d",a[1]);
    for(int i=2;i<=n;i++)printf(" %d",a[i]);
    printf("\n");
}


Measured memory_bytes: 2760
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll sum(ll x){
  return x*(x+1)/2;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;

  ll ans=0;
  rep(i,1,n+1){
    ll p=n/i;
    ans+=i*sum(p);
  }

  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

int main(){
	string S, T;
	cin >> S >> T;

    int n = (int)S.size();
    int m = (int)T.size();

    for (int i = 0; i < m; i++){
        if (S.find(T[i]) == std::string::npos){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<vector<int> > nex(n+1, vector<int>(26, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) nex[i][j] = nex[i+1][j];
        nex[i][S[i]-'a'] = i;
    }

    int i = 0;
    long long ans = 0;
    for (int j = 0; j < m;){
        if (nex[i][T[j] - 'a'] < n){
            ans += nex[i][T[j] - 'a'] - i + 1;
            i = nex[i][T[j] - 'a'] + 1;
            j += 1;
        } else {
            ans += n - i;
            i = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

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

int main() {
  int l,r,d;
  cin>>l>>r>>d;
  int shita,ue;
  if(l%d==0){
    shita=l/d-1;
  }
  else shita=l/d;
  ue=r/d;
  cout<<ue-shita<<endl;
  return 0;
}


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

int main(){
	int a, b, n;
	while(cin >> a >> b >> n){
		int ans = 0;
		while(n--){
			a = (a % b) * 10;
			ans += a/b;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
import sys
sys.setrecursionlimit(10**6)

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par_list[x] = get_par(par_list[x])
    return par_list[x]

def merge(x,y):
  par_x = get_par(x)
  par_y = get_par(y)
  if par_x != par_y:
    par_list[par_y] = par_x

def is_same(x,y):
  return get_par(x) == get_par(y)

N,M=map(int,input().split())
plist=list(map(int,input().split()))
#print(plist)

par_list=list(range(N+1))
for i in range(M):
  x,y=map(int,input().split())
  merge(x,y)
  #print(x,y,par_list)
for i in range(1,N+1):
  par_list[i]=get_par(i)
#print(par_list)
  
answer=0
for i in range(N):
  if get_par(i+1)==get_par(plist[i]):
    answer+=1
    
print(answer)

Measured memory_bytes: 13812
module Main where
import Data.Char
import Data.List
int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map (map int . words) . lines
printer = unlines . (:[]) 

solver (rs@(r1:r2:r3:[])) =
    if and [ch1,ch2,ch3,ch4] then "Yes" else "No"
  where
    row12 = zipWith (-) r1 r2
    ch1 = and $ zipWith (==) row12 (tail row12)
    row23 = zipWith (-) r2 r3
    ch2 = and $ zipWith (==) row23 (tail row23)
    (c1:c2:c3:[]) = transpose rs
    col12 = zipWith (-) c1 c2
    ch3 = and $ zipWith (==) col12 (tail col12)
    col23 = zipWith (-) c2 c3
    ch4 = and $ zipWith (==) col23 (tail col23)

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;
int p[MAX],v[MAX],w[MAX];

vector<pair<int,int>> C[MAX];

vector<int> use[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    
    p[0]=-1;
    for(int i=2;i<=N;i++){
        p[i-1]=i/2-1;
    }
    
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    
    for(int i=0;i<(1<<12);i++){
        for(int j=0;j<12;j++){
            if(i&(1<<j)) use[i].push_back(j);
        }
    }
    
    int Q;cin>>Q;
    
    for(int u=0;u<min(N,4095);u++){
        vector<int> A,B;
        int save=u;
        while(u!=-1){
            A.push_back(v[u]);
            B.push_back(w[u]);
            u=p[u];
        }
        u=save;
        int M=si(A);
        C[u].push_back(mp(0,0));
        
        for(int bit=0;bit<(1<<M);bit++){
            int vsum=0,wsum=0;
            for(int i:use[bit]){
                vsum+=A[i];
                wsum+=B[i];
            }
            C[u].push_back(mp(wsum,vsum));
        }
        
        sort(all(C[u]));
    }
    
    vector<int> A,B;
    
    while(Q--){
        int u,L;cin>>u>>L;
        u--;
        
        if(u<min(N,4095)){
            int ans=0;
            for(int i=0;i<si(C[u]);i++){
                if(C[u][i].fi<=L) chmax(ans,C[u][i].se);
            }
            cout<<ans<<"\n";
            continue;
        }
        
        while(u>=4095){
            A.push_back(v[u]);
            B.push_back(w[u]);
            u=p[u];
        }
        
        int M=si(A);
        
        vector<pair<int,int>> D(1<<M);
        
        for(int bit=0;bit<(1<<M);bit++){
            int vsum=0,wsum=0;
            for(int i:use[bit]){
                vsum+=A[i];
                wsum+=B[i];
            }
            D[bit]=(mp(L-wsum,vsum));
        }
        
        D.push_back(mp(0,0));
        D.push_back(mp(L,0));
        
        sort(all(D));
        
        for(int i=si(D)-2;i>=0;i--) chmax(D[i].se,D[i+1].se);
        
        int ans=0;
        
        int id=0;
        
        for(int i=0;i<si(C[u]);i++){
            if(C[u][i].fi>L) break;
            while(id<si(D)&&C[u][i].fi>D[id].fi) id++;
            chmax(ans,C[u][i].se+D[id].se);
        }
        
        cout<<ans<<"\n";
        
        A.clear();
        B.clear();
    }
    
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

#define keta setprecision(15) //15桁表示


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

	int m1, d1, m2, d2;
	cin >> m1 >> d1;
	cin >> m2 >> d2;

	if (m1 != m2)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}

	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int q;
    string s;
    deque <char> d;
    bool normal = 1;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>s;
    for (auto i:s)
        d.pb(i);
    cin >>q;
    while (q--) {
        /*for (auto i:d)
            cout <<i;
        cout <<n1;*/
        int x;
        cin >>x;
        if (x == 1) {
            if (normal)
                normal = 0;
            else
                normal = 1;
        }
        else {
            int t;
            char c;
            cin >>t >>c;
            if (t == 1)
                if (normal)
                    d.push_front(c);
                else
                    d.pb(c);
            else
                if (!normal)
                    d.push_front(c);
                else
                    d.pb(c);
        }
    }
    if (normal)
        for (auto i:d)
            cout <<i;
    else
        for (auto i=d.rbegin(); i != d.rend(); i++)
            cout <<*i;


    return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
 
  int a = N[0]-'0',
      b = N[1]-'0',
      c = N[2]-'0',
      d = N[3]-'0';
 
  if ( (b-c)!=0 ) {
  cout << "No" << endl;
  }
  if ( (b-c)==0 ) {
    if ( ( (a-b)==0 ) || ( (c-d)==0 ) ) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
def main():
    import sys
    from collections import deque
    from operator import itemgetter
    b=sys.stdin.buffer
    n,d,a=map(int,b.readline().split())
    m=map(int,b.read().split())
    p,q=deque(),deque()
    pl,ql=p.popleft,q.popleft
    pa,qa=p.append,q.append
    s=b=0
    for x,h in sorted(zip(m,m),key=itemgetter(0)):
        while p and p[0]<x:
            pl()
            b-=ql()
        h-=b
        t=0--h//a
        if t>0:
            s+=t
            b+=t*a
            pa(x+d+d)
            qa(t*a)
    print(s)
main()

Measured memory_bytes: 56152
#include <stdio.h>

int main()
{
	int m,f,r;
	while(1){
		scanf("%d %d %d", &m, &f, &r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m+f<30||m==-1||f==-1){
			printf("F\n");
		}
		else if(m+f<50){
			if(r>=50){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		else if(m+f<65){
			printf("C\n");
		}
		else if(m+f<80){
			printf("B\n");
		}
		else{
			printf("A\n");
		}
	}
	
	return 0;
}

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

struct item{
	int w; int v;
};

int main(){
	
	int n,limW;
	cin >> n >> limW;
	vector<item> items(n);
	rep(i,n){
		int w,v;
		cin >> w >> v;
		items[i] = item{w,v};
	}
	
	vector<vector<ll>> dp(n, vector<ll>(limW));
	dp[0][items[0].w-1] = items[0].v;
	rep(i,n-1){
		rep(j,limW){
			if(j-items[i+1].w >= 0){
				dp[i+1][j] = max(dp[i][j], dp[i][j-items[i+1].w] + items[i+1].v);
			}
			else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}	
	
	ll res = 0;
	rep(j,limW){
		res = max(res, dp[n-1][j]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 79488
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  map<int,int> foods;
  
  for(int i = 0; i < N; i++){
    int K = 0;
    cin >> K;
    for(int j = 0; j<K; j++){
      int a = 0;
      cin >> a;
      foods[a]++;
    }
  }
  int counter = 0;
  for(int i = 0; i <= M; i++){
    if(foods[i] == N) counter++;
  }
  cout << counter;
  
}


Measured memory_bytes: 256
#include<stdio.h>
int count;
int sumofintegers ( int N, int S, int I ) {
    /*printf("N%d S%d I%d\n", N, S, I);*/
    if ( N == 0 && S == 0 ) count++;
    else if ( N > 0 && S >= 0 && I <= 9) { 
        sumofintegers(N, S, I + 1);
        if ( S - I >= 0 ) sumofintegers(N - 1, S - I, I + 1);
    }
    return count;
}
int main(void) {
    int n, s, i = 0;
    scanf("%d %d", &n, &s);
    while ( 1 ) {
        i = 0;
        printf("%d\n", sumofintegers(n, s, i));
        scanf("%d %d", &n, &s);
        if ( n == 0 && s == 0 ) break;
        count = 0;
    }
    return 0;
}

Measured memory_bytes: 1776
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n,x,m;
	cin>>n>>x>>m;
	int out=x;
	n--;

	vi used(m),dp(m);
	used[x]=1;
	dp[x]=x;
	bool h=false;
	while(n){
		int nx=x*x%m;
		out+=nx;
		n--;
		if(!h&&used[nx]){
			out+=(out-dp[nx])*(n/(used[x]+1-used[nx]));
			n%=used[x]+1-used[nx];
			h=true;
		}
		dp[nx]=dp[x]+nx;
		used[nx]=used[x]+1;
		x=nx;
	}

	cout<<out<<endl;
}


Measured memory_bytes: 4772
/******
	~site:    atcoder.jp
	~user:    Turkhuu
	~problem: AtCoder Beginner Contest 177 - D (abc177_d)
** **/

#include<bits/stdc++.h>

#define FFOR(i,s,e,k) for(int i=s;(k==1?i<=e:i>=e);i+=k)
#define FOR(i,n) FFOR(i,0,n-1,1)
#define FORR(i,s,e) FFOR(i,s,e,1)
#define ll long long
#define PQ priority_queue
#define pb push_back
#define ppb pop_back()
#define pp push
#define MIN(v) *min_element(v.begin(),v.end())
#define MAX(v) *max_element(v.begin(),v.end())
#define SORT(v) sort(v.begin(),v.end())
#define TROS(v) sort(v.rbegin(),v.rend())
#define CNT(v,x) count(v.begin(),v.end(),x)
#define FIND(v,x) find(v.begin(),v.end(),x)

using namespace std;

int link[200001],sz[200001];

int find(int x){
	while(x!=link[x]) x=link[x];
	return x;
}

void unite(int a,int b){
	a=find(a);
	b=find(b);
	if(sz[a]<sz[b]) swap(a,b);
	sz[a]+=sz[b];
	link[b]=a;
}

bool same(int a,int b){
	return find(a)==find(b);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	FOR(i,n) {link[i]=i; sz[i]=1;}
	
	FOR(i,m){
		int a,b;
		cin>>a>>b;
		if(same(a,b)) continue;
		unite(a,b);
	}
	
	int ans=0;
	FOR(i,n) ans=max(ans,sz[i]);
	cout<<ans;
}

Measured memory_bytes: 5180
N,K = map(int,input().split())

#Kが奇数の場合、N mod K = 0を満たす数の3乗が解
if K % 2 == 1:
    print((N // K) ** 3)

#Kが偶数の場合、Kで割って0あまるものの個数とK / 2あまるものの個数の3乗が解
else:
    K2 = K // 2
    #Kで割ってK / 2余る個数を算出
    half = (N // K2 - N // K)
    print(half ** 3 + (N // K) ** 3)


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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

int main()
{
    int N;
    while(cin >> N && N)
    {
        map<string, ll> mp;
        rep(i, N)
        {
            string s;
            int p;
            cin >> s >> p;

            mp[s] = p;

        }

        int M;
        cin >> M;

        rep(i, M)
        {
            int num;
            ll sum = 0;
            string maked;
            cin >> maked >> num;

            rep(i, num)
            {
                string mat;
                cin >> mat;
                sum += mp[mat];
            }

            mp[maked] = min(sum, mp[maked]);
        }

        string t;
        cin >> t;

        cout << mp[t] << endl;

    }
    
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
	This is me trying to upsolve, atcoder beginner contest 147 problem D
	I have two methods of solving in my mind
	1. Recursion (Will use this as I am still trying to learn, I am not using it :()
	2. Normal iteration 
*/
ll ans(ll n,ll a[]){
	ll temp=1,an=0;
	for(ll i=0;i<n;i++){
		if(a[i]==temp){
			temp++;an++;}
	}
	return an;	
}
int main(){
	ll n; cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	ll x=ans(n,a);
	if(x==0) cout<<-1;
	else cout<<n-x;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    constexpr int K = 50;
    ll m = (1LL << (K + 1)) - 1;

    for (int l = K; l >= 0; l--) {
        m ^= 1LL << l;

        int dp[K + 1][K + 1] = {}; // iをjに変えられるなら1
        for (int i = 0; i <= K; i++) {
            dp[i][i] = 1;
        }
        for (int k = 1; k < K; k++) {
            if (m & 1LL << k) {
                for (int i = 0; i <= K; i++) {
                    dp[i][i % k] = 1;
                }
            }
        }
        for (int k = 1; k < K; k++) {
            if (m & 1LL << k) {
                for (int i = 0; i <= K; i++) {
                    for (int j = 0; j < i; j++) {
                        dp[i][j] |= dp[i][i % k] & dp[i % k][j];
                    }
                }
            }
        }

        int t = 1;
        for (int i = 0; i < n; i++) {
            if (dp[a[i]][b[i]] == 0) {
                t = 0;
                break;
            }
        }
        if (t == 0) {
            m ^= 1LL << l;
            if (l == K) break;
        }
    }

    if (m >= 1LL << K) {
        cout << -1 << endl;
    } else {
        cout << m << endl;
    }

    return 0;
}

Measured memory_bytes: 256