akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int N, K;
    cin >> N >> K;

    vector<int> A(N);

    rep(i,K) {
        int d;
        cin >> d;
        rep(j,d) {
            int tmp;
            cin >> tmp;
            tmp--;
            A[tmp] = 1;
        }
    }

    int sum = accumulate(A.begin(), A.end(), 0);

    cout << N - sum << endl;
    
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>

int main(int argc, char const* argv[])
{
    int n, k;
    std::cin >> n >> k;

    double sum = 0;
    for(int i=1; i<=n;++i)
    {
        int value = i;
        int tmp = 1;
        while(value < k)
        {
            value = value << 1;
            tmp = tmp << 1;
        }

        sum += ((double)1.0 / (double)n)
            * ((double)1.0 / (double)tmp);
    }

    std::cout
        << std::setprecision(9)
        << sum << std::endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int K=sc.nextInt();
		int T=sc.nextInt();
		int[] sum=new int[T];
		for(int i=0; i<T; i++) {
			sum[i]=sc.nextInt();
		}
		if(T==1) {
			pl(K-1);
		}
		else {
			for(int i=0; i<T; i++) {
				if(K-sum[i]+1<sum[i]) {
					pl(sum[i]-(K-sum[i]+1));
					System.exit(0);
				}
			}
			pl(0);
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

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

int main(){
    int N;
    int a[110];
    cin >> N;
    for (int i=0; i<N; i++) cin >> a[i];

    sort(a, a+N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i=0; i<N; i++){
        if (i % 2 == 0){
            Alice += a[i];
        } else {
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    ll n;
    ll ans = 1;
    rep(i,N){
        cin >> n;
        ans = ans / gcd(ans,n) * n;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3220
import java.math.BigInteger;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++) {
			BigInteger s1 = new BigInteger(stdIn.next());
			BigInteger s2 = new BigInteger(stdIn.next());
			
			s1 = s1.add(s2);
			String tmp = s1.toString();
			if(tmp.length() > 80) {
				tmp = "overflow";
			}
			System.out.println(tmp);
		}
		
	}
	
}

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


int main()
{
    ll score;
    cin >> score;
    string ans = score >= 1200 ? "ARC" : "ABC";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = sorted([[int(a) for a in input().split()] for _ in range(n)], reverse=True)
cd = sorted([[int(a) for a in input().split()] for _ in range(n)],key=lambda  x:x[1])
count = 0
for c in cd:
    for a in ab:
        if (a[0]<c[0]) and (a[1]<c[1]):
            count += 1
            ab.remove(a)
            break
print(count)


Measured memory_bytes: 3064
a,b=map(int,input().split())

def gcd(x,y):
    c=x
    d=y
    if y>x:
        x=d
        y=c
    
    if y == 0:
        return x
    
    else:
        return gcd(y,x%y)
    
print(int((a*b)/gcd(a,b)))        
        

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    int n;
    cin>>n;
    priority_queue<float, vector<float>, greater<float>>pq;
    for(int i=0;i<n;i++){
        float f;
        cin>>f;
        pq.push(f);
    }
    while(pq.size()!=1){
        float f1=pq.top();
        pq.pop();
        float f2=pq.top();
        pq.pop();
        pq.push(float((f1+f2)/2));
    }
    cout<<pq.top();
}



Measured memory_bytes: 3792
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 10000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N;
	cin>>N;
	int co=0;
	if(N%10==2)co++;
	if((N/10)%10==2)co++;
	if((N/100)%10==2)co++;
	if(N/1000==2)co++;
	
	cout<<co<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n,k,c=map(int,input().split())
s=input()
ne=10**6*(-1)
fow=[]
bac=[]
for i in range(n):
    if i>ne and s[i]!="x":
        ne=i+c
        fow.append(i)
    if len(fow)==k:
        break
ne=10**6
for i in range(n-1,-1,-1):
    if i<ne and s[i]!="x":
        ne=i-c
        bac.append(i)
    if len(bac)==k:
        break
bac.sort()
for i,j in zip(fow,bac):
    if i==j:
        print(i+1)

Measured memory_bytes: 20724
#include "bits/stdc++.h"
using namespace std;
const int maxn = 300300;
int occ[maxn];
int main(){
    int n;
    cin >> n;
    map<int,int> o;
    for(int e = 0; e < n; e++){
        int x; cin >> x;
        o[x]++;
    }
    int ans = 0;
    for(auto & it : o){
        if(it.second >= it.first) ans += it.second - it.first;
        else ans += it.second;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
   ios_base::sync_with_stdio(false); cin.tie(NULL);
   int n, a, b, l, i, mayor;

   cin >> n >> l;
   cin >> a;

   mayor = -1;
   for( i = 1; i < n; i++ ){
        cin >> b;
        if( a + b >= l ) mayor = i;
        a = b;
   }

   if( mayor == -1 ) cout << "Impossible";

   else{
        cout << "Possible\n";
        for( i = 1; i < mayor; i++ ){
            cout << i << "\n";
        }

        for( i = n-1; i > mayor; i-- ){
            cout << i << "\n";
        }
       cout << mayor << "\n";
   }




   return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod=998244353;
int const mod1=1000000007;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// *** Using PBDS ***
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// *** Using PBDS ***
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}
bool comp(pii a,pii b)
{
    if(a.first==b.first)
    return a.second<b.second;
    return a.first>b.first;
    
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//unordered_map<long long, int, custom_hash> safe_map;



signed main()
{
	haha
	int s,w;
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe";
	else
	cout<<"safe";
	
	
	
}


  
    

Measured memory_bytes: 3600
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n,m;
	cin >> n >> m;
	int s[10];
	int c[10];
	rep(i,m)cin >> s[i] >> c[i];

	int a,b;
	if(n == 1){
		a = 0;
		b = 10;
	}
	if(n == 2){
		a = 10;
		b = 100;
	}
	if(n == 3){
		a = 100;
		b = 1000;
	}

	for(int i = a;i < b;i++){
		int f = 1;
		rep(j,m){
			int x = 1;
			rep(k,n-s[j]+1)x *= 10;
			if(i%x/(x/10) != c[j])f = 0;
		}
		if(f){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;



	

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc157.contest.atcoder.jp/tasks/abc157_c

Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, 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

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

dic = defaultdict(int)

for a in A:
	dic[a] ^= 1

#print(dic)
print(sum([dic[x] for x in dic]))
	


Measured memory_bytes: 18360
#include <iostream>
    #include <string>
    #include <set>  
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
	#include <cassert>
    #include <iomanip>
    #include <sstream> 
    #include <cstdlib>
using namespace std;
const int MAXN=1e5+10;
int a[MAXN];
int n,cnt2,cnt4;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		if(a[i]%4==0)cnt4++;
		else if(a[i]%2==0)cnt2++;
	}
	if(cnt4>=n/2||cnt2==n||cnt4*2+cnt2>=n)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
while ((n,x = gets.split(" ").map(&:to_i)).inject(:+) != 0) do
  max = 3*(n-1)
  if !((6..max).include?(x))
    puts 0
    next
  end
  r = []
  n.downto(1) do |n1|
    (n1-1).downto(1) do |n2|
      (n2-1).downto(1) do |n3|
        if ((n1 + n2 + n3) == x)
          r<<[n1,n2,n3]
          break
        end
      end
    end
  end
  puts r.length
end

Measured memory_bytes: 8752
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<ll> lis;
void dfs(vector<ll>& use, ll sz, string num, ll obj){
    if(num.size() == sz){
        ll lnum = stoll(num);
        if(obj <= lnum) lis.pb(lnum);
        return;
    }
    for(int i=0; i<use.size(); i++){
        char c = use[i] + '0';
        dfs(use, sz, num+c, obj);
    }
}
void solve(){
    string n;
    ll k; 
    cin >> n >> k;
    vector<ll> d(10, 0);
    REP(i, k){
        ll din; cin >> din;
        d[din] = -1;
    }
    vector<ll> use;
    for(int i=0; i<10; i++){
        if(d[i] != -1) use.pb(i);
    }
    dfs(use, n.size(), "", stoll(n));
    dfs(use, n.size()+1, "", stoll(n));
    ll res;
    sort(ALL(lis));
    REP(i, lis.size()){
        if(lis[i] >= stoll(n)){
            cout << lis[i] << endl;
            exit(0);
        }
    }
}

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

Measured memory_bytes: 3776
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	for(int i=0;i<=n;i++)
		ans+=abs(arr[i]-arr[i+1]);
	for(int i=1;i<=n;i++){
		int tmp=ans;
		tmp-=abs(arr[i-1]-arr[i]);
		tmp-=abs(arr[i]-arr[i+1]);
		tmp+=abs(arr[i-1]-arr[i+1]);
		printf("%d\n",tmp);
	}	
	return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

int mp[111111];

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

	int n, m;cin >> n >> m;
	REP(i, m){
		int l, r;cin >> l >> r;
		mp[l]++;
		mp[r+1]--;
	}

	REP(i,111000)mp[i+1] += mp[i];

	int ans = 0;
	REP(i, 111111)if(mp[i] == m)ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))

ans = 0
sm = 0
for i in range(n):
    if i % 2 == 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
    if i % 2 != 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
print(min(ans, ans1))


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	int even, odd;

	rep(i, n) {
		cin >> a[i];

		if (a[i] % 2 == 0) {
			even++;
		} else {
			odd++;
		}
	}

	if (odd % 2 == 1) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main()
{
    int a, b, c, k;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if (a >= k)
    {
        printf("%d", k);
        return 0;
    }
    else if ((a+b) >= k)
    {
        printf("%d",a);
        return 0;
    }
    else
    {
       int d = k-(a+b);
       int e =(-1)*d;
       printf("%d",a+e);
       return 0;

    }
    
    
    
}

Measured memory_bytes: 1696
#include <iostream>
#include <math.h>
using namespace std;
 
int main (){
	int n,y = 0,ans = 0,z = 0;
  	cin >> n;
  	double x = n;
  	while(n != 0){
    	n /= 10;
      	y++;
    }
  	//cout << y << "桁" << endl;
	if(y == 1){
    	cout << x;
    } 
  	else if(y % 2 == 1){
    	if(y == 3){
          	for(int i = 100;i <= x;i++){
              	z++;
        		ans = z;
            }
          	cout << ans + 9;
        }
      	if(y == 5){
          	for(int i = 10000;i <= x;i++){
              	z++;
        		ans = z;
            }
          	cout << ans + 909;
        }
    }
  	else if(y % 2 == 0){
    	if(y == 2){
        	cout << 9;
        }
      	if(y == 4){
        	cout << 909;
        }
      	if(y == 6){
        	cout << 90909;
        }
    }
}	

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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n;
    cin>>n;
    vi a(n), freq(n+1);
    for(int i=0; i<n; i++) {
        cin>>a[i];
        freq[a[i]]++;
    }
    int ans =0;
    for(int i=1;i <=n; i++) {
        ans += freq[i]*(freq[i]-1)/2;
    }
    for(int i=0; i<n; i++) {
        int cnt = freq[a[i]];
        cout << ans - cnt*(cnt-1)/2 + (cnt-1)*(cnt-2)/2 << "\n";
    }
    return 0;
}



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

using namespace std;

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

    string first_str = str.substr(0,2);
    string second_str = str.substr(2,2);

    stringstream first_str_temp(first_str);
    stringstream second_str_temp(second_str);

    int str1 = 0, str2 = 0;
    first_str_temp >> str1;
    second_str_temp >> str2;

    if (str1 <= 12 && str1>0 && str2 <= 12 && str2>0)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if(str1 <= 12 && str1>0)
    {
        cout << "MMYY" << endl;
    }
    else if(str2 <= 12 && str2>0)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

void main(){
  int n,m,x;
  int c[16];
  int a[16][16];
  scanf("%d %d %d",&n,&m,&x);
  int i,j,k;
  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  
  int limit=1;
  for(i=0;i<n;i++){
    limit*=2;
  }
  int min=-1;
  for(i=1;i<limit;i++){
  	int kingaku=0;
  	int rikaido[16]={0};
  	int tassei=1;
    for(j=0;j<n;j++){
      if((i&(1<<j))!=0){//j番目購入
        kingaku+=c[j];
        for(k=0;k<m;k++){
          rikaido[k]+=a[j][k];
        }
      }
    }
    puts("");
    for(j=0;j<m;j++){
      if(rikaido[j]<x){
        tassei=0;
        break;
      }
    }
    if(tassei){
      if(min==-1){
        min=kingaku;
      }else if(kingaku<min){
        min=kingaku;
      }
    }
  }
  printf("%d\n",min);
}

Measured memory_bytes: 1736
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
    
  while (input.hasNext()) {
    val S = input.next()
    val end1 = (S.length - 1) / 2
    val start2 = (S.length + 3) / 2
    var isPalindrom = true
    
    for (i in 0..S.length - 1) {
      if(S[i] != S[S.length - i - 1]) {
        isPalindrom = false
        break
      }
    }
    
    var isPalindrom1 = true
    for (i in 0..end1 - 1) {
      if(S[i] != S[end1 - i - 1]) {
        isPalindrom1 = false
        break
      }
    }
    
    var isPalindrom2 = true
    for (i in start2 - 1..S.length - 1) {
      if(S[i] != S[S.length - i - 1]) {
        isPalindrom2 = false
        break
      }
    }
    
    if (isPalindrom && isPalindrom1 && isPalindrom2) {
      println("Yes")
    } else {
      println("No")
    }
  }
}

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

int dp[110000];

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < 110000; i++) {
    dp[i] = 1000000000;
  }
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= n; j++) {
      dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3548
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

ll n,m;
ll bb[55][55];
bool reached[60];

ll search(ll a){
    if(reached[a]==true) return 0;
    reached[a] =true;
    rep(i,n){
        if(bb[a][i]==1){
            search(i);
        }
    }
}

signed main(){
    scanf("%lld %lld",&n,&m);
    vector<pair<ll,ll>> d(m);
    rep(i,m) {
        scanf("%lld %lld",&d[i].first,&d[i].second);
        d[i].first--;
        d[i].second--;
        bb[d[i].first][d[i].second]++;
        bb[d[i].second][d[i].first]++;
    }
    ll t1,t2=0,ct=0;
    rep(i,m){
        t1 = d[i].first;
        t2 = d[i].second;
        bb[d[i].first][d[i].second]--;
        bb[d[i].second][d[i].first]--;
        rep(j,60) reached[j]=false;
        // cout<<i<<endl;
        search(0);
        rep(j,n){
            if(reached[j]==false){
                ct++;
                break;
            }
        }
        bb[d[i].first][d[i].second]++;
        bb[d[i].second][d[i].first]++;
    }
    printf("%lld\n",ct);
}


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

int main(){
  int h,w;
  cin >> h >> w;
  while(h*w){
    for(int i=0;i<w;i++)cout << "#";
    cout << endl;
    for(int i=1;i<h-1;i++){
      for(int j=0;j<w;j++){
	if(j==0 || j==w-1)cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    for(int i=0;i<w;i++)cout << "#";
    cout << endl;
    cin >> h >> w;
    cout << endl;
  }
  return 0;
}

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

int N;

int main(){
	while(cin >> N){
		set<int> s;
		for(int i=0;i<N;i++){
			int d;
			cin >> d;
			s.insert(d);
		}
		cout << s.size() << endl;
	}
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    s = 'abcdefghijklmnopqrstuvwxyz'
    assert len(s) == 26
    cur = []
    while N > 0:
        amari = N % 26
        if amari == 0:
            amari += 26
        cur.append(s[amari-1])
        N -= amari
        N //= 26
    print(''.join(cur[::-1]))
main()



Measured memory_bytes: 83604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    vector<ll> T(2), A(2), B(2);
    for(int i = 0; i < 2; ++i)  cin >> T[i];
    for(int i = 0; i < 2; ++i){
        cin >> A[i];
        A[i] *= T[i];
    }
    for(int i = 0; i < 2; ++i){
        cin >> B[i];
        B[i] *= T[i];
    }
    if(A[0] + A[1] == B[0] + B[1]){
        cout << "infinity\n";
        return 0;
    }
    if(A[0] + A[1] < B[0] + B[1])   swap(A, B);
    ll foo = B[0] - A[0];
    ll bar = A[0] + A[1] - B[0] - B[1];
    ll ans = 0;
    if(foo > 0){
        ans = ((foo - 1) / bar + 1) * 2 - 1;
        if(foo % bar == 0)  ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define y2 y1919810
typedef pair <int, int> PII;
//#define int long long
#define all(x) (x.begin(),  x.end())
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t)  for (int i = s; i <= (int)t; i++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
long long qread() {
	char c = getchar();
	int neg = 1;
	long long val = 0;
	while (c != '-' && !isdigit(c)) c = getchar();
	if (c == '-') c = getchar(), neg = -1;
	while (isdigit(c)) val = (val << 3) + (val << 1) + c - '0', c = getchar();
	return neg * val;
}
int main() {
	int  a = qread(), b = qread(), c = qread(), k = qread();
	int ans = 0;
	if (k <= a + b) ans = min(a, k);
	else if (k > a + b) ans = a - (k - a - b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3644
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    auto c = new string[](2);
    c[0] = readln.chomp;
    c[1] = readln.chomp;

    string ans = (equal(c[0], c[1].retro)) ? "YES" : "NO";

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  char c = s[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != c) {
      c = s[i];
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  int64_t l0 = 2;
  int64_t l1 = 1;
  int64_t l2;
  for (int i = 0; i < N; i++)
  {
    l2 = l1 + l0;
    l0 = l1;
    l1 = l2;
  }
  cout << l0 << endl;
}

Measured memory_bytes: 256
N, K = map(int, raw_input().split())
R0, R1 = range(K), range(K + 1)
D = [[0] * (K + 1) for i in R1]
a = b = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    p = (x / K + y / K + c) % 2
    D[y % K + 1][x % K + 1] += 1 - 2 * p
    b += p

for i in R0:
    for j in R1:
        D[i + 1][j] += D[i][j]

for i in R1:
    for j in R0:
        D[i][j + 1] += D[i][j]

for i in R1:
    for j in R1:
        S = D[i][K] + D[K][j] - D[i][j] * 2
        a = max(a, S, D[K][K] - S)

print a + b

Measured memory_bytes: 23024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public void solve() {
		String s = next();
		out.println(s.substring(0,4) + " " + s.substring(4));
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8148
class Solution:
    def solve(self, S: str, T: str) -> str:

        def str2pattern(S: str) -> str:
            swap = {}
            a = ord('a')
            pattern = ""
            for s in S:

                if not s in swap:
                    swap[s] = chr(a)
                    a += 1

                pattern += swap[s]

            return pattern

        if str2pattern(S) == str2pattern(T):
            return "Yes"
        else:
            return "No"


if __name__ == '__main__':

    # standard input
    S = input()
    T = input()

    # solve
    solution = Solution()
    print(solution.solve(S, T))


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
ll pre[N], suf[N];
ll n, c, x[N], v[N];
ll f[N], g[N];

int main() {
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &v[i]);

  pre[0] = 0;
  for (int i = 1; i <= n; i++) pre[i] = v[i] + pre[i - 1];

  suf[n + 1] = 0;
  for (int i = n; i >= 1; i--) suf[i] = v[i] + suf[i + 1];

  f[0] = 0;
  for (int i = 1; i <= n; i++) f[i] = max(f[i - 1], pre[i] - x[i]);

  g[n + 1] = 0;
  for (int i = n; i >= 1; i--) g[i] = max(g[i + 1], suf[i] - c + x[i]);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, pre[i] - x[i]);
    ans = max(ans, pre[i] - 2 * x[i] + g[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    ans = max(ans, suf[i] - c + x[i]);
    ans = max(ans, suf[i] - 2 * (c - x[i]) + f[i - 1]);
  }
  
  printf("%lld\n", ans);
}



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

int H, W;
string grid;
vector<int> dp;

const int md = 1e9 + 7;

void add(int& x, int y) {
    x += y;
    if (x > md) x -= md;
}

int compress(int i, int j) {
    return i*W + j;
}

int solve(int p) {
    if (p == H*W-1) return 1;
    if (dp[p] != -1) return dp[p];
    int i = p / W;
    int j = p % W;
    
    int right = 0;
    if (j < W - 1 && grid[compress(i,j+1)] != '#') {
        add(right, solve(compress(i,j+1))); 
    }

    int down = 0;
    if (i < H - 1 && grid[compress(i + 1, j)] != '#') {
        add(down, solve(compress(i + 1, j)));
    }
    
    int res = 0;
    add(res, right);
    add(res, down);
    return dp[p] = res; 
}

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

    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string s;
        cin >> s;
        grid += s;
    }
    
    dp = vector<int>(H*W + 1, -1);
    cout << solve(0) << "\n";
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 262144 << 1, K = 18;  // N = 1 << (K + 1)
vector<int> v[N];
int n, m, i, k;
int a[N + 10], b[N + 10];
int P = 924844033, G = 5, g[K + 1], ng[K + 10], inv[N + 10], inv2;
int power(int a, int b) {
    int t = 1;
    for (; b; b >>= 1, a = (ll)a * a % P)
        if (b & 1) t = (ll)t * a % P;
    return t;
}
void NTT(int* a, int n, int t) {
    for (int i = 1, j = 0; i < n - 1; i++) {
        for (int s = n; j ^= s >>= 1, ~j & s;)
            ;
        if (i < j) {
            int k = a[i];
            a[i] = a[j];
            a[j] = k;
        }
    }
    for (int d = 0; (1 << d) < n; d++) {
        int m = 1 << d, m2 = m << 1, _w = t == 1 ? g[d] : ng[d];
        for (int i = 0; i < n; i += m2)
            for (int w = 1, j = 0; j < m; j++) {
                int &A = a[i + j + m], &B = a[i + j], t = (ll)w * A % P;
                A = B - t;
                if (A < 0) A += P;
                B = B + t;
                if (B >= P) B -= P;
                w = (ll)w * _w % P;
            }
    }
    if (t == -1)
        for (int i = 0, j = inv[n]; i < n; i++) a[i] = (ll)a[i] * j % P;
}
int f[N + 10], rf[N + 10];
void init() {
    g[K] = power(G, (P - 1) / N), ng[K] = power(g[K], P - 2);
    for (i = K - 1; ~i; i--)
        g[i] = (ll)g[i + 1] * g[i + 1] % P,
        ng[i] = (ll)ng[i + 1] * ng[i + 1] % P;
    for (inv[1] = 1, i = 2; i <= N; i++)
        inv[i] = (ll)(P - inv[P % i]) * (P / i) % P;
    inv2 = inv[2];
    f[0] = 1;
    for (int i = 1; i <= N; i++) f[i] = (ll)f[i - 1] * i % P;
    rf[N] = power(f[N], P - 2);
    for (int i = N; i; i--) rf[i - 1] = (ll)rf[i] * i % P;
}
int C(int n, int m) {
    if (n < m || m < 0) return 0;
    return (ll)f[n] * rf[m] % P * rf[n - m] % P;
}
int ans[N + 10], sz[N + 10], cnt[N + 10];
void dfs(int x, int fx) {
    sz[x] = 1;
    for (auto y : v[x]) {
        if (y == fx) continue;
        dfs(y, x);
        sz[x] += sz[y];
    }
    if (fx) ++cnt[n - sz[x]], ++cnt[sz[x]];
}
int main() {
    init();
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) cnt[i] = (ll)cnt[i] * f[i] % P;
    for (int i = 0; i <= n; i++) a[i] = rf[n - i];
    for (k = 1; k <= (n<<1); k <<= 1)
        ;
    NTT(cnt, k, 1), NTT(a, k, 1);
    for (int i = 0; i < k; i++) b[i] = (ll)cnt[i] * a[i] % P;
    NTT(b, k, -1);
    for (int i = 1; i <= n; i++) {
        ans[i] = (ll)b[i + n] * rf[i] % P;
        // printf("%d %d %d\n",i+n,b[i+n],rf[i]);
        ans[i] = ((ll)n * C(n, i) % P - ans[i] + P) % P;
        printf("%d\n", ans[i]);
    }
    return 0;
}

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

int main(){
int a,b;
char op;

while(1){
cin >> a >> op >> b;
if(op == '+'){
cout << a + b << endl;
}else if(op == '-'){
cout << a - b << endl;
}else if(op == '/'){
cout << a / b << endl;
}else if(op == '*'){
cout << a * b << endl;
}else if(op == '?'){
break;
}
}
return 0;
}


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

using namespace std;
typedef long long ll;
int n, N;
ll a[1000005];
int f[1 << 18], g[1 << 18]; int stk[50]; int tp = 0;
int vis[1 << 18];
ll ans[1 << 18];
int cmp(int x, int y){
	return a[x] > a[y];
}
int main(){
	scanf("%d", &n); N = 1 << n;
	for(int i = 0; i < N; i ++){
		scanf("%lld", &a[i]);
	}
	for(int i = 1; i < N; i ++){
		tp = 0;
		for(int j = 0; j < n; j ++){
			if(!(i & (1 << j))) continue;
			if(!vis[f[i ^ (1 << j)]]) stk[++tp] = f[i ^ (1 << j)], vis[f[i ^ (1 << j)]] = 1;
			if(!vis[g[i ^ (1 << j)]]) stk[++tp] = g[i ^ (1 << j)], vis[g[i ^ (1 << j)]] = 1;
		}
		stk[++tp] = i;
		sort(stk + 1, stk + tp + 1, cmp);
		f[i] = stk[1], g[i] = stk[2];
		for(int j = 1; j <= tp; j ++) vis[stk[j]] = 0;
	}
	for(int i = 1; i < N; i ++) {
	//	printf("%d %d\n", f[i], g[i]);
		ans[i] = a[f[i]] + a[g[i]];
		ans[i] = max(ans[i], ans[i - 1]);
		printf("%lld\n", ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 11264
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
g = [[] for i in range(n)]
cc = dict()
for i in range(n-1):
    a,b,c = inpl()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    cc[(a,b)] = c
    cc[(b,a)] = c
q,k = inpl()
k -= 1
cost = [INF] * n
cost[k] = 0
def dfs(node,c):
    for next in g[node]:
        if cost[next] == INF:
            cost[next] = c + cc[(node,next)]
            dfs(next,cost[next])

dfs(k,0)
res = [0] * q
for i in range(q):
    x,y = inpl()
    x -= 1
    y -= 1
    res[i] = cost[x] + cost[y]
for z in res:
    print(z)


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

int n,m,a[100009],b[100009];
long long solve(int x){
	int i; long long tmp=0;
	for (i=1; i<=n; i++) if (a[i]==(x&a[i])) tmp+=b[i];
	return tmp;
}
int main(){
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]);
	long long ans=solve(m);
	for (i=30; i>=0; i--) if (m>>i&1){
		int x=m^(1<<i); x|=(1<<i)-1;
		ans=max(ans,solve(x));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int x2=1e9;

int main() {
  int x3,y3;
  ll S;
  cin >> S;
  x3 = (x2-S%x2) % x2;
  y3 = (S+x3) / x2;
  cout << "0 0 1000000000 1 " << x3 << " " << y3 << endl;
}

Measured memory_bytes: 256
N = input()
D = len(N)
N = int(N)
ans = 0
def dfs(v):
    global ans
    if v > N: return 0
    if len(set(str(v))) == 3: ans += 1
    for i in (3,5,7):
        dfs(v*10+i)

dfs(0)
print(ans)


Measured memory_bytes: 48604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    vector<ll> p(N);

    rep(i,N){
        cin>>p[i];
    }

    sort(all(p));

    ll ans = 0;

    rep(i,K){
        ans+=p[i];
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3592