akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static long Solve(int N, long[] A, long[] B)
    {
        long min = long.MaxValue;
        for (int i = 0; i < N; ++i)
        {
            if (A[i] > B[i]) { min = Math.Min(B[i], min); }
        }
        return (min < long.MaxValue) ? A.Sum() - min : 0;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = new long[N];
        var B = new long[N];
        for (int i = 0; i < N; ++i)
        {
            var V = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            A[i] = V[0];
            B[i] = V[1];
        }
        Console.WriteLine(Solve(N, A, B));
    }
}


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

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

  bool ans=false;
  for(int i=0; i<=n/7; i++){
    if((n-7*i)%4==0){
      ans=true;
      break;
    }
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  int r = 0, w = 0, swap = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'W') {
      ++w;
    } else {
      ++r;
    }
  }
  int ans = min(r, w);

  for (int i = 0; i < r; ++i) {
    if (s[i] == 'W') {
      ++swap;
    }
  }
  ans = min(ans, swap);

  cout << ans << '\n';

  return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<ll>ans(13,0);
	vector<ll>ansbu = ans;
	vector<ll>anszero = ans;
	if (s.at(0) == '?') {
		for (int i = 0; i < 10; i++) ans.at(i)++;
	}
	else ans.at(s.at(0) - '0')++;
	for (int i = 1; i < s.length(); i++) {
		//10倍phase
		for (int j = 0; j < 13; j++) ansbu.at((j * 10) % 13) += ans.at(j);
		ans = ansbu;
		ansbu = anszero;
		//追加phase
		if(s.at(i)=='?'){
			for (int j = 0; j < 13; j++) {
				for (int k = 0; k < 10; k++) {
					ansbu.at((j + k) % 13) += ans.at(j);
				}
			}
		}
		else {
			for (int j = 0; j < 13; j++)ansbu.at((j + (s.at(i) - '0')) % 13) += ans.at(j);
		}
		ans = ansbu;
		ansbu = anszero;
		//mod
		for (int j = 0; j < 13; j++)ans.at(j) %= 1000000007;
	}
	cout << ans.at(5) << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N, A[200000], Lev[200001], Lod[200001], Rev[200001], S, MIN;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	Lev[0] = Lod[0] = 0;
	for (int i = 0; i < N; ++i) {
		S += A[i];
		if (A[i]) {
			Lev[i + 1] = min(S, Lev[i] + A[i] % 2);
			Lod[i + 1] = min(Lev[i + 1], Lod[i] + (A[i] + 1) % 2);
		}
		else {
			Lev[i + 1] = min(S, Lev[i] + 2);
			Lod[i + 1] = min(Lev[i + 1], Lod[i] + (A[i] + 1) % 2);
		}
	}
	S = 0;
	for (int i = N - 1; i >= 0; --i) {
		S += A[i];
		if (A[i]) {
			Rev[i] = min(S, Rev[i + 1] + A[i] % 2);
		}
		else {
			Rev[i] = min(S, Rev[i + 1] + 2);
		}
	}
	MIN = llmax;
	for (int i = 0; i <= N; ++i) {
		MIN = min(MIN, Lod[i] + Rev[i]);
	}
	cout << MIN << endl;
	return 0;
}

Measured memory_bytes: 6528
import copy

sw = []
N = int(input())
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

Speak = [{} for i in range(N)]
for i in range(N):
   A = int(input())
   for j in range(A):
       XY = input().split()
       Speak[i][XY[0]] = XY[1]

ans = 0
for peaples in sw: #0が真実で1が嘘
    true_list = [-1]*N
    isMujun = False
    for i in range(N):
         if peaples[i] == 1:
             for k,v in Speak[i].items():
                 k = int(k)
                 v = int(v)
                 if peaples[k-1] != v:
                     isMujun = True
                     break
                 elif (true_list[k-1] != -1) and (true_list[k-1] != v):
                     isMujun = True
                     break
                 else:
                     true_list[k-1] = v
    if not isMujun:
        ans = max(ans, sum(peaples))
print(ans)

Measured memory_bytes: 56152
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  string S; cin >> S;
  string ans;
  if(S == "Sunny") ans = "Cloudy";
  if(S == "Cloudy") ans = "Rainy";
  if(S == "Rainy") ans = "Sunny";
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

    rep(i, max(a, b)) {
        cout << min(a, b);
    }
    cout << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535

ll dp[200004][105];

