akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
import time


_, = map(int,readline().split())
D = 365
*c, = map(int,readline().split())
s = tuple(tuple(map(int,readline().split())) for _ in range(D))

def output(ans):
    for i in ans: print(i+1)

def score(ans,s,c): # ans: 0-indexed としたときのスコアの計算
    last = [-1]*26
    score = 0
    for i, ai in enumerate(ans):
        score += s[i][ai]
        last[ai] = i
        for ci,li in zip(c,last):
            score -= ci*(i-li)
        #print(score) # i日目のスコア
    return score


#ans = [max(range(26),key=lambda x: si[x]) for si in s]
#ans = (list(range(26))*20)[:365]

def first_solution(s,c):
    minus = c[:]
    ans = [0]*365
    for i, si in enumerate(s):
        ans[i] = idx = max(range(26), key=lambda x:si[x]+minus[x])
        for i in range(26):
            minus[i] += c[i]
        minus[idx] = 0
    return ans        


"""
solution = 初期解(ランダム生成や、貪欲法など他の手法で求めたものを利用)
while 時間のある限り:
    solution を(ランダムに)少し変形
    if 変形前より解が悪化:
        solution を変形前の状態に戻す
"""


from bisect import bisect_left, bisect_right
"""
i 日目と i+1 日目を入れ替え
"""
def swap(i,ans,days,c,s):
    j = i+1
    ai = ans[i]
    aj = ans[j]
    di = days[ai]
    dj = days[aj]
    idx_i = bisect_left(di,-i)
    idx_j = bisect_left(dj,-j)
    
    #print(di,i,idx_i,ai)
    #print(dj,j,idx_j,aj)
    #assert di[idx_i] == -i and dj[idx_j] == -j 
    
    i_prev = -di[idx_i - 1]
    i_next = -di[idx_i + 1] if di[-1] != -i else -1

    j_prev = -dj[idx_j - 1]
    j_next = -dj[idx_j + 1] if dj[-1] != -j else -1

    delta_i = -c[ai]*(2*i-i_prev-i_next) + s[j][ai] - s[i][ai]
    delta_j = -c[aj]*(j_prev+j_next-2*i) - s[j][aj] + s[i][aj]
    #delta = delta_i + delta_j

    return delta_i + delta_j,idx_i,idx_j


def main(ans,s,c):
    from random import randrange,random
    from math import exp
    best = ans[:]
    start = time.time()
    days = [[-365] for _ in range(26)]
    for i in range(364,-1,-1):
        days[ans[i]].append(-i)

    while time.time() - start < 1.8:
        T = 200000*(max(2.0 - (time.time() - start),0.1))
        i = randrange(364)
        if ans[i] != ans[i+1]:
            delta,idx_i,idx_j = swap(i,ans,days,c,s)
            if delta > 0 or exp(-delta/T) >= random():
                days[ans[i]][idx_i] -= 1
                days[ans[i+1]][idx_j] += 1
                ans[i],ans[i+1] = ans[i+1],ans[i]
                if score(ans,s,c) > score(best,s,c):
                    best = ans[:]

        idx = randrange(26)
        a0 = ans[0]
        if a0 != idx:
            delta = s[0][idx] - s[0][a0] + c[a0]*(days[a0][-2]) - c[idx]*(days[idx][-1]+1)
            
            if delta > 0 or exp(-delta/T) >= random():
                ans[0] = idx
                days[idx].append(0)
                days[a0].pop()
                
                if score(ans,s,c) > score(best,s,c):
                    best = ans[:]
        
                

    return ans

#print(score(ans,s,c))
output(main(first_solution(s,c),s,c))







Measured memory_bytes: 85460
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

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

int main(){
  ll N;
  ll T[1111111];
  ll i;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> T[i];
  if(N>1){
    ll ans = lcm(T[0],T[1]);
    for(i=1;i<=N-1;i++)
    ans = lcm(ans,T[i]);
    cout << ans << endl;
    }
  else cout << T[0] << endl;
}

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

using namespace std;

typedef long long ll;


int main(int argc, char const *argv[])
{
	int N;
	cin >> N ;
	std::vector<int> T(N+1);
	ll sum = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> T[i];
		sum += T[i];
	}
	int M;
	cin >> M;
	std::vector<int> P(M+1) ;
	std::vector<int> X(M+1) ;

	for (int i = 1; i <= M; i++)
	{
		cin >> P[i] >> X[i];
	}

//	cout << sum << ":" << endl;

	for (int i = 1; i <= M; i++)
	{	
		cout << sum -T[P[i]]  + X[i] << endl;
	}

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

int N, K;
vi H;

