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

using namespace std;

using int64 = long long;

struct Combination {
  int mod;
  vector< int64_t > mfact, rfact;

  Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

const int mod = 998244353;

int main() {


  int64 N, A, B, K;
  cin >> N >> A >> B >> K;
  Combination beet(N, mod);
  int64 ret = 0;
  for(int x = 0; x <= N; x++) {  // 赤色ブロックの数を全探索
    int64 rest = K - A * x;
    if(rest < 0) continue;
    if(rest % B != 0) continue;
    int64 y = rest / B;
    ret += beet.C(N, x) * beet.C(N, y) % mod;
    ret %= mod;
  }
  cout << ret << endl;
}

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

int main(){
    int n, k;
    if (scanf("%d %d", &n, &k) < 2) exit(1);
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        if (scanf("%d", &h[i]) < 1) exit(1);
    }
    vector<int> a = h;
    sort(a.begin(), a.end());
    //座圧 -> id 復元 -> res
    map<int, int> id;
    map<int, int> res;
    int now = 1;
    for (int i = 0; i < n; i++){
        if (id[a[i]] == 0) {
            id[a[i]] = now;
            res[now] = a[i];
            now++;
        }
    }
    long long INF = ((long long)1 << 40);
    vector<vector<long long>> dp(n - k + 1, vector<long long>(n + 1, INF));
    vector<vector<long long>> pd = dp;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++){
        pd = dp;
        for (int j = 0; j <= n - k; j++){
            for (int m = 0; m <= n; m++){
                if (dp[j][m] == INF) continue;
                if (j == n - k) continue;
                pd[j + 1][id[h[i]]] = min(pd[j + 1][id[h[i]]], dp[j][m] + max(0, h[i] - res[m]));
            }
        }
        dp = pd;
    }
    long long ans = INF;
    for (int i = 0; i <= n; i++) ans = min(ans, dp[n - k][i]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 1664
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range(N-M+1):
        for j in range(N-M+1):
            ok = True
            for x in range(M):
                for y in range(M):
                    if A[i+x][j+y] != B[x][y]:
                        ok = False
            if ok:
                print("Yes")
                return
    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 40304
#include<stdio.h>
#include<vector>
#include<cmath>
using namespace std;

int main(){

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

    vector<int> x, y;
    for(int i=0; i<n; i++){
        int tmp;
        scanf("%d", &tmp);
        x.push_back(tmp);
    }
    for(int i=0; i<n; i++){
        int tmp;
        scanf("%d", &tmp);
        y.push_back(tmp);
    }

    double sum1 = 0;
    for(int i=0; i<n; i++){
        sum1 += abs(x[i] - y[i]);
    }
    printf("%.8f\n", sum1);

    double _sum2 = 0, sum2 = 0;
    for(int i=0; i<n; i++){
        _sum2 += (x[i] - y[i])*(x[i] - y[i]);
    }
    sum2 = sqrt(_sum2);
    printf("%.8f\n", sum2);

    double _sum3 = 0, sum3 = 0;
    for(int i=0; i<n; i++){
        _sum3 += abs((x[i] - y[i])*(x[i] - y[i])*(x[i] - y[i]));
    }
    sum3 = pow(_sum3, 1.0/3.0);
    printf("%.8f\n", sum3);

    double max = -1;
    for(int i=0; i<n; i++){
        int tmp = abs(x[i] - y[i]);
        if(tmp > max) max = tmp;
    }
    printf("%.8f\n", max);

    return 0;
}


Measured memory_bytes: 2988
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;
const int BIT_SIZE = 64;

long long power(long long m, long long n){
    long long ans = 1;
    long long tmp = m;
    for(int i = 0; i < BIT_SIZE; i++){
        if(((n >> i) & 1) == 1){
            ans = ans * tmp;
        }
        tmp = (tmp * tmp);
    }
    return ans;
}
int main(){
    long long N;
    long long P;
    cin >> N >> P;
    if(N == 1){
        cout << P << endl;
    } else if(N >= 40){
        cout << 1 << endl;
    } else {
        long long gcd = 1;
        long long max_candidate = 0;
        while(true){
            if(power(gcd, N) > P){
                break;
            }
            //cout << gcd << " " << N << endl;
            //cout << power(gcd, N) << endl;
            if(P % power(gcd, N) == 0){
                max_candidate = gcd;
            }
            gcd++;
        }
        cout << max_candidate << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int n;
string str;

typedef unsigned long long ull;
ll B[2] = {1009, 1013};
const int maxn = 5005;
const int hs = 2;
ll v[maxn][hs];
ll mod[hs] = {1000000007LL, 1000000009LL}; // 9999991, 1e9 + 9はsampleでダメ
ll t[maxn][hs];

void build(string a) {
    int al = (int)a.length();
    
    rep(j, hs) t[0][j] = 1;
    rep(i, al - 1) rep(j, hs) (t[i + 1][j] = t[i][j] * B[j]) %= mod[j];
    
    rep(i, al) rep(j, hs) {
        (v[i + 1][j] += v[i][j] + t[al - 1 - i][j] * a[i]) %= mod[j];
    }
}


bool check(int x) { // 長さxの重ならない文字列ありますか
    set<ll> s[hs];
    map<ll, int> mp[hs]; // 始めのindex管理
    int cnt[hs] = {0};
    for (int i = 0; i + x <= sz(str); ++i) {
        int flg = 0;
        rep(j, hs) {
            ll tmp = (v[i + x][j] - v[i][j] + mod[j]) % mod[j] * t[i][j] % mod[j];
            if (s[j].find(tmp) != s[j].end() && mp[j][tmp] - 1 + x <= i) {
                flg++;
                if (flg == 2) return 1;
            }
            s[j].insert(tmp);
            if (mp[j][tmp] == 0) mp[j][tmp] = ++cnt[j];
        }
    }
    return 0;
}

int binary_search(int ok, int ng) {
    // assert(check(ok) == true);
    // assert(check(ng) == false);
    while (abs(ng - ok) > 1) {
        int mid = (ng + ok) / 2;
        (check(mid) ? ok : ng) = mid;
        // cout << "ok " << ok << " " << ng << endl;
    }
    return ok;
}


int main() {
    cin >> n;
    cin >> str;
    
    build(str);
    cout << binary_search(0, n) << endl;
}



Measured memory_bytes: 1536
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[505][505];
int main(){
   ll n,m,q;
   cin>>n>>m>>q;
   for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      dp[a][b]++;
   }
   for(int i=0;i<=n;i++)for(int j=i;j<=n;j++)dp[i][j+1]+=dp[i][j];
   while(q--){
      int l,r;
      cin>>l>>r;
      ll ans=0;
      for(int i=l;i<=r;i++){
         ans+=dp[i][r]-dp[i][l-1];
      }
      cout<<ans<<endl;
   }
}

Measured memory_bytes: 2944
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();
    	String s=sc.next();
    	String t=sc.next();


    	int min=2*N;
    	for(int i=1;i<=N;i++) {
    		String subs=s.substring(N-i, N);
    		String subt=t.substring(0,i);

    		if(subs.equals(subt)) {

    			min=2*N-i;

    		}
    	}

    	System.out.println(min);

    }


}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
using namespace std;


    
int main(){
    long long int A,B,K;
    cin >> A >> B >> K;//2 3 3 
    if(A>=K){
        A-=K;
    }
    else if(A+B>=K){
        B-=K-A;
        A=0;
    }
    else{
        A=0;
        B=0;
    }

    cout << A << ' ' << B;
    
}

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

