akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main()
{
	int N = 0;
	std::string S = "";
	std::cin >> N >> S;
	
	if (N % 2 != 0)
	{
		std::cout << "No\n";
		return 0;
	}

	std::string T = "";
	for (int i = 0, n = N / 2; i < n; ++i)
	{
		T += S.at(i);
	}
	
	std::string answer = T + T;
	if (answer == S)
	{
		std::cout << "Yes\n";
	}
	else
	{
		std::cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
#define int long long
using namespace std;
signed main() {
    int N, M;
    cin >> N >> M;
    if (N == M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>

main(){
  int R,G,B,N;
  scanf("%d%d%d%d",&R,&G,&B,&N);
  int ans=0;
  for(int i=0;i<=N/R;i++){
    for(int j=0;j<=N/G;j++){
      if(((N-i*R-j*G)%B==0)&&(N-i*R-j*G>=B||N-i*R-j*G==0))ans++;
    };
  };
  
  printf("%d",ans);
  return 0;
}


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

struct node{
    node *l,*r;
    int d;
    node(){
        l=r=NULL;
        d=-1;
    }
};

int number(string &S, int &i){
    int ret=0;
    while(isdigit(S[i])){
        ret*=10;
        ret+=S[i]-'0';
        i++;
    }
    return ret;
}

node* parse(string &S, int&i){
    if(S[i]==')') return NULL;
    node *p = new node();
    i++;
    p->l = parse(S,i);
    i+=2;
    p->d = number(S,i);
    i+=2;
    p->r = parse(S,i);
    i++;
    return p;
}

node* unite(node* pA, node *pB){
    if(pA==NULL||pB==NULL) return NULL;
    node *p = new node();
    p->d = pA->d + pB->d;
    p->l = unite(pA->l,pB->l);
    p->r = unite(pA->r,pB->r);
    return p;
}

string tree(node *p){
    if(p==NULL) return "";
    return "("+tree(p->l)+")["+to_string(p->d)+"]("+tree(p->r)+")";
}

int main(){
    string A,B;
    cin>>A>>B;
    node *pA, *pB, *pC;
    int i=0;
    pA=parse(A,i);
    i=0;
    pB=parse(B,i);
    pC=unite(pA,pB);
    cout<<tree(pC)<<endl;
    return 0;
}

Measured memory_bytes: 3296
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<int,int> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	long long n,x,p;
	vector<long long> a;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>p;
		a.push_back(p);
	}
	sort(a.begin(),a.end());
	long long tmp=0,ans=0;
	for(int i=0;i<n;i++){
		tmp+=a[i];
		if(tmp<=x){ 
			if(i==n-1){
				if(x==tmp) ans++;
			}else ans++;
		}
		else break;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
  	int X;
  	cin >> X;
  	int ans = 1;
  	for(int b = 1; b <= sqrt(X); b++){
      	int B = b;
      	for(; 1 < B && B <= X / b; ){
          	B *= b;
        }
      	if(ans < B){
          	ans = B;
        }
    }
  	cout << ans;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	const int R = 0;
	const int W = 1;
	vector<int> c(n);
	//set<int> rs;
	vector<int> rs;
	for (int i = 0; i < n; i++) {
		char ch;
		cin >> ch;
		if (ch == 'R') {
			c[i] = R;
		} else {
			c[i] = W;
		}
      	if (c[i] == R) {
				rs.push_back(i);
		}
	}
	int index = 0;
	int ans = 0;
	while (!rs.empty() && index < n) {
		if (c[index] == R) {
			index++;
			continue;
		}
		int ri = rs.back();
		if (index < ri) {
			c[index] = R;
			c[ri] = W;
			rs.erase(rs.end()-1);
			ans++;
		} else {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5000
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int N,c0=0,c1=0;
  string S;
  cin >> N >> S;
  rep(i,N) {
    if (S[i]=='R') c0++;
  }
  rep(i,c0){
    if (S[i]=='W') c1++;
  }
  cout << c1 << endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

signed main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    rep(i,M){
      int L, R, D;
      cin >> L >> R >> D;
      --L; --R;
      if(uf.issame(L,R)){
        int diff = uf.diff(L, R);
        if(diff != D){
          cout << "No" << endl;
          return 0;
        }
      }
      else{
        uf.merge(L, R, D);
      }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

const int inf = 1e9;
const ll inf64 = 1e18;

const int LOG = 20;
const int X = 1 << LOG;
const int N = 5e5 + 5;
const int mod = inf + 7;

inline int _add(int &x, int y) {
    if ((x += y) >= mod) {
        x -= mod;
    }
}

inline int _sub(int &x, int y) {
    if ((x -= y) < 0) {
        x += mod;
    }
}

inline int _mul(int a, int b) {
    return (1ll * a * b) % mod;
}

int n;
int a[N];
int p[N];
vector<int> arr[X];
int pw2[N];
int cnt0[N];

int main() {

    pw2[0] = 1;
    for (int i = 1; i < N; i++) {
        pw2[i] = (2ll * pw2[i - 1]) % mod;
    }

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        p[i] = p[i - 1] ^ a[i];
    }

    for (int i = 0; i <= n; i++) {
        arr[p[i]].push_back(i);
    }

    for (int i = 0; i <= n + 2; i++) {
        cnt0[i] = (i ? cnt0[i - 1] : 0) + (p[i] == 0);
    }

    int res = 0;

    if (p[n] == 0) {
        int sz = (int)arr[0].size() - 2;
        _add(res, pw2[sz]);
    }

    for (int x = 1; x < X; x++) {
        if (p[n] != 0 && p[n] != x) continue;
        if (arr[x].empty()) continue;
        auto &ar = arr[x];
        int sz = (int) ar.size();
        vector<int> dp(sz);
        int sum_dp = 0;
        int sum_cnt_dp = 0;
        for (int i = 0; i < sz; i++) {
            dp[i] = 1;
            _add(dp[i], _mul(cnt0[ar[i]], sum_dp));
            _add(dp[i], sum_cnt_dp);
//            for (int j = i - 1; j >= 0; j--) {
//                _add(dp[i], _mul(cnt0[ar[i]] - cnt0[ar[j]], dp[j]));
//            }
            _add(sum_dp, dp[i]);
            _sub(sum_cnt_dp, _mul(cnt0[ar[i]], dp[i]));
        }
        if (p[n] == x) {
            _add(res, dp[sz - 1]);
        } else {
            for (int i = 0; i < sz; i++) {
                _add(res, dp[i]);
            }
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 42228
def is_ok_under(array, mid, target):
    return array[mid] < target


def is_ok_over(array, mid, target):
    return array[mid] > target


# ok is -1. ng is len(array)
def bSearchUnder(array, ok, ng, target):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok_under(array, mid, target):
            ok = mid
        else:
            ng = mid
    return ok


# ng is -1. ok is len(array)
def bSearchOver(array, ok, ng, target):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok_over(array, mid, target):
            ok = mid
        else:
            ng = mid
    return ok


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

ans = 0

for i in range(len(b)):
    add = 1
    add *= bSearchUnder(a, -1, len(a), b[i]) + 1
    add *= len(c) - bSearchOver(c, len(c), -1, b[i])
    ans += add

print(ans)


Measured memory_bytes: 24180
#include<stdio.h>

int main(){

	char b;
	scanf("%c",&b);
	switch(b){
	case 'A':printf("T");break;
	case 'T':printf("A");break;
	case 'C':printf("G");break;
	case 'G':printf("C");break;
}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{

    static void Main()
    {
        long x, y;
        string[] s = Console.ReadLine().Split(' ');
        x = int.Parse(s[0]);
        y = int.Parse(s[1]);
        List<long> ans=new List<long>();
        ans.Add(y - x);
        ans.Add(y + x+1);
        ans.Add(-y - x+1);
        ans.Add(-y + x + 2);
        Console.WriteLine(ans.Where(ss => ss > 0).Min());
    }
    
}




Measured memory_bytes: 3032
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;
using pii = pair<int,int>;

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

   int x, y;
   cin >> x >> y;

   outl(__gcd(x,y));
}




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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    string ANS;
    rep(i,N)cin>>S[i];

    vector<map<int,int>> mp(N);

    rep(i,N){
        rep(j,S[i].length()){
            mp[i][S[i][j]-'a']++;
        }
    }
    rep(i,26){
        int Co=INF;
        rep(j,N){
            Co=min(Co,mp[j][i]);
        }
        rep(j,Co){
            ANS+=char('a'+i);
        }
    }
    sort(ALL(ANS));
    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,m,sum=0;
  int A[100][100];
  int b[100];
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf("%d ",&A[i][j]);
    }
  }
  for(int i=0;i<m;i++){
    scanf("%d",&b[i]);
  }
  for(int i=0;i<n;i++){
    sum=0;
    for(int j=0;j<m;j++){
      sum+=A[i][j]*b[j];
    }
    printf("%d\n",sum);
  }
  return 0;
}   


Measured memory_bytes: 1984
N = int(input())
A = list(map(int, input().split()))


ans = 0
naw = A[0]

for i in range(1,N):
    if A[i-1] > A[i]:
        ans +=  A[i-1] - A[i]
        A[i] = A[i-1]
        naw = A[i]
    else:
        naw = A[i]

print(ans)


Measured memory_bytes: 32224
N = int(input())
T, A = map(int, input().split())
Hs = [int(H) for H in input().split()]
min_diff = 10e9
ans = 0
for i, H in enumerate(Hs):
    T_at_H = T - H*0.006
    diff = abs(A - T_at_H)
    if diff < min_diff:
        min_diff = diff
        ans = i + 1
print(ans)

Measured memory_bytes: 3188
import math
N, K = map(int, input().split())

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

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while abs(r - l) > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 31212
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];


int main(){
  ll n;cin>>n;
  vll h(n);
  rep(i,0,n){
    cin>>h[i];
  }
  ll ans=h[0];
  rep(i,1,n){
    if(h[i]>h[i-1]){
      ans+=h[i]-h[i-1];
    }
    
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		int N = scanner.nextInt();
 		int sum = 0;
 		int tako[] = new int[N];
 		for (int i = 0; i < N; i++) {
 			tako[i] = scanner.nextInt();
 		}
 		for (int i = 0; i < N - 1; i++) {
 			for (int j = i + 1; j < N; j++) {
 				sum += tako[i] * tako[j];
 			}
 		}
 		System.out.println(sum);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))


int main()
{
	int k;
	vector<int> a(5);
	rep(i, 0, 4)cin >> a[i];
	cin >> k;
	sort(a.begin(), a.end());
	if (k < a[4] - a[0])cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int N; cin >> N;
    ll A[N];
    rep(i, 0, N) cin >> A[i];
    ll cnt = 0;
    rep(i, 0, N) {
        rep(j, 0, N) {
            if (A[j] % 2 == 0) {
                A[j] /= 2;
                cnt++;
            }
        }
        if (cnt % N == 0) continue;
        else break;
    }
    if (cnt / N == 6)
        cout << "8" << endl;
    else
        cout << cnt / N << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <atcoder/lazysegtree>
using namespace atcoder; 

struct S {
  ll zeros;
  ll ones;
  ll inversions;
};

S op(S x, S y) {
  return {
    x.zeros+y.zeros,
    x.ones+y.ones,
    x.inversions+y.inversions+x.ones*y.zeros
  };
}

S e() {
  return {0, 0, 0};
}

struct F {
  bool flipped;
};

S mapping(F f, S x) {
  if (f.flipped) {
    return {
      x.ones,
      x.zeros,
      x.ones*x.zeros-x.inversions
    };
  } else {
    return x;
  }
}

F composition(F f, F g) {
  return { f.flipped != g.flipped };
}

F id() {
  return { false };
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, q; cin >> n >> q;
  vector<S> a(n); 
  rep (i, n) {
    int x; cin >> x;
    a[i] = {x==0, x==1, 0};
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> st(a);

  while (q--) {
    int t, l, r; cin >> t >> l >> r;
    l--;
    if (t == 1) {
      st.apply(l, r, {true});
    } else {
      cout << st.prod(l, r).inversions << '\n';
    }
  }
  
  return 0;
}

Measured memory_bytes: 20420
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
typedef long long ll;
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += (n - i - 1);
    }
    for (int i = 0; i < m; ++i)
    {
        sum += (m - i - 1);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3608
#define _GLIBCXX_IOSTREAM
#include<bits/stdc++.h>
#define mod 1000000007
#define maxn 310
using namespace std;
typedef pair<int,int> par;
vector<par>v[maxn];
int n,m,dp[maxn][maxn][maxn];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r,x;i<=m;++i)
		scanf("%d%d%d",&l,&r,&x),v[r].push_back(par(l,x));
	dp[0][0][0]=1;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			for(int k=0;k<=n;++k)if(dp[i][j][k]){
				int x=dp[i][j][k],y=max(i,max(j,k));
				for(int l=0;l<v[y].size();++l)
					if((i>=v[y][l].first)+(j>=v[y][l].first)+(k>=v[y][l].first)!=v[y][l].second)
						{dp[i][j][k]=0;goto nxt;}
				dp[y+1][j][k]=(dp[y+1][j][k]+x)%mod;
				dp[i][y+1][k]=(dp[i][y+1][k]+x)%mod;
				dp[i][j][y+1]=(dp[i][j][y+1]+x)%mod;
				nxt:;
			}
	int ans=0;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			ans=(1ll*ans+dp[i][j][n]+dp[i][n][j]+dp[n][i][j])%mod;
	printf("%d",ans);
}

Measured memory_bytes: 114944
#include <iostream>
#include <map>

using namespace std;

map<int, int> m;

long long com(int n, int k)
{
	if (n == k || k == 0)
		return 1;

	if (n < k)
		return 0;

	if (k > n - k)
		k = n - k;

	long long aux = 1;
	for (int i = n - k + 1; i <= n; i++)
		aux *= i;

	for (int i = 2; i <= k; i++)
		aux /= i;

	return aux;
}

int v[200010];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		m[v[i]]++;
	}

	long long sum = 0;
	for (auto it : m)
		sum += com(it.second, 2);

	for (int i = 0; i < n; i++)
	{
		cout << sum - m[v[i]] + 1 << '\n';
	}
	return 0;
}


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

struct card{char suit, value;};

void show(struct card A[],int N){
    for(int i = 0; i < N;i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void selection(struct card A[],int N){
    for(int i=0; i < N-1; i++){
        int min = A[i].value;
        int index = i;
        for(int j = i+1; j < N; j++){
            if(A[j].value < min){
                min = A[j].value;
                index = j;
            }
        }
        if(i != index){
            swap(A[i],A[index]);
        }
    }
}

void bubble(struct card A[],int N){
    for(int i = 0; i < N-1; i++){
        int j = N-1;
        while(j > i){
            if(A[j-1].value > A[j].value){
                swap(A[j-1],A[j]);
            }
            j--;
        }
    }
}

bool judge(struct card A[],struct card B[], int N){
    for(int i = 0; i < N; i++){
        if(A[i].suit != B[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    cin >> N;
    struct card A[N];
    struct card B[N];
    for(int i = 0; i < N; i++){
        cin >> A[i].suit >> A[i].value;
    }
    
    for(int i = 0; i < N; i++){
        B[i] = A[i];
    }
    
         
    bubble(A,N);
    selection(B,N);
    bool hoge = judge(A,B,N);

    show(A,N);
    cout <<"Stable" << endl;
    show(B,N);
    if(hoge) cout <<"Stable"<< endl;
    else cout << "Not stable" << endl;
    
    return 0;

}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,a,b;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a>>b;
    if ((abs(b-a)-1)%2>0) cout<<"Alice"<<"\n";
    else cout<<"Borys"<<"\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=500100;
int n,m,s[N],a[N],f[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>s[0];
	for(int i=1;i<=n;++i){
		cin>>a[i];s[i]=s[i-1];
		if(s[i]>=a[i])s[i]-=a[i];
		else s[i]=min(s[i],a[i]-s[i]);
	}
	f[n]=1;
	for(int i=n;i;--i)if(f[i]<=a[i]/2)f[i-1]=f[i];
	else f[i-1]=f[i]+a[i];
	for(cin>>m;m --> 0;){
		int x;cin>>x;
		cout<<(s[x-1]>=f[x]?"YES\n":"NO\n");
	}
	return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n,k;
    cin>>n>>k;
    long double num=1.0/n;
    long double ans=0;
    rep(p,1,n+1){
        int cnt=0,tmp=p;
        while(tmp<k){
            tmp*=2;
            cnt++;
            //cout<<tmp<<" ";
        }
        ans+=num*powl(0.5,cnt);
        //cout<<endl;
    }
    printf("%.12Lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll N,K;
    cin >> N >> K;
    ll L[15], R[15];
    rep(i,0,K){
        cin >> L[i] >> R[i];
    }

    ll dp[200010] = {};
    dp[1] = 1;
    rep(i,1,N){
        dp[i] += dp[i-1];
        dp[i] %= MOD;
        rep(j,0,K){
            if(i + L[j] <= N){
                dp[i+L[j]] += dp[i];
                dp[i+L[j]] %= MOD;
                if(i+R[j]+1 <= N){
                    dp[i+R[j]+1] = (dp[i+R[j]+1] - dp[i] + 2 * MOD) % MOD;
                }
            }
        }
    }
    // printa(dp, N+1);

    print(dp[N]);



}

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

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=110;
string all[maxn];
bool cmp(string str1,string str2);

int main()
{
    int n,l;
    scanf("%d %d",&n,&l);
    for(int i=0;i<n;i++)
        cin>>all[i];
    sort(all,all+n,cmp);
    string ans;
    for(int i=0;i<n;i++)
        ans+=all[i];
    cout<<ans<<endl;
    return 0;
}

bool cmp(string str1,string str2)
{
    return str1+str2<str2+str1;
}

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

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort(v.begin(), v.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed

int main(){
    int N, K;
    cin >> N >> K;
    int ans=0;
    rep(i, N){
        int x;
        cin >> x;
        ans += 2*min(x, K-x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
dic = {}
for s in S:
    if(s not in dic):
        dic[s] = 1
    else:
        dic[s] += 1

max_d = max(dic.values())
ans = []
for k in dic:
    if(dic[k]==max_d):
        ans.append(k)

ans.sort()

for a in ans:
    print(a)


Measured memory_bytes: 35216
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;

    int nb_ans = 0;
    vector<P> ans;
    int TN = N;
    if (N%2 == 1) {
        TN -= 1;
    }
    rep(i, N-1) {
        repr(j, i+1, N) {
            if (i + j + 2 == TN +1) continue;
            ans.emplace_back(i, j);
        }
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i].first + 1 << " " << ans[i].second +1 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      int[] n = Console.ReadLine().Split(' ').ToList().Select(int.Parse).ToArray();
      int count = 0;
      for(int i = n[0]; i <= n[1]; ++i) {
        if(n[2] % i == 0) count++;
      }
      Console.WriteLine(count);
    }
  }
}

Measured memory_bytes: 9608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	ld i,x;
	vector<ld> a;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.pb(x);
	}
	for(i=1;i<n;i++)
	{
		sort(a.begin(),a.end());
		x=a[0]+a[1];
		x/=2;
		a[0]=mod;
		a[1]=x;
	}
	cout<<fixed<<setprecision(7)<<x;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#define MN 200010
#define MM 800010
#define inf 999999999
using namespace std;
int fr[MN],dy[MN],ne[MM],v[MM],w[MM],bs=0;
void add(int a,int b,int c)
{
	v[bs]=b;
	w[bs]=c;
	ne[bs]=fr[a];
	fr[a]=bs++;
}
void addb(int a,int b,int c)
{
	add(a,b,c);
	add(b,a,0);
}
int dl[MN],jl[MN],N,S,T;bool bk[MN];
bool bfs()
{
	for(int i=1;i<=N;i++)
	{
		bk[i]=false;
		jl[i]=inf;
	}
	bk[S]=true;jl[S]=0;
	int he=0,ta=1;dl[0]=S;
	while(he<ta)
	{
		int u=dl[he++];
		for(int i=fr[u];i!=-1;i=ne[i])
		{
			if(w[i]>0&&!bk[v[i]])
			{
				bk[v[i]]=true;
				jl[v[i]]=jl[u]+1;
				dl[ta++]=v[i];
			}
		}
	}
	return jl[T]<inf;
}
int dfs(int u,int z)
{
	if(u==T)
		return z;
	for(int &i=dy[u];i!=-1;i=ne[i])
	{
		if(w[i]>0&&jl[v[i]]==jl[u]+1)
		{
			int t=dfs(v[i],z<w[i]?z:w[i]);
			if(t!=-1)
			{
				w[i]-=t;
				w[i^1]+=t;
				return t;
			}
		}
	}
	return -1;
}
int dinic()
{
	int jg=0;
	while(bfs())
	{
		for(int i=1;i<=N;i++)
			dy[i]=fr[i];
		while(1)
		{
			int t=dfs(S,inf);
			if(t==-1)
				break;
			jg+=t;
		}
	}
	return jg;
}
vector<int> ve[100010],to[100010];
int pp[100010],fa[100010];
void dfs2(int u,int f)
{
	if(bk[u])return;
	fa[u]=f;bk[u]=true;
	for(int i=0;i<to[u].size();i++)
		dfs2(to[u][i],u);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++)
	{
		int s,a;
		scanf("%d",&s);
		for(int j=0;j<s;j++)
		{
			scanf("%d",&a);
			ve[i].push_back(a);
		}
	}
	N=n*2+1;S=N-1;T=N;
	for(int i=1;i<=N;i++)
		fr[i]=-1;
	for(int i=1;i<=n-1;i++)
	{
		addb(S,i,1);
		for(int j=0;j<ve[i].size();j++)
			addb(i,ve[i][j]+n-1,1);
	}
	for(int i=1;i<=n;i++)
		addb(i+n-1,T,1);
	if(dinic()!=n-1)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		bk[i]=false;
	for(int i=1;i<=n-1;i++)
	{
		for(int j=fr[i];j!=-1;j=ne[j])
		{
			int t=v[j];
			if(t>n-1&&w[j]==0)
			{
				pp[i]=t-(n-1);
				break;
			}
		}
		for(int j=0;j<ve[i].size();j++)
		{
			if(ve[i][j]!=pp[i])
				to[ve[i][j]].push_back(pp[i]);
		}
		bk[pp[i]]=true;
	}
	int ro=-1;
	for(int i=1;i<=n;i++)
	{
		if(!bk[i])
		{
			ro=i;
			break;
		}
	}
	for(int i=1;i<=n;i++)bk[i]=false;
	dfs2(ro,0);
	for(int i=1;i<=n;i++)
	{
		if(i!=ro&&fa[i]==0)
		{
			printf("-1");
			return 0;
		}
	}
	for(int i=1;i<=n-1;i++)
		printf("%d %d\n",pp[i],fa[pp[i]]);
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  int s,d,p;
  s=a+b;
  d=a-b;
  p=a*b;
  
  cout << max(max(s,d),p) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int a[111111];

int main()
{
    int n, m, ans = 0;
    cin>>n>>m;
    REP(i,m) {
        int l, r;
        cin>>l>>r;
        a[l]++;
        a[r+1]--;
    }
    REP(i,111100) {
        a[i+1] += a[i];
        if (a[i] == m)
            ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
f=f=1,*(1..m=1000003).map{|i|f=f*i%m}
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%m}
gets
$<.map{|s|x,d,n=s.split.map &:to_i
p d<1?o[x,n]:(u=f[n+t=x*o[d,m-2]%m-1])?u*o[f[t],m-2]*o[d,n]%m:0}

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

const ll MAX_N = 200000;
const ll MOD = 1000000007;

class Prod {
public:
	vector<ll> K_;
	vector<ll> invK_;
	vector<ll> invN_;
	Prod() {
		K_.assign(MAX_N, 1);
		invK_.assign(MAX_N, 1);
		invN_.assign(MAX_N, 1);
		for (ll i = 2; i < MAX_N; i++) {
			K_.at(i) = (K_.at(i - 1) * i) % MOD;
			invN_.at(i) = MOD - ((invN_.at(MOD % i) * (MOD / i)) % MOD);
			invK_.at(i) = (invK_.at(i - 1) * invN_.at(i)) % MOD;
//			cout << "(" << i << "," << K_.at(i) << "," << invN_.at(i) << "," << invK_.at(i) << ")" << endl;
		}
	}
	ll kaijo(ll v) { return(K_.at(v)); }
	ll inv(ll v) {
		if (v < MAX_N) {
			return(invN_.at(v));
		}
		else {
			return(MOD - ((inv(MOD % v) * (MOD / v)) % MOD));
		}
	}
	ll invKaijo(ll v) { return(invK_.at(v)); }
	ll comb(ll v, ll w) { return((K_.at(v) * invK_.at(w) % MOD) * invK_.at(v - w) % MOD); }
	ll combinv(ll v, ll w) { return((invK_.at(v) * K_.at(w) % MOD) * K_.at(v - w) % MOD); }
};

Prod p;
ll N;

class Node {
public:
	ll id_;
	pair<ll, ll> all_;
	map<Node*, pair< ll, ll> > f_; // first から入ってきたら、このノードの(個数,dp) ＝ (second.(first, second)
	void printLink() {
		for (auto it = f_.begin(); it != f_.end(); it++) {
			cout << "Link " << id_ << " to " << it->first->id_ << endl;
		}
	};
	void insertLink(Node* l) { f_[l].first = 0; f_[l].second = 0; }
	pair<ll,ll> setDpFirst(Node* prev) { // (house_,dp_)
		ll count = 0;
		ll prod = 1;
		for (auto it = f_.begin(); it != f_.end(); it++) {
			if (it->first != prev) {
				pair<ll, ll> next = it->first->setDpFirst(this);
				count += next.first;
				prod = (prod * next.second % MOD) * p.invKaijo(next.first) % MOD;
			}
		}
		ll mydp = (prod * p.kaijo(count)) % MOD;
		if (prev != nullptr) {
			f_[prev] = pair<ll, ll>(count + 1, mydp);
		}
		all_ = pair<ll, ll>(count, prod);
		return(pair<ll, ll>(count + 1, mydp));
	};
	pair<ll, ll> setDpSecond(Node* prev, ll prevcount, ll prevdp) { // (house_,dp_) reverse
		if (prev == nullptr) {
			prevcount = 0;
			prevdp = 1;
		}
		ll count = all_.first;
		ll prod = all_.second;
		if (all_.first < N - 1) {
			for (auto it = f_.begin(); it != f_.end(); it++) {
				if (it->second.first > 0) {
					pair<ll, ll> next = it->first->setDpSecond(this, it->second.first, it->second.second);
					count += next.first;
					prod = (prod * next.second % MOD) * p.invKaijo(next.first) % MOD;
				}
			}
		}
		all_.first = count;
		all_.second = prod;
		ll mydp = (prod * p.kaijo(count)) % MOD;
		return(pair<ll, ll>(N - prevcount, ((all_.second * p.inv(prevdp) % MOD) * p.kaijo(prevcount) % MOD) * p.kaijo(N - prevcount - 1) % MOD));
	};
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N;
	Node* nodes = new Node[N];
	for (int i = 0; i < N; i++) {
		nodes[i].id_ = i + 1;
		nodes[i].all_ = pair<ll, ll>(0, 0);
	}
	for (int i = 1; i <= N - 1; i++) {
		int ai, bi;
		cin >> ai >> bi;
		nodes[ai - 1].insertLink(&(nodes[bi - 1]));
		nodes[bi - 1].insertLink(&(nodes[ai - 1]));
	}
	nodes[0].setDpFirst(nullptr);
	for (ll i = 0; i < N; i++) {
		pair<ll,ll> ret = nodes[i].setDpSecond(nullptr,0,1);
		cout << ret.second << endl;
	}
}






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

int main(){
	int K, S;
	cin >> K >> S;
	ll ans = 0;

	if (S %3 == 0) ans++;

	rep(i,K+1) {
		int x = S - 2*i;
		if (x == i) continue;	
		if (x>=0 && x<=K) ans += 3;
	}
	
	for (int i = 0; i <= K; i++) {
		for (int j = i+1; j <= K; j++) {
			int x = S - i - j;
			if (x>j && x<=K) ans += 6;
		}
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3616
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		String str[]=new String[a];
		int x[]=new int[a];
		for(int i=0;i<a;i++) {
			str[i]=scan.next();
			x[i]=scan.nextInt();
		}
		int b[][]=new int[a][2];
		for(int i=0;i<a;i++) {
			String stri=str[i];
			int z=x[i];
			int an=1;
			for(int j=0;j<a;j++) {
				String s=str[j];
				if(stri.compareTo(s)>0) {
					an++;
				}
				if(stri.equals(s)) {
					if(z<x[j]) {
						an++;
					}
				}
			}
			b[i][0]=an;
			b[i][1]=i;
		}
		Arrays.sort(b,(q, y)->Integer.compare(q[0],y[0]));
		for(int i=0;i<a;i++) {
			System.out.println(b[i][1]+1);
		}
	}
}


Measured memory_bytes: 26320
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<double,int> P;

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int n;
  while(cin>>n,n){
    pair<int,P> build[n];
    REP(i,n){
      int b,x,y;
      cin>>b>>x>>y;
      build[i].first = b;
      build[i].second.first = x;
      build[i].second.second = y;
    }

    double d[n+1][n+1];
    REP(i,n+1){
      fill( d[i], d[i]+n+1, INF );
    }
    d[0][0] = 0;
    REP(i,n){
      REP(j,n){
	P from = build[i].second;
	P to = build[j].second;
	double cost = sqrt(pow((double)from.first-to.first,2) +
			   pow((double)from.second-to.second,2));
	if(cost <= 50 ){
	  d[build[i].first][build[j].first] = 
	    d[build[j].first][build[i].first] = cost;
	}
      }
      d[i+1][i+1] = 0;
    }
    /*
    cout << "::" << d[20][18] << endl;
    cout << "::" << d[18][19] << endl;
    cout << "::" << d[19][6] << endl;

    cout << ":::" << d[20][11] << endl;
    cout << ":::" << d[11][6] << endl;
    */
    //    cout << n << endl;

    int m;
    cin>>m;
    REP(_t,m){
      int s,g;
      cin>>s>>g;
      
      priority_queue<P,vector<P>,greater<P> > que;
      double dis[n+1];
      fill( dis, dis+n+1, INF );
      int back[n+1];
      fill( back, back+n+1, INF );
      dis[s] = 0;
      que.push( P(0,s) );

      while( ! que.empty() ){
	P e = que.top(); que.pop();

	if( e.first > dis[e.second] )
	  continue;
	//	dis[e.second] = e.first;

	/*	if( e.second == g ){
	  cout << "end:" << e.second << endl;
	  break;
	  }*/

	REP(i,n+1){
	  if( dis[i] > dis[e.second] + d[e.second][i] ){
	    dis[i] = dis[e.second] + d[e.second][i];
	    que.push( P(dis[i],i) );
	    back[i] = e.second;
	  }
	}
      }

      if(dis[g]==INF){
	cout << "NA" << endl;
	continue;
      }

      vector<int> res;
      res.PB(g);

      int i=g;
      while(back[i]!=INF){
	res.PB(back[i]);
	i=back[i];
      }

      reverse(ALL(res));
      REP(i,res.size()){
	if(i!=0)
	  cout << " ";
	cout << res[i];
      }
      cout << endl;

    }
  }

  return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n;
  cin>>n;
  ll i,x;
  vector<ll> v;
  for(i=0;i<n;i++)
  {
    cin>>x;
    v.push_back(x);
  }
  ll dp[n+7];
  dp[0]=0;
  dp[1]=v[1]-v[0];
  for(i=1;i<n;i++)
  {
    dp[i]=min(dp[i-2]+abs(v[i]-v[i-2]),dp[i-1]+abs(v[i]-v[i-1]));
  }
  cout<<dp[n-1];

 }


Measured memory_bytes: 1908
#include <iostream>
#define NMAX 100005
using namespace std;
int n,a,b,c,d[NMAX][3],i;
int main()
{
    cin>>n;
    cin>>d[1][0]>>d[1][1]>>d[1][2];
    for(i=2;i<=n;i++)
    {
        cin>>a>>b>>c;
        d[i][0]=a+max(d[i-1][1],d[i-1][2]);
        d[i][1]=b+max(d[i-1][0],d[i-1][2]);
        d[i][2]=c+max(d[i-1][0],d[i-1][1]);
    }
    cout<<max(max(d[n][0],d[n][1]),d[n][2]);
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

int main(){
  string E,O;
  cin>>E>>O;
  for(ll i=0; i<E.size(); ++i){
    cout<<E[i];
  if(i<O.size())cout<<O[i];
}
  cout<<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N, M;
int imos[123456];

int main(void)
{
	cin >> N >> M;
	vector<int>m;
	for (int i = 0; i < M; ++i) {
		int tmp; cin >> tmp;
		m.push_back(tmp - 1);
	}
	for (int i = 0; i < N; ++i) {
		auto itr = upper_bound(m.begin(), m.end(), i);
		if (itr != m.begin()) {
			--itr;
			imos[i - *itr + 1]--;
		}
	}
	imos[0] = N;
	for (int i = 1; i <= N + 100; ++i) {
		imos[i] += imos[i - 1];
	}
	for (int i = 0; i <= N + 100; ++i) {
		imos[i] = -imos[i];
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int l;
		cin >> l;
		auto itr = lower_bound(imos, imos + N + 100, -l);
		int ans = itr - imos;
		if (ans > N) {
			ans = -1;
		}
		if (ans == 0)ans = 1;
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3776
n,q = map(int,input().split())
s = input()
s_count = [0]
for i in range(len(s)):
  if s[i:i+2] == "AC":
    s_count.append(s_count[i] + 1)
  else:
    s_count.append(s_count[i])

for i in range(q):
  l,r = map(int,input().split())
  count = s_count[r-1] - s_count[l-1]
  print(count)

Measured memory_bytes: 6200
#include<cstdio>
int main(){
    int n,cnt[10]={};
    for(int i=0;i<4;i++){
        scanf("%d",&n);
        cnt[n]++;
    }
    if(cnt[1]==1&&cnt[9]==1&&cnt[7]==1&&cnt[4]==1)printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    long x;
    cin >> x;
    long a[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    long y = 0;
    long ans = 0;
    for(int i = 0;i < n;i++){
        if(x < a[i] + y){
            ans += a[i] + y - x;
            y = x - y;
        }
        else{
            y = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

#print(n)
if((a+b) != 0):
    s = n//(a+b)*a
    l = n - n//(a+b)*(a+b)
    if(l >= a):
        l = a
    print(s+l)
else:
    print(0)


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
  int n,m=0,a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  for(n=a;n<=b;n++){
    if(c%n==0)m++;
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 596
y,m,z,e;main(k){
	for(;m=1e7,scanf("%d",&e)*e;z=!printf("%d\n",m))
		for(;(k=z*z*z)<=e;z++){
			y=sqrt(e-k);
			k=y+z+e-y*y-k;
			if(m>k)m=k;
		}
}

Measured memory_bytes: 0
import heapq
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=[0]*(n+1)
dp=[0]*(10**5+1)
h=0
for i in range(10**5+1):
    if h==n:
        dp[i]=h
        continue
    if i<=a[h]:
        dp[i]=h
    else:
        while h<n and i>a[h]:
            h+=1
        dp[i]=h



for i in range(n):
    s[i+1]=s[i]+a[i]
def test(x):
    count=0
    for i in range(n):
        buf=x-a[i]
        #idx=bisect.bisect_left(a,x-a[i])
        if buf<0:
            idx=0
        elif buf>=10**5+1:
            idx=n
        else:
            idx=dp[buf]
        if i>=idx:
            count+=(i-idx)*2+1
    return count


def search():
    mn=-1
    mx=m*max(a)*2
    buf=0
    while mx-mn>1:
        buf=(mx+mn)//2
        count=test(buf)
        if count>=m:
            mn=buf
        else:
            mx=buf
    return mn
x=search()
y=test(x)
#print(x,y)
count=0
for i in range(n):
    idx=bisect.bisect_left(a,x-a[i])
    if i>=idx:
        count+=(2*i-2*idx)*a[i]+(s[i+1]-s[idx])*2
        #print(count,i-idx+1)
print(count-(y-m)*x)


Measured memory_bytes: 56304
#include <iostream>

using namespace std;

int main()
{
  /********input********/
  int N;
  cin >> N;

  int A[N];
  int i;
  for( i=0; i<N; i++ ){
    cin >> A[i];
  }
  //  while( cin >> A[i] ){
  //    i++;
  //  }
  /********input********/
  
  int j = 0;
  int c = 0;

  while( A[j]%2 == 0 ){
    A[j] /= 2;
    j++;
    if( j == N ){
      c++;
      j = 0;
    }
  }

  cout << c << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int n,a,b;
	
	scanf("%d %d %d",&n,&a,&b);
	int sum =0;
	for(int i=1 ; i<=n;i++){
		if((i/10000)+((i/1000)%10)+((i/100)%10)+((i/10)%10)+(i%10)>=a&&((i/10000)+((i/1000)%10)+((i/100)%10)+((i/10)%10)+(i%10))<=b){
			sum +=i;
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 1728
from itertools import combinations
from collections import Counter
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

N, M = [int(i) for i in input().split()]

def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
        primfac.append(n)
    return primfac

ans = 1
divisors = primes(M)
for k, v in Counter(divisors).items():
    ans *= ncr(N - 1 + v, v)
print(ans % (10**9 + 7))


Measured memory_bytes: 38896
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,M,L=map(int,readline().split())
#print("N M L:",N,M,L)

root=[[10**10 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  A,B,C=map(int,readline().split())
  root[A][B],root[B][A]=C,C
  
Q=int(readline())
S,T=[0]*Q,[0]*Q
for i in range(Q):
  S[i],T[i]=map(int,readline().split())
#print("root:",root)
#print("S:",S)
#print("T:",T)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root)
for i in range(1,N+1):
  for j in range(1,N+1):
    if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root)

for i in range(Q):
  print(root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1)

Measured memory_bytes: 54492
#include<stdio.h>
int main() {
	int d, n;
	scanf("%d%d", &d, &n);
	int ans = 1;
	if (d == 1) {
		ans = 100;
	}
	if (d == 2) {
		ans = 10000;
	}
	if (n == 100) {
		n = 101;
	}
	printf("%d\n", ans*n);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    /**
     * 81
     * @param 1 ≤ N ≤ 100
     */
    public static void main(String...args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            if (check(n)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

    public static boolean check(int n) {
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if (i * j == n) {
                    return true;
                }
            }
        }
        return false;
    }
}

Measured memory_bytes: 23764