int main() {
    cin >> N >> K;
    H = vi(N);
    REP (i, N) cin >> H[i];
    sort(ALL(H));
    ll ans = 0;
    REP (i, N-K) ans += H[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
s_num=int(input())
s=[]
for i in range(s_num):
	s.append(input())  

t=[]
t_num=int(input())
for i in range(t_num):
	t.append(input()) 

max=0

for i in range(s_num):
    if max < int(s.count(s[i]) - t.count(s[i])):
        max = int(s.count(s[i]) - t.count(s[i]))
        #print('int(s.count(s[i]) - t.count(s[i]))=',int(s.count(s[i]) - t.count(s[i])))
print(max)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		 Scanner sc = new Scanner(System.in);
	        String s = sc.next();

	        int length = s.length();
	        String[] a = new String[length];

	        for(int b=0; b<length; b++){
	        	a[b] = s.substring(b,b+1);

	        	if((b+1)%2 != 0){
	        		System.out.print(a[b]);
	        	}

	        }


	}

}


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

int n,m,q;
int one[2010][2010];
int l[2010][2010];
int u[2010][2010];
char grid[2010][2010];

int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",grid[i]+1);
		for(int j=1;j<=m;j++)
		{
			one[i][j]=one[i-1][j]+one[i][j-1]-one[i-1][j-1]+(grid[i][j]=='1');
			l[i][j]=l[i-1][j]+l[i][j-1]-l[i-1][j-1]+(grid[i][j]=='1'&&grid[i][j-1]=='1');
			u[i][j]=u[i-1][j]+u[i][j-1]-u[i-1][j-1]+(grid[i][j]=='1'&&grid[i-1][j]=='1');
		}
	}
	while(q--)
	{
		int x1,x2,y1,y2;
		cin>>x1>>y1>>x2>>y2;
		int dots=one[x2][y2]-one[x2][y1-1]-one[x1-1][y2]+one[x1-1][y1-1];
		dots-=l[x2][y2]-l[x2][y1]-l[x1-1][y2]+l[x1-1][y1];
		dots-=u[x2][y2]-u[x2][y1-1]-u[x1][y2]+u[x1][y1-1];
		cout<<dots<<endl;
	}
	return 0;
}

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
	FASTIO;
	ll s,x,i;
	string t;
	cin>>t;
	s=t.size();
	char arr[s];
	for(i=0;i<s;i++)
    {
        if(t[i]!='?')
            cout<<t[i];
        else
            cout<<"D";
           // arr[i]=t[i];
      //  if(t[i]=='?')
      //  {
          //  if(t[i-1]=='P')
           //     arr[i]='D';
           // else if(t[i+1]=='D')
       // }
    }



}


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

