akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class UnionFind:
    def __init__(self, N): self.N, self.root, self.rank = N, [-1] * N, [0] * N
    def __repr__(self): return '\n'.join(f"{r}: {self.members(r)}" for r in self.roots())

    def find(self, x):
        while self.root[x] >= 0: x = self.root[x]
        return x

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.rank[x] > self.rank[y]: x, y = y, x
        self.root[y] += self.root[x]
        self.root[x] = y
        if self.rank[x] == self.rank[y]: self.rank[y] += 1

    def same(self, x, y): return self.find(x) == self.find(y)
    def count(self, x): return -self.root[self.find(x)]
    def members(self, x): return [i for i in range(self.N) if self.same(x, i)]
    def roots(self): return [i for i, x in enumerate(self.root) if x < 0]
    def all_groups(self): return {r: self.members(r) for r in self.roots()}


def main():
    N, Q = LI()
    TUV = LIR(Q)

    uf = UnionFind(N+1)

    for t, u, v in TUV:
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.same(u, v)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 110192
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 400000 + 10;
int n,st[N],pt[N],nxt[N],pa[N],ent;
int sz[N],vis[N],q[N],cnt,totn,mxc,root,tt;
LL w[N],a[N],dis[N];
struct edge {
    int u,v; LL w;
} e[N * 10];
void link (int u,int v,int _w) {
    pt[++ent]=v; nxt[ent]=st[u]; st[u]=ent; w[ent]=_w;
    pt[++ent]=u; nxt[ent]=st[v]; st[v]=ent; w[ent]=_w;
}
void dp (int x,int f) {
    sz[x] = 1; int crc = 0;
    for(int i=st[x];i;i=nxt[i])
        if(pt[i]!=f && !vis[pt[i]]) {
            dp(pt[i],x);
            sz[x] += sz[pt[i]];
            crc = max(crc,sz[pt[i]]);
        }
    crc = max(crc,totn-sz[x]);
    if(crc < mxc) mxc = crc, root = x;
}
void dfs (int x,int f) {
    q[++tt] = x;
    for(int i=st[x];i;i=nxt[i])
        if(pt[i]!=f && !vis[pt[i]]) {
            dis[pt[i]] = dis[x] + w[i];
            dfs(pt[i],x);
        }
}
void solve (int x) {
    vis[x] = true;
    tt = 0; dis[x] = 0; dfs(x,0);
    LL mn = 1e18, cr = 0;
    for(int i=1;i<=tt;i+=1)
        if(dis[q[i]] + a[q[i]] < mn) mn = dis[q[i]] + a[q[i]], cr = q[i];
    for(int i=1;i<=tt;i+=1) e[++cnt] = (edge){q[i],cr,dis[q[i]]+a[q[i]]+mn};
    for(int i=st[x];i;i=nxt[i])
        if(!vis[pt[i]]) {
            mxc = 1e9; root = -1; totn = sz[pt[i]];
            dp(pt[i],0);
            solve(root);
        }
}
bool cmp (const edge &x, const edge &y) {
    return x.w < y.w;
}
int find (int x) {
    return pa[x]==x ? x : pa[x]=find(pa[x]);
}
int main () {
    n = gi();
    for(int i=1;i<=n;i+=1) a[i] = gi();
    int u,v,_w;
    for(int i=1;i<n;i+=1) {
        u = gi(); v = gi(); _w = gi(); link(u,v,_w);
    }
    totn = n; mxc = 1e9; root = -1;
    dp(1,0);
    solve(root);
    sort(e+1,e+cnt+1,cmp);
    for(int i=1;i<=n;i+=1) pa[i] = i;
    int rr = 0; LL ans = 0;
    for(int i=1;i<=cnt && rr<n;i+=1) {
        if(find(e[i].u) == find(e[i].v)) continue;
        ++rr; pa[find(e[i].u)] = find(e[i].v); ans += e[i].w;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 83456
#include<stdio.h>
int main(void){
  char s[200020];
  char t[200020];
  int i,k=0;
  scanf("%s %s",s,t);
  for(i=0;s[i];i++){
  if(s[i]-t[i]) k++;
  }
  printf("%d",k); 
  
 return 0; 
}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n =sc.nextInt();
		int l =sc.nextInt();
		String temp="";
		
		String [] s = new String[n];
		s[0]=sc.nextLine();
		for(int i=0 ; i<n ; i++) {
			s[i]=sc.nextLine();
		}
		
		for(int i = 0; i<n ; i++ ) {
			for(int j=0 ; j<n ; j++) { 
				if(s[i].compareTo(s[j])<0) {
					temp=s[i];
					s[i]=s[j];
					s[j]=temp;
				}
			}
		}
		for(int i = 0 ; i<n ; i++)
			System.out.print(s[i]);
		
		
		sc.close();

	}

}