int main() 
{
    FAST;
    ll n,w;
    cin>>n>>w;
    ll aw[n],av[n];
    for(int i=0;i<n;i++)
        cin>>aw[i]>>av[i];
    memset(dp,-1,sizeof(dp));
    dp[aw[0]][0]=av[0];
    dp[0][0]=0;
    for(int j=1;j<n;j++)
    {
        for(ll i=0;i<100004;i++)
        {
            if(i>=aw[j] && dp[i-aw[j]][j-1]!=-1)
                dp[i][j]=max(dp[i][j],dp[i-aw[j]][j-1]+av[j]);
            dp[i][j]=max(dp[i][j],dp[i][j-1]);
        }
    }
    ll ma=0;
    for(ll i=0;i<=w;i++)
        ma=max(dp[i][n-1],ma);
    cout<<ma;
    return 0;
}

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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 100000 + 5;

int a[MAXN];

int main() {
  int n, L;
  scanf("%d%d", &n, &L);
  For(i, 1, n) {
    scanf("%d", &a[i]);
  }
  int pos = 0;
  FOR(i, 1, n) {
    if (a[i] + a[i + 1] >= L) {
      pos = i;
      break;
    }
  }
  if (!pos) {
    puts("Impossible");
    exit(0);
  }
  puts("Possible");
  FOR(i, 1, pos) {
    printf("%d\n", i);
  }
  REP(i, n, pos) {
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 1152
N = int(input())
ans_lis = [0]*10001
for x in range(1, 41+1):
    for y in range(x, 58+1):
        for z in range(y, 99+1):
            tmp = x*(x+y+z)+y*(y+z) + z**2
            if tmp > 10000:
                continue
            if x == y and y == z:
                ans_lis[tmp] += 1
            elif x == y or x == z or y == z:
                ans_lis[tmp] += 3
            else:
                ans_lis[tmp] += 6
for i in range(1, N+1):
    print(ans_lis[i])


Measured memory_bytes: 9292
import java.util.*;

class Main {

    static public boolean solve(String s) {
        int mid = s.length()/2;
        String lh = s.substring(0, mid);
        String rh = s.substring(mid+1);
        if (! lh.equals(rh)) return false;
        int i = 0, j = lh.length()-1;
        while (i < j) {
            if (lh.charAt(i) != lh.charAt(j)) {
                return false;
            }
            i++; j--;
        }
        return true;
    }

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

        String s = sc.next();

        sc.close();

        System.out.println(solve(s) ? "Yes" : "No");

    }
}

Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    Range[] ranges = new Range[N];
    for (int i = 0; i < N; i++) {
      int X = scanner.nextInt();
      int L = scanner.nextInt();
      ranges[i] = new Range(X - L, X + L);
    }
    Arrays.sort(ranges, (r1, r2) -> {
      if (r1.right != r2.right) return r1.right - r2.right;
      return r2.left - r1.left;
    });
    int count = 1;
    int current = ranges[0].right;
    for (int i = 1; i < N; i++) {
      if (ranges[i].left >= current) {
        count++;
        current = ranges[i].right;
      }
    }
    System.out.println(count);
  }

  private static class Range {
    private final int left;
    private final int right;

    private Range(int left, int right) {
      this.left = left;
      this.right = right;
    }
  }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k) {
        cout << k << endl;
    } else {
        ll cnt = a;
        k -= a;
        if(b >= k) {
            cout << cnt << endl;
        } else {
            k -= b;
            cnt -= k;
            cout << cnt << endl;
        }
    }
    return 0;
}


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

int main()
{
    ll n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(ll i=0;i<n-2;i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool ok;
    for(int i=0;;i++) {
        if(i%2==0) {
            c -= b;
            if(c<=0) {
                ok = true;
                break;
            }
        }
        else {
            a -= d;
            if(a<=0) {
                ok = false;
                break;
            }
        }
    }
    if(ok) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		int dataNum;
		int aNum = 0, bNum = 0;
		int aPoint = 0, bPoint = 0;
		int[] game = new int[10];

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int j;
		for (j = 0; j < 5; j++) {

			String str = br.readLine();

			dataNum = Integer.parseInt(str);
			if (dataNum == 0) {
				break;
			}

			aPoint = 0;
			bPoint = 0;
			aNum = 0;
			bNum = 0;
			for (int i = 0; i < dataNum; i++) {
				StringBuffer sb = new StringBuffer(new String(br.readLine()));
				aNum = Character.getNumericValue(sb.charAt(0));
				bNum = Character.getNumericValue(sb.charAt(2));

				if (aNum > bNum) {
					aPoint += aNum + bNum;
				} else if (bNum > aNum) {
					bPoint += aNum + bNum;
				} else {
					aPoint += aNum;
					bPoint += bNum;
				}
			}
			game[2 * j] = aPoint;
			game[2 * j + 1] = bPoint;

		}
		for (int i = 0; i < j; i++) {
			System.out.println(game[2 * i] + " " + game[2 * i + 1]);
		}
		// String str = br.readLine();
		// StringBuffer sb = new StringBuffer(str);

	}

}