int main(int argc, const char * argv[]) {
    int n;
    string s;
    cin>>n>>s;
    int wcount=0,ecount=0;
    for(int i=1;i<n;i++){
        if(s[i] == 'E')ecount++;
    }
    int ans = wcount+ecount;
    for(int i=1;i<n;i++){
        if(s[i-1]=='W')wcount++;
        if(s[i]=='E')ecount--;
        ans = min(ans,wcount+ecount);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 900
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] ans=new boolean[n];
		Unionfind uf=new Unionfind(n);
		for(int i = 0; i<m; i++){
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int z = sc.nextInt();
			uf.unite(x,y);
		}
		long count=0;
		for(int i=0; i<n; i++){
			if(!ans[uf.root(i)]){
				ans[uf.root(i)]=true;
				count++;
			}
		}
		System.out.println(count);
	}
	static class Unionfind{
		int[] parent;
		public Unionfind(int n){
			this.parent=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
	}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n,mcnt=0;
	ll a,sum;
	cin >> n;
	vector<ll>arr;
	rep(i, n) {
		cin >> a;
		if (a < 0)mcnt++;
		arr.push_back(abs(a));
	}
	sort(all(arr));
	sum = accumulate(all(arr), 0LL);
	if (mcnt % 2 == 0) {
		cout << sum << endl;
	}
	else {
		sum -= (arr[0] * 2LL);
		cout << sum << endl;
	}
	return 0;
}



Measured memory_bytes: 4232
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N, M := nextInt(), nextInt()
	sum := 0
	sum += N * (N - 1) / 2
	sum += M * (M - 1) / 2
	fmt.Println(sum)

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


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

#define NIL -1
#define RECO -2

typedef struct Node
{
  int parent;
  int firstchild;
  int rightsibling;
}Node;

