akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while wait_q:
    parent = wait_q.pop()
    already[parent] = True
    for child in graph[parent]:
        if already[child] == True:continue
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)


Measured memory_bytes: 56088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;
    VS S(H);
    rep(i, 0, H) cin >> S[i];

    VVL L(H+2, VL(W+2, 0)), R(H+2, VL(W+2, 0)), U(H+2, VL(W+2, 0)), B(H+2, VL(W+2, 0));
    
    rep(h, 1, H+1){
        rep(w, 1, W+1){
            if(S[h-1][w-1] == '#') L[h][w] = 0;
            else L[h][w] = L[h][w-1] + 1;
        }
        for(ll w = W; w > 0; w--){
            if(S[h-1][w-1] == '#') R[h][w] = 0;
            else R[h][w] = R[h][w+1] + 1;
        }
    }

    rep(w, 1, W+1){
        rep(h, 1, H+1){
            if(S[h-1][w-1] == '#') U[h][w] = 0;
            else U[h][w] = U[h-1][w] + 1;
        }
        for(ll h = H; h > 0; h--){
            if(S[h-1][w-1] == '#') B[h][w] = 0;
            else B[h][w] = B[h+1][w] + 1;
        }
    }
    
    
    ll ans = 0;
    rep(h, 1, H+1){
        rep(w, 1, W+1){
            if(S[h-1][w-1] == '#') continue;
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + B[h][w] - 3);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 131968
#include<stdio.h>
#include<iostream>
using namespace std;
long result[105];
long long search(int k,int n)
{
    for(int i=1;i<=n;i++)
    {
        result[i] = 1;
        for(int j=i-1;j>=1;j--)

            result[j] = result[j-1]+result[j];

        result[0] = 1;
    }
    return result[k];
}
int main()
{
    int n,p;
    cin>>n>>p;
    int i;
    int ji=0,o=0;
    int bei;
    long long ans=0;
    for(i=1;i<=n;i++)
    {
        cin>>bei;
        if(bei%2==0)
            o++;
        else

            ji++;

    }
    if(p==0)
    {
        long long a=1;
        if(o==0)

            a=1;

        else
        {
        for(i=1;i<=o;i++)

            a=a*2;

        }
        long long b=0;
        if(ji==0)

            b=1;

        else
        {
        for(i=0;i<=ji;i=i+2)

            b=b+search(i,ji);

        }
        ans=a*b;
    }
    else if(p==1)
    {
        long long a=1;
        for(i=1;i<=o;i++)

            a=a*2;

        long long b=0;
        if(ji==0)
        {
            b=0;
        }
        else
        {
            for(i=1;i<=ji;i=i+2)

                b=b+search(i,ji);

        }
        ans=a*b;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
 
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> cnt(26,vector<int>(n));
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        for(int j = 0; j < s.size(); j++) cnt[s[j]-'a'][i]++;
    }
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < *min_element(cnt[i].begin(),cnt[i].end()); j++){
            cout << char('a'+i);
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi v(10);
    while (n--) {
      int c;
      cin >> c;
      v[c]++;
    }
    for (int x : v) cout << (x ? string(x, '*') : "-") << endl;
  }
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main{
  static int A,B,Q;
  static Long[] S,T,X;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    A = sc.nextInt();
    B = sc.nextInt();
    Q = sc.nextInt();
    S = new Long[A+2];
    T = new Long[B+2];
    X = new Long[Q];
    for(int i=1;i<=A;i++){
      S[i]=sc.nextLong();
    }
    S[0]=-100000000000000000L;
    S[A + 1]=100000000000000000L;
    for(int i=1;i<=B;i++){
      T[i]=sc.nextLong();
    }
    T[0]=-100000000000000000L;
    T[B + 1]=100000000000000000L;
    for(int i=0;i<Q;i++){
      X[i]=sc.nextLong();
    }
    for(int i=0;i<Q;i++){
      System.out.println(Qanswer(i));
    }
  }



  static int binary_search(Long[] Array,Long key,int r,int l){
    int mid = 0;
    if(l-r<=1){
      return r;
      //return Math.min(Math.abs(key-Array[r]),Math.abs(key-Array[l]));
    }
    else{
      if(Math.abs(r-l)%2==0){
        mid = (r+l)/2;
      }
      else{
        mid = (r+l)/2+1;
      }
      if(Array[mid]<=key){
        return binary_search(Array,key,mid,l);
      }
      else{
        return binary_search(Array,key,r,mid);
      }
    }
  }

  static Long Qanswer(int i){
    int Snear = binary_search(S,X[i],0,S.length-1);
    int Tnear = binary_search(T,X[i],0,T.length-1);

    /* ======== DEBUG ======== */
    //System.out.println("[" + S[Snear] + ", " + X[i] + ", " + S[Snear + 1] + "]");
    //System.out.println("[" + T[Tnear] + ", " + X[i] + ", " + T[Tnear + 1] + "]");
    /* ======== /DEBUG ======== */

    return minimum(caliculate(i,Snear,Tnear),caliculate(i,Snear,Tnear+1),caliculate(i,Snear+1,Tnear),caliculate(i,Snear+1,Tnear+1));
    /*if((Snear<=X[i] && Tnear<=X[i]) || (Snear>=X[i] && Tnear>=X[i])){
      return Math.max(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear));
    }
    else{
    return Math.max(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear))+2*Math.min(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear));
    }
    */
  }

  static Long caliculate(int i,int r,int l){
    return Math.min(Math.abs(X[i]-S[r]) + Math.abs(T[l]-S[r]), Math.abs(X[i]-T[l]) + Math.abs(S[r]-T[l]));
    //if((S[r]<=X[i] && T[l]<=X[i]) || (S[r]>=X[i] && T[l]>=X[i])){
    //  /* ======== DEBUG ======== */
    //  //System.out.println("1: " + Math.abs(X[i] - S[r]) + ", " + Math.abs(X[i] - T[l]));
    //  /* ======== /DEBUG ======== */
    //  return Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //}
    //else{
    //  /* ======== DEBUG ======== */
    //  //Long t = Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l])) + 2*Math.min(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //  //System.out.println("2: " + t);
    //  /* ======== /DEBUG ======== */
    //  return Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]))+2*Math.min(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //}
  }

  static Long minimum(Long a,Long b,Long c,Long d){
    Long ans = 100000000000000000L;
    Long[] Arra= new Long[4];
    Arra[0] = a;
    Arra[1] = b;
    Arra[2] = c;
    Arra[3] = d;
    for(int i=0;i<4;i++){
      if(ans>=Arra[i]){
        ans = Arra[i];
      }
    }
    return ans;
  }

}