Measured memory_bytes: 29160
a,b,c=map(int, input().split())
ans=0
while a%2==0 and b%2==0 and c%2==0 and ans<10000:
    a,b,c=b//2+c//2,a//2+c//2,a//2+b//2
    ans+=1
if ans==10000:ans=-1
print(ans)

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

ans=0
if a<=c:
    ans+=b-c
    if d<=b:
        ans-=b-d
else:
    ans+=d-a
    if b<=d:
        ans-=d-b

if ans>=0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cassert>

#define debug(x) cout << #x << "==" << x << endl;

using namespace std;

//??\???
#define MAX_N 100
#define MAX_NUM 20
int N;
int num[MAX_N];
long long dp[MAX_N+1][MAX_NUM+1];
bool checked[MAX_N+1][MAX_NUM+1];

void print_dp_table() {
  for(int i = 0; i < N; i++ ) {
    for(int s = 0; s < MAX_NUM; s++ ) {
      cout << setw(3) << dp[i][s] << " ";
    }
    cout << "\n";
  }
  cout << "\n";

}

// i??????????????????????????§?????°???????????????sum??????????????¨?????§?????????????????????????????°
long long rec(int i, int sum) {

  if( sum < 0 || sum > 20 ) return 0;
  if ( i == 0 ) return (sum == num[i]);

  if( checked[i][sum] ) {
    return dp[i][sum];
  } else {
    checked[i][sum] = true;
    return dp[i][sum] = rec(i - 1, sum - num[i]) + rec(i - 1, sum + num[i]);
  }

}

int main() {
  ios::sync_with_stdio(false);

  cin >> N;

  for(int i = 0; i < N; i++) {
    cin >> num[i];
  }

  int sum = num[N-1];

  cout << rec(N-2, sum) << endl;

  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b || b <= c && c <= a) cout << "Yes" << endl;
	else cout << "No" << endl;

	/*string s;
	cin >> s;
	int n = s.size();

	for (int i = 0; i < n; i++) {
		s.insert(s.begin() + i, 'A');
		if (s == "AKIHABARA") {
			cout << "YES" << endl;
			return 0;
		}
		s.erase(i);
	}
	cout << "NO" << endl;*/
	
	//string s;
	//cin >> s;
	//reverse(s.begin(), s.end());
	//int n = s.size();
	//vector<vector<int>> dp(n, vector<int>(2, INF));

	//dp[0][0] = s[0] - '0';
	//dp[0][1] = 1 + 10 - (s[0] - '0');

	//for (int i = 1; i < n; i++) {
	//	// i-1桁において、繰り下げがなかった場合
	//	dp[i][0] = (s[i] - '0') + dp[i - 1][0];
	//	dp[i][1] = 1 + 10 - (s[i] - '0') + dp[i - 1][0];
	//	dp[i][1] = min(dp[i][1], 1 + (s[i] - '0') + dp[i - 1][0]);

	//	// i-1桁において、繰り下げがあった場合
	//	if (s[i] - '0' != 9) dp[i][0] = min(dp[i][0], dp[i - 1][1] + (s[i] - '0'));
	//	dp[i][1] = min(dp[i][1], 1 + 10 - (s[i] - '0') + dp[i - 1][1]);
	//	dp[i][1] = min(dp[i][1], 1 + (s[i] - '0') + dp[i - 1][1]);
	//}
	//cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);



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

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>> pq,q;
    for(int i=0;i<n;i++){
        pq.push({a[i],i});
        q.push({a[i],i+1});
    }
    int ans[n*n]={};
    for(int i=0;i<n;i++){
        ans[a[i]] = i+1;
    }
    int now = 0;
    while(pq.size()){
        array<int,2> r = pq.top();
        pq.pop();
        int cnt = 0;
        while(now<n*n && cnt<r[1]){
            if(ans[now]){
                now++;
                continue;
            }
            ans[now] = r[1]+1;
            cnt++;
            now++;
        }
        if(r[0] < now){
            cout << "No\n";
            return 0;
        }
    }
    now = 0;
    while(q.size()){
        array<int,2> r = q.top();
        q.pop();
        int cnt = 0;
        // r[1] を、n-r[1]こ
        while(cnt<n-r[1]){
            if(ans[now]){
                now++;
                continue;
            }
            if(now <= r[0]){
                cout << "No\n";
                return 0;
            }
            ans[now] = r[1];
            cnt++;
            now++;
        }
    }
    cout << "Yes\n";
    for(int i=0;i<n*n;i++){
        cout << ans[i]<<" ";
    }
    cout << endl;


}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> v[200005];
ll a[200005]={0};
ll sum[200005]={0};
bool vis[200005]={0};
void dfs(int u,ll t)
{
    sum[u]=t+a[u];
    //if(u==1)
      //  cout<<"II"<<sum[u];
    for(int i=0;i<v[u].size();i++)
    {
        if(!vis[v[u][i]])
        {
            vis[v[u][i]]=true;
            dfs(v[u][i],t+a[u]);

        }
    }

}
int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++)
    {
        int c,d;
        cin>>c>>d;
        v[c].push_back(d);
        v[d].push_back(c);
    }
    for(int i=0;i<q;i++)
    {
        int p,x;
        cin>>p>>x;
        a[p]+=x;
    }
    vis[1]=true;
    dfs(1,0);
    for(int i=1;i<=n;i++)
        cout<<sum[i]<<" ";

}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll a,b,c;cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0)out(0);
  else {
    vector<ll>v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(),v.end());
    out(v[0]*v[1]);
  }



  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K; cin >> N >> K;
    vector<bool> flag(N, false);
    rep(i, K){
        ll d; cin >> d;
        rep(j, d){
            ll tmp;
            cin >> tmp;
            tmp--;
            flag.at(tmp) = true;
        }
    }
    ll cnt = 0;
    rep(i, N){
        if (flag.at(i) == false){cnt += 1;}
        // cout << flag.at(i) << endl;
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;};
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}