int main(){
  int N;
  int V[50],C[50],sub[50];
  
  cin >> N;
  rep(i,N){
    cin >> V[i];
  }
  rep(i,N){
    cin >> C[i];
  }
  rep(i,N){
    sub[i] = V[i]-C[i];
  }
  
  int total = 0;
  for(int i=0; i<(1<<N); i++){
    int tmp_total = 0;
    rep(j,N){
      if(i & (1<<j)){
        tmp_total += sub[j];
      }
    }
    total = max(total,tmp_total);
  }
  
  cout << total << endl;
  
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		int k=scanner.nextInt();
		List<Integer>p=new ArrayList<>();
		List<Integer>m=new ArrayList<>();
		p.add(0);
		m.add(0);
		for(int i=0;i<n;i++) {
			int x=scanner.nextInt();
			if(x>0) {
				p.add(x);
			}else {
				m.add(x*-1);
			}
		}
		Collections.sort(m);
		long min=Integer.MAX_VALUE;
		for(int i=0;i<=k;i++) {
			int j=k-i;
			if(i>m.size()-1||j>p.size()-1) {
				continue;
			}
			int tmp=0;
			if(i==0||j==0) {
				tmp=m.get(i)+p.get(j);
			}else {
				tmp=Math.min(m.get(i)*2+p.get(j),m.get(i)+p.get(j)*2);
			}
			min=Math.min(min, tmp);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 60996
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = list(map(int,input().split()))

# nCr : nが大きく、rがnの半分くらいの時が最大
maxA = max(A)
half = maxA/2

t = 10**10
for i in range(N):
    # 最大の要素ではない and 真ん中からの絶対値が小さい → 値を更新
    if A[i] != maxA and abs(A[i]-half) < abs(t-half):
        t = A[i]

print(maxA,t)

Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD (int)(1e9+7)
#define INF 0x3f3f3f3f
#define MAXN (int)(1e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
int main()
{
	fastio;
	int n;cin>>n;
	vector<vi> match(n,vi(n));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			cin>>match[i][j];
	}
	//dp[i][mask] represent number of ways to match subset women(mask) with upto 0 to i men
	//for i+1 iterate over masks then jth women 
	//if jth women can pair with ith men
	//dp[i+1][mask^(1<<j)]+=dp[i][mask]
	//else dp[i+1][mask]+=dp[i][mask]//dont pair ith men(note if we iterate mask big to small then this will be first update of dp[i+1][mask])
	vector<int> dp(1<<n);
	dp[0]=1;
	for(int i=0;i<n;i++)//ith men
	{
		vector<int> newdp(1<<n,0);
		for(int mask=0,lim=(1<<n);mask<lim;mask++)
		{
			if (dp[mask]==0)continue;
			for(int j=0;j<n;j++)
			{
				if(match[i][j] && !(mask&(1<<j)))
				{
					newdp[mask^(1<<j)]=addmod(newdp[mask^(1<<j)],dp[mask]);
				}
			}
		}
		dp=newdp;
	}  
	cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 19672
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main(){
  ll n,d;
  cin>>n;
  if(n%500==0)
    d = 2*n;
  else if(n%5==0)
    d = (n/500)*1000+n%500;
  else 
    d =(n/500)*1000+((n%500)/5)*5;
  cout<<d<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{int N,A,M,B,x,i,k,l,m,flag,sum;
	scanf("%d",&N);
	flag=0;
	char s[100][1];
    for(i=0;i<=N-1;i++){
    	scanf("%s",s[i]);}
    for(i=0;i<=N-1;i++){
    	if(s[i][1]=='Y'){
    		flag=1;
    		break;}}
    if(flag==0){
    	printf("Three");}
    	else if(flag==1){
    		printf("Four");}
    	
		



	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];
vector<vector<ll>>road(101010);
vector<bool>flag(101010);
vector<bool>flag2(101010);
vector<ll>ans(101010, -1);
queue<ll>q;
vector<ll>dist(101010, INF);
vector<ll>pre(101010, -1);

void bfs(ll x) {
	q.push(x);
	while (!q.empty()) {
		ll y = q.front();
		q.pop();
		for (auto nx : road[y]) {
			if (dist[nx] != INF)continue;
			dist[nx] = dist[y] + 1;
			pre[nx] = y;
			q.push(nx);
		}
	}
}

//long longしか使わない
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll>a(m), b(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		road[a[i]].push_back(b[i]);
		road[b[i]].push_back(a[i]);
	}
	bool flag3 = true;
	bfs(0);
	for (ll i = 1;i < n;++i) {
		if (pre[i] == -1) {
			flag3 = false;
		}
	}
	if (flag3) {
		puts("Yes");
		for (ll i = 1;i < n;++i) {
			cout << pre[i] + 1 << endl;
		}
	}
	else {
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 17628
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	int a, b, n;
	while (scanf("%d %d %d\n", &a, &b, &n) != EOF)
	{
		int s = 0;
		a %= b;
		for (int i = 0; i < n; ++i)
		{
			a *= 10;
			if (a >= b)
			{
				s += a/b;
				a %= b;
			}
		}
		printf("%d\n", s);
	}

	return 0;
}

Measured memory_bytes: 0
def kuraiwa(M):
    S=str(M)
    ans=0
    for i in S:
        ans+=int(i)
    return ans
N=int(input())
res=N
for i in range(1,N):
    A=i
    B=N-i
    tmp=kuraiwa(A)+kuraiwa(B)
    if tmp<res:
        res=tmp
print(res)


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n;
	cin >> n;

	string s = to_string(n);

	bool b = true;

	ll res = 0;

	for (ll i = 1; i < s.length(); i++)
	{
		if (s[i] != '9')
		{
			b = false;
		}
	}
	for (ll i = 0; i < s.length() - 1; i++)
	{
		res += 9;
	}

	if (b)
	{
		res += stoll(s.substr(0, 1));
	}
	else if (n >= 10)
	{
		res += stoll(s.substr(0, 1)) - 1;
	}
	else
	{
		res = n;
	}

	println(res);
}


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n],x=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i>1)x^=a[i];
    }
    int sum=a[0]+a[1];
    if((sum-x)%2){
        cout << -1;
        return 0;
    }
    int y=(sum-x)/2;
    if(y<0 or y>a[0] or (y&x)){
        cout << -1;
        return 0;
    }
    int ans=y;
    for(int i=60;i>=0;i--){
        if(x&(1ll<<i)){
            if(ans+(1ll<<i)<=a[0])ans+=(1ll<<i);
        }
    }
    if(ans==0)cout << -1;
    else cout << a[0]-ans;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int b1 = 0, b2;
  long long ans = 0;
  for(int& i : a) cin >> i;
  for(int i = 0; i < n; ++i) {
    cin >> b2;
    if (b1 >= a.at(i)) {
      ans += a.at(i);
      b1 = b2;
    } else {
      if (b1 + b2 >= a.at(i)) {
        ans += a.at(i);
        b1 = b1 + b2 - a.at(i);
      } else {
        ans += b1 + b2;
        b1 = 0;
      }
    }
  }
  
  if (b1 >= a.at(n)) {
    ans += a.at(n);
  } else {
    ans += b1;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *

H, W = MAP()
A = [input() for _ in range(H)]
cnt = [[-1]*W for _ in range(H)]
q = deque()

for y in range(H):
    for x in range(W):
        if A[y][x] == "#":
            cnt[y][x] = 0
            q.append((y, x))

dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]

