akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
         char a,b,c;
         cin>>a>>b>>c;
         if(a==b&&b==c) cout<<"No"<<endl;
         else if(a!=b && b!=c && c!=a) cout<<"No"<<endl;
         else cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;
int mod=1000000007;

int extgcd(int a, int b ,int &x, int&y){
  int d = a;
  if( b != 0 ){
    d = extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1,y=0;
  }
  return d;
}
int mod_inverse( int a, int m ){
  int x, y ;
  extgcd( a, m , x, y);
  return (m+x%m)%m;
}

int calc(int r, int c){
   long long ans = 0;
   long long tmp = 1;
   for(int i=0;i<=c; i++){
      tmp *= r+1+i;
      tmp %= mod;
      tmp *= mod_inverse( i+1, mod );
      tmp %= mod;
      ans += tmp;
      ans %= mod;
   }
   //cout << r << ", " << c << ": " <<  ans << endl;
   return ans;
}

int main(){
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   long long ans = calc(c, d);
   ans += mod;
   ans -= calc(a-1, d);
   ans %= mod;
   ans += mod;
   ans -= calc(c, b-1);
   ans %= mod;
   ans += calc(a-1, b-1);
   ans %= mod;
   cout << ans << endl;
   return 0;
}


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

int main(int argc, char const *argv[])
{
	int s;
	cin>>s;
	int ym=0,my=0;
	if (1<=s/100&&s/100<=12)
	{
		my=1;
	}
	if (1<=s%100&&s%100<=12)
	{
		ym=1;
	}
	if (ym==1)
	{
		if (my==1)
		{
			cout<<"AMBIGUOUS\n";
		}
		else
		{
			cout<<"YYMM\n";
		}
	}
	else
	{
		if (my==1)
		{
			cout<<"MMYY\n";
		}
		else
		{
			cout<<"NA\n";
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int par[213456], size1[345678];//親
int depth[213456];//木の深さ
//n要素で初期化
void init(int n) {
	for (int i = 0; i <= n; i++) { par[i] = i; size1[i] = 1; depth[i] = 0; }
}
//木の根を求める
int find(int x) {
	if (par[x] == x) { return x; }
	else { return par[x] = find(par[x]); }
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) { par[x] = y; size1[y] += size1[x]; }
	else { par[y] = x; size1[x] += size1[y]; if (depth[x] == depth[y])depth[x]++; }
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
int tomodati[345678], ok[345678];
signed main() {
	int n, k, l, a, b, c, d; cin >> n >> k >> l;
	vector<vector<int>>test(n + 1, vector<int>(2));
	init(n + 1);
	for (int h = 0; h < k; h++) {
		cin >> a >> b; if (a > b) { swap(a, b); } unite(a, b);
		tomodati[a]++; tomodati[b]++;
	}
	for (int h = 1; h <= n; h++) {
		test[h][0] = find(h);
	}
	for (int h = 0; h < l; h++) {
		cin >> c >> d; if (same(find(c), find(d))) { ok[c]++; ok[d]++; }
	}
	for (int h = 1; h <= n; h++) {
		int ans = size1[find(h)] - ok[h] - tomodati[h] - 1;
		if (h == 1) { cout << ans; }
		else { cout << ' ' << ans; }
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 15616
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
p = LI()
ps = []
for i in range(N):
    ps.append((p[i] + 1) / 2)

anss = []
tmp = 0
for i in range(N):
    tmp += ps[i]
    if i > K - 1:
        tmp -= ps[i - K]
    anss.append(tmp)

print(max(anss))


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

vector<int> v[100001];

void dfs(int s, int d[]){
    for(auto i: v[s]){
        if(d[i] == 0){
            d[i] = d[s] +1;
            dfs(i, d);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int dl[n] = {};
    dl[0] = 1;          // to keep topological order
    int dr[n] = {};
    dr[n-1] = 1;
    dfs(0, dl);
    dfs(n-1, dr);
    int ans = 0;
    for(int i=0; i<n; i++){
        if(dl[i] <= dr[i]) ans++;
    }
    if(ans > n-ans)
        cout << "Fennec" << endl;
    else
        cout << "Snuke" << endl;    
    return 0;
}

Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
import math


def read():
    A = int(input().strip())
    B = int(input().strip())
    C = int(input().strip())
    X = int(input().strip())
    return A, B, C, X

def solve(A, B, C, X, XMAX=20001):
    dp = [[0 for j in range(XMAX)] for i in range(4)]
    dp[0][0] = 1
    for i, (v, c) in enumerate(zip([500, 100, 50], [A, B, C])):
        for x in range(XMAX):
            for j in range(c+1):
                if x - j * v >= 0:
                    dp[i+1][x] += dp[i][x - j * v]
    return dp[3][X]


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 3820
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
struct P {
    lli a, b, c;
};
int main()
{
    lli mod = 1e9 + 7;
    lli n;
    cin >> n;
    map<lli, map<lli, lli>> m;
    lli ma, mb;
    cin >> ma >> mb;
    lli a[501], b[501], c[401];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    lli dp[2][610][610];
    int now = 0, next = 1;
    rep(i, 610) rep(j, 610)
    {
        dp[0][i][j] = mod * mod;
        dp[1][i][j] = mod * mod;
    }
    dp[now][0][0] = 0;
    dp[1][0][0]=0;

    rep(i, n)
    {
        rep(j, 410) rep(k, 410)
        {
            if (dp[now][j][k] != mod * mod) {
                dp[next][j + a[i]][k + b[i]] = min(dp[now][j][k] + c[i], dp[now][j + a[i]][k + b[i]]);
            }
        }
        rep(j, 410) rep(k, 410)
        {
            dp[now][j][k] = dp[next][j][k];
        }
    }
    lli ans = mod * mod;
    for (int i = 1; i < 400 && i * ma <= 400 && i * mb <= 400; i++) {
        ans = min(ans, dp[now][i * ma][i * mb]);
    }
    if (ans == mod * mod) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    };
}


Measured memory_bytes: 6016
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int n;
  scanf("%d",&n);
  if(n%2){
    PRF(1.0*(n/2+1)/n);
  }else{
    PRF(0.5);
  }
  return 0;
}


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

struct data{
  int ac,pe,id;
  bool operator == (const data& p) const{
    return ac==p.ac && pe==p.pe;
  }
  bool operator < (const data& p) const{
    if(ac!=p.ac)return ac>p.ac;
    if(pe!=p.pe)return pe<p.pe;
    return id>p.id;
  }
};

int wa_cnt[51][11];

data team[51];

void init();

int main(){
  int M,T,P,R;
  while(1){
    cin>>M>>T>>P>>R;
    if(M==0&&T==0&&P==0&&R==0)break;
    init();
    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;t--;
      if(m>M)continue;
      if(j==0){
	team[t].ac++;
	team[t].pe+=(wa_cnt[t][p]*20);	
	team[t].pe+=m;
      }else{
	wa_cnt[t][p]++;
      }
    }

    sort(team,team+T);
    for(int i=0;i<T;i++){
      if(i>0){
	if(team[i-1]==team[i])cout<<'=';
	else cout<<',';
      }
      cout<<team[i].id;
    }
    cout<<endl;
  }
  return 0;
}

void init(){
  for(int i=0;i<51;i++)for(int j=0;j<11;j++)wa_cnt[i][j]=0;
  for(int i=0;i<51;i++){
    team[i].id=i+1;
    team[i].pe=team[i].ac=0;
  }
}

Measured memory_bytes: 1188
#include <stdio.h>

void gcd(int,int);

int main(){
  int x,y;

  scanf("%d %d",&x,&y);
  gcd(x,y);
  
  return 0;
}

void gcd(int x,int y){
  int n,r;
  if(x>y){
    while(y>0){
    r = x%y;
    x = y;
    y = r;
  }
  printf("%d\n",x);
  }
  else{
    while (x>0){
    r = y%x;
    y = x;
    x = r;
    }
    printf("%d\n",y);
  }
}
 
  
    
  



Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w;
	cin>>h>>w;
	ll n;
	cin>>n;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		for(ll j=0;j<now;j++){
			ch.push_back(i+1);
		}
	}
	vector<ll>ans[h];
	for(ll i=0;i<ch.size();i++){
		ans[i/w].push_back(ch[i]);
	}
	for(ll i=0;i<h;i++){
		if(i%2==0){
			reverse(ans[i].begin(),ans[i].end());
		}
		for(ll j=0;j<w;j++){
			cout << ans[i][j]<<" ";
		}
		cout <<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

vector<int> ans[2000];

int main() {
    ll n;
    cin >> n;
    ll k = -1;
    bool ok = false;
    for (int i = 0; i * (i - 1) / 2 <= 100005; i++) {
        if (i * (i - 1) / 2 == n) {
            k = i;
            ok = true;
            break;
        }
    }
    if (!ok) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        cout << k << endl;
        int tmp = 1;
        for (int i = 0; i < k; i++) {
            for (int j = i + 1; j < k; j++) {
                ans[i].push_back(tmp);
                ans[j].push_back(tmp);
                tmp++;
            }
        }
        for (int i = 0; i < k; i++) {
            string s = "";
            int len = ans[i].size();
            s += to_string(len);
            for (int j = 0; j < len; j++) {
                s += " ";
                s += to_string(ans[i][j]);
            }
            cout << s << endl;
        }
    }
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i=1;;i++){
            int x = sc.nextInt();
            if(x == 0)
                break;
            System.out.println("Case "+i+": "+ x);
        }
}
}


Measured memory_bytes: 41404
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
r,x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!
#これを消すとなぜかWAになる呪い
for i in range(10):
    y = r*y-x
    print(y)

Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii; 
int n,all,ans,nw;
int a[1000]; 
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		all+=a[i];
	}
	ans=1e9;
	for(int i=0;i<n;i++){
		nw+=a[i];
		while(a[i+1]==a[i]){
			nw+=a[i];
			i++; 
		}
		ans=min(ans,abs(all-2*nw));
	}
	cout<<ans<<endl;
    return 0; 
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int M, K;
    cin >> M >> K;

    if (K >= (1 << M)) {
        cout << -1 << endl;
        return 0;
    }

    if (M == 1) {
        if (K == 0) cout << "0 0 1 1\n";
        else cout << -1 << "\n";
        return 0;
    }

    int rest = 0;
    for (int i = 0; i < (1 << M); i++) {
        if (i != K) {
            cout << i << " ";
            rest ^= i;
        }
    }
    assert(rest == K);

    cout << K << " ";

    for (int i = (1 << M) - 1; ~i; i--) {
        if (i != K)
            cout << i << " ";
    }

    cout << K << endl;

    return 0;
}



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