int main()
{
//	freopen("input.txt","r",stdin);
	int x;
	cin>>x;
	cout<<360/__gcd(x,360)<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
class stoneProblemK
{
private:
	vector<bool> table;
	vector<int> moves;
	int stone_count;
	int set_size;
	void completeTable();
	void display();
public:
	stoneProblemK();

};

stoneProblemK::stoneProblemK() {
	cin >> set_size;
	cin >> stone_count;
	for (int i = 0; i < set_size; i++) {
		int move;
		cin >> move;
		moves.push_back(move);
	}
	completeTable();
	display();
	
}
void stoneProblemK::display() {
	if (table[stone_count]) {
		cout << "First";
	}
	else {
		cout << "Second";
	}
}
void stoneProblemK::completeTable() {
	for (int i = 0; i <= stone_count; i++) {
		if (i == 0) {
			table.push_back(false);
			continue;
		}
		bool can_win = false;
		for (auto x : moves) {
			if ((i - x) >= 0 && !table[i - x]) {
				can_win = true;
				break;
			}
		}
		table.push_back(can_win);
	}
}

int main()
{
	stoneProblemK* x = new stoneProblemK();


	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define N 1001
using namespace std;
struct d{
  int h;
  int p;
  int q;
};
int main(){
  int n,m,a,i,j,l;
  struct d data[N];
  while(1){
    cin >> n >> m >> a;
    if(n==0&&m==0&&a==0) break;
    for(i=0;i<m;i++){
      cin >> data[i].h >> data[i].p >> data[i].q;
    }
    for(i=0;i<m;i++){
      for(j=1;j<m;j++){
	if(data[j].h>data[j-1].h) swap(data[j],data[j-1]);
      }
    }
    l=a;
    for(i=0;i<m;i++){
      if(data[i].p==l-1) l-=1;
      else if(data[i].q==l+1) l+=1;
      if(i==m-1){
	cout << l << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1168
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,al,bl;
    int cnt=0,nn;
    cin>>n;
    cin>>a>>b;
    cin>>al>>bl;
    for(;;)
    {
        a-=al;
        b-=bl;
        cnt++;
        if(a<=0&&b<=0)break;
    }
    nn=n-cnt;
    cout<<nn<<endl;
    return 0;
}

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

int main(){
    string s;
    cin>>s;

    if(s[0] == 'A'){
        bool flag = false;
        bool last = true;
        int cnt = 0;
        for(int i=2; i<s.size()-1; i++){
            if(s[i] == 'C') cnt++;
        }
        if(cnt == 1) flag = true;

        if(flag){
            for(int i=0; i<s.size(); i++){
                if(s[i] == 'A' || s[i] == 'C') continue;
                if(s[i] >= 'A' && s[i] <= 'Z') last = false; 
            }
            
            if(last){
                cout<<"AC"<<endl;
                return 0;
            }
        }
    }

    cout<<"WA"<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.math.*;
import java.util.*;
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if(a>b) {
				for(int i=0;i<a;i++) {
					System.out.print(b);
				}
			}else {
				for(int i=0;i<b;i++) {
					System.out.print(a);
				}
			}
			
			
		}
				
	}

Measured memory_bytes: 21716
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    char[] s = scanner.next().toCharArray();
    int diff = 0;
    for (int i = 0; i < N - 1; i++) if (s[i] != s[i + 1]) diff++;
    System.out.println(N - 1 - diff + Math.min(diff, K * 2));
  }
}


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

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define pb push_back
#define X first
#define Y second

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;

#ifdef umang99m
    #include "/home/umang/.templates/header.h"
#else
    #define dbg(args...)
    #define timer()
#endif


const ll maxn = 200001;
ll f[maxn];

ll po(ll a, ll b){
    if(b==0) return 1;
    ll cur = ((b&1)?a:1);
    ll s = po(a,b/2);
    return (((s*s)%MOD)*cur)%MOD;
}

ll inv(ll a){
    return po(a,MOD-2);
}

ll c(ll n, ll r){
    if(r>n) return 0;
    return (((f[n]*inv(f[n-r]))%MOD)*inv(f[r]))%MOD;
}

void init(){
    f[0] = 1;
    repA(i,1,maxn-1){
        f[i] = (f[i-1] * i)%MOD;
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    init();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ans = 0;
    rep(i,h-a){
        ans += (c(b-1+i,i)*c(w-b+h-i-2,h-i-1))%MOD;
        ans %= MOD;
    }
    cout<<ans<<endl;
    timer();
    return 0;

}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    X=list(map(int,input().split()))
    ans=INF
    for i in range(1,101):
        tmp=0
        for n in X:
            tmp+=(n-i)**2
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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));
  ll ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      if (l[i] == l[j]) continue;
      for (int k = j + 1; k < n; k++) {
        if (l[i] == l[k] || l[j] == l[k]) continue;
        if (l[k] < l[i] + l[j]) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll HMOD = (ll)1e9 + 7;
const ll LMOD = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
const long double EPS = 1e-10;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	string S; cin >> S;
	if (S[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	int cnt = 0;
	FOR(i, 2, S.size() - 1) {
		if (S[i] == 'C') cnt++;
	}
	if (cnt != 1) {
		cout << "WA" << endl;
		return 0;
	}
	REP(i, S.size()) {
		
		if (i == 0) continue;
		if (2 <= i && i <= S.size() - 2 && S[i] == 'C') continue;
		if (S[i] - 'A' <= 25) {
			cout << "WA" << endl;
			return 0;
		}
		
	}
	cout << "AC" << endl;
	
	return 0;
}



Measured memory_bytes: 256
S = input()
A = ['R', 'U', 'D']
B = ['L', 'U', 'D']
for i,j in enumerate(S):
    if((i+1)%2==0):
        if( j not in B):
            print('No')
            exit()
    else:
        if(j not in A):
            print('No')
            exit()
print('Yes')


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

using namespace std;

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

    long long m = 100;
    int y = 0;

    while (m < x) {
        m *= 1.01;
        ++y;
    }

    cout << y << endl;

    return 0;
}


Measured memory_bytes: 3644
import sys
from collections import Counter
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

CA = Counter(A)
CB = Counter(B)

right_idx = defaultdict(lambda: -1)
left_idx = defaultdict(lambda: -1)

for i in range(N):
    a = A[i]
    right_idx[a] = i

for i in range(N)[::-1]:
    b = B[i]
    left_idx[b] = i

# check
for X in [A, B]:
    for x in X:
        if CA[x] + CB[x] > N:
            print("No")
            exit()


shift = 0
for x in range(1, N + 1):
    if right_idx[x] == -1 or left_idx[x] == -1:
        continue

    shift = max(right_idx[x] - left_idx[x] + 1, shift)


ANS = B[-shift:] + B[:-shift]

print("Yes")
print(" ".join(map(str, ANS)))



Measured memory_bytes: 101764
#include<stdio.h>
 
int count;
 
void binarysearch(int S[], int n, int key){
  int top = 0, tail = n, a;
  while(top != tail){
    a = (top + tail)/2;
    if (S[a] == key){
      count++;
      break;
    } else if(S[a] < key) top = a + 1;
    else tail = a;
  }
}
 
int main(void){
  int i, n, q, b, S[100000];
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &S[i]);
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &b);
    binarysearch(S, n, b);
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 2248
def prime_factorize(N): #素因数分解
    exponent = 0
    while N%2 == 0:
        exponent += 1
        N //= 2
    #if exponent: factorization = [[2,exponent]]
    if exponent: factorization = [[1,pow(2,exponent)]]
    else: factorization = []
    i=1
    while i*i <=N:
        i += 2
        if N%i: continue
        exponent = 0
        while N%i == 0:
            exponent += 1
            N //= i
        factorization.append([1,pow(i,exponent)])
        #factorization.append([i,exponent])
    #if N!= 1: factorization.append([N,1])
    if N!= 1: factorization.append([1,N])
    assert N != 0, "zero"
    return factorization

def Garner_NOmod(alst,mlst):
    x = 0; M = 1
    # 互いに素を仮定
    for a,m in zip(alst,mlst):
        c = (a-x)*modinv(M,m)%m
        x += c*M
        M *= m
    return x

def extgcd(x,y):
    if y==0: return 1,0 #g=x
    r0,r1,s0,s1 = x,y,1,0
    while r1 != 0:
        r0,r1, s0,s1 = r1,r0%r1, s1,s0-r0//r1*s1
    #g = r0
    return s0,(r0-s0*x)//y
    
def modinv(a,MOD):
    x,y = extgcd(a,MOD)
    return x%MOD

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int, readline().split())
#lr = [list(map(int, readline().split())) for _ in range(q)]