while q:
    y, x = q.popleft()
    for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == -1:
            cnt[ny][nx] = cnt[y][x] + 1
            q.append((ny, nx))

ans = 0
for i in range(H):
    ans = max(ans, max(cnt[i]))
print(ans)


Measured memory_bytes: 114676
from fractions import gcd
from math import sqrt


def prime_factorize(n):
    result = []
    for i in range(2, int(sqrt(n)) + 1):
        if n % i != 0:
            continue
        t = 0
        while n % i == 0:
            n //= i
            t += 1
        result.append((i, t))
        if n == 1:
            break
    if n != 1:
        result.append((n, 1))
    return result


A, B = map(int, input().split())
print(len(prime_factorize(gcd(A, B))) + 1)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  string s;
  cin>>s;
  int64_t K;
  cin>>K;
  K--;
  int st=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!='1'){st=i;break;}
  }
  if(st<=K){cout<<s[st]<<endl;}
  else{cout<<1<<endl;}
  return 0;  
}

Measured memory_bytes: 3624
*> AtCoder My Practice
           *> author: Leonardone @ NEETSDKASU
           *>
           IDENTIFICATION DIVISION.
           PROGRAM-ID. Answer.
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           REPOSITORY.
                  FUNCTION ALL INTRINSIC.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
                  01 Input-Values.
                         05 a      BINARY-SHORT.
                         05 b      BINARY-SHORT.
                         05 s      PIC X(100).
                  01 Calc-Values.
                         05 disp   PIC X(5).
           PROCEDURE DIVISION.
           AnswerMain SECTION.
           000-Start.
           
                  ACCEPT s.
                  UNSTRING s DELIMITED BY SPACE INTO a b
                  
                  MOVE MOD(a,2) TO a.
                  MOVE MOD(b,2) TO b.
                  
                  MOVE "Odd" TO disp.
                  IF a = 0 OR b = 0 THEN
                         MOVE "Even" TO disp
                  END-IF.
     
                  DISPLAY TRIM(disp).
           END PROGRAM Answer.

Measured memory_bytes: 636
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

set<int> g[100005];
int q[100005];
int n;

int main(){
	scanf("%d",&n);
	fore(_,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].insert(y);g[y].insert(x);
	}
	fore(x,0,n)if(SZ(g[x])==1){
		while(1){
			assert(SZ(g[x])==1);
			int y=*g[x].begin();
			if(SZ(g[y])==2){
				assert(!q[y]);
				g[x].erase(y);
				g[y].erase(x);
				g[x].insert(*g[y].begin());
				g[*g[y].begin()].erase(y);
				g[*g[y].begin()].insert(x);
				g[y].clear();
			}
			else {
				q[y]++;
				break;
			}
		}
	}
	int r=0;
	fore(i,0,n)r+=max(q[i]-1,0);
	r=max(r,1);
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 14720
program AGC014C
    implicit none
    integer(8)::A,B,C,A1,B1,C1,ans=0
    read*,A,B,C
    if(A==B.and.B==C)then
        if(mod(A,2)==0)then
            print'(i0)',-1
        else
            print'(i0)',0
        end if
    else
        do
            if(mod(A,2)==1.or.mod(B,2)==1.or.mod(C,2)==1)exit
            A1=(B+C)/2
            B1=(A+C)/2
            C1=(A+B)/2
            A=A1
            B=B1
            C=C1
            ans=ans+1
        end do
        print'(i0)',ans
    end if
end program AGC014C

Measured memory_bytes: 512
package main

import "fmt"
import "bufio"
import "os"
import "strconv"

//   1 2 3 4 5 6 7 8 9
// 2 . 2 . 2 . 2 . 2 .
// 3 . . 3 . . 3 . . 3
var _sw = bufio.NewScanner(os.Stdin)