Measured memory_bytes: 23764
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let s: Vec<i32> = get!(String)
        .chars()
        .map(|c| c as i32 - '0' as i32)
        .collect();
    let n = s.len() - 1; //3
    for i in 0..1 << n {
        let mut ans = s[0].to_string();
        let mut sum = s[0];
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                sum += s[j + 1];
                ans += "+";
                ans += &s[j + 1].to_string();
            } else {
                sum -= s[j + 1];
                ans += "-";
                ans += &s[j + 1].to_string();
            }
        }
        if sum == 7 {
            ans += "=7";
            println!("{}", ans);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 500001;

string S;
int Q, nex[MX][27], jmp[19][MX];

void init() {
    F0R(i,sz(S)+1) F0R(j,27) nex[i][j] = MOD;
    F0R(i,19) jmp[i][sz(S)] = MOD;
    F0Rd(i,sz(S)) {
        char cur = S[i]; nex[i][cur-'a'] = i+1;
        int x = i+1;
        while (1) {
            x = nex[x][cur-'a'];
            if (x == MOD) break;
            nex[i][cur-'a'+1] = x;
            if (cur == 'z') {
                F0R(j,27) if (nex[i][j] == MOD) nex[i][j] = nex[x][j];
                break;
            } else cur ++;
        }
        jmp[0][i] = nex[i][26];
        // cout << i << " " << jmp[0][i] << "\n";
    }
    FOR(i,1,19) F0R(j,sz(S)+1) {
        if (jmp[i-1][j] == MOD) jmp[i][j] = MOD;
        else jmp[i][j] = jmp[i-1][jmp[i-1][j]];
    }
}

int getBes(int l, int r) {
    F0Rd(i,19) if (jmp[i][l] <= r) l = jmp[i][l];
    return l;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> S >> Q;
    init();
    F0R(i,Q) {
        int l, r; cin >> l >> r; 
        int t = getBes(l-1,r);
        // cout << l << " " << r << " " << t << "\n";
        if (t == r) cout << "Yes\n";
        else cout << "No\n";
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 91164
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
  int n,d;
  cin >> n >> d;
  int x[100][100];
  FOR(i,n){
    FOR(j,d){
      cin >> x[i][j];
    }
  }
  int ans=0;

  FOR(i,n){
    FOR(j,n){
      if(i==j)continue;
      int sum=0;
      FOR(k,d){
        sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      FOR(k,400){
        if(sum==k*k)ans++;
      }
    }
  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int maxH = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            int h = sc.nextInt();
            if (h >= maxH) {
                maxH = h;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22608
s = list(str(input()))

len_s = len(s)
key = "L"
num = 0
ans = []
for i in range(len_s):
  if s[i] != key:
    num += 1
  else:
    ans.append(num)
    num = 1
    if key == "R":
      key = "L"
    else:
      key = "R"
ans.append(num)

len_ans = len(ans)
for i in range(len_ans):
  if i % 2 == 0:
    for j in range(ans[i]-1):
      print(0, end=" ")
    print((ans[i]+1)//2+(ans[i+1])//2, end=" ")
  else:
    print((ans[i-1])//2 + (ans[i]+1)//2, end=" ")
    for j in range(ans[i]-1):
      print(0, end=" ")

Measured memory_bytes: 5540
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = (l); i <= (r); i++)
#define LOG(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
const int N = 2000000 + 5, MOD = 1000000007;
int fac[N], n, x, y, ifac[N];

int qpow (int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1ll * res * a % MOD;
		a = 1LL * a * a % MOD;
		b >>= 1;
	}
	return res; 
} 
int inv (int x) {
	return qpow (x, MOD - 2);
}
int main() {
	scanf ("%d%d", &x, &y);
	n = max(x, y) * 2; 
	fac[0] = 1; 
	rep (i, 1, n) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[n] = qpow(fac[n], MOD - 2);
	for (int i = n - 1; i >= 0; i--) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % MOD;
	
	int ans = 2 * y - x;
	if (ans < 0 || ans % 3) return puts("0"), 0;
	int yy = ans / 3, xx = y - 2 * yy; 
	
	if (2 * xx + yy != x || xx < 0) return puts("0"), 0;
	
	cout << 1LL * fac[xx + yy] * ifac[xx] % MOD * ifac[yy] % MOD << endl;
	return 0;
}


Measured memory_bytes: 15872
import io.{StdIn => in}

object Main extends App {
  val s = Iterator.continually(in.readLine).take(3).map(_ + ".").toArray
  val p = Array.ofDim[Int](3)
  val map = Map('a' -> 0, 'b' -> 1, 'c' -> 2)
  def f(n:Int):Int = {
    if(s(n).charAt(p(n)) == '.') n
    else {
      val ch = s(n).charAt(p(n))
      p(n) += 1
      f(map(ch))
    }
  }

  val ans = f(0) match {
    case 0 => "A"
    case 1 => "B"
    case 2 => "C"
    case _ => "error"
  }
  println(ans)
}

Measured memory_bytes: 26808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> vec(N, 0);
  for (int i = 0; i < M; ++i){
    int a, b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }

  for (int i = 0; i < vec.size(); ++i){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
x = int(input())

import math

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

while True:
  if is_prime(x):
    print(x)
    break
  x += 1

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

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

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

int main() {
  int N;
  int J = 1;
  cin >> N;
  bool finished = false;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == J) {
      J++;
    }
    else {
    }
  }
  if (J != 1) {
    cout << N - J + 1 << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1024
//
//  main.cpp
//  chalka
//
//  Created by Бахтияр on 16/11/19.
//  Copyright © 2019 Бахтияр. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
int n,a[20];
 
long long dp(int l,int r,long long xl,long long xr) {
    if(l+1==r) return 0;
    long long ret=1e18;
    for(int i=l+1;i<r;i++) ret=min(ret,dp(l,i,xl,xl+xr)+dp(i,r,xl+xr,xr)+(xl+xr)*a[i]);
    return ret;
}
 
int main() {
    cin>>n;for(int i=1;i<=n;i++) cin>>a[i];
    cout<<dp(1,n,1,1)+a[1]+a[n];
    return 0;
}


Measured memory_bytes: 384
/********************/
                    /*user -> tushar284*/
                    /******************/
#include<bits/stdc++.h>
                                                    /*********/            
using namespace std;                             /*   __   __   */
#define  f              first                    /*   @ ) ( @   */
#define  s              second                   /*     / \     */            
#define  mp             make_pair                /*  __  -  __  */
#define  loop(i,s,e)    for(int i=s;i<e;i++)     /*    ..^..    */
#define  rev(i,s,e)     for(int i=s;i>=e;i--)     /*     |     */
#define  mod            1000000007                  /*   |   */
#define  pb             push_back                      /***/
#define  start	        int main()                     
#define  fast           ios_base::sync_with_stdio(false);cin.tie(0);
#define  test            int t; cin>>t;while(t--)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

struct node{
    int a,b,c,d;
};
ll ans=0,n,m,Q;
vi arr;
vector<node> q;
void gen(int pos){
    if(pos == n+1){
        ll cnt = 0; 
        loop(i,0,Q){
            if(arr[q[i].b]-arr[q[i].a] == q[i].c)cnt += q[i].d;
        }
        ans = max(ans,cnt);
    }
    else{
        loop(i,arr[pos-1],m+1){
            arr.pb(i);
            gen(pos+1);
            arr.pop_back();
        }
    }
}

start
{   
    int a,b,c,d;
    cin>>n>>m>>Q;
    loop(i,0,Q){
        cin>>a>>b>>c>>d;
        q.pb({a,b,c,d});
    }
    arr.pb(1);
    gen(1);
    cout<<ans;
	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;
int a[maxn], b[maxn], c[maxn];

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

	}
	for(int i = 1; i <= n; i += 2)
		b[a[i]] ++;
	for(int i = 2; i <= n; i += 2)
		c[a[i]] ++;
	int t1 = 0, t2 = 0;
	for(int i = 1; i <= 100000; i ++)
	{
		if(b[i] > b[t1])
		{
			t2 = t1;
			t1 = i;
		}
		else if(b[i] > b[t2])
			t2 = i;
	}
	int t3 = 0, t4 = 0;
	for(int i = 1; i <= 100000; i ++)
	{
		if(c[i] > c[t3])
		{
			t4 = t3;
			t3 = i;
		}
		else if(c[i] > c[t4])
			t4 = i;
	}
	//cout << t1 << " " << t2 << " " << t3 << " " << t4 << endl;;
	//cout << b[t1] << " " << b[t2] << " " << c[t3] << " " << c[t4] << endl;
	if(t1 != t3)
	{
		cout << n - b[t1] - c[t3];
	}
	else
	{
		if(b[t1] + c[t4] > c[t3] + b[t2])
			cout << n - b[t1] - c[t4];
		else
			cout << n - c[t3] - b[t2];
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  mem(a);
  rep(i,m) {
    ll k;
    R k;
    rep(j,k) {
      ll x;
      R x;
      x--;
      a[x]|=1<<i;
    }
  }
  ll y=0;
  rep(i,m) {
    ll x;
    R x;
    if(x) y|=1<<i;
  }
  ll ans=0;
  rep(t,1<<n) {
    ll x=y;
    rep(i,n) {
      if(t&(1<<i)) x^=a[i];
    }
    if(!x) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db long double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
string a,b;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b;
    int m=a.length(),n=b.length();
    a=" "+a;
    b=" "+b;
    vector<vector<int> > dp(m+1,vector<int>(n+1));
    for (int i=1;i<=m;i++)
    for (int j=1;j<=n;j++) 
    if (a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1;
    else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    string ans="";
    while(m>0&&n>0)
    {
        if (a[m]==b[n]&&dp[m][n]==dp[m-1][n-1]+1) 
        {
            ans+=a[m];
            m--;
            n--;
        }
        else if (dp[m][n]==dp[m-1][n]) m--;
        else n--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    stack<char> st;
    ll n = s.length();

    rep(i, n) {
        if (s[i] == '0') {
            st.push('0');
        }
        if (s[i] == '1') {
            st.push('1');
        }
        if (s[i] == 'B') {
            if (st.empty())
                continue;
            else
                st.pop();
        }
    }

    stack<char> out;
    while (!st.empty()) {
        out.push(st.top());
        st.pop();
    }

    while (!out.empty()) {
        cout << (char)out.top();
        out.pop();
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=ITP1_8_D
int main(void) {
    int i, len;
    char s[4096], p[4096], s2[4096];  /* 100バイト以上 */
    scanf("%s", s);
    scanf("%s", p);
    //例 s="vanceknowledgetoad"
    //例 p="advance"
    // s2 = "vanceknowledgetoad" + "vanceknowledgetoad"

    sprintf(s2, "%s%s", s, s);  // 文字列を連結する
    /*printf("%s\n", s2);*/

    // strstr という関数で部分文字列を探す
    if(strstr(s2, p) == NULL) {
		printf("No\n");
    }
    else
    	printf("Yes\n");

    return 0;
}



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

typedef long long ll;

const int N = 1e2+5 , M = 1e5+5;
ll const inf = 0x3f3f3f3f3f3f3f3f;

int n , m , r;
ll w[N] , v[N] , dp[N][M];

int main(){

  cin >> n >> m;

  for(int i = 1 ; i <= n ; i++) cin >> w[i] >> v[i];

  for(int i = 1 ; i < N ; i++)
    for(int j = 1 ; j < M ; j++) dp[i][j] = inf;
  dp[1][v[1]] = w[1];

  for(int i = 2 ; i <= n ; i++){
    for(int j = 0 ; j < M ; j++) dp[i][j] = min(dp[i][j],dp[i-1][j]);
    for(int j = v[i] ; j < M ; j++) dp[i][j] = min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
  }

  for(int i = 0 ; i < M ; i++)
    if(dp[n][i] <= m) r = max(r,i);
  
  cout << r << "\n";

}


Measured memory_bytes: 84840
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> div;
    div = divisor(N);
    ll ans = 0;
    rep(i, div.size()) {
        ll m = div[i] - 1;
        ll r = N / div[i];
        if (0 <= r && r < m ) {
            ans += m;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
        public class Main {
        	public static void main(String[] args){
        		Scanner sc = new Scanner(System.in);
        		String s = sc.next();
              if(s.equals("ABC")){
              	System.out.println("ARC");
              }
              else{
                System.out.println("ABC");
              }
                   
        	}
        }

Measured memory_bytes: 35608
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define l(i,n) for(int i=0; i<n; i++)
int main()
{
    std::ios::sync_with_stdio(false);
    set<char> s;
    int n;
    cin>>n;
    char c;
    for(int i=0; i<n; i++){
        cin>>c;
        s.insert(c);
    }
    if(s.size()==4) cout<<"Four\n";
    else cout<<"Three\n";
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll ans=0;
  for(int i=1;i<=n;++i){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

	vector<int> a(n), d(n);
	
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	
	for (int i = 0; i < n; i++) {
		if (i != n - 1) d[i] = a[i + 1] - a[i];
		else d[i] = (k - a[n - 1]) + a[0];
	}
	sort(d.begin(), d.end());

	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans += d[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
function main()
	H,W=map(x->parse(Int,x),split(readline()))
	A=zeros(Int,H,W)
	for i=1:H
		j=0
		for a=map(x->parse(Int,x),split(readline()))
			A[i,j+=1]=a
		end
	end
	for i=1:H
		j=0
		for a=map(x->parse(Int,x),split(readline()))
			j+=1
			A[i,j]=abs(A[i,j]-a)
		end
	end
	dp=zeros(BigInt,H,W);
	dp[1,1]=big"2"^(A[1,1]+12800);
	for i=1:H,j=1:W
		if i<H
			dp[i+1,j]|=(dp[i,j]<<A[i+1,j])|(dp[i,j]>>A[i+1,j])
		end
		if j<W
			dp[i,j+1]|=(dp[i,j]<<A[i,j+1])|(dp[i,j]>>A[i,j+1])
		end
	end
	ans=12800
	x=dp[H,W]
	for j=0:25600
		if x%2==1
			ans=min(ans,abs(12800-j))
		end
		x>>=1
	end
	println(ans)
end
main()


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

using ll = long long int;

const int MAX_N = (int)(1e1 + 5);

int n, m;

vector<set<int>> graph(MAX_N);

vector<int> order;

int ans;

bool check() {
  for (int i = 0; i < n - 1; ++i) {
    int src = order[i];
    int tar = order[i + 1];
    if (graph[src].find(tar) == graph[src].end()) return false;
  }
  return true;
}

int main(void) {
    // Here your code !
    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; ++i) {
      int a, b;
      scanf("%d %d", &a, &b);

      graph[a].insert(b);
      graph[b].insert(a);
    }

    for (int i = 1; i <= n; ++i) {
      order.push_back(i);
    }

    check();

    do {
      if (check()) ans += 1;
    } while(next_permutation(order.begin() + 1, order.end()));

    printf("%d\n", ans);

    return 0;
}

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

int main() {
  long long int N;
  string S;
  cin >> N >> S;
  int arr[26];
  for (int i=0; i<26; i++) arr[i] = 1;
  for (int i=0; i<S.size(); i++) {
    char c = S[i];
    int j = (int)(c - 97);
    arr[j]++;
  }
 
  long long int ans = 1;
  for (int i=0; i<26; i++) {
    ans *= arr[i];
    ans %= 1000000007;
  }
 
  cout << ans - 1 << endl;
 
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            while(true) {
                var input = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).Where(p => p != -1).ToArray();
                if(input.Length != 6) {
                    break;
                }
                Console.WriteLine((new DateTime(input[3], input[4], input[5]) - new DateTime(input[0], input[1], input[2])).TotalDays);
            }
        }
    }
}

Measured memory_bytes: 6044
s = gets.to_s.chomp
k = gets.to_s.to_i

a = s.chars 
b = s.bytes
# p "az".bytes #=> [97, 122]
ans = s.chars
b.each_with_index do |c, i|
  
  if c == 97
    next
  else
    d = 123 - c
    if d <= k
      k -= d
      ans[i] = 'a'
    end
  end
end

ans[-1] = (97 + (ans[-1].ord + k - 97) % 26).chr

puts ans.join

Measured memory_bytes: 17020
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int k = 0,t = N;
  while(t>0){
    k = k+t%10;
    t = t/10;
  }
  if(N%k == 0){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

int k, n;

int main() {	
	cin >> k >> n;
	vector<int> cur(n + 1);
	
	if (k % 2 == 0) {
		cout << k / 2 << " ";
		for (int i = 1; i < n; i++) cout << k << " ";
		return 0;
	}
	
	
	for (int i = 0; i < n; i++) cur[i] = (k + 1) / 2;
	
	int last = n - 1;
	for (int it = 0; it < n / 2; it++) {
		if (cur[last] == 1) {
			last--;
		} else {
			cur[last]--;
			while (last + 1 < n) cur[last + 1] = k, last++;
		}
	}
	for (int i = 0; i <= last; i++) cout << cur[i] << " ";
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3456
N = int(input())
adj = [[] for _ in range(N)]
 
for i in range(N-1):
    u,v,w = map(int,input().split())
    u,v = u-1, v-1
    w %= 2
    adj[u].append((v,w))
    adj[v].append((u,w))
 
color = [None]*N
color[0] = False
stack = [0]
 
while stack:
    u = stack.pop()
    for v,w in adj[u]:
        if color[v] is None:
            color[v] = (w%2) ^ color[u]
            stack += [v]
 
for c in color:
    print(1 if c else 0)

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

bool solve() {
	lli n = 1;
	string s;
	if ( cin >> s );
	else return false;
	
	lli ans = 0, par = 1, sz = s.size();
	vcL three( sz, 1 );
	
	for (int i = 1; i < sz; ++i) three[i] = ( 3 * three[ i-1 ] ) % mod;
	
	for (int i = 0; i < sz; ++i) {
		if ( s[i] == '1' ) {
			ans += three[ sz-i-1 ] * par;
			par *= 2;
			ans %= mod;
			par %= mod;
		}
		if ( i == sz-1 ) ans += par;
	}
	
	cout << ans%mod << '\n';
	
	return true;
}

int main() {
	precal();
	int t = INT_MAX;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		if ( !solve() ) break;
	}
	return 0;
}


Measured memory_bytes: 1280
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::max;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let i = scan.read::<i64>();
    let o = scan.read::<i64>();
    let t = scan.read::<i64>();
    let j = scan.read::<i64>();
    let l = scan.read::<i64>();
    let s = scan.read::<i64>();
    let z = scan.read::<i64>();
    let mut ret = len(i,o,j,l);
    if i>=1 && j>=1 && l>=1 {
        ret = max(ret, len(i-1,o,j-1,l-1) + 6);
    }
    println!("{}", ret/2);
}

fn len(i: i64, o: i64, j: i64, l: i64) -> i64 {
    i/2*4+o*2+j/2*4+l/2*4
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main(void) {
  ll N, K; cin >> N >> K;
  ll v[55];
  ll l, r;
  ll i, j;
  ll dp[55][55]={};
  
  for(i=0; i<N; i++) cin >> v[i];
  
  for(l=0; l<N; l++) {
    for(r=l; r<=N; r++) {
      for(i=0; i<l; i++)
        dp[l][r]+=v[i];
      for(i=r; i<=N; i++)
        dp[l][r]+=v[i];
      
    }
  }
  
  vector<ll> a[55][55];
  for(l=0; l<N; l++) {
    for(r=l; r<=N; r++) {
      for(i=0; i<l; i++)
        a[l][r].pb(v[i]);
      for(i=r; i<=N; i++)
        a[l][r].pb(v[i]);
      
      sort(a[l][r].begin(), a[l][r].end());
    }
  }
  
  
  ll ans=0;
  for(l=0; l<N; l++) {
    for(r=l; r<=N; r++) {
      
      if(l+(N-r)>K) continue;
      
      ll c=max(0, K-l-(N-r));
      ll t=dp[l][r];
      for(i=0; i<min(c, (ll)a[l][r].size()); i++) {
        ll u=a[l][r][i];
        if(u>=0) break;
        
        t-=u;
      }
      
      chmax(ans, t);
    }
  }
  
  pt(ans);
}












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

int main(){
  int n,sum=0;
  cin>>n;
  vector<int> num(2*n);
  for(int i=0;i<2*n;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  for(int i=0;i<n;i++){
    sum+=num[i*2];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	if(s=="SUN") cout<<7<<endl;
	if(s=="SAT") cout<<1<<endl;
	if(s=="FRI") cout<<2<<endl;
	if(s=="THU") cout<<3<<endl;
	if(s=="WED") cout<<4<<endl;
	if(s=="TUE") cout<<5<<endl;
	if(s=="MON") cout<<6<<endl;
	return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
// aとbの最大公約数
// O(log (a+b) )
LL gcd(LL a,LL b){
    return (b==0)?a:gcd(b,a%b);
}

// aとbの最小公倍数
// O(log (a+b) )
LL lcm(LL a,LL b){
    return (a*b)/gcd(a,b);
}

int main(){
    int N;
    cin>>N;
    LL res;
    cin>>res;
    REP(i,N-1){
        LL t;
        cin>>t;
        LL g=gcd(res,t);
        t/=g;
        res*=t;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int E[N][N];
  int n,u,k,v;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      E[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
    v--;
    E[i][v]=1;
      }
}
  for(i=0;i<n;i++){
  for(j=0;j<n;j++){
    if(j) printf(" ");
    printf("%d",E[i][j]);
  }
  printf("\n");
}
  return 0;
}



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

int main(){
  string S; cin >> S;
  for(int i=0; i<S.size()-1; i++){
    if(S.substr(i,2)=="AC"){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		final int n = Integer.parseInt(sc.nextLine());
		String[] str = sc.nextLine().split(" ");
		boolean f =false;//Three
		for(int i=0;i<n;i++){
			if(str[i].equals("Y")){
				f=true;
				break;
			}
		}
		if(f){
			System.out.println("Four");
		}else{
			System.out.println("Three");
		}

	}
}

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

typedef long long ll;
#define pii pair<int, int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll used(ll a){
    if(a % 3 && a % 5)
        return true;
    return false;

}

int main()
{
    _FastIO;
    ll n , ans = 0;
    cin >> n;
    for(ll x = 1; x <= n; x++){
        if(used(x))
            ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
   ll N;
   cin >> N;
   vector<ll>d;
   if(N==2){cout << 1 << endl;return 0;}
   for(ll i=1;i<=sqrt(N);i++){
      if(N%i==0){d.push_back(i);}
      if(N!=i*i){d.push_back(N/i);}
   }
   set<ll>ans;
   ll ni=N-1;
   for(ll i=2;i<=sqrt(ni);i++){
      if(ni%i==0){
         ans.insert(i);
         if(ni!=i*i)ans.insert(ni/i);
      }
   }
   for(auto r:d){
      ll Nr=N;
      if(r==1)continue;
      while(Nr%r==0){Nr/=r;}
      if(Nr%r==1){ans.insert(r);}
   }
   ans.insert(N-1);
   cout << ans.size() << endl;

   return 0;
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    vi k(3);
    vi dp(n);
    rep(i,n){
        ll a;cin>>a;
        ll num=0;
        rep(j,3)if(a==k[j])num++;
        if(!num){
            out(0);
            return 0;
        }
        if(i)dp[i]=dp[i-1]*num;
        else dp[i]=num;
        rep(j,3)if(a==k[j]){
            k[j]++;
            break;
        }
        dp[i]%=mod;
    }
    out(dp[n-1]);
}

Measured memory_bytes: 1024
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
        int c=0;
 for(int i =0;i<5;i++){
         int a;
         cin>>a;
         if (a==0)c=++i;
 }cout<<c;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> sum(n,0);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    if(i==0) {
      sum[i]=a[i];
    }
    else {
      sum[i]=sum[i-1]+a[i];
    }
  }
  ll small=1e18;
  for(int i=0;i<n;i++) {
    small=min(small, abs(sum[n-1]-2*sum[i]));
  }
  cout << small << endl;
}

Measured memory_bytes: 3456
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)
ok = A[-1] * F[0]
ng = -1
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for i in range(n):
        if A[i] * F[i] > mid:
            ret += (A[i] * F[i] - mid) // F[i] + bool((A[i] * F[i] - mid) % F[i])
    if ret > k:
        ng = mid
    else:
        ok = mid


print(ok)

Measured memory_bytes: 109388
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n, k, ans = 0;
    vector<int> v;
    cin >> n >> k;
    v.assign(n, 0);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int left = 0; left <= n; left++){
        for(int right = 0; left + right <= n && left + right <= k; right++){
            vector<int> w;
            int sum = 0;
            for(int i = 0; i < left; i++){
                w.push_back(v[i]);
                sum += v[i];
            }
            for(int i = 0; i < right; i++){
                w.push_back(v[n-1-i]);
                sum += v[n-1-i];
            }
            sort(w.begin(), w.end());
            ans = max(ans, sum);
            for(int i = 0; i < w.size() && i < k-right-left; i++){
                sum -= w[i];
                ans = max(ans, sum);
            }
        }
    }
    cout << ans << endl;
}


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

const int maxn=2005;
int n,tot,cnt;
int par[maxn],a[maxn],id[maxn],dep[maxn],deg[maxn],cur[maxn];
vector<int>ver[maxn],ans;
bool spe[maxn];

void work(int v){
	ans.push_back(v);
	int tmpa=a[v],tmpc=cur[v],ov=v;
	while(v){
		swap(a[par[v]],tmpa);
		swap(cur[par[v]],tmpc);
		v=par[v];
	}
	a[ov]=tmpa;cur[ov]=tmpc;
}

int main(){
	scanf("%d",&n);
	par[0]=-1;
	for(int i=1;i<n;i++){
		scanf("%d",&par[i]);
		deg[par[i]]++;
		dep[i]=dep[par[i]]+1;
	}
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	tot=n;
	while(tot){
		for(int i=0;i<n;i++){
			spe[i]=false;
			if(cur[i]==1)cur[i]=0;
		}
		cnt=0;
		for(int i=0;i<n;i++)if(cur[i]==0&&deg[i]==0){
			ver[cnt].clear();
			int v=i;
			while(v>=0&&deg[v]<=1){
				spe[v]=true;
				id[v]=cnt;
				ver[cnt].push_back(v);
				v=par[v];
			}
			cnt++;
		}
		int now=0;
		for(int i=0;i<cnt;i++){
			now+=int(ver[i].size());
			tot-=int(ver[i].size());
			for(int j=0;j<int(ver[i].size());j++)if(ver[i][j])
				deg[par[ver[i][j]]]--;
		}
		while(now){
			cur[0]=0;
			int x=a[0];
			if(spe[x]){
				int c=0;
				for(int i=0;i<int(ver[id[x]].size());i++)
					if(a[ver[id[x]][i]]>x&&cur[ver[id[x]][i]]==2)c++;
				work(ver[id[x]][c]);
				cur[ver[id[x]][c]]=2;
				now--;
			}
			else{
				int cv=-1,cdep=-1;
				for(int i=0;i<cnt;i++){
					int v=ver[i][0];
					while(v>=0&&cur[v])v=par[v];
					if(v>=0&&dep[v]>cdep)cdep=dep[v],cv=v;
				}
				work(cv);
				cur[cv]=1;
			}
		}
	}
	for(int i=0;i<n;i++)assert(a[i]==i);
	printf("%d\n",int(ans.size()));
	for(int i=0;i<int(ans.size());i++)printf("%d\n",ans[i]);
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int x;
  cin >> x;
  if(x == 0) cout << 1 <<endl;
  else cout << 0 <<endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

const int NMAX=1e4+5;
ll n,a[NMAX],b[NMAX];


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

	cin >> n;
	
	ll s1=0,s2=0,difference=0,marge=0;
	
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	
	for(int i=0;i<n;i++){
		s1+=a[i];
		s2+=b[i];
		difference+=max((ll)0,b[i]-a[i])/2;
		marge-=min((ll)0,b[i]-a[i]);
	}
	ll a=min(difference,marge);
	marge-=a;
	difference-=2*a;
	s2+=a;
	s1+=2*a;
	
	if(s2>=s1 && marge==0){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
	
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


void solve(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  ll now = 1;
  rep(i, N){
    if(A[i] == now) now++;
    else ans++;
  }
  if(now == 1) ans = -1;
  cout << ans << endl;
}


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


Measured memory_bytes: 1792