int CountDepth(Node*,int);

int main()
{
  int a,b,c,list,nodeID, nextsibling=0;
  scanf("%d", &a);
  
  Node* TreeList =(Node*)malloc(a*sizeof(Node));
  
  for(int i=0;i<a;i++)
    { TreeList[i].parent=NIL;TreeList[i].firstchild=RECO;TreeList[i].rightsibling=RECO;}
  for(int i=0;i<a;i++){
      scanf("%d %d", &nodeID, &b);
      for(int j=0;j<b;j++)
        {
	  scanf("%d", &list);
	  
	  TreeList[list].parent = nodeID;
	  
	  if(j==0){TreeList[nodeID].firstchild=list;}
	  else
            {
	      TreeList[nextsibling].rightsibling=list;
            }
	  nextsibling = list;
        }
    }
  
  for(int i=0;i<a;i++){
      printf("node %d: parent = %d, depth = %d,", i, TreeList[i].parent, CountDepth(TreeList, i));
      if(CountDepth(TreeList, i)==0){printf(" root, [");}
      else if(TreeList[i].firstchild==RECO){printf(" leaf, [");}
      else{printf(" internal node, [");}
      if(TreeList[i].firstchild!=RECO)
        {
	  printf("%d", TreeList[i].firstchild);
	  c = TreeList[i].firstchild;
	  while(TreeList[c].rightsibling!=RECO)
            {
	      printf(", %d", TreeList[c].rightsibling);
	      c = TreeList[c].rightsibling;
            }
        }
      
      printf("]\n");
        
    }
  free(TreeList);
  
  return 0;
}

int CountDepth(Node* List, int ID)
{
  int s=0;
  while(List[ID].parent!=NIL)
    {
      s++;
      ID = List[ID].parent;
    }
  return s;
}