func main() {
	lower := NextInt()
	upper := NextInt()
	n := NextInt()
	m := NextInt()

	lower--

	ans := ((upper / n) - (lower / n)) + ((upper / m) - (lower / m)) - ((upper / LCM(n, m)) - (lower / LCM(n, m)))
	fmt.Println(upper - lower - ans)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func LCM(a, b int, integers ...int) int {
	result := a * b / GCD(a, b)

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, A[200100];
int B[200100], C[200100];

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> A[i];
    }

    for(int i=1;i<=N;++i){
        B[i] = std::max(A[i], B[i-1]);
    }

    for(int i=N;i>=1;--i){
        C[i] = std::max(A[i], C[i+1]);
    }

    for(int i=1;i<=N;++i){
        int res = std::max(B[i-1], C[i+1]);
        std::cout << res << std::endl;
    }
}


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

int main() {
string op;
int a,b;

 while(true){
   cin >> a >> op >> b;
   if(op=="?") break;

  int ans;
 if(op == "+") ans = a+b;
 if(op == "-") ans = a-b;
 if(op == "*") ans = a*b;
 if(op == "/") ans = a/b;
  cout<< ans <<endl;
  }
  return 0;

  
}


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

int main() {
	int N; cin >> N;
	map<char, long> mp;
	for(int i=0; i<26; ++i) mp['A'+i]=0;
	string S;
	for(int i=0; i<N; ++i){
	    cin >> S;
	    ++mp[S[0]];
	}
	long ans=0, plus;
	map<int, string> se;
	se[0]="MAR"; se[1]="MAC"; se[2]="MAH"; se[3]="MRC"; se[4]="MRH";
	se[5]="MCH"; se[6]="ARC"; se[7]="ARH"; se[8]="ACH"; se[9]="RCH";
	for(int i=0; i<10; ++i){
	    plus=mp[se[i][0]]*mp[se[i][1]]*mp[se[i][2]];
	    ans += plus;
	}
	cout << ans << endl;
	return 0;
}


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

int sumDigits(int num) { return num / 10000 + num % 10000 / 1000 + num % 1000 / 100 + num % 100 / 10 + num % 10; }
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int sum = sumDigits(i);
        if (A <= sum && sum <= B) {
            ans += i;
        }
    }

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

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