if n==1:
    print(1)
    exit()

lst = prime_factorize(2*n)

res = []
from itertools import product
for a in product(*lst):
    v = 1
    for i in a: v*= i
    w = 2*n//v
    res.append(Garner_NOmod([0,w-1],[v,w]))

res.sort()
"""
for i in res:
    #print(n,i,i*(i+1)//2)
    assert (i*(i+1)//2)%(n)==0
"""

print(res[1])



Measured memory_bytes: 69288
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x;
    cin>>x;
    long long a=100;
    int count=0;
    while(a<x)
    {
        a=a+a/100;
       // cout<<a<<'\n';
        count++;
    }
    cout<<count<<'\n';
    return 0;
}

Measured memory_bytes: 3644
N = int(input())
X = list(map(int, input().split()))

X.sort()
mi = X[0]
ma = X[N-1]

ans = 10**9
for i in range(mi,ma+1):
  sum = 0
  for j in range(N):
    sum += abs(X[j]-i)**2
  ans = min(ans, sum)

print(ans)

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

typedef long long LL;
const int MAXN = 5010;
const int MAXM = 210;
int B[MAXM][MAXN];
LL A[MAXN][MAXN];
LL pre[MAXN];
int n, m;
void solve(int l, int r, int * C, int lst = 0) {
	if (l > r) return ;
	int at = std::max_element(C + l, C + r + 1) - C;
	A[l][r] += C[at] - lst;
	solve(l, at - 1, C, C[at]);
	solve(at + 1, r, C, C[at]);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 2; i <= n; ++i)
		std::cin >> pre[i], pre[i] += pre[i - 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			std::cin >> B[j][i];
	for (int i = 1; i <= m; ++i) solve(1, n, B[i]);
	for (int i = 1; i <= n; ++i)
		for (int j = n; j; --j)
			A[i][j] += A[i][j + 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			A[i][j] += A[i - 1][j];
	LL ans = std::numeric_limits<LL>::min();
	for (int i = 1; i <= n; ++i)
		for (int j = i; j <= n; ++j)
			ans = std::max(ans, A[i][j] - pre[j] + pre[i]);
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 200320
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    int cnt = 0;
    for(int i=0;i<N;i++){
        int h;
        cin>>h;
        if (h>=K){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        map<string, vector<int> > name;
        int prev = -1;
        vector<int> tmp;
        cin.ignore();
        for(int i=0; i<n; ++i){
            string s;
            getline(cin, s);
            int j = s.find_first_not_of(' ');
            s = s.substr(j);
            if(j < prev){
                while(j < prev){
                    tmp.pop_back();
                    -- prev;
                }
                ++ tmp.back();
            }else if(j == prev){
                ++ tmp.back();
            }else{
                tmp.push_back(0);
                ++ prev;
            }
            name.insert(make_pair(s, tmp));
        }

        for(int i=0; i<m; ++i){
            string x0, y0, s;
            cin >> x0 >> s >> s >> s >> y0 >> y0;
            y0.resize(y0.size() - 1);

            vector<int> x = name[x0];
            vector<int> y = name[y0];

            if(s == "child" || s == "parent"){
                if(s == "parent")
                    swap(x, y);
                x.resize(x.size() - 1);
            }else if(s == "sibling"){
                x.resize(x.size() - 1);
                y.resize(y.size() - 1);
            }else{
                if(s == "ancestor")
                    swap(x, y);
                if(x.size() > y.size())
                    x.resize(y.size());
            }

            if(x == y)
                cout << "True" << endl;
            else
                cout << "False" << endl;
        }

        cout << endl;
    }
}

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

int main(){
  int N; cin >> N;
  vector<pair<long long,long long>> MY(N);
  for(int i=0;i<N;i++){
    cin >> MY[i].first >> MY[i].second;
  }
  long long count=0;
  long long ans=0;
  for(int i=N-1;i>=0;i--){
    MY[i].first+=count;
    long long k=(MY[i].second-(MY[i].first%MY[i].second))%MY[i].second;
    count+=k;
    ans+=k;
  }
  cout << ans << endl;
}

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

using namespace std;

int N;
vector<long long int> V;
long long int A[100005];
long long int S[100005];

int main(void) {

	cin >> N;
	long long int tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp; V.push_back(tmp);
	}

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

	for (int i = 0; i <= N - 1; i++) {
		A[i + 1] = V[i];
	}

	S[0] = 0;
	for (int i = 1; i <= N; i++) {
		S[i] = A[i] + S[i - 1];
	}

	int ans = 0;

	/*for (int i = 0; i < N; i++) {
		cout << " " << V[i];
	}cout << endl;
	*/
	for (int i = 1; i <= N; i++) {
		long long int L = A[i]*2;
		while (1) {
			int I = upper_bound(V.begin(), V.end(), L) - V.begin();
			//cout <<"i= " <<i <<" L= " <<L<< " I= " << I << endl;
			if (I == N) { ans++; break; }
			if (S[I]*2 <= L) { break; }
			else { L = S[I]*2; }
		}
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

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

a = [1]
p = [1]
for i in range(N):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)

# レベル lv のバーガーの下から x 枚に含まれるパティの数
def f(lv, x):
    if lv == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[lv-1]:
        return f(lv-1, x-1)
    else:
        return p[lv-1] + 1 + f(lv-1, x -1 -a[lv-1] -1)

def main():
    print(f(N,X))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>

using namespace std;
#define MAX_N 86
typedef long long unsigned int ll;
ll L[MAX_N];

ll f(int d) {
    if (L[d] != 0) return L[d]; 
    if (d == 0 ) return 2;
    else if (d == 1) return 1;
    else {
        return L[d] = f(d - 1) + f(d - 2);
    }
}

int main() {
    for (int i = 0; i < MAX_N; i++) {
        L[i] = 0;
    }
    int n;
    scanf("%d", &n);
    printf("%lld\n", f(n));
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n;
    cin>>n;
    vector<in> a(n);
        rep(i,n) cin>>a.at(i);
    in x=0ll;
    rep(i,n){
        if(i%2==0) x+=a[i];
        else x -=a[i];
    }
    vector<in> ans(n);
    ans[0]=x;
    REP(i,1,n) ans[i] =2*a[i-1]-ans[i-1];
    rep(i,n-1) cout<<ans[i]<<" ";
    cout<<ans[n-1]<<endl;
}

//./problem.exe

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

int main() {
	int a[4], b[4];
	while(cin >> a[0]) {
		bool v[10];
		memset(v, 0, sizeof v);
		v[a[0]] = 1;
		for(int i = 1; i < 4; i ++) {
			cin >> a[i];
			v[a[i]] = 1;
		}
		int hit = 0, blow = 0;
		for(int i = 0; i < 4; i ++) {
			cin >> b[i];
			if(a[i] == b[i])
				hit ++;
			if(v[b[i]])
				blow ++;
		}
		blow -= hit;
		cout << hit << ' ' << blow << '\n';
	}
	return 0;
}

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

using namespace std;

#define int long long
#define f first
#define s second

pair <int, int> a[3500];
int f[200000], fr[200000], d[10000], mod = 1e9 + 7;
int n,m,k;

bool cmp(pair <int, int> x, pair <int, int > y){
	return x.f + x.s < y.f + y.s;
}

int bp(int x, int y){
	int res = 1;
	while (y){
		if (y & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

int cc(int x, int y){
	return f[x] * fr[y] % mod * fr[x - y] % mod;
}

main(){
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++){
		cin >> a[i].f >> a[i].s;
	}
	f[0] = 1;
	fr[0] = 1;
	for (int i = 1; i < 200000; i++) (f[i] = f[i - 1] * i) %= mod, fr[i] = bp(f[i], mod - 2);
	sort(a, a + k, cmp);
	for (int i = 0; i < k; i++){
		int x = a[i].f, y = a[i].s;
		int ans = cc(x - 1 + y - 1, x - 1);  
		for (int j = 0; j < i; j++){
			if (x >= a[j].f && y >= a[j].s){
				//cout << "asd";
				(ans = ans - cc(x - a[j].f + y - a[j].s, y - a[j].s) * d[j] + mod) %= mod;
			}
		}
		d[i] = ans;
		//cout << d[i] << " " << x << " " << y << endl;
 	}
 	//return 0;
 	int ans = cc(n + m - 2, m - 1);
 	//cout << ans << " << ans\n";
 	for (int i = 0; i < k; i++){
 		ans = (ans - (cc(n - a[i].f + m - a[i].s, n - a[i].f) * d[i]) % mod + mod) % mod;
 		//cout << << " " << d[i] << endl;
  	}
 
 	cout << ans;
	return 0;
}

















Measured memory_bytes: 3456
#include<stdio.h>
#include<math.h>
int main(){
    int a,max=0,i,d=0;
    scanf("%d",&a);
    int b[10000]={0};
    for(i=0;i < a;i++){
        scanf("%d",&b[i]);
    }
    for(int j=0;j<100;j++){
    for(i=0;i<a;i++){
        if(b[i]%2==0){
            b[i]=b[i]/2;
                d++;
        }
        }
    }
    printf("%d",d);
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
	for j in range(b + 1):
		for k in range(c + 1):
			if 500 * i + 100 * j + 50 * k == x:
				cnt += 1

print(cnt)

Measured memory_bytes: 3060
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)
dp = [[0]*(X+1) for _ in range(N+1)]
dp[0][X] = 1
MOD = 10**9+7

for i in range(N):
    for j in range(X+1):
        dp[i+1][j%S[i]] += dp[i][j]
        dp[i+1][j%S[i]] %= MOD
        dp[i+1][j] += (N-i-1)*dp[i][j]
        dp[i+1][j] %= MOD

ans = 0

for i in range(X+1):
    ans += dp[N][i]*i
    ans %= MOD

print(ans)

Measured memory_bytes: 192152
package main

import "fmt"

func main() {
	var n, res, sumAll int
	arr := make([]int, 0)
	lookup := make(map[int]int)
	lookup2 := make(map[int]int)
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &res)
		lookup[res]++
		arr = append(arr, res)
	}

	for key, value := range lookup {
		lookup2[key] = (value * (value - 1)) / 2
		sumAll += (value * (value - 1)) / 2
	}
	// fmt.Println(lookup)
	// fmt.Println(lookup2)
	// fmt.Println(sumAll)
	for i := 0; i < n; i++ {
		tmp := arr[i]
		sumTmp := sumAll
		valueCountSum, _ := lookup2[tmp]
		// fmt.Printf("sum1: %d %d\n", sumTmp, valueCountSum)
		sumTmp -= valueCountSum
		valueCount, _ := lookup[tmp]
		// fmt.Printf("sum2: %d %d\n", sumTmp, valueCount)
		sumTmp = sumTmp + ((valueCount - 1) * (valueCount - 2) / 2)
		fmt.Println(sumTmp)
	}
}


Measured memory_bytes: 25476
n, m = map(int, input().split())
a_list = [int(i) for i in input().split()]
if (n >= m):
    ans = 0
else:
    a_list = sorted(a_list)
    b_list = [(a_list[i+1] - a_list[i]) for i in range(len(a_list)-1)]
    b_list = sorted(b_list)
    ans = sum(b_list[0:(m-n)])
print(ans)

Measured memory_bytes: 13840
n=int(input())
letter="zabcdefghijklmnopqrstuvwxy"
nam=[]
p=n
while p>0:
  q=p%26
  p=p//26
  if q==0:
    p-=1
  nam.append(letter[q])
nam.reverse()
ans="".join(nam)
print(ans)

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

using namespace std;

const int N_MAX = 5 * 100000;
const int MOD = 1000 * 1000 * 1000 + 7;

int factm[N_MAX + 1];
int ifactm[N_MAX + 1];

int addm(int a, int b)
{
	return (0LL + a + b) % MOD;
}

int subm(int a, int b)
{
	return addm(a, MOD - b);
}

int mulm(int a, int b)
{
	return (1LL * a * b) % MOD;
}

int powm(int a, int n)
{
	if (n == 0) {
		return 1;
	}
	else {
		int ans = powm(mulm(a, a), n / 2);
		if (n & 1) {
			ans = mulm(ans, a);
		}
		return ans;
	}
}

int invm(int a)
{
	return powm(a, MOD - 2);
}

void init()
{
	factm[0] = 1;
	for (int i = 1; i <= N_MAX; ++i) {
		factm[i] = mulm(i, factm[i - 1]);
	}

	ifactm[N_MAX] = invm(factm[N_MAX]);
	for (int i = N_MAX - 1; i >= 0; --i) {
		ifactm[i] = mulm(i + 1, ifactm[i + 1]);
	}
}

int combm(int n, int k)
{
	int ans = factm[n];
	ans = mulm(ans, ifactm[n - k]);
	ans = mulm(ans, ifactm[k]);
	return ans;
}

int main()
{
	init();

	int n, k;
	cin >> n >> k;

	int ans = 1;
	for (int i = 0; i < n; ++i) {
		if (n - i <= k) {
			ans = addm(ans, mulm(combm(n, i), combm(n - 1, i - 1)));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4096