Measured memory_bytes: 104592
#include <iostream>
#include <string>

int main()
{
	int N = 0;
	std::cin >> N;

	std::string S;
	std::cin >> S;

	if (N % 2 != 0)
	{
		std::cout << "No" << std::endl;
		return 0;
	}
	else
	{
		int A = N / 2; 
		for (int i = 0; i < A; i++){
			if (S[i] != S[i + A]){
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}

	std::cout << "Yes" << std::endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    n,k=map(int,input().split())
    mod=10**9+7
    if n-k==-1:
        print(1)
    else:
        ans=(n+2*k)*(n-k+1)*(n-k+2)//6+n-k+2
        print(ans%mod)
if __name__=="__main__":
    main()

Measured memory_bytes: 9184
#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define PI 3.14159265
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


long long int fact(long long int n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(long long int n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

long long int gcd(long long int a,long long int b)
{
  if(a==0)
  return b;
  else
  return gcd(b%a,a);
}

long long int lcm(long long a,long long b)
{
    return (a*b)/gcd(a,b);
}

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

  
// Function to find the permutations 
// void findPermutations(int a[], int n) 
// { 
  
//     // Sort the given array 
//     sort(a, a + n); 
  
//     // Find all possible permutations 
//     cout << "Possible permutations are:\n"; 
//     do { 
//         forp(i,0,n)
//           cout<<a[i]<<" ";
//         cout<<"\n"; 
//     } while (next_permutation(a, a + n)); 
// }

int main() 
{ 
  fast_io

int n,m,k,ans=1,c=0;
cin>>n>>k;
int a[10]={0};
forp(i,0,k)
{
  cin>>m;
  a[m]++;
}

while(1)
{
  m=n;
  c=0;
  while(m)
  {
    if(a[m%10]==1)
    {
      c=1;
      break;
    }
    m/=10;
  }
  if(c)
  n++;
  else
  {
    cout<<n;
    break;
  }
}
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
ans=0
S=[]
for i in range(M):
    s=list(map(int,input().split()))
    K=s.pop(0)
    S.append(s)
P = list(map(int, input().split()))
for i in range(1<<N):
    ok=True
    for j in range(M):
        cnt=0
        for s in S[j]:
            if ((i>>s-1)&1):
                cnt+=1
        if cnt%2!=P[j]:
            ok=False
    if ok:
        ans+=1
print(ans)



Measured memory_bytes: 9216
// top down approach
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define MOD ll(1e9L+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll tt;cin>>tt;while(tt--) 
#define t2() ll tt2; cin>>tt2; for(ll tti=1;tti<=tt2;tti++)
#define printcj "Case #"<<tti<<": "
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << "\n";

const ll sz=100001;
ll n,k,a[sz];
ll dp[sz];
//return true if child win
bool ischildwin(ll currentk)
{
    if(currentk<0){
        return true;
    }
    else if(currentk==0) return false;

    if(dp[currentk]!=-1) return dp[currentk];

    bool iwin=false;
    for(ll i=0;i<n;i++){
        if(!ischildwin(currentk-a[i])) iwin = true;
    }
    // debug2(currentk,iwin);
    return dp[currentk]=iwin;
}


int main()
{
    fastio;
    ll i,j;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<=k;i++) dp[i] = -1;
    if(ischildwin(k))cout<<"First";
    else cout<<"Second";
    

    
}

Measured memory_bytes: 10576
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    long long s = 0;
    for(int i = 1; i <= n; i ++){
        if(i % 3 == 0 || i % 5 == 0)
            continue;
        s += i;
    }
    cout << s;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main(void)
{
	int e,y,i;
	scanf("%d %d",&e,&y);
	if(e==0){
		if(y>=1868&&y<=1911){
			printf("M%d\n",y-1867);
		}
		if(y>=1912&&y<=1925){
			printf("T%d\n",y-1911);
		}
		if(y>=1926&&y<=1988){
			printf("S%d\n",y-1925);
		}
		if(y>=1989&&y<=2016){
			printf("H%d\n",y-1988);
		}
	}
	else{
		if(e==1){
			printf("%d\n",1868+(y-1));
		}
		if(e==2){
			printf("%d\n",1912+(y-1));
		}
		if(e==3){
			printf("%d\n",1926+(y-1));
		}
		if(e==4){
			printf("%d\n",1989+(y-1));
		}
	}
	return 0;
}


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

bool seen[100010]={false};

void g(ll j,vector<vector<ll>> &a){
    seen[j]=true;
    for(ll k=0;k<a[j].size();k++){
        if(seen[a[j][k]]==false){
            g(a[j][k],a);
        }
    }
}

int main() {
    ll n;cin>>n;
    ll a[n];
    vector<ll> b;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b.push_back(a[i]);
    }
    sort(b.begin(),b.end());
    for(ll i=0;i<n;i++){
        if(a[i]==b[n-1]){
            cout<<b[n-2]<<endl;
        }else{
            cout<<b[n-1]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 4848
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;cin >> s;
	for(auto c : s){
		if(c == '?') cout << 'D';
		else cout << c;
	}
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using G = vector<vector<int>>;

vector<int> b_pos(100,-1);

int main(){
    bool result = false;
    vector<int> a(9,0);
    vector<int> ans(9,0);
    rep(i,9){
        cin >> a[i];
        b_pos[a[i]] = i;
    }
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n) {
        cin >> b[i];
        if(b_pos[b[i]] == -1) continue;
        ans[b_pos[b[i]]] = 1;
    }
    for(int i=0;i<9;i+=3){
        //横
        if((ans[i] + ans[i+1] + ans[i+2] )> 2) result = true;

    }
    //縦
    for(int i=0;i<3;i++){
        if((ans[i] + ans[i+3] + ans[i+6] > 2)) result = true; 
    }
    //斜め
    if((ans[0] + ans[4] + ans[8]) > 2 || (ans[2] + ans[4] + ans[6]) > 2) result = true;
    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	vector<int> v(3);
	for (int i = 0; i < 3; i++) cin >> v[i];
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << (i + 1 < v.size() ? " " : "");
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    ll m, n, a[100010];
    cin >> m >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    if (m == 2) {
        ll tmp = 0;
        for (int i = 0; i < n; i++) tmp += (a[i] == i % 2 + 1);
        cout << min(tmp, n - tmp) << endl;
    }
    else {
        vector<int> v;
        int idx = 0;
        while (idx < n) {
            int sub = 0;
            while (idx + sub < n && a[idx] == a[idx + sub]) sub++;
            v.push_back(sub);
            idx += sub;
        }

        int ans = 0;
        for (int i = 0; i < v.size(); i++) {
            ans += v[i] / 2;
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
V<ll> tree;
V<ll> lazy;
V<int> arr;
int n;

void update(int l, int r, int val, int node = 0, int start = 0, int end = n-1){
    if(lazy[node]){
        tree[node]+=lazy[node];
        if(start != end){
            lazy[2*node+1]+=lazy[node];
            lazy[2*node+2]+=lazy[node];
        }
        lazy[node]=0;
    }
    if(l > end || r < start)return;
    if(l <= start && end <= r){
        tree[node]+=val;
        if(start != end){
            lazy[2*node+1]+=val;
            lazy[2*node+2]+=val;
        }
        return ;
    }
    int mid = start+end>>1;
    update(l,r,val,2*node+1,start,mid);
    update(l,r,val,2*node+2,mid+1,end);

}

ll query(int l, int r, int node = 0, int start=0, int end = n-1){
    if(lazy[node]){
        tree[node]+=lazy[node];
        if(start != end){
            lazy[2*node+1]+=lazy[node];
            lazy[2*node+2]+=lazy[node];
        }
        lazy[node]=0;
    }
    if(l > end || r < start)return 0;
    if(l <= start && end <= r){
        return tree[node];
    }
    int mid = start+end>>1;
    auto p1 = query(l,r,2*node+1,start,mid);
    auto p2 = query(l,r,2*node+2,mid+1,end);
    return p1+p2;
}

int main(){
    ll d,a;
    cin >> n >> d >> a;
    tree = V<ll>(n<<2,0);
    lazy = V<ll>(n<<2,0);
    V<PLL> arr(n);
    loop(i,0,n)cin >> arr[i].F >> arr[i].S;
    sort(all(arr));
    ll ans = 0;
    loop(i,0,n){
        if(arr[i].S - query(i,i) <= 0)continue;
        int r = upper_bound(all(arr),mp(arr[i].F+d+d,inf))-arr.begin();
        r--;
        ll current_val = arr[i].S - query(i,i);
        ll to_del = current_val/a + (current_val%a != 0);
        ans+=to_del;
        to_del*=a;
        update(i,r,to_del);
    }
    cout << ans;
   return 0;
}

Measured memory_bytes: 15872
using System;
class Program
{
    static void Main(string[] args)
    {
        /*
        // 整数の入力
        int a = int.Parse(Console.ReadLine());
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int b = int.Parse(input[0]);
        int c = int.Parse(input[1]);
        // 文字列の入力
        string s = Console.ReadLine();
        //出力
        Console.WriteLine((a + b + c) + " " + s);

        Console.ReadLine();
        */
        String s = Console.ReadLine();
        int x = s.Replace("0", "").Length;

        Console.WriteLine(x);
        Console.ReadLine();
    }
}

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

int main()
{int a[4];
 string input;
 cin >> input;
 string s;
 for(int i=0; i<4; i++){
   a[i] = input[i] - '0';} 
 for(int x=0; x<8; x++){
   int sum = 0;
   sum += a[0];
   string s;
   s += input[0];
   for(int i=0; i<3; i++){
     if(x&(1<<i)){
       s += '+';
       s += input[i+1];
     	sum += a[i+1];}
     else{ 
       s += '-';
       s += input[i+1];
     	sum -= a[i+1];}}
   if(sum==7){
     s += "=7";
     cout << s<< endl;
     return 0;}
 }
          
   
       
   
 }

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

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

    int n;
    cin >> n;
    int a = 0;

    vector<int> p(n), q;
    rep(i, 0, n) cin >> p[i];

    q = p;
    sort(q.begin(), q.end());

    rep(i, 0, n) {
        if (q[i] != p[i])
            a++;
    }

    if (a < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] inputNum = br.readLine().split(" ");

			int a = Integer.parseInt(inputNum[0]);
			int b = Integer.parseInt(inputNum[2]);

			if (inputNum[1].equals("+")) {
				System.out.println(a + b);
			}else if (inputNum[1].equals("-")) {
				System.out.println(a - b);
			}else if (inputNum[1].equals("*")) {
				System.out.println(a * b);
			}else if (inputNum[1].equals("/")) {
				System.out.println(a / b);
			}else if (inputNum[1].equals("?")) {
				break;
			}
		}

	}

}

Measured memory_bytes: 17092
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int x,n;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  int ans = 1e8;
  vector<int>p(n);
  set<int>st;
  rep(i,n) cin >> p[i];
  rep(i,n) st.insert(p[i]);
  for(int i=101;i>=0;i--){
    if(st.count(i))continue;
    if(abs(ans-x)>=abs(i-x))ans=i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
N = int(input())
R = [list(map(int,input().split())) for i in range(N)]
B = [list(map(int,input().split())) for i in range(N)]
R.sort(key = lambda x:x[1], reverse=True)
B.sort(key = lambda x:x[0], reverse=False)
ans = 0
for b in B:
    for r in R:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            R.remove(r)
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	int n, d, i, x, y;
	cin >> n >> d;
	int ans = 0;
	fo(i, 0, n) {
		cin >> x >> y;
		ll res = 1ll * x * x + 1ll * y * y;
		if(res <= 1ll * d * d) ++ans;
	}
	cout << ans;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

//142 A
int main(void) {
	ll a;
	cin >> a;
	if (a % 2 == 0)cout << fixed << setprecision(10) << 1 / (double)2 << endl;
	else cout << fixed << setprecision(10) << ((a + 1) / (double)2) / (double)a << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int n;
	int a;
	int ans = 0;
	
	scanf("%d",&n);
	int i;for(i = 1;i <= n;++i){
		scanf("%d",&a);
		if(i%2==1&&a%2==1){
			ans++;
			
		}
	}
	
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	int N;
	cin >> N;
	vector<ll> vec(N);
	ll an = 0;
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	rep(i, N) {
		rep(j, N) {
			if (i != j) {
				an += vec.at(i) * vec.at(j);
			}
		}
	}
	
	
	cout << an/2<< endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
      	int a = s.nextInt();
      	int b = s.nextInt();
      	int c = s.nextInt();
      	int ans = max(max(a*10+b+c,b*10+a+c),c*10+a+b);
      	System.out.println(ans);
    }
  	static int max (int a, int b) {
      return a > b ? a : b;
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
    int n;
    cin >> n;
    vector <int> x(n);
    for(int i=0;i<n;++i) cin >> x[i];
    sort(x.begin(), x.end());
    int l=x[0];
    int r=x[n-1];
    int ans=1000000;
    for(int i=l;i<=r;++i) {
        int cnt=0;
        for(int j=0;j<n;++j) {
            cnt+=pow((x[j]-i),2);
        }
        ans=min(ans, cnt);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, Z, W, a, b;
int main() {
    cin >> N >> Z >> W;
    for(int i{}; i < N - 1; ++i) cin >> a;
    cin >> b;
    if(N == 1) {
        cout << (ll)abs(b - W) << endl;
        return 0;
    }
    cout << max((ll)abs(a - b), (ll)abs(b - W)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0

typedef long long int ll;       //TYPEDEFS
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;          //COMMON MODULO
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss<b.ss);
}
void sieve(vl &prime){          //SIEVE OF ERATOSTHENES
    ll maxN=1e6;
    vector<bool> pr(maxN+1,1);
    for(int i=2;i*i<=maxN;i++)
        if(pr[i]==1)
            for(int j=i*i;j<=maxN;j+=i)
                pr[j]=0;
    for(ll i=2;i<=maxN;i++)
        if(pr[i]==1)
            prime.pb(i);
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    cin>>n;
    ll a=0,b=0,c=0,d=0;
    itr(i,n){
        str s;
        cin>>s;
        if(s=="AC"){
            a++;
        }
        else if(s=="WA"){
            b++;
        }
        else if(s=="TLE"){
            c++;
        }
        else if(s=="RE"){
            d++;
        }
    }
    cout<<"AC x "<<a nn;
    cout<<"WA x "<<b nn;
    cout<<"TLE x "<<c nn;
    cout<<"RE x "<<d nn;
    return 0;
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

i64 n;

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

	cin >> n;
	if (n == 2) {
		cout << 1 << '\n';
		return 0;
	}	
	int cnt = 0;
	for (i64 i = 2; i*i <= n-1; ++i) {
		if ((n-1)%i == 0) {
			++cnt;
			if (i*i != n-1) ++cnt;
		}
	}
	++cnt;
//	cerr << cnt << endl;
	for (i64 i = 2; i*i <= n; ++i) {
		if (n%i == 0) {
			i64 tn = n;
			while (tn%i == 0) {
				tn /= i;
			}	
			if (tn%i == 1) ++cnt;
			if (i*i != n) {
				tn = n;
				while (tn%(n/i) == 0) tn /= n/i;
				if (tn%i == 1) ++cnt;
			}
		}
	}
	++cnt;
	cout << cnt << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;


int main() {
	int n, m = 1, count = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == m) {
			count++;
			m++;
		}
	}
	if (count == 0)cout << -1 << endl;
	else cout << n - count << endl;
	
  

	return 0;
}


Measured memory_bytes: 1024
from collections import Counter, defaultdict

N = int(input())

# 素数のリスト
def createPrimeList(N, isTable=True):
    isPrime = [True] * N
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, N):
        if not isPrime[i]:
            continue
        for p in range(i * 2, N, i):
            isPrime[p] = False
    return isPrime if isTable else [i for i in range(2, N) if isPrime[i]]

# 素因数分解(複数回)
isPrime = createPrimeList(10**5, False)
def primeFactorization(N):
    primes = Counter()
    for p in isPrime:
        while N % p == 0:
            N //= p
            primes[p] += 1
    return primes

primes = Counter()
for i in range(1, N + 1):
    primes += primeFactorization(i)

cnt = defaultdict(int)
for c in primes.values():
    c += 1
    for d in (3, 5, 15, 25, 75):
        if c >= d:
            cnt[d] += 1

ans = 0
ans += cnt[5] * (cnt[5] - 1) * (cnt[3] - 2) // 2
ans += cnt[25] * (cnt[3] - 1)
ans += cnt[15] * (cnt[5] - 1)
ans += cnt[75]
print(ans)


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int count = 0;
  for (int i = 1; i <= N; i++) {
    string S = to_string(i);
    if (i < 10) {
      int a = stoi(S);
      if (A <= a && a <= B) count += i;
    }
    else if (10 <= i && i < 100) {
      string p, q;
      p = S.at(1);
      q = S.at(0);
      int a = stoi(p);
      int b = stoi(q);
      if (A <= a+b && a+b <= B) count += i;
    }
    else if (100 <= i && i < 1000) {
      string p, q, r;
      p = S.at(2);
      q = S.at(1);
      r = S.at(0);
      int a = stoi(p);
      int b = stoi(q); 
      int c = stoi(r);
      if (A <= a+b+c && a+b+c <= B) count += i;
    }
    else if (1000 <= i && i < 10000) {
      string p, q, r, s;
      p = S.at(3);
      q = S.at(2);
      r = S.at(1);
      s = S.at(0);
      int a = stoi(p);
      int b = stoi(q); 
      int c = stoi(r);
      int d = stoi(s);
      if (A <= a+b+c+d && a+b+c+d <= B) count += i;
    }
    else if (i = 10000) {
      string p, q, r, s, t;
      p = S.at(4);
      q = S.at(3);
      r = S.at(2);
      s = S.at(1);
      t = S.at(0);
      int a = stoi(p);
      int b = stoi(q); 
      int c = stoi(r);
      int d = stoi(s);
      int e = stoi(t);
      if (A <= a+b+c+d+e && a+b+c+d+e <= B) count += i;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;

    if (s[0] == 'S') {
        cout << "Cloudy" << "\n";
    } else if (s[0] == 'C') {
        cout << "Rainy" << "\n";
    } else {
        cout << "Sunny" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	ll ans=0;
	int n=N;
	int keta=0;
	int Ntop;
	while(n){
		Ntop=n%10;
		keta++;
		n/=10;
	}
	ll plus[7]={0,0,1,11,111,1111,11111};
	ll cnt1=plus[keta-1];
	rep1(A,N){
		if(A%10==0) continue;
		else{
			int now=A;
			int b,e=A%10;
			while(now){
				if(now<10){
					b=now;
					break;
				}
				else now/=10;
			}
			if(b==e) ans++;
			ans+=cnt1;
			if(e==Ntop){
				if(N-b-Ntop*(int)(pow(10,keta-1)+eps)>=0) ans++;
				ans+=(N-b-Ntop*(int)(pow(10,keta-1)+eps))/10;
			}
			else if(e<Ntop){
				ans+=(int)(pow(10,keta-2)+eps);
			}
		}
		//printf("A:%d ans:%lld\n",A,ans);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
tr=[[] for i in range(n+1)]
for i in range(m):
  a,b=map(int,input().split())
  if a!=1 and b!=n:
    continue
  if a==1:
    if tr[b]==[n]:
      print("POSSIBLE")
      exit()
    else:
      tr[b].append(a)
  if b==n:
    if tr[a]==[1]:
      print("POSSIBLE")
      exit()
    else:
      tr[a].append(b)
else:
  print("IMPOSSIBLE")


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define e "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

#define N 5010

void solve()
{
    int n;
    cin>>n;
    int a=0;
    for (int i=0; i<n; i++){
        int x;
        cin>>x;
        if (x%2==1) a++;
    }
    cout<<(a%2==1?"NO":"YES");
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3640
#include<iostream>
#include<vector>

using namespace std;
#define int long long
const int mod=1e9+7;

signed main(){

   int N;
   cin>>  N;

   int p[N+1];
   for(int i=0; i<=N; i++){
      p[i]=1;
   }
   p[0]=p[1]=0;
   for(int i=2; i*i<=N; i++){
      if(p[i])for(int j=2; i*j<=N; j++){
         p[i*j]=0;
      }
   }
   vector<int> q;
   for(int i=2; i<=N; i++){
      if(p[i]) q.push_back(i);
   }
   int r[N+1]={};
   for(int i=2; i<=N; i++){
      int j=i;
      for(int P: q){
         while(j%P==0){
            j/=P;
            r[P]++;
         }
         if(j==1) break;
      }
   }

   int s=1;
   for(int i=0; i<=N; i++){
      (s*=(r[i]+1))%=mod;
   }

   cout<< s<< endl;

   return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

while True:
    A = set()
    B = set()
    C = set()
    D = set()
    E = set()
    while True:
        try:
            name, _ = raw_input().split()
            if name == 'R':
                break
            globals()[name] = set(map(int, raw_input().split()))
        except:
            exit()
    U = A | B | C | D | E

    # evaluate operation
    def operate(term1, term2, op):
        if op == 'u':
            return term1 | term2
        if op == 'i':
            return term1 & term2
        if op == 'd':
            return term1 - term2
        if op == 's':
            return term1 ^ term2

    # evaluate expression without bracket
    def calc(S):
        if len(S) == 1:
            if type(S[0]) == type(""):
                return globals()[S[0]]
            else:
                return S[0]
        for i in range(len(S) - 1, -1, -1):
            if S[i] in ['u', 'i', 'd', 's']:
                return operate(calc(S[:i]), calc(S[i + 1:]), S[i])
        return U - calc(S[1:]) # case of ['inv']

    # evaluate expression
    def br(S):
        index = 0
        lst = []
        while True:
            if index >= len(S) or S[index] == ')':
                return index, calc(lst)
            elif S[index] == '(':
                ret, value = br(S[index + 1:])
                index += ret + 1
                lst.append(value)
            else:
                lst.append(S[index])
            index += 1

    def split(S):
        ret = []
        for c in S:
            if c == 'c':
                ret.append('inv')
            else:
                ret.append(c)
        return ret

    S = raw_input()
    ans = br(split(S))[1]
    print ' '.join(map(str, sorted(list(ans)))) if len(ans) > 0 else 'NULL'


Measured memory_bytes: 5036
#include <stdio.h>

constexpr int kInf = int(2E9 + 10), kN = int(1E2 + 10);

int min(int a, int b) {return a > b ? b : a;}

int dis[kN][kN];

void out(int n) {n == kInf ? printf("INF") : printf("%d", n);}

int main () {
	int n, m, l, r, c;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dis[i][j] = kInf;
	for (int i = 0; i < n; i++) dis[i][i] = 0;
	while (m--) {
		scanf("%d%d%d", &l, &r, &c);
		dis[l][r] = c;
	}
	for (int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if (dis[i][k] != kInf && dis[k][j] != kInf) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	for (int i = 0; i < n; i++) if (dis[i][i] < 0) {
		printf("NEGATIVE CYCLE\n");
		return 0;
	}
	for (int i = 0; i < n; i++) {
		out(dis[i][0]);
		for (int j = 1; j < n; j++) {
			printf(" ");
			out(dis[i][j]);
		}
		printf("\n");
	}
}



Measured memory_bytes: 2784
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

ans = a[0]
for i in range(1,n):
    ans = gcd(ans, a[i])
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
#include <string.h>
 
int N;
char line[17][15];
 
 
int get_level(char *p)
{
  if(*p != '.')
    return(0);
  return (1+get_level(p+1));
}
 
 
int evaluate(int ln,int level)
{
  int   i,ret;
 
  if(isdigit(line[ln][level]))
    return(line[ln][level]-'0');
  else if (line[ln][level]=='+')
    {
      ret=0;
      for(i=ln+1;i<N;i++)
    {
      if(get_level(&line[i][0])==level)
        break;
      if(get_level(&line[i][0])==level+1)
        ret += evaluate(i,level+1);
    }
    }
  else if (line[ln][level]=='*')
    {
      ret=1;
      for(i=ln+1;i<N;i++)
    {
      if(get_level(&line[i][0])==level)
        break;
      if(get_level(&line[i][0])==level+1)
        ret *= evaluate(i,level+1);
    }
    }
  return(ret);
}
 
main()
{
  int i,ret;
   
 
  while(scanf("%d",&N)  && (N))
    {
      for(i=0;i<N;i++)
    {
      scanf("%s",&line[i][0]);
      //printf("%s [%d]\n",&line[i][0],get_level(&line[i][0]));
    }
      ret=evaluate(0,0);
      printf("%d\n",ret);
    }
  return(0);
}


Measured memory_bytes: 2044
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
 
bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int a,b;
  cin >> a >> b;
  if (a<=8&&b<=8) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
  return 0;
}

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

int main(){
    vector<int> a(1000000);
    cin >> a[1];

    bool ok = true;
    int pos = -1;
    if(a[1]==4 || a[1] == 1 || a[1] == 2){
        cout << 4 <<endl;
    }else{
        for(int i = 2;i <= 1000000;i++){
            if(a[i-1]%2 == 0){
                a[i] = a[i-1]/2;
            }else{
                a[i] = (a[i-1]) * 3 + 1;
            }
            if(a[i] == 4){
                pos  = i;
                break;
            }
        }
            cout << pos +3<<endl;
    }

}


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


bool is(ll n, ll k){
    while(n >= k){
        if(n % k == 0){
            n =  n / k;
        }else{
            n %= k;
        }
    }
    return n == 1;
}

void solve(long long N){
  	if(N == 2){
      cout<<1<<endl;
      return;
    }
    ll ans = 0;
    for(ll i = 2;i <= sqrt(N); i++){
        if(N % i != 0)continue;
        if(is(N, i)){
            ans++;
        }
        
        if(is(N, N / i)){
            ans++;
          	if(i * i == N)ans--;
        }
    }
    ans += 2;

    for(ll i = 2;i <= sqrt(N-1);i++){
        if((N-1) % i == 0){
            ans += 2;
            if(i * i == N-1)ans--;
        }
    }
    
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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


int main() {
  ll n,k; cin >> n >> k;
  ll ans = 1;
  rep(i,n){
    if(ans > k) ans += k;
    else ans *= 2;
  }
  cout << ans << endl;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;


int main() {
	ll ans;
	ll n, k, i, j;

	cin >> n >> k;

	ans = 1;
	for (i = 1; i < k; i *= 2);
	j = i;

	repj(i, 2, n + 1) {
		if (i >= k) {
			ans += j * (n - i + 1);
			break;
		}
		else{
			ll a, b;
			for (a = i, b = 1; a < k; a *= 2, b*=2);
			ans += j / b;
		}
	}

	cout << setprecision(20) << ans / (double)j / (double)n;

	return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N)
{
    if (N % 10 == 9 || N / 10 == 9)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256