int main()
{
  int a,b;
  cin >> a >> b;
  if(a*b % 2 == 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;
using std::pair;
using std::make_pair;

using std::min;
using std::max;
using std::sort;
using std::abs;

using std::fixed;
using std::setprecision;
using std::setw;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 314;

int main() {
    int m;
    cin >> m;
    cout << (24 + (24 - m)) << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

ll n;
ll A[20][20];

ll calc(ll H) {
    ll tts = 0;
    rep(i,0,n) {
        rep(j,0,n) {
            if(H & (1<<i) && H & (1<<j)) {
                tts += A[i][j];
            }
        }
    }
    return tts;
}

void wr(ll a) {
    rep(i,0,n) {
        if(a & (1<<i)) cout << 1;
        else cout << 0;
    }
    cout << endl;
}

ll memo[1<<17];
ll dp(ll have) {
    if(memo[have] != -1) return memo[have];
    ll val = calc(have);
    ll mask = have;
    for(ll submask = mask; ; submask = (submask - 1) & mask) {
        if(submask == 0) break;
        if(submask != mask) {
            val = max(val, dp(submask) + dp(have ^ submask));
        }
    }
    return memo[have] = val;
}

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    rep(i,0,n) {
        rep(j,0,n) cin >> A[i][j];
    }
    memset(memo,-1,sizeof(memo));
    cout << dp((1<<n)-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
        int n;
        cin >> n;
        int a[n];int b[n];
        for(int i=0;i<n;i++){
          cin >> a[i];
          b[i]=a[i];
        }
        sort(b,b+n);
        int p=b[n/2];
        int q=b[(n/2)-1];
        for(int i=0;i<n;i++){
          if(a[i]<p) cout << p<<endl;
          else cout <<q<<endl;
        }
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const int vx[4]={0,1,0,-1},vy[4]={1,0,-1,0};
using namespace std;

int main(){
  ll N,ans=0,cnt=0,bonus=0;
  cin>>N;
  
  ll A[N+2];
  A[0]=0;
  A[N+1]=0;
  for(int i=1; i<=N; ++i) cin>>A[i];
  
  for(int i=1; i<=N; ++i){
    bonus=(cnt+A[i])/2;
    ans+=bonus;
    cnt=cnt+A[i]-2*bonus;
    if(A[i]==0) cnt=0;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  if(k>n)
    k=n-1;
  int arr[n+1];
  for(int i=1;i<=n;i++)
    cin>>arr[i];
  int dp[n+1];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(arr[2]-arr[1]);
  for(int i=3;i<=n;i++)
  {
    int temp=1;
    int minimum=INT_MAX;
    while(i-temp>=1 && temp<=k)
    {
      minimum=min(minimum,dp[i-temp]+abs(arr[i]-arr[i-temp]));
      temp++;       
    }
    dp[i]=minimum;
  }
  cout<<dp[n]<<endl;
  return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;

    for(char c:s){
        char target = c+n;
        if(target > 'Z'){
            target-='Z'-'A'+1;
            
        }
        cout << target;
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int n, m, s, g;
int dv[] = {-1,0,1};

struct S{
    int cur, prev, vel;
    double dist;
    S(int cur, int prev, int vel, double dist):cur(cur),prev(prev),vel(vel),dist(dist){}
    bool operator>(const S &p) const{
        return dist > p.dist;
    }
};

int main() {
    while(cin >> n >> m, n || m){
        cin >> s >> g;
        s--; g--;
        vector<vector<pii> > path(n,vector<pii> (n,mp(INF,INF)));
        rep(i,m){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--; y--;
            path[x][y] = mp(d,c);
            path[y][x] = mp(d,c);
        }

        double d[32][32][32];
        rep(i,32)rep(j,32)rep(k,32) d[i][j][k] = INF;
//        d[s][s][0] = 0;
        priority_queue<S, vector<S>, greater<S> > que;
        que.push(S(s,s,0,0));
        double ans = -1;
        while(!que.empty()){
            S tmp = que.top(); que.pop();
            int cur = tmp.cur, prev = tmp.prev, vel = tmp.vel;
            double dist = tmp.dist;
            if(dist >= d[cur][prev][vel]) continue;
            d[cur][prev][vel] = dist;
            if(vel == 1 && cur == g) {
                ans = dist;
                break;
            }
            rep(i,n)rep(j,3){
                if(i == prev || path[cur][i].first == INF) continue;
                if(vel + dv[j] > 0 && vel + dv[j] <= path[cur][i].second){
                    que.push(S(i,cur,vel+dv[j],dist + 1.0 * path[cur][i].first / (vel+dv[j])));
                }
            }
        }
        if(ans>=0) printf("%.8f\n",ans);
        else cout << "unreachable\n";
    }
    return 0;
}

Measured memory_bytes: 21544
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k, p, p2[200000] = {};
lldo ans = 0;

int main() {
	cout << setprecision(10);
	cin >> n >> k;
	rep(i, n) {
		cin >> p;
		if (i == 0) {
			p2[0] = p + 1;
		}
		else {
			p2[i] = p2[i - 1] + p + 1;
		}
	}
	rep(i, n - k + 1)ans = max((lldo)ans, (p2[i + k - 1] - p2[i - 1]) * 0.5);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main(void)
{
	//変数の宣言
	
	//int n,k;
	
	int N;
	
	//データの読み込み
	//scanf("%d %d",&n,&k)
	
	scanf("%d",&N);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	if(N%2==0){
		printf("%d",N);
	}else{
		printf("%d",N*2);
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl v(MAX_N);
    rep(i, n) {
        ll a;
        cin >> a;
        v[a]++;
    }
    
    ll m = 0;
    rep(i, MAX_N) {
        if(v[i] > 0) {
            m++;
        }
    }

    if(m <= k) {
        out(0);
    }
    else {
        sort(all(v));
        ll ans = 0;
        ll cnt = 0;
        rep(i, MAX_N) {
            if(v[i] == 0) {
                continue;
            }
            ans += v[i];
            cnt++;
            if(cnt == m -k) {
                break;
            }
        }
        out(ans);
    }
    
    re0;
}

Measured memory_bytes: 1792
n=int(input())
d=list(map(int,input().split()))
l=[0]*(max(d)+1)
for i in range(n):
    l[d[i]]+=1
for i in range(1,n):
    if d[i]==0:
        print(0)
        break
else:
    if l[0]!=1:
        print(0)
    else:
        ans=1
        for i in range(len(l)-1):
            ans*=((l[i]**(l[i+1]))%998244353)
        print(ans%998244353)

Measured memory_bytes: 54452
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = ip()                              #入力整数1つ
#x,y= (int(i) for i in input().split())      #入力整数横2つ
x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#x = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意


print(x*y//2)

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


template <int mod>
struct ModInt {
  int val;
  int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  ModInt(int v = 0) : val(trim(v % mod)) {}
  ModInt(long long v) : val(trim(v % mod)) {}
  ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  ModInt operator*(const ModInt &oth) const { return 1LL * val * oth.val % mod; }
  ModInt operator/(const ModInt &oth) const {
    function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
      if (b == 0) return trim(x);
      return modinv(b, a - a / b * b, y, x - a / b * y);
    };
    return *this * modinv(oth.val, mod, 1, 0);
  }
  bool operator==(const ModInt &oth) const { return val == oth.val; }
  ModInt operator-() const { return trim(mod - val); }
  template<typename T> ModInt pow(T pw) {
    bool sgn = false;
    if (pw < 0) pw = -pw, sgn = true;
    ModInt ans = 1;
    for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
      if (pw&1) ans = ans * cur;
    }
    return sgn ? ModInt{1} / ans : ans;
  }
};

using mint = ModInt<1000000007>;

mint go(long long L, long long R) {
  mint cur[2][2][2], pre[2][2][2];
  cur[1][1][1] = 1;
  for (int i = 60; i >= 0; --i) {
    swap(cur, pre);
    for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) 
      for (int k = 0; k < 2; ++k) {
        cur[i][j][k] = 0;
      }
    int lb = (L>>i)&1, rb = (R>>i)&1;
    for (int ld : {0, 1}) {
      for (int xt : {0, 1}) {
        for (int yt : {0, 1}) {
          for (int yn : {0, 1}) {
            for (int xn : {0, 1}) {
              if (yn == 0 and xn == 1) continue;
              if (ld and (!xn xor !yn)) continue;
              if (xt and lb and !xn) continue;
              if (yt and !rb and yn) continue;
              cur[ld and !yn and !xn][xt and lb == xn][yt and rb == yn] = 
              cur[ld and !yn and !xn][xt and lb == xn][yt and rb == yn] + 
              pre[ld][xt][yt];
            }
          }
        }
      }
    }
  }
  mint ans = 0;
  for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) {
    ans = ans + cur[0][i][j];
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  long long L, R; cin >> L >> R;
  cout << go(L, R).val << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

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

    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    rep(i, n) {
        cin >> v[i];
    }
    int ans = 0, sum = 0;
    for(int i = 1; i <= n + 1; i++) {
        if(sum <= x)
            ans++;
        sum += v[i - 1];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3648
import sys
from collections import defaultdict


time = 1


def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1])


if __name__ == "__main__":
    main()



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

using namespace std;

int m,n,ans=0,temp=0;

int main()

{

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

    for(int i=1;i<=m;i++)

    {

        scanf("%d",&temp);

        ans+=temp;

    }

    printf("%d",(ans<=n)?(n-ans):-1);

    return 0;

}

Measured memory_bytes: 3764
from collections import deque
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
while 1:
    w, h = map(int, raw_input().split())
    if w == h == 0:
        break
    P = [list(raw_input()) for i in xrange(h)]
    L = [[None]*w for i in xrange(h)]

    deq = deque()
    cnt = 0
    g = []; XL = []; XR = []; M = []; C = []
    for i in xrange(h):
        for j in xrange(w):
            if P[i][j] is '.':
                continue
            if L[i][j] is None:
                p = P[i][j]
                deq.append((j, i))
                L[i][j] = cnt
                if i == h-1 or p != P[i+1][j] != '.':
                    xl = xr = j
                else:
                    xl = w; xr = -1;
                s = 2 + j
                while deq:
                    x, y = deq.popleft()
                    for dx, dy in dd:
                        nx = x + dx; ny = y + dy
                        if 0 <= nx < w and 0 <= ny < h and p == P[ny][nx] and L[ny][nx] is None:
                            deq.append((nx, ny))
                            L[ny][nx] = cnt
                            s += nx
                            if ny == h-1 or p != P[ny+1][nx] != '.':
                                xl = min(xl, nx); xr = max(xr, nx)
                cnt += 1
                g.append(set()); M.append(s); C.append(4); XL.append(xl); XR.append(xr+1)
            if i:
                if L[i][j] != L[i-1][j] != None and L[i-1][j] not in g[L[i][j]]:
                    g[L[i][j]].add(L[i-1][j])
                    M[L[i][j]] += M[L[i-1][j]]
                    C[L[i][j]] += C[L[i-1][j]]
    for i in xrange(cnt):
        if not XL[i]*C[i] < M[i] < XR[i]*C[i]:
            print "UNSTABLE"
            break
    else:
        print "STABLE"

Measured memory_bytes: 6872
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
map<string,int> mp;
int c[5];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    mp["AC"]=0; mp["WA"]=1;
    mp["TLE"]=2; mp["RE"]=3;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string ss;
        cin>>ss;
        c[mp[ss]]++;
    }
    cout<<"AC x "<<c[0]<<'\n';
    cout<<"WA x "<<c[1]<<'\n';
    cout<<"TLE x "<<c[2]<<'\n';
    cout<<"RE x "<<c[3]<<'\n';
    return 0;
}


Measured memory_bytes: 3664
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~ Aashutosh Rathi~~~~~~
// ~~~~~~~~aashutoshrathi~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
// Use memcpy while copying matrix :D
// o_O Never do calculation in if block -_- 
// Use __builtin_popcount(z) to get set bit count of z
 
#include <bits/stdc++.h> 	// Apne aap me sab kuch hai isme 
#include <stdio.h>

using namespace std;	// Kyuki yahi mai-baap hai
 
#define mod(x) 			x%1000000007
#define MIN(n1, n2)     ((n1) > (n2) ? (n2) : (n1))
#define MAX(n1, n2)     ((n1) > (n2) ? (n1) : (n2))
#define MID(s, e)       (s+(e-s)/2)
#define fast fin; fout; fio;
#define fin cin.tie(NULL)
#define fout cout.tie(NULL)
#define fio ios::sync_with_stdio(false)
typedef pair <long, long> lpairs;
typedef long long ll;

int main() {
    fast
    ll t;
    cin >> t;
    string s;
    cin >> s;
    if(t<3200) {
        cout << "red" << endl;
    } else {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class RoundRobinScheduling
{
  static void Main(string[] args)
  {
    string[] pName;
    int[] pTime;
    
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int q = int.Parse(input[1]);

    pName = new string[n];
    pTime = new int[n];
    
    for( int i = 0; i < n; i++ )
      {
        input = Console.ReadLine().Split(' ');
        pName[i] = input[0];
        pTime[i] = int.Parse(input[1]);
      }

    RoundRobinScheduling rrs = new RoundRobinScheduling();

    rrs.solve(q, pName, pTime);
  }

  public void solve( int q, string[] name, int[] time )
  {
    Queue<string> nq = new Queue<string>();
    Queue<int> tq = new Queue<int>();

    int ft = 0;
    int ct;
    string cn;
    
    for(int i = 0; i < name.Length; i++)
      {
        nq.Enqueue(name[i]);
        tq.Enqueue(time[i]);
        
      }

    while(nq.Count > 0)
      {
        cn = nq.Dequeue();
        ct = tq.Dequeue();
        if(ct > q)
          {
            nq.Enqueue(cn);
            tq.Enqueue(ct-q);
            ft += q;
          }
        else
          {
            ft += ct;
            Console.WriteLine("{0} {1}", cn, ft);      
          }
      }
  }
}

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

using namespace std;
using nagai = long long;
#define sz(x) int((x).size())

const int H=1010;
bool matr[H][H];
int d[H][H];
int h,w;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>h>>w;
	vector<pair<int,int>>q;
	for(int i=0;i<h;++i)
		for(int j=0;j<w;++j)d[i][j]=-1;
	for(int i=0;i<h;++i){
		string s;
		cin>>s;
		for(int j=0;j<w;++j){
			matr[i][j]=s[j]=='#';
			if(matr[i][j])
				q.emplace_back(i,j),d[i][j]=0;
		}
	}
	vector<int>dx={1,0,-1,0},dy={0,1,0,-1};
	int mx=0;
	for(int i=0;i<q.size();++i){
		int x=q[i].first;
		int y=q[i].second;
		mx=max(mx,d[x][y]);
		for(int k=0;k<4;++k){
			int x1=x+dx[k];
			int y1=y+dy[k];
			if(x1>=0&&y1>=0&&x1<h&&y1<w&&d[x1][y1]==-1)
				d[x1][y1]=d[x][y]+1,q.emplace_back(x1,y1);
		}
	}
	cout<<mx<<'\n';
	return 0;
}



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

using namespace std;

const int X = (int)1e6 + 100;

bool used[X];
vector <int> top;

void dfs(int s, auto &lst) {
    if (used[s]) return;
    used[s] = true;
    for (auto to : lst[s]) {
        dfs(to, lst);
    }
    top.push_back(s);
}

int dp[X];

bool cmp(int a, int b) {
    return dp[a] > dp[b];
}

int main() {
    long long n;
    cin >> n;
    vector <int> pr(n);
    vector <vector<int>> lst(n);
    for (int i = 1; i < n; i++) {
        cin >> pr[i];
        lst[pr[i] - 1].push_back(i);
    }
    dfs(0, lst);
    for (int i = 0; i < n; i++) {
        int a = top[i];
        if (lst[a].empty()) {continue;}
        sort(lst[a].begin(), lst[a].end(), cmp);
        int p = 1;
        dp[a] = 0;
        for (auto to : lst[a]) {
            dp[a] = max(dp[a], dp[to] + p);
            p++;
        }
    }
    cout << dp[0];
    return 0;
}


Measured memory_bytes: 11764
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

const div = 2019

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	l, r := nextInt(), nextInt()

	if r-l >= 2019 {
		fmt.Println(0)
		return
	}

	re := int64(9999999999)
	for i := l; i <= r; i++ {
		for j := i; j <= r; j++ {
			if i == j {
				continue
			}
			v := i * j % div
			if re > v {
				re = v
			}
			if re == 0 {
				fmt.Println(re)
				return
			}
		}
	}

	fmt.Println(re)
}


Measured memory_bytes: 640