Measured memory_bytes: 2520
#include<stdio.h>
int main(void)
{
	int n;
	int p[201][4];
	int flg[201][4];
	int i,j,k;
	int sum[201];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			scanf("%d",&p[i][j]);
			flg[i][j]=0;
		}
	}
	for(k=0;k<3;k++){
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(p[i][k]==p[j][k]){
					flg[i][k]=1;
					flg[j][k]=1;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		sum[i]=0;
		for(j=0;j<3;j++){
			if(flg[i][j]==0){
				sum[i]+=p[i][j];
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",sum[i]);
	}
	return 0;
}

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

int main() {
	int n,m;cin>>n>>m;
	vector<int> mm;
	for(int i=1;i<=m;i++){
		if(i*i>m)break;
		if(m%i==0){
			mm.push_back(i);
		}
	}

	for(int i=mm.size()-1;i>=0;i--){
		mm.push_back(m/mm[i]);
	}
	int ans=0;
	for(int i=0;i<mm.size();i++){
		if(m/mm[i]>=n){
			if(ans<mm[i]){
				ans=mm[i];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
MOD = 1000000007

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

A.sort(key=lambda x: abs(x))

neg = []
pos = []
zero = 0

for i in range(N):
    if A[i] > 0:
        pos.append(A[i])
    elif A[i] < 0:
        neg.append(A[i])
    else:
        zero += 1

res = 1
sign = 1

for i in range(K):
    res *= A[~i]
    res %= MOD
    if A[~i] < 0:
        sign *= -1

    if A[~i] == 0:
        sign = 0

if sign == 1:
    print(res % MOD)

elif sign == 0:
    print(0)

else:
    flag1 = False
    tmp1 = -1
    minneg = None
    for i in range(K):
        if A[~i] < 0:
            minneg = ~i
    maxpos = None
    for i in range(N - K):
        if A[i] > 0:
            flag1 = True
            maxpos = i
    if maxpos is not None:
        tmp1 *= A[maxpos]
        tmp1 /= A[minneg]
    flag2 = False
    tmp2 = -1
    minpos = None
    for i in range(K):
        if A[~i] > 0:
            minpos = ~i
    maxneg = None
    for i in range(N - K):
        if A[i] < 0:
            maxneg = i
    if maxneg is not None and minpos is not None:
        flag2 = True
        tmp2 *= A[maxneg]
        tmp2 /= A[minpos]
    if flag1 and flag2:
        if A[maxpos] * A[minpos] > A[maxneg] * A[minneg]:
            print(res * A[maxpos] * pow(A[minneg], MOD - 2, MOD) % MOD)
        else:
            print(res * A[maxneg] * pow(A[minpos], MOD - 2, MOD) % MOD)
    elif flag1:
        print(res * A[maxpos] * pow(A[minneg], MOD - 2, MOD) % MOD)
    elif flag2:
        print(res * A[maxneg] * pow(A[minpos], MOD - 2, MOD) % MOD)
    else:
        if zero:
            print(0)
        else:
            res = 1
            for i in range(K):
                res *= A[i]
                res %= MOD
            print(res % MOD)

Measured memory_bytes: 114744
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      
      	System.out.println(Math.min(a*n, b));
    }
}

Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
int x[1005],y[1005],dis[45],cnt,n;
char ans[1005][45];
void calc(int num)
{
    dis[++cnt]=num;
    for(int i=0;i<n;i++)
    {
        if(abs(x[i])>abs(y[i]))
        {
            if(x[i]>0) ans[i][cnt]='R',x[i]-=num;
            else ans[i][cnt]='L',x[i]+=num;
        }
        else 
        {
            if(y[i]>0) ans[i][cnt]='U',y[i]-=num;
            else ans[i][cnt]='D',y[i]+=num;
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=30;i>=0;i--)
        calc(1<<i);
    if(x[0]||y[0]) calc(1);
    for(int i=0;i<n;i++)
        if(x[i]||y[i]) 
        {
            printf("-1\n");
            return 0;
        }
    printf("%d\n",cnt);
    for(int i=1;i<=cnt;i++)
        printf("%d%c",dis[i],i==cnt?'\n':' ');
    for(int i=0;i<n;i++)
        printf("%s\n",ans[i]+1);
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
# coding: utf-8

def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)

def main():
    N, K = map(int, open(0).read().split())
    debug([N, K])
    r = N % K
    a = min(r, K - r)
    print(a)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
A, B, C, D = gets.chomp.split(" ").map(&:to_i)

dm1 = A.divmod(D)
dm2 = C.divmod(B)

puts dm1[0] + (dm1[1]==0 ? 0:1) >= dm2[0] + (dm2[1]==0 ? 0:1) ? 'Yes' : 'No'


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

int main()
{
	while(true){
		string s1;
		cin >> s1;

		if(s1==".")
			break;

		string s2;
		cin >> s2;

		if(s1==s2){
			cout << "IDENTICAL" << endl;
			continue;
		}

		string t1 = s1;
		string t2 = s2;

		while(true){
			size_t d1b = t1.find('\"');
			if(d1b==string::npos)
				break;
			t1.replace(d1b, 1, "@");

			size_t d1e = t1.find('\"');
			t1.replace(d1e, 1, "@");

			size_t d2b = t2.find('\"');
			if(d2b==string::npos)
				break;
			t2.replace(d2b, 1, "@");

			size_t d2e = t2.find('\"');
			t2.replace(d2e, 1, "@");

			string u1 = s1;
			u1.replace(d1b+1, d1e-d1b-1, "");
			string u2 = s2;
			u2.replace(d2b+1, d2e-d2b-1, "");

			if(u1==u2){
				t1 = u1;
				t2 = u2;
				break;
			}
		}

		if(t1==t2){
			cout << "CLOSE" << endl;
		}
		else{
			cout << "DIFFERENT" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;



int main(){

    string s;
    cin >> s;

    int sn = 0;
    int n = 0;
    int k = 1;

    int size = s.size();

    rep(i,size){
        int tmp = (int)(s[size - 1 - i] - '0');
        sn = sn + tmp;
        n = n + tmp * k;
        k = k * 10; 
    }

    cout << (n % sn == 0 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REP2(a,b) for(lo j=(a);j<(b);j++)
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++
#define INF 2000000000
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 
//UVa
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
 

lo cel(lo x,lo y){
	if(x%y<=1)return x/y;
	else return x/y +1;
}
 void solve(){
 	lo n;
 	cin>>n;
 	float x, d=1.08;
 	x=float(n)/d;
 	lo xx,yy;
 	xx=lo(x);
 //	if() ==)
 	float kk;
 	kk=float(xx)*1.08;
 	yy=lo(kk);
 //	cout<<yy<<"xx"<<endl;
 	if(yy==n){
 		cout<<xx;
 		return;
 	}
 	kk=float(xx+1)*1.08;
 	yy=lo(kk);
 	 //	cout<<yy<<"xx"<<endl;

 	if(yy==n){
 		cout<<xx+1;
 		return;
 	}
 	cout<<":(";
 }

int main(){
	
	
 
	lo n;
	//cin>>n;
	//while(n--)
		solve();
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

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

    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (a.size() < b.size()) {
        cout << "LESS" << endl;
        return 0;
    }
    else {
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                return 0;
            }
            if (a[i] < b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  int s=0;
  string S;
  cin >> S;
  x=S.size();
  
  for (int i=0; i<x/2; i++) {
    if(S[i]!=S[x-i-1]) s++;
  }
  
  cout << s;
  
  return 0;
      
}

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

int main() {
  int N, a;
  a = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r, b;
    cin >> l >> r;
    b = r - l + 1;
    a += b;
  }

  cout << a << endl;
}

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

int main(void){
  int i, ans=0, kind=0, cnt=0;
  char s[10];

  scanf("%s", s);
  if(s[0] == s[1]){
    if(s[2] == s[3]){
      if(s[0] != s[3]) printf("Yes");
      else printf("No");
    }
    else printf("No");
  }
  else if(s[0] == s[2]){
    if(s[1] == s[3]) printf("Yes");
    else printf("No");
  }
  else if(s[0] == s[3]){
    if(s[1] == s[2]) printf("Yes");
    else printf("No");
  }
  else printf("No");


  return 0;
}


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

int main() {
int n,k;
long long b[101][101][256];
long long f[104],p=1e9+7,c=0;
cin>>n>>k;
f[0]=1;
for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
        for(int l=0;l<256;l++){
            b[i][j][l]=0;
        }
    }
    f[i+1]=((i+1)*f[i])%p;
}


b[0][0][0]=1;

for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    for(int j=0;j<i;j++){
        for(int l=0;l<256;l++){
            b[i][j][l]+=b[i-1][j][l];
            b[i][j+1][l^a]+=b[i-1][j][l];
            b[i][j][l]%=p;
            b[i][j+1][l^a]%=p;
        }
    }
}
for(int j=0;j<=n;j++){
    c+=b[n][j][k]*f[j];
    c%=p;
}
cout<<c<<endl;
	return 0;
}

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

//#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

struct UnionFind {
    vector<int> data;
    vector<int> sizes;
    
    UnionFind(int n) : data(n) ,sizes(n, 1){
        for(int i = 0; i < n; i++) data[i] = i;
    }
    
    int root(int x) {
        if (data[x] == x) return x;
        return data[x] = root(data[x]);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (y < x) swap(x, y);
        data[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int treesize(int x) {
        return sizes[root(x)];
    }
    ll size(){
        set<int> st;
        REP(i,0,data.size()) st.insert(root(i));
        return st.size();
    }
};

struct Edge
{
    int a, b, cost;
    bool operator<(const Edge& o) const {
        return cost < o.cost;
    }
};
struct Graph{
    int n;
    vector<Edge> e;
};

signed main(){start();
    int n;
    cin>>n;
    Vi x(n),y(n);
    vector<Tiii> a(n),b(n);
    Graph g;
    REP(i,0,n){
        cin>>x[i]>>y[i];
        a[i]=mt(x[i],y[i],i);
        b[i]=mt(y[i],x[i],i);
    }

    sort(ALL(a));
    sort(ALL(b));
    REP(i,1,n){
        int x,y,id,px,py,pid;
        tie(x,y,id)=a[i];
        tie(px,py,pid)=a[i-1];
        Edge e;
        e.a=pid;
        e.b=id;
        e.cost=x-px;
        g.e.pb(e);
    }
    REP(i,1,n){
        int y,x,id,py,px,pid;
        tie(y,x,id)=b[i];
        tie(py,px,pid)=b[i-1];
        Edge e;
        e.a=pid;
        e.b=id;
        e.cost=y-py;
        g.e.pb(e);
    }
    sort(ALL(g.e));
    
    UnionFind UF(n);
    int ans=0;
    REP(i,0,g.e.size()){
        if(!UF.same(g.e[i].a,g.e[i].b)){
            ans+=g.e[i].cost;
            UF.unite(g.e[i].a,g.e[i].b);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7924
#include <iostream>
using namespace std;
#include <utility>
using P = pair<int,int>;
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#include<algorithm>
int main(){
    int N,count = 0;
    cin >> N;
    int e=0,s=0;
    vector<P> p(N);
    rep(i,N){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(),p.end());
    e = p[0].first;
    s = p[0].second;
    count++;
    for(int i=1;i<N;i++){
        if(e < p[i].second){
            count++;
            e = p[i].first;
        }
    }
    cout << count << endl;
}


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

public class B
{
    static void Main()
    {
        int[] intRecord = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();

        var h = intRecord[0];
        var n = intRecord[1];

        int[] a_i = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();

        var sumAttack = 0;
        for (int i = 0; i < n; i++)
        {
            sumAttack += a_i[i];
        }

        var answer = sumAttack >= h ? "Yes" : "No";
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 19680
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890

using namespace std;

int main()
{
    int i,j;
    int a,b;

    scanf("%d %d",&a,&b);
    int ans = a+b;
    ans = max(ans,a-b);
    ans = max(ans,a*b);
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,m,a,c1,c2,s;
    s=0;
    cin>>n;
    long long arr[n+10];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        s+=arr[i];
    }
    c1=0;
    c2=s;
    l=1000000000000000;
    for(i=0;i<n-1;i++)
    {
        c1+=arr[i];
        s-=arr[i];
        k=abs(c1-s);
        if(k<l)
        {
            l=k;
        }

    }
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
    int n;
    int a[55];
    int b[5637];
    cin >> n;
    a[0]=2;
    b[0]=2;
    int num=1;
    int cnta=0;
    for(int cnt=1;cnt<5637;num+=2){
        if (num<3)continue;
        b[cnt]=num;
        bool flag=true;
        for (int i=0;i<cnt;i++){
            if(b[i]*b[i]>b[cnt])break;
            if(b[cnt]%b[i]==0){
                flag=false;
            }
        }
        if(flag){
            if(b[cnt]%5==1 && cnta<55){
                a[cnta]=b[cnt];
                cnta++;
            }
            cnt++;
        }
    }
/*    cnt=5;
    for (int i=5;;i++){
        a[num]=b[cnt];

    }*/
    for(int i=0;i<n;i++){
        cout << a[i];
        if (i<n-1){
            cout <<" ";
        }
    }
        cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int A,B,C;
  int X;

  cin >> A >> B >> C >> X;

  const  int Y = X/50;; // Xは50円玉何枚分か

  int N_500,N_100; // 500円玉、100円玉を使った枚数を決めた時の残額

  int a,b; // 500,100円玉は最大何枚使えるか
  int c; // 最後に必要となる50円玉の枚数
  int ans = 0; // 場合の数

  a = min(Y/10,A);
  for( int i = 0; i <= a; i++ ){
    N_500 = Y-10*i;
    //    cout << "N_500: " << N_500 << endl;
    b = min(N_500/2,B);
    for( int j = 0; j <= b; j++ ){
      N_100 = N_500-2*j;
      c = N_100;
      //      cout << "N_100: " << N_100 << endl;
      if( C >= c ){
	ans += b-j+1;
	break;
      }
    }
  }

  cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x=> x*1);
  let N = inp[0];
  let K = inp[1];
  let ans = 0;
  while(N >= K){
  	N = N / K;
    ++ans;
  }
  console.log(ans + 1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
vector<int>graph[200000];
vector<int>hate_graph[200000];
vector<bool>visited(100003,false);
vector<int>degree(100003,0);
void dfs(int start,vector<int>&connected_component,vector<bool>&visited1)
{
	    visited[start]=true;
	    visited1[start]=true;
	    connected_component.emplace_back(start);
	    for(auto &x:graph[start])
	    	if(!visited[x])
	    		dfs(x,connected_component,visited1);
}
signed main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 int n,m,k;
	 cin>>n>>m>>k;
	 for(int i=0;i<m;i++)
	 {
	 	    int u,v;
	 	    cin>>u>>v;
	 	    graph[u].emplace_back(v);
	 	    graph[v].emplace_back(u);
	 	    degree[u]++;
	 	    degree[v]++;
	 }
	 for(int i=0;i<k;i++)
	 {
	 	    int u,v;
	 	    cin>>u>>v;
	 	    hate_graph[u].emplace_back(v);
	 	    hate_graph[v].emplace_back(u);
	 }
	 vector<int>res(n+1);
	 for(int i=1;i<=n;i++)
	 {
            if(!visited[i])
            {
            	  vector<int>connected_component;
            	  vector<bool>visited1(n+1,false);
            	  dfs(i,connected_component,visited1);
            	  for(auto &x:connected_component)
            	  {
            	  	    res[x]=(int)connected_component.size();
            	  	    res[x]-=degree[x];
            	  	    for(auto &y:hate_graph[x])
            	  	    	if(visited1[y])
            	  	    		res[x]--;
            	  }
            }
	 }
	 for(int i=1;i<=n;i++)
	 	cout<<res[i]-1<<" ";
	  cout<<endl;
	  return 0;
}


Measured memory_bytes: 20988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

int main(void) {
    int A, B;
    cin >> A >> B;

    if(A>=13) cout << B << endl;
    else if(A>=6&&A<=12) cout << B/2 << endl;
    else cout << 0 << endl;

    return (0);
}


Measured memory_bytes: 256
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint;
// }}}

void main() {
  bool[101010] e;
  e[2 .. 101010] = true;
  e[0 .. 2] = false;
  foreach (i; 2 .. 101010) {
    if (e[i]) {
      for (int j = i * i; j < e.length; j += i) e[j] = false;
    }
  }
  long[101010] sum;

  for (int i = 1; i < e.length; i += 2) {
    if (e[i] && e[(i + 1) / 2]) sum[i] = 1;
  }
  foreach (i; 1 .. 101010) {
    sum[i] += sum[i - 1];
  }

  int q = readln.chomp.to!int;
  foreach (i; 0 .. q) {
    int[] ra = readln.chomp.split.to!(int[]);
    writeln(sum[ra[1]] - sum[ra[0] - 1]);
  }
}


Measured memory_bytes: 2684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner sin=new Scanner(System.in);
	    int n=sin.nextInt();
	    boolean ok=true;
		for (int i = 0; i < n; i++) {
			int a=sin.nextInt();
			if(a%2==0&&a%3!=0&&a%5!=0){
				ok=false;
			}
		}if(ok){
			System.out.println("APPROVED");
		}else System.out.println("DENIED");
    }
}


Measured memory_bytes: 23252
from collections import deque
import bisect

N = int(input())
h = deque([int(input())])

for _ in range(N-1):
  a = int(input())
  i = bisect.bisect_left(h, a)
  if i == 0:
    h.appendleft(a)
  else:
    h[i-1] = a
    
print(len(h))

Measured memory_bytes: 77036
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    l = reduce(lcm, (2 * m + 2 if _a % c or not _a // c % 2 else _a for _a in a))
    return str((m - l // 2) // l + 1) if l <= 2 * m else "0"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 17172
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, m, a, b, s = 0;
  cin >> n >> m;
  vector<lld> h(n);
  for (lld i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> p(n);
  for (lld i = 0; i < m; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }

  for (lld i = 0; i < n; i++) {
    for (auto &t:p[i]) {
      if (h[t] >= h[i]) {
        goto no;
      }
    }
    s++;
    no:;
  }

  cout << s << "\n";
}

Measured memory_bytes: 9068
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    ll cnt = 0;
    ll res = 0;
    int N = S.size();
    for(ll i = S.size() - 1; i >= 0; i--) {
        if(S[i] == 'B') {
            res += (N - 1 - cnt) - i;
            cnt++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
S = "Yes"
A = [(0,0,0)]
for i in range(N):
    t,x,y = map(int,input().split())
    A.append((t,x,y))
A = sorted(A)
for i in range(N):
    t1,x1,y1 = A[i]
    t2,x2,y2 = A[i+1]
    if abs(x2-x1)+abs(y2-y1) > t2-t1  or   (abs(x2-x1)+abs(y2-y1))%2 != (t2-t1)%2:
        S = "No"
        break
print(S)

Measured memory_bytes: 18068
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    int res = 1111;

    for(int i = 0; i < n; ++i) {
        int c, x;
        cin >> c >> x;
        if(x <= t) res = min(res, c);
    }

    if(res == 1111) puts("TLE");
    else printf("%d\n", res);
}

Measured memory_bytes: 256
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
#def OutH(lst): print(*lst)
#def OutV(lst): print(*lst, sep="\n")
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

## 貪欲法で、その日に一番スコアが高くなるテストをする

N_ALP = 26

D = iIn()
C = iInLH()
S = iInLD(D)

T = []

for i in range(365):
  print(10)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,T,k,q;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 200001;

ll deg[MAXN] = {0};
ll pek[MAXN] = {0};
ll nonpick[MAXN] = {0};

ll par(ll i){
    ll i2 = i;
    while(i2 != pek[i2]){
        i2 = pek[i2];
    }
    return i2;
}

ll ans = 0;

vi ind;
vl A,B,V;

ll merg(ll i, ll j, ll v){
    ll i2 = par(i);
    ll j2 = par(j);
    if(i2 != j2 && v > min(nonpick[i2],nonpick[j2])){
        ans += v;
        if(deg[i2] < deg[j2])swap(i2,j2);
        ans -= min(nonpick[i2],nonpick[j2]);
        nonpick[i2] = max(nonpick[i2],nonpick[j2]);
        deg[i2] += deg[j2];
        pek[j2] = i2;
    }
    else{
        if(v > nonpick[i2]){
            ans += v-nonpick[i2];
            nonpick[i2] = v;
        }
    }
}

bool comp(ll i, ll j){
    return V[i] > V[j];
}

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

    //freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> k >> n >> m;
    rep(c1,0,k){
        cin >> a >> b >> c;
        a--;
        b--;
        b += n;
        ind.push_back(c1);
        A.push_back(a);
        B.push_back(b);
        V.push_back(c);
    }

    rep(c1,0,n+m){
        deg[c1] = 1;
        pek[c1] = c1;
        nonpick[c1] = 0;
    }

    sort(all(ind),comp);

    rep(c1,0,k){
        a = ind[c1];
      //  cerr << A[a] << " " << B[a] << "\n";
        merg(A[a],B[a],V[a]);
    }

    rep(c1,0,n+m){
      //  cerr <<c1 << ":  par - " <<  par(c1) << "   nonpick - " << nonpick[par(c1)] << "\n";
    }

    cout << ans  << "\n";

    return 0;
}


Measured memory_bytes: 7768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int n; cin>>n;
   cout << (n>=1000?"ABD":"ABC") << endl;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> height(n);
    for(int i = 0; i < n; ++i){
        cin >> height[i];
    }
    if(n == 2){
        cout << abs(height[1] - height[0]);
        return 0;
    }
    int min_cost = 0, prev = 0;
    vector<int> dp(n);
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        dp[i] = dp[i - 1] + abs(height[i] - height[i - 1]);
        for(int j = 2; j <= k and (i - j) >= 0; ++j){
            dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include<tuple>

using namespace std;

int main(){
	int A[3];
	int m = 0;
	int ans = 0;

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

	for (int i = 0; i < 3; i++) {
		int n = abs(A[i] - A[(i + 1) % 3]);
		ans += n;
		m = max(n, m);
	}

	cout << ans - m << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define get(vv, times) for(int ii = 0; ii < times; ++ii) {int jj; cin >> jj; (vv).pb(jj);}
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;

string s;
vector <int> st;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    rep(i, 0, (int)s.length(), 1) {
        if (s[i] == '0' || s[i] == '1') st.pb(s[i]);
        if (s[i] == 'B') {
            if (!st.empty()) st.pop_back();
            else continue;
        }
    }
    for (auto it:st) cout << (char)it;
    time;
}

Measured memory_bytes: 3720
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
x = 0
lst = [a,b,c,d,e]
lst2 = []
for i in lst:
  if i%10 == 0:
    lst2.append(10)
  else:
    lst2.append(i%10)
y = lst[lst2.index(min(lst2))]
del lst[lst2.index(min(lst2))]
for i in lst:
  if i%10 == 0:
    x += i
  else:
    x += (i//10+1)*10
x = x + y
print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int cnt[200005][26];

int main(){
	string s;cin>>s;
	for(int i=1;i<=s.length();i++){
		for(int j=0;j<26;j++){
			cnt[i][j] += cnt[i-1][j];
		}
		cnt[i][s[i-1]-'a']++;
	}

	long long n = s.length();
	long long ans = n*(n+1)/2LL;

	ans -= (long long)s.length();

	for(int i=1;i<s.length();i++){
		ans -= (long long)cnt[s.length()][s[i-1]-'a'] -  cnt[i][s[i-1]-'a'];
	}

	cout<<(ans+1)<<endl;

	return 0;

}


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

int main(){
    int x,y;
    while(1){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x > y){
            cout << y  << ' ' << x << endl;
        } else {
            cout << x  << ' ' << y << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3064
def solve():
    N = int(input())

    numDivs = [0] * (N+1)
    for div in range(1, N+1):
        for x in range(div, N+1, div):
            numDivs[x] += 1

    ans = 0
    for C in range(1, N+1):
        ans += numDivs[N-C]

    print(ans)


solve()


Measured memory_bytes: 16788
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

ans = 0

if X > sum(A):
    print(N-1)
else:
    for i in range(len(A)):
        if X >= A[i]:
            X -= A[i]
            ans += 1
        else:
            break
    print(ans)


Measured memory_bytes: 9076
def main():
    MOD = 10**9 + 7
    S = input()
    N = len(S)
    CHARS = ['A', 'B', 'C']
    dp = [[0 for _ in range(4)] for _ in range(N + 1)]
    dp[N][3] = 1
    for i in range(N - 1, -1, -1):
        a = 3 if S[i] == '?' else 1
        dp[i][3] = a * dp[i + 1][3]
        dp[i][3] %= MOD
    for i in range(N - 1, -1, -1):
        a = 3 if S[i] == '?' else 1
        ch = S[i]
        for j in range(3):
            b = 1 if ch in ['?', CHARS[j]] else 0
            dp[i][j] = a * dp[i + 1][j] + b * dp[i + 1][j + 1]
            dp[i][j] %= MOD
    print(dp[0][0])


if __name__ == '__main__':
    main()

Measured memory_bytes: 27616
A, B, C, D = map(int, input().split(' '))
answer = 0
if A <= C and B <= D:
  answer = B-C
if A <= C and B >D:
  answer = D-C
if A > C and B <= D:
  answer = B-A
if A > C and B > D:
  answer = D-A
if answer < 0:
  answer = 0
print(answer)

Measured memory_bytes: 9192