using P = pair<int, int>;

P solve(int n, vector<int> &v, vector<int> &w, vector<int> &ma, vector<int> &mb){
	if(n == 0) return P(0, 0);
	if(ma[n] < 1e6) return P(ma[n], mb[n]);
	for(size_t i=0; i<v.size(); ++i){
		if(v[i] > n) break;
		if(v[i] == n){
			ma[n] = 1;
			break;
		}
		ma[n] = min(ma[n], 1+solve(n-v[i], v, w, ma, mb).first);
	}
	for(size_t i=0; i<w.size(); ++i){
		if(w[i] > n) break;
		if(w[i] == n){
			mb[n] = 1;
			break;
		}
		mb[n] = min(mb[n], 1+solve(n-w[i], v, w, ma, mb).second);
	}
	return P(ma[n], mb[n]);
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	const int N = 1'000'000;
	vector<int> v, w, ma(N, N), mb(N, N);
	for(int i=1; i<=1000; ++i){
		int t = i * (i+1) / 2 * (i+2) / 3;
		v.push_back(t);
		if(t % 2 == 1) w.push_back(t);
	}
	for(int i=1; i<N; ++i) solve(i, v, w, ma, mb);
//	for(size_t i=0; i<v.size(); ++i) cout << i << " " << v[i] << "\n";
	while(1){
		int n; cin >> n;
		if(n == 0) break;
		cout << ma[n] << " " << mb[n] << "\n";
	}
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
double PI=acos(-1.0);
signed main(){
    ll z=1000000000000000000;
    ll n;cin>>n;
    ll ans=1;
    rep(i,n){
        ll a;cin>>a;
        if(a==0){
            ans=0;
            continue;
        }
        if(ans==-1){
            continue;
        }
        if((z)/a+1<=ans){
            ans=-1;
        }else{
            ans*=a;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
  int L;
  int A, B, C, D;
  cin >> L;
  cin >> A >> B >> C >> D;
  cout << L - max((A + C - 1) / C,(B + D - 1) / D) << endl;
  return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <cmath>

using namespace std;


int main(){
  int n;
  double t, a;
  cin >> n;
  cin >> t;
  cin >> a;

  int i;
  double l;
  double h[n];
  for (i=0; i<n; i++){
    cin >> l;
    h[i] = t - 0.006 * l;
  }

  int ans = 0;
  for (i=0; i<n; i++){
    if ((abs(a - h[i])) < ((abs(a - h[ans])))) ans = i;
  }

  cout << ans+1 << "\n";
  return 0;
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

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

	vector<pair<int, int>> p;
	int a, b;
	rep(i, m) {
		cin >> a >> b;
		p.emplace_back(b,a);
	}
	sort(all(p));
	
	int ans = 0, t = 1;
	rep(i, m) {
		if (t <= p[i].second) {
			t = p[i].first;
			ans++;
		}
	}
	cout << ans << endl;
	
}



Measured memory_bytes: 1400
function Main(input) {
    var result;
    const N = parseInt(input.shift());
    var Ws = input.map(v => parseInt(v));
    var sum = 0;
    Ws.forEach(element => {
        sum += element;
    });

    var smallSum = 0;
    var div = Number.MAX_SAFE_INTEGER;
    for (var i = 0; i < Ws.length; i++) {
        div = Math.min(div, Math.abs(sum - smallSum * 2));
        smallSum += Ws[i];
    }
    div = Math.min(div, Math.abs(sum - smallSum * 2));
    console.log(div);
    
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 11468
#include<stdio.h>

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

int main(){
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long ans=0;
	if(a%c==0)ans+=b/c-a/c+1;
	else ans+=b/c-a/c;
	if(a%d==0)ans+=b/d-a/d+1;
	else ans+=b/d-a/d;
	long long g=c*d/gcd(c,d);
	if(a%g==0)ans-=b/g-a/g+1;
	else ans-=b/g-a/g;
	printf("%lld\n",b-a+1-ans);
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
 
static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int prior[21];
int credit[21];
int dp[1<<20];
int bitcount[1<<20];
int total_subjects;
int credit_requirement;

class State {
public:
  int S;
  int sum;
  State(){}
  bool operator<(const State& s) const {
    return bitcount[S] < bitcount[s.S];
  }
  bool operator>(const State& s) const {
    return bitcount[S] > bitcount[s.S];
  }
  State(int S,int sum) : S(S),sum(sum) {}
};

int bfs(){
  priority_queue<State,vector<State>,greater<State> > que;
  que.push(State(0,0));
  int next_sum;
  int next_S;
  State s;
  int rest;
  while(!que.empty()){
    s = que.top();
    que.pop();
    for(int i = 0; i < total_subjects; i++){
      if(dp[next_S = (s.S | (1<<i))] != -1) continue;
      if((prior[i] | s.S) == s.S){
	next_sum = s.sum + credit[i];
	dp[next_S] = next_sum;

	if(next_sum >= credit_requirement) {
	  return bitcount[s.S] + 1;
	}
	que.push(State(next_S,next_sum));
      }
    }
  }
  return 0;
}

int main(){
  for(int S = 0; S < (1<<20); S++){
    bitcount[S] = __builtin_popcount(S);
  }
  
  while(~scanf("%d %d",&total_subjects,&credit_requirement)){
    if(total_subjects == 0 && credit_requirement == 0) break;
    memset(dp,-1,sizeof(dp));
    memset(prior,0,sizeof(prior));

    for(int subject_i = 0; subject_i < total_subjects; subject_i++){
      int prior_subject_num;
      scanf("%d %d",&credit[subject_i],&prior_subject_num);
      for(int subject_j = 0; subject_j < prior_subject_num; subject_j++){
	int subject_code;
	scanf("%d",&subject_code);
	prior[subject_i] |= (1<<subject_code);
      }
    }
    
    printf("%d\n",bfs());
  }
}

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

using namespace std;
#define taskname "A"
#define pb  push_back
#define mp  make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e3 + 5;
const int maxm = maxn * maxn;
const int mod = 1e9 + 7;
int n , k , dp[maxn][maxn];
int f[maxm] , rf[maxm];
int C(int n , int k){
    if(k < 0 || n < 0 || k > n)return 0;
    return (ll)f[n] * rf[n - k] % mod * rf[k] % mod;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> k;
    dp[0][0] = 1;
    f[0] = f[1] = rf[0] = rf[1] = 1;
    if(k == 1)return cout << 1 , 0;
    for(int i = 2 ; i < maxm ; ++i){
        f[i] = (ll)f[i - 1] * i % mod;
        rf[i] = (mod - (ll)(mod / i) * rf[mod % i] % mod);
    }
    for(int i = 2 ; i < maxm ; ++i)rf[i] = (ll)rf[i - 1] * rf[i] % mod;
    for(int i = 0 ; i <= n ; ++i){
        for(int j = 0 ; j <= n ; ++j){
            if(i == 0 && j == 0)continue;
            if(i > j)continue;
            if(i > 0)dp[i][j] = dp[i - 1][j];
            if(j > 0)dp[i][j] += (ll)dp[i][j - 1] * C(i + j * (k - 1) - 1 , k - 2) % mod;
            if(dp[i][j] >= mod)dp[i][j] -= mod;
//            cout << i << " " << j << " " << dp[i][j] << " " <<
//            i + j * (k - 1) - 1 << " " << k - 2 << " "  << C(i + j * (k - 1) - 1 , k - 2) <<endl;
        }
    }
    cout << ((ll)dp[n][n] * f[n]) % mod;
}


Measured memory_bytes: 47360
nn = 2002002
P = 10**9+7
fa = [1] + [0] * nn
for i in range(nn): fa[i+1] = fa[i] * (i+1) % P
f = lambda a, b: fa[a+b+2] * pow(fa[a+1] * fa[b+1], P-2, P) % P - 1
r1, c1, r2, c2 = map(int, input().split())
print((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)

Measured memory_bytes: 82136
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.LongSupplier;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static final long[] fal_rnd(long[] ar,LongSupplier sp){
		int l=-1,r=ar.length;
		while(l+1!=r)
			ar[Math.random()<0.5?++l:--r]=sp.getAsLong();
		return ar;
	}
	static final IntStream REPS(int v){
		return IntStream.range(0,v);
	};
	public static void main(String[] __){
		int n=s.nextInt(),m=s.nextInt();
		int[] r=new int[n];
		for(int i=0;i<m;i++) {
			
			int a=s.nextInt(),b=s.nextInt();
			if(a>b) {
				final int buf=a;
				a=b;
				b=buf;
			}
			r[a-1]++;
			if(b!=n)
				r[b-1]--;
		}
		Arrays.parallelPrefix(r,Integer::sum);
		
		System.out.println(
				Arrays.stream(r).parallel().anyMatch(i->i%2==1)?"NO":"YES");
	}
}


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


int main() {

	string a, b, c;
	int A=0, t = 0, C, z, I=1;


	cin >> a >> b;
	c = a + b;
	for (int i = c.size() - 1; i >= 0; i--) {
		z = c[i] - '0';
		C = z * I;
		A += C;
		I *= 10;
	}
	for (int i = 0; i < A; i++) {
		if (i*i == A) {
			t = 1;
		}
	}
	if (t == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}



Measured memory_bytes: 256
n, d = list(map(int, input().split(" ")))
d_2 = d**2
count = 0
for i in range(n):
    x, y = list(map(int, input().split(" ")))
    d_xy = x**2 + y **2
    if d_xy<=d_2:
        count+=1
print(count)


Measured memory_bytes: 9180
#include<iostream>                                                                                     
#include<algorithm>
using namespace std;
int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  cout << a[0] << " " << a[1] << " " << a[2] << endl;
  return 0;
}

Measured memory_bytes: 1184
n, m = gets.chomp.split.map(&:to_i)
arr = Array.new(n){[]}
while true
    worker, kind, count = gets.chomp.split.map(&:to_i)
    break if [worker, kind, count] == [0, 0, 0]
    arr[worker-1] << [kind-1, count]
end
l = gets.to_i
l.times{
    tanka = gets.chomp.split.map(&:to_i)
    temp = Array.new(n, 0)
    arr.each_with_index{|ar, i|
        ar.each{|k, c| temp[i] += tanka[k] * c}
    }
    puts temp.join(" ")
}


Measured memory_bytes: 14916
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 230300;const ll inf=1e16;
int n,x,y,z;ll res,a[N],b[N];
struct node{
	int a,b,c;
}s[N];
bool cmp(node x, node y){return x.c>y.c;}
int main() {
	read(x);read(y);read(z);n=x+y+z;
	rep(i,1,n)read(s[i].a),read(s[i].b),read(s[i].c),res+=s[i].c,s[i].a-=s[i].c,s[i].b-=s[i].c;
	rep(i,1,n)s[i].c=s[i].a-s[i].b;
	sort(s+1,s+n+1,cmp);
	priority_queue<int,vector<int>,greater<int> >heap;ll now=0;
	rep(i,1,n){
		now+=s[i].a;heap.push(s[i].a);
		if(SZ(heap)>x)now-=heap.top(),heap.pop();
		if(SZ(heap)==x)a[i]=now;else a[i]=-inf;
	}
	while(!heap.empty())heap.pop();now=0;
	per(i,n,1){
		now+=s[i].b;heap.push(s[i].b);
		if(SZ(heap)>y)now-=heap.top(),heap.pop();
		if(SZ(heap)==y)b[i]=now;else b[i]=-inf;
	}
	ll ans=0;rep(i,1,n-1)ans=max(ans,res+a[i]+b[i+1]);//WA
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6140
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define rep0(i,j) for(int (i)=0;(i)<(j);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(k);(i)--)
#define repdown0(i,j) for(int (i)=(j);i>=0;i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
const ll INFL = (1ll << 62) - 1;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

//_____________________________________Templates_________________________________________//

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

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k,x,y;
//vvll dp(400, vll(400));
vll dp(1 << 16, -1e18);
string s;
vvll v(16, vll(16));
vll cost(1 << 16);

ll g(ll x){
  if(x == 1){
    return 1;
  }
  return g(x/2ll)*2+1;
}

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

  ll h;
  IN(h);
  ll ans = g(h);
  OUT(ans);
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(void)
{
	int N, x, y, b, p, i, ans,anss;
	scanf("%d", &N);
	for (i = 0; i< N; i++)
	{
		scanf("%d %d %d %d", &x, &y, &b, &p);
		anss = x*b + y*p;
		if (b >= 5 && p >= 2)
		{
			ans = (x*b + y*p)*0.8;
			printf("%d\n", ans);
		}
		else
		{
			if (b < 5)
				b = 5;
			if (p < 2)
				p = 2;
			ans = (x*b + y*p)*0.8;
			if (anss > ans)
				printf("%d\n", ans);
			else
				printf("%d\n", anss);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int V, E;
const int MAX_V = 200009;
using DD = int;
#define INF 1e9+7
DD d[MAX_V];
struct edge {int to; DD cost; };
vector<edge> G[MAX_V];

int pprev[MAX_V];

void add_edge(int from, int to, DD dist) {
    G[from].push_back((edge){to, dist}); 
}
void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    fill(pprev, pprev + V, -1);
    d[s] = 0;
    que.push(P(0, s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first)continue;
        for (int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if (d[e.to] >  d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
                pprev[e.to] = v;
            }
        }
    }
}
vector<int> get_path(int t) {
    vector<int> path;
    for(; t != -1; t = pprev[t])path.push_back(t);
    reverse(ALL(path));
    return path;
}

int main() {
    cin >> V >> E;
    rep(i, E){
        int a, b;
        cin >> a >> b;
        add_edge(a - 1, b - 1, 1);
        add_edge(b - 1, a - 1, 1);
    }
    int s = 0;
    
    dijkstra(s); // O(M log N)
    
    rep(i, V){
        //cout << i << " " << d[i] << endl;
        if (d[i] == INF){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" << endl;
    reps(i, 1, V){
        cout << pprev[i] + 1 << endl;
    }
    
    return 0;
}

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

int main(){
    std::string S;
    std::cin >> S;
    if(S == "SUN") std::cout << 7 << std::endl;
    else if(S == "MON") std::cout << 6 << std::endl;
    else if(S == "TUE") std::cout << 5 << std::endl;
    else if(S == "WED") std::cout << 4 << std::endl;
    else if(S == "THU") std::cout << 3 << std::endl;
    else if(S == "FRI") std::cout << 2 << std::endl;
    else if(S == "SAT") std::cout << 1 << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=2e5+5;
long long a[N],n,m,k,vis[N],b[N],cnt,lop[N],ans[N],res[N];
int main(){
	scanf("%lld",&n);
	rep(i,1,n) scanf("%lld",&a[i]);
	per(i,n,1) a[i]=a[i]-a[i-1],b[i]=i;
	scanf("%lld%lld",&m,&k);
	rep(i,1,m){
		int R;
		scanf("%d",&R);
		swap(b[R],b[R+1]);
	}
	rep(i,1,n){
		if(vis[i]) continue;
		lop[cnt=1]=i;
		for(int pos=b[i];pos!=i;pos=b[pos]){
			vis[pos]=1;
			lop[++cnt]=pos;
		}
		rep(j,1,cnt) ans[lop[j]]=lop[(j+k-1)%cnt+1];
	}
	rep(i,1,n) res[i]=a[ans[i]];
	rep(i,1,n) printf("%lld.0\n",res[i]+=res[i-1]);
	return 0;
}


Measured memory_bytes: 9216
N, L = map(int, input().split())

Sum = N*(N-1)//2 + N*L

apple = 100000000000
for i in range(1, N+1):
    tmp = abs(L + (i - 1))
    if tmp < apple:
        eat = L + i - 1
        apple = tmp

print(Sum-eat)


Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys


def solve(N: int, X: int, L: "List[int]"):
    d = [0]*(N+1)
    for i in range(1,N+1):
        d[i] = d[i-1] + L[i-1]

    ans = 0
    for i in range(N+1):
        if(d[i] <= X):
            ans += 1

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    L = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int count = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        while (true) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 != 0) {
                    System.out.println(count);
                    System.exit(0);
                } else {
                    a[i] /= 2;
                }
            }
            count++;
        }
    }
}

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

using namespace std;

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

  int low = 0, high = S.size() + 1;

  auto check = [&](int v)
  {
    int left = (int) S.size() - v;
    int right = v;
    for(int i = left + 1; i < right; i++) {
      if(S[i - 1] != S[i]) return (false);
    }
    return (true);
  };

  while(high - low > 1) {
    int mid = (low + high) / 2;
    if(check(mid)) low = mid;
    else high = mid;
  }

  cout << low << endl;
}

Measured memory_bytes: 512
N, D = map(int, input().split())
 
# 前から最適に配置せよ
# 一人目は, 1,...,D, D+1, D+2,...,2D+1 を監視
# 二人目は, 2D+2,..., 3D+2, ...,4D+2 を監視
# x人まで繰り返すと、1,...,x(2D+1)まで監視できる
 
# x(2D+1) > N を満たす最小のxは？
# x_min = ceil(N/(2D+1))
 
# ceil(B/A) = floor((A+B-1)/A)
print((N+2*D) // (2*D+1))

Measured memory_bytes: 9140
N=int(input())
a=list(map(int,input().split()))
ans=b=a[0]
s=sum(a)
c=s/2
for i in range(1,N-1):
    b+=a[i]
    if abs(c-ans)>abs(c-b):ans=b
print(abs(s-2*ans))

Measured memory_bytes: 24832
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        xx = x - (500 * i + 100 * j)
        if xx >= 0 and xx % 50 == 0 and xx // 50 <= c:
            ans += 1
print(ans)

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

int main ()
{
    int N;
    std::cin >> N;
    
    if (N % 2 == 0)
    {
        cout << N << endl;;
    }
    else
    {
        cout << 2*N << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int const MOD = 1000000007;
int calc(int a, int b, int op) {
    if(op == 0) return a + b;
    if(op == 1) return a - b;
    if(op == 2) return a * b;
}

char op[3] = {'+', '-', '*'};
bool flag;
void solve(int a, int b, int c, int d) {
    rep(i,0,3) rep(j,0,3) rep(k,0,3) {
        if(calc(calc(a, b, i), calc(c, d, j), k) == 10) {
            printf("((%d %c %d) %c (%d %c %d))\n", a, op[i], b, op[k], c, op[j], d);
            flag = true;
            return;
        }
        if(calc(calc(calc(a, b, i), c, j), d, k) == 10) {
            printf("(((%d %c %d) %c %d) %c %d)\n", a, op[i], b, op[j], c, op[k], d);
            flag = true;
            return;
        }
        if(calc(calc(a, calc(b, c, i), j), d, k) == 10) {
            printf("((%d %c (%d %c %d)) %c %d)\n", a, op[j], b, op[i], c, op[k], d);
            flag = true;
            return;
        }
    }
}

int main() {
    int a,b,c,d;
    while(cin >> a >> b >> c >> d) {
        if(a == 0 && b == 0 && c == 0 && d == 0) break;
        vector<int> v(4);
        v[0] = a, v[1] = b, v[2] = c, v[3] = d;
        sort(v.begin(), v.end());
        flag = false;
        do {
            solve(v[0], v[1], v[2], v[3]);
        }while(next_permutation(v.begin(), v.end()) && !flag);
        if(!flag) cout << 0 << endl;
    }
    return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
//#define INF 1e9
constexpr ll INF = 1LL << 62;
constexpr int mod = 1e9+7;
ll ans = 1;
void solveA(ll N){
  if(N > 2){
    ans++;
  }
  N--;
  for(ll x = 2; x*x <= N; x++){
    if(N % x ==0){
      ans++;
      if((ll)x*x != N){
        ans++;
      }
    }
  }
}
void solveB(ll N){
  for(ll x = 2; x*x <= N; x++){
    if(N % x != 0) continue;
    ll  n = N;
    while(n%x==0){
      n/=x;
    }
    if(n %x == 1){
      ans++;
    }
    n = N;
    ll a = N / x;
    while(n % a){
      n /= a;
    }
    if(n % a == 1){
      ans++;
    }
  }
}
void solve(ll N){
  solveA(N);
  solveB(N);
}
int main(){
  ll N;
  cin >> N;
  solve(N); 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int n=sc.nextInt();
		
		int[] a=new int[n];
				int sum=0;

		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		
		if(sum<h)System.out.println("No");
		else System.out.println("Yes");
	}
}


Measured memory_bytes: 49916
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define in int
signed main()
{
  int n;
  int k;
  cin>>n>>k;
  vector<int> v;
  for(int i=0;i<n;i++)
  {int a;
  cin>>a;
    v.push_back(a);
  }
  vector<int> b(n,1e9);
  b[n-1]=0;
  //cout<<b[1];
  for(int i=n-2;i>=0;i--)
  {
    for(int j=1;j<=k;j++)
    {
    if(i+j<n)
    {
      b[i]=min(b[i],abs(v[i+j]-v[i])+b[i+j]);
    }
    //cout<<v[i]<<" "<<v[i+j]<<endl;
    }
  
  }
    cout<<b[0];
    //return 0;
  }
  


Measured memory_bytes: 1908
#include <stdio.h>
 
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int ans1=a+a-1;
  int ans2=b+b-1;
  int ans3=a+b;
  int x[3]={ans1,ans2,ans3};
  int i,max=0;
  for(i=0;i<3;++i)
  {
    if(max<x[i])
        max=x[i];
  }
  
  printf("%d",max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll a,b;cin>>a>>b;
    if(b>a){
        cout<<min(a,b-a)<<"\n";
    }else{
        ll u = (a/b+1)*b-a;
        ll l = a-(a/b)*b;
        cout<<min(u,l)<<"\n";
    }
    
    return;
}

int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    vector<int> x(5);
    int ans=0;
    rep(i, 0, 5) {
        cin >> x[i];
        if(x[i]==0) ans=i+1;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3596
n=int(input())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]
for i in range(2,n):
  cost.append(min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1])))
print(cost[n-1])


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

int	main()
{
	int	A[20] = {};
	bitset<40001>	feasible(1);
	int	n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> A[i];
	int	q;
	cin >> q;
	int	m;
	for (int i = 0; i < n; ++i) 
		feasible |= (feasible << A[i]);
	for (int i = 0; i < q; ++i) {
		cin >> m;
		if (feasible[m])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}



Measured memory_bytes: 3120
import math
N,M = map(int,input().split())
if(abs(N - M) >= 2):
  print("0")
else:
  if(N != M):
    print(str(((math.factorial(N) * math.factorial(M)) % (10 ** 9 + 7))))
  else:
    print(str(((math.factorial(N) * math.factorial(M))* 2 % (10 ** 9 + 7))))

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string ss;
    cin >> ss;
    deque<char> s;
    for (auto el : ss)
    {
        s.push_back(el);
    }
    int q;
    cin >> q;
    int fl = 1;
    for (int _ = 0; _ < q; ++_)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            fl ^= 1;
        }
        else
        {
            int f;
            char c;
            cin >> f >> c;
            --f;
            if (f ^ fl)
            {
                s.push_front(c);
            }
            else
            {
                s.push_back(c);
            }
        }
    }
    if (!fl)
    {
        reverse(s.begin(), s.end());
    }
    for (auto el : s)
    {
        cout << el;
    }
    cout << endl;
    return 0;
}


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

int main(){
  int n,m; cin >>n >>m;
  int a[50], b[50], c[50], d[50];
  rep(i,n) cin >>a[i] >>b[i];
  rep(i,m) cin >>c[i] >>d[i];
  rep(i,n){
    int min_dist = abs(a[i]-c[0])+abs(b[i]-d[0]), checkpoint = 1;
    for(int j = 1; j<m; j++){
      const int cur_dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(min_dist>cur_dist){
        min_dist=cur_dist;
        checkpoint=j+1;
      }
    }
    cout << checkpoint << endl;
  }
  return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


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

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n;
    cin >> n;
    Int x = 0, y = 0, t = 0;
    REP(n,i){
        Int pt, px, py;
        cin >> pt >> px >> py;
        if (abs(pt - t) >= abs(px-x) + abs(py-y) && ((pt  - t)- (abs(px-x) + abs(py-y)) )% 2 == 0) {
        }else{
            cout << "No" << endl;
            return 0;
        }
        t = pt;
        x = px;
        y = py;
    }
    cout << "Yes" << endl;
    return 0;
}




Measured memory_bytes: 256