akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
T = {"mi":0, "pu":0, "zero":0}

for i in range(N):
    if A[i] < 0:
        T["mi"] += 1
    elif A[i] == 0:
        T["zero"] += 1
    else:
        T["pu"] += 1
mod = 10**9+7
for i in range(N):
    if A[i] < 0:
        B.append([A[i]*(-1), 1])
    else:
        B.append([A[i], 0])
A.sort()
B.sort(reverse=True)

ans = 1
c = 0
for i in range(K):
    ans *= B[i][0]
    ans %= mod
    c += B[i][1]

if c % 2 == 0:
    print(ans)
elif K > T["pu"]+T["mi"]:
    print(0)
elif T["mi"] == 1 and K > T["pu"]:
    ans = 1
    for i in range(N):
        ans *= A[i]
        ans %= mod
    if T["zero"] != 0:
        ans = 0
    print(ans)
elif T["pu"] == 1 and K > T["mi"]:
    ans = 1
    for i in range(N):
        ans *= A[i]
        ans %= mod
    if T["zero"] != 0:
        ans = 0
    print(ans)
elif T["pu"] == 0:
    ans = 1
    A.reverse()
    for i in range(K):
        ans *= A[i]
        ans %= mod
    if T["zero"] != 0:
        ans = 0
    print(ans)
elif N == K:
    ans = 1
    for i in range(N):
        ans *= A[i]
        ans %= mod
    print(ans)
else:
    change1 = B[K-1][1]
    change2 = (change1 + 1)%2
    chindex1 = K-1
    chindex2 = -1
    for i in range(K-1, -1, -1):
        if B[i][1] == change2:
            chindex2 = i
            break
    afterindex1 = -1
    afterindex2 = -1
    for i in range(K, N):
        if B[i][1] == change2:
            afterindex1 = i
            break
    for i in range(K, N):
        if B[i][1] == change1:
            afterindex2 = i
            break
    result1 = 0
    result2 = 0
    if chindex1 >= 0 and afterindex1 >= 0:
        ans = 1
        for i in range(N):
            if i <= K-1 or i == afterindex1:
                if i != chindex1:
                    ans *= B[i][0]
                    ans %= mod
        result1 = ans
    if chindex2 >= 0 and afterindex2 >= 0:
        ans = 1
        for i in range(N):
            if i <= K-1 or i == afterindex2:
                if i != chindex2:
                    ans *= B[i][0]
                    ans %= mod
        result2 = ans
    if result1 == 0 and result2 == 0:
        print(0)
    elif result1 == 0:
        print(result2)
    elif result2 == 0:
        print(result1)
    elif B[afterindex1][0]*B[chindex2][0] - B[afterindex2][0]*B[chindex1][0] > 0:
        print(result1)
    else:
        print(result2)

Measured memory_bytes: 118172
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int (i) = 0; i < (n); i++)
#define REP(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF LLONG_MAX - 10
#define MOD 1000000000
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

    int n;
    cin >> n;
    
    int x1 = 1e9, y1, x2 = 1, y2;
    int m = n % MOD;
    if(m == 0) {
        y1 = 0;
    } else {
        y1 = MOD - m;
    }
    y2 = (n + y1) / MOD;
    
    cout << 0 << " " << 0 << " " << x1 << " " << x2 << " " << y1 << " " << y2 << endl;
 	return 0;
}


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

const int N_MAX = 100;

int n, l;
string str[N_MAX + 2];

int main()
{
    cin >> n >> l;
    for(int i = 1; i <= n; i++)
        cin >> str[i];

    sort(str + 1, str + n + 1);

    for(int i = 1; i <= n; i++)
        cout << str[i];


    return 0;
}


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

#define ll long long
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ii pair < ll , ll >
#define all(x) std::begin(x), std::end(x)

ll const MAX = 100005 ;
ll const INF = 1e9 ;
ll const mod = 1000000007 ;


ll dp[MAX] ;
ll a[MAX] ;
ll n ;

ll cost ( int ndx )
{
    if ( ndx >= n - 1 )
        return 0 ;

    ll &ret = dp[ndx] ;
    if ( ret != -1 )
        return ret ;
    if ( ndx == n - 2 )
        return ret = abs ( a[ndx] - a[ndx+1] ) ;
    return ret = min ( abs ( a[ndx] - a[ndx+1] ) + cost ( ndx + 1 ) , abs ( a[ndx] - a[ndx+2] ) + cost ( ndx + 2 ) ) ;
}


int main ()
{
    //freopen ( "portals.in" , "r" , stdin ) ;
    FASTIO ;

    cin >> n ;
    memset ( dp , -1 , sizeof dp ) ;
    for ( int i = 0 ; i < n ; i ++ )
        cin >> a[i] ;

    cout << cost ( 0 ) ;


}


Measured memory_bytes: 3328
using System;

    class Program
    {
        static void Main(string[] args)
        {
            // get a int N
            int n = Convert.ToInt16(Console.ReadLine());
            string hat = Console.ReadLine();
            int redCount = 0;
            for(int i =0; i < n; i ++)
            {
                if (hat[i] == 'R')
                    redCount++;
            }
            if (redCount > (n - redCount))
                Console.Write("Yes");
            else
                Console.Write("No");
        }
    }

Measured memory_bytes: 11220
#include<stdio.h>
int main(void)
{
	double n,n2;
	int nn,ama,i;
	int data[12];
	
	while(1)	{
		scanf("%lf",&n);
		if(n<0.0)	{
			break;
		}
		n=n*16.0;
		nn=n;
		if((double)nn!=n)	{
			printf("NA\n");
		}
		else {
			for(i=11;i>=0;i--)	{
				data[i]=nn%2;
				nn=nn/2;
			}
			for(i=0;i<8;i++)	{
				printf("%d",data[i]);
			}
			printf(".");
			for(i=8;i<12;i++)	{
				printf("%d",data[i]);
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 648
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n; cin >> n;
    int sx=0,sy=0,st=0;
    int gx,gy,gt,dt,dis,ans=1;
    for(int i=0;i<n;i++){
        cin >> gt>>gx>>gy;
        dt=gt-st;
        dis=abs(gx-sx)+abs(gy-sy);
        if(dis>dt||dt%2!=dis%2)ans = 0;
        sx=gx;sy=gy;st=gt;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define F first
#define S second
#define N 100005
using namespace std;

typedef long long ll;
ll n, mn, s, s2, ans[N];
pair<ll, ll> a[N];
vector<ll> b, c, d;
int main()
{
	int i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%lld", &a[i].F);
		a[i].S = i;
	}
	sort(a + 1, a + n + 1);
	b.push_back(0);
	c.push_back(0);
	d.push_back(0);
	for (i = 1; i <= n; i++) {
		if (a[i].F == a[i - 1].F) {
			s++;
		} else {
			if (i > 1) c.push_back(s);
			b.push_back(a[i].F);
			d.push_back(a[i].S);
			s = 1;
		}
	}
	c.push_back(s);
	mn = 2e9;
	for (i = b.size() - 1; i > 0; i--) {
		mn = min(mn, d[i]);
		s2 += c[i];
		ans[mn] += (b[i] - b[i - 1]) * s2;
	}
	for (i = 1; i <= n; i++) {
		printf("%lld\n", ans[i]);
	}
    return 0;
}


Measured memory_bytes: 5984
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
   //     Scanner sc = new Scanner(System.in);
        int[] list1 = new int[180];
        int[] cnt1 = new int[1000001];
        int[] cnt2 = new int[1000001]; 
        for(int i = 0; i < 180; i++) {
            list1[i] = (i+1)*(i+2)*(i+3)/6;
        }
        // Here your code !
        for(int i = 0; i <= 1000000; i++){
            cnt1[i] = i;
            cnt2[i] = i;
        }
        
        for(int n = 3, p = 4; p <= 1000000; n++){
            for(int i = 0; i+p <= 1000000; i++){
                cnt1[i+p] = Math.min(cnt1[i+p], cnt1[i] + 1);
            }
            if(p % 2 == 1){
                for(int i = 0; i+p <= 1000000; i++){
                    cnt2[i+p] = Math.min(cnt2[i+p], cnt2[i] + 1);
                }
            }
            // p?????????????????§??´??°
            p = n * (n+1) * (n+2) / 6;
        }
        
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            int num = Integer.parseInt(br.readLine());
            if(num == 0) break;
            System.out.println(cnt1[num] + " " + cnt2[num]);
        }
    }
}

Measured memory_bytes: 32496
#include <iostream>

using namespace std;

const int max_pp = 664579;
const int max_p = 10000000;
bool prime[max_p + 1];
int p[max_pp + 1];

void init_prime()
{
    int idx = 0;

    for (int i = 0; i <= max_p; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < max_p; i++)
        if (prime[i])
            for (int j = 2 * i; j <= max_p; j += i)
                prime[j] = false;

    for (int i = 0; i <= max_p; i++)
        if (prime[i])
            p[idx++] = i;
}

int main()
{
    int n;

    init_prime();

    while (cin >> n, n) {
        int idx = max_pp - 1;
        
        while (p[idx] > n) 
            idx--;
        while (true) {
            if (p[idx] == p[idx - 1] + 2 &&
                p[idx] == p[idx - 2] + 6 &&
                p[idx] == p[idx - 3] + 8) {
                cout << p[idx] << endl;
                break;
            }
            idx--;
        }
    }

    return 0;
}

Measured memory_bytes: 13520
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

vector<int> bfs(int src, vector<vector<int>> &Tree) {
  int N = Tree.size();
  vector<int> dist(N, -1);
  dist[src] = 0;

  queue<int> que;
  que.push(src);
  while (!que.empty()) {
    int cur_v = que.front();
    que.pop();
    for (auto nxt_v : Tree[cur_v]) {
      if (dist[nxt_v] != -1) {
        continue;
      }
      dist[nxt_v] = dist[cur_v] + 1;
      que.push(nxt_v);
    }
  }
  return dist;
}

int main() {
  int N;
  cin >> N;

  vector<vector<int>> Tree(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    Tree[a].push_back(b);
    Tree[b].push_back(a);
  }

  vector<int> dist_from_1 = bfs(0, Tree);
  vector<int> dist_from_n = bfs(N - 1, Tree);

  int alice = 0;
  int bob = 0;

  for (int i = 0; i < N; i++) {
    if (dist_from_1[i] <= dist_from_n[i]) {
      alice++;
    } else {
      bob++;
    }
  }
  cout << (alice > bob ? "Fennec" : "Snuke") << endl;

  return 0;
}

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

int main() {
  
  int a;
  cin >> a;
  int b;
  cin >> b;
  
  int c;
  if (b/10==0) c=a*10+b;
  else if (b/100==0) c=a*100+b;
  else c=a*1000+b;
  
  vector<int> vec(320);
  for (int i=0; i<320; i++) vec.at(i)=pow(i+1, 2);
  
  int s=0;
  for (int i=0; i<320; i++) {
    if (c==vec.at(i)) {
      cout << "Yes" << endl;
      s++;
      break;
    }
  }
  
  if (s==0) cout << "No" << endl;
}

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

int main(){
  
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s+='?';
  int a[100000]={0},b[100000]={0};
  int j=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0') b[j]++;
    else a[j]++;
    if(s[i]=='0'&&s[i+1]=='1') j++;
  }
  if(k>j) cout<<n<<endl;
  else{
    int sum=a[k];
    for(int i=0;i<k;i++){
      sum+=a[i];
      sum+=b[i];
    }
    int l=0,ans=sum;
    for(int i=k;i<=j;i++){
      sum-=a[l];
      sum-=b[l];
      l++;
      sum+=a[i+1];
      sum+=b[i];
      ans=max(ans,sum);
    }
    cout<<ans<<endl;
  }
  
}

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

bool f(int x)
{
    if(x==0)return 0;
    if(x%10==3)return 1;
    else f(x/=10);
}

int main()
{
    int n;
    cin>>n;
    rep(i,1,n+1)
    {
        if(i%3==0)cout<<" "<<i;
        else if(f(i)==1)cout<<" "<<i;
    }
    cout<<endl;
}


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

int mojikazoeru(string a,char b){
  int l=a.size();
  int ikutu = 0;
  for(int i=0;i<l;i++){
    if(a[i] == b) ikutu++;
  }
  return ikutu;
}


int main(){
  string s;
  cin >>s;
  cout << mojikazoeru(s,'+')-mojikazoeru(s,'-') <<endl;
}

Measured memory_bytes: 256
from collections import Counter
N,K=map(int,input().split(' '))
A=(Counter(list(map(int,input().split(' ')))))
A=sorted(A.items(),key=lambda x:x[1])
ans = 0
if len(A)>K:
    for i in A[:len(A)-K]:
        ans += i[1]
print(ans)

Measured memory_bytes: 37784
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
void call(int n) {
	int i = 1;
CHECK_NUM:
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
INCLUDE3:
	if (x % 10 == 3) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
	x /= 10;
	if (x) goto INCLUDE3;
END_CHECK_NUM:
	if (++i <= n) goto CHECK_NUM;

	cout << endl;
}
void solv() {

	int n;
	cin >> n;
	//call(n);

	for (size_t i = 1; i <= n; i++)
	{
		if (i % 3 == 0) {
			cout << " " << i;
			continue;
		}
		int x = i;
		while (x > 0)
		{
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}

int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3096
n=int(input())
s=input()
s=list(s)

flag = True

ans = []

count = 0

for i in s:
    if flag:
        if i==')':
            ans.append(')')
            ans.insert(0, '(')
        else:
            flag = False
            ans.append('(')
            count += 1
    else:
        if i=='(':
            count += 1
            ans.append('(')
        else:
            ans.append(')')
            count -= 1
            if count == 0:
                flag = True
                
for j in range(count):
    ans.append(')')

print(''.join(map(str,ans)))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define INF 1050000000

int main()
{
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  int i,j;
  for(i=0;i<n;i++)cin>>a.at(i)>>b.at(i)>>c.at(i);
  vector<vector<int>> val(n+1,vector<int>(3,INF));
  for(i=0;i<3;i++)val.at(0).at(i)=0;
  for(i=1;i<=n;i++)
  {
    val.at(i).at(0)=max(val.at(i-1).at(1)+a.at(i-1),val.at(i-1).at(2)+a.at(i-1));
    val.at(i).at(1)=max(val.at(i-1).at(0)+b.at(i-1),val.at(i-1).at(2)+b.at(i-1));
    val.at(i).at(2)=max(val.at(i-1).at(0)+c.at(i-1),val.at(i-1).at(1)+c.at(i-1));
  }
  int ans=0;
  for(i=0;i<3;i++)ans=max(ans,val.at(n).at(i));
  cout<<ans<<endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int S, W;
    cin >> S >> W;
    if (W >= S){
        cout << "unsafe";
    } else {
        cout << "safe";
    }
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;


int main() {
	int h, w;
	cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> dp(h, vector<int>(w, INF));
    if(s[0][0]=='#') dp[0][0] = 1;
    else             dp[0][0] = 0;
    rep(i,h) rep(j,w) {
        if (i) {
            if (s[i][j]=='#' && s[i-1][j]=='.') dp[i][j] = min(dp[i][j], dp[i-1][j] + 1);
            else                                dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
        if (j) {
            if (s[i][j]=='#' && s[i][j-1]=='.') dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);
            else                                dp[i][j] = min(dp[i][j], dp[i][j-1]);
        }
    }
	cout << dp[h-1][w-1] << endl;
	return 0;
}


Measured memory_bytes: 256
d=[[10*[0]for _ in range(3)]for _ in range(4)]
n=int(input())
for _ in range(n):
  b,f,r,v=map(int,input().split())
  d[b-1][f-1][r-1]+=v
for i in range(4):
  for j in d[i]:print(" "+" ".join([str(i)for i in j]))
  if i!=3:print("#"*20)


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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  cout << "ABC" << n << endl;
    
  return 0;
}


Measured memory_bytes: 3604
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int A, B; cin >> A >> B;
  if (B % A == 0) cout << A + B << endl;
  else cout << B - A << endl;

  return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>inline bool read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c)){if(c==EOF)return false;f^=c=='-',c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
    return true;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10^48);
}
template<class T>inline void print(T x,char c){print(x),putchar(c);}
template<class T,class ...S>inline bool read(T &x,S &...y){return read(x)&&read(y...);}

ll f[3005][3005][5],a[3005][3005];
int n,m,l,x,y;

int main(){
	read(n,m,l);
	for (int i=1;i<=l;i++)
	read(x,y),read(a[x][y]);
	if (a[1][1]) f[1][1][1]=a[1][1];
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	for (int k=0;k<=3;k++){
		f[i+1][j][0]=max(f[i+1][j][0],f[i][j][k]);
		f[i+1][j][1]=max(f[i+1][j][1],f[i][j][k]+a[i+1][j]);
		f[i][j+1][k]=max(f[i][j+1][k],f[i][j][k]);
		f[i][j+1][k+1]=max(f[i][j+1][k+1],f[i][j][k]+a[i][j+1]);
	}
	printf("%lld\n",max(max(f[n][m][0],f[n][m][1]),max(f[n][m][2],f[n][m][3])));
}

Measured memory_bytes: 426316
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

Pll exgcd(ll a, ll b)
{
	if (!b) return{ 1, 0 };
	ll x, y;
	tie(x, y) = exgcd(b, a%b);
	return{ y, x - (a / b)*y };
}
int main() {
	ll n;
	scanf("%lld",&n);
	n<<=1;
	ll m=n;
	Vll v;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			while(n%i==0){
				v.pb(i);
				n/=i;
			}
		}
	}
	if(n>1)v.pb(n);
	int N=v.size();
	ll ans=INF;
	fup(i,0,(1<<N)-1,1){
		ll x=1,y=1;
		fup(k,0,N-1,1){
			if(i&(1<<k))x*=v[k];
			else y*=v[k];
		}
		if(gcd(x,-y)==-1)
		{
			auto [a,b]=exgcd(x,-y);
			if(a==0)a=1;
			ans=min(ans,a*x);
		}
		else if(gcd(x,-y)==1){
			auto [a,b]=exgcd(x,-y);
			a*=-1,b*=-1;
			if(a<0){
				a%=y;
				a+=y;
			}
			ans=min(ans,a*x);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3792
#include <stdio.h>
#include <inttypes.h>

#define MAX (1 << 18) /* 262144 */
#define INF INT64_C(11111111111111111)

int64_t ki[MAX * 2 - 1];
int64_t* ki_data = ki + (MAX - 1);

void ki_init(void) {
	int i;
	for (i = (MAX - 1) - 1; i >= 0; i--) {
		int64_t c1 = ki[i * 2 + 1], c2 = ki[i * 2 + 2];
		ki[i] = c1 >= c2 ? c1 : c2;
	}
}

int64_t ki_get_i(int idx, int qmin, int qmax, int smin, int smax) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		return -INF;
	} else if (qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		return ki[idx];
	} else {
		int smid = smin + (smax - smin) / 2;
		int64_t left, right;
		left = ki_get_i(idx * 2 + 1, qmin, qmax, smin, smid);
		right = ki_get_i(idx * 2 + 2, qmin, qmax, smid, smax);
		return left >= right ? left : right;
	}
}

int64_t ki_get(int min, int max) {
	return ki_get_i(0, min, max, 0, MAX);
}

int N;
int64_t C;
int64_t x[114514];
int64_t v[114514];

int64_t solve(void) {
	int64_t answer = 0; /* 何もせず帰れば0キロカロリーを得られる */
	int i;
	ki_data[0] = 0;
	for (i = 1; i < N * 2; i++) {
		ki_data[i] = ki_data[i - 1] + v[i % N] - ((x[i % N] + C - x[(i - 1) % N])) % C;
	}
	ki_init();
	for (i = 0; i <= N; i++) {
		int64_t candidate = -(C - x[i]);
		candidate += ki_get(i, i + N) - ki_data[i];
		candidate += v[i];
		if (candidate > answer) answer = candidate;
	}
	return answer;
}

int main(void) {
	int i;
	int64_t a1, a2;
	if (scanf("%d%" SCNd64, &N, &C) != 2) return 1;
	x[0] = 0;
	v[0] = 0;
	N++;
	for (i = 1; i < N; i++) {
		if (scanf("%" SCNd64 "%" SCNd64, &x[i], &v[i]) != 2) return 1;
	}
	x[N] = C;
	v[N] = 0;
	/* 反時計回りに移動→そこの寿司を食べる→時計回りに移動して食べる */
	a1 = solve();
	/* 反対まわりにして解く */
	for (i = 1; i < N; i++) x[i] = C - x[i];
	for (i = 1; i < N - i; i++) {
		int64_t t = x[i];
		x[i] = x[N - i];
		x[N - i] = t;
		t = v[i];
		v[i] = v[N - i];
		v[N - i] = t;
	}
	a2 = solve();
	/* いい方を出力する */
	printf("%" PRId64 "\n", a1 >= a2 ? a1 : a2);
	return 0;
}


Measured memory_bytes: 5376
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============
set<ll> make_divisions(ll num) {
    set<ll> st;
    REP(i, 1, sqrtl(num) + 1) {
        if (num%i == 0) {
            st.insert(i);
            st.insert(num / i);
        }
    }
    if (st.find(1) != st.end())st.erase(1);
    return st;
}
int main()
{
    ll N;
    cin >> N;
    set<ll> res = make_divisions(N - 1);
    for (auto K : make_divisions(N)) {
        ll M = N;
        while (M%K == 0)M /= K;
        if (M%K == 1)res.insert(K);
    }
    output(res.size());
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

bool dp[100005];

void solve(){
    int n,k;
    cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    dp[0]=false;
    for(int i=0;i<=k;++i){
        rep(j,n){
            if(i-a[j]==0)dp[i]=1;
            else if(i-a[j]>0)dp[i]|=1-dp[i-a[j]];
        }
    }
    if(dp[k])cout<<"First\n";
    else cout<<"Second\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long a,b,x;
  cin >> a >> b >> x;
  long long min,max;
  if(a%x==0){
    min=a/x;
  }
  if(a%x!=0){
    min=a/x+1;
  }
  max=b/x;
  long long cnt=max-min+1;
  cout << cnt << endl;
}


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

int main () {

    int N;
    cin >> N;

    bool ans = false;
    for (int a = 1; a < 10; a++) {
        for (int b = 1; b < 10; b++) {
            if (a * b == N) {
                ans = true;
                break;
            }
        }
    }
    cout << ((ans)? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
class BIT():
    def __init__(self,size):
        self.size=size
        self.node=[0]*(size+1)

    def sum(self,idx):
        ret=0
        while idx>0:
            ret+=self.node[idx]
            idx-=idx&(-idx)
        return ret

    def add(self,idx,x):
        while idx<=self.size:
            self.node[idx]+=x
            idx+=idx&(-idx)

n,m=map(int,raw_input().split())
L=[[] for _ in xrange(m+1)]
for i in xrange(n):
    l,r=map(int,raw_input().split())
    r+=1
    L[r-l].append(l)
bit=BIT(m+1)
ans=n
total=0
for d in xrange(1,m+1):
    for l in L[d]:
        r=l+d
        bit.add(l,1)
        bit.add(r,-1)
    total+=len(L[d])
    ans=n-total
    now=0
    while now<=m:
        ans+=bit.sum(now)
        now+=d
    print(ans)

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

using int64 = long long;
using Graph = vector<vector<int>>;

Graph tree;
vector<int64> counter;

void DFS(int u, int parent) {
    for (int child : tree[u]) {
        if (child == parent) continue;

        counter[child] += counter[u];
        DFS(child, u);
    }
}

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

    int N, Q;
    cin >> N >> Q;

    tree.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    counter.resize(N, 0);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;

        p--;
        counter[p] += x;
    }

    DFS(0, -1);

    for (int i = 0; i < N; i++) {
        cout << counter[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 24320
import java.util.*;
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int wei=sc.nextInt();
  int w[]=new int[n];
 long v[]=new long[n];
  for(int i=0;i<n;i++){
  w[i]=sc.nextInt();
    v[i]=sc.nextLong();
  }
  long sto[][]=new long[n+1][wei+1];
  
  
  for(int i=0;i<=n;i++){
  for(int j=0;j<=wei;j++){
      
      if(i==0 || j==0)
      sto[i][j]=0;
  else if(w[i-1]<=j){
  sto[i][j]=Math.max(sto[i-1][j],v[i-1]+sto[i-1][j-w[i-1]]);
  }
    else{
    sto[i][j]=sto[i-1][j];
    }
  }
  }
  
  System.out.println(sto[n][wei]);
}
}

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

char GetGrade(const int* personal_score) {
	if(personal_score[0] == -1 || personal_score[1] == -1) return 'F';

	int score = personal_score[0]+personal_score[1];
	if(score >= 80) return 'A';
	else if(score >= 65 && score < 80) return 'B';
	else if(score >= 50 && score < 65) return 'C';
	else if(score >= 30 && score < 50) {
		return (personal_score[2]>=50)?'C':'D';
	}
	else if(score < 30) return 'F';
}

int main(int argc, char** argv) {
	int personal_score[3];
	int m, f, r;
	list<char> list;

	while(1) {
		cin >> m >> f >> r;
		if(m==-1 && m==f && f==r && r==m) break;
		personal_score[0] = m;
		personal_score[1] = f;
		personal_score[2] = r;
		list.push_back(GetGrade(personal_score));
	}
	for(std::list<char>::iterator it = list.begin(); it != list.end(); ++it)
		cout << *it << endl;
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,ob;
  cin >> N >> ob;
  ob = ob/100;
  
  vector<int> p(N),c(N);
  for(int i=0; i<N; i++) {
    cin >> p.at(i) >> c.at(i);
    c.at(i) /= 100;
  }
  
  
  vector<int> psum(N),psumc(N);
  for (int i=0; i<N; i++) {
    psum.at(i) = (i+1)*p.at(i);
    psumc.at(i) = psum.at(i) + c.at(i);
  }
  
   int ans = 100000;
     
  for (int i=0; i<(1 << N); i++) {
      int a = 0;
      int b = 0;
      for (int j=0; j<N ; j++) {
          if (i & (1 << j)) {
          a += psumc.at(j);
          b += p.at(j);
          }
       }
       if(a >= ob && b < ans){
         ans = b;
       }
       else if (a < ob) {
         bool flag = true;
          for (int k=N-1; k>=0 ;k--){ 
              if((~i) & (1 << k) && flag) {
                flag = false;
                   for(int l = 0; l<p.at(k); l++){
                       a += k+1;
                       b += 1;
                          if(a >= ob && b < ans){
                               ans = b;
                               break;
                          }
                          else if (a >= ob && b >= ans)
                               break;
                    }
               } 
          } 
       }
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
N = int(input())
q = []
time = 0
for x in range(N):
    A , B = map(int, input().split())
    task = (B , A)
    heapq.heappush(q, task)
for y in range(N):
    task = heapq.heappop(q)
    time += task[1]
    if time > task[0]:
        ans = "No"
        break
else:
    ans = "Yes"
print(ans)

Measured memory_bytes: 28768
#include<stdio.h>
int main()
{
    int x,a;
    scanf("%d%d",&x,&a);
    if((x>=0 && x<=9) && (a>=0 && a<=9))
    if(x<a)
        printf("0\n");
        else
            printf("10\n");




    return 0;
}


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

const int N = 10005, A = 1000005;
const int MOD = 1e9 + 7;

int n, a[N], b[N];

vector<int> factor(A);
vector<int> lcm_(A);
map<int, int> mp[N];

void enum_prime() {
  rep(i, A) factor[i] = i;
  for (int i = 2; i < A; i++) {
    if (factor[i] != i) continue;
    for (int j = 2 * i; j < A; j += i) factor[j] = i;
  }
  return;
}

int modinv(int a) {
  int b = MOD, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) b[i] = a[i];
  enum_prime();
  rep(i, n) {
    while (a[i] > 1) {
      int f = factor[a[i]];
      mp[i][f]++;
      a[i] /= f; 
    }
    for (auto itr = mp[i].begin(); itr != mp[i].end(); itr++) {
      lcm_[itr->first] = max(lcm_[itr->first], itr->second);
    }
  }
  int l = 1;
  rep(i, A) rep(j, lcm_[i]) l = (ll)l * i % MOD;
  int ans = 0;
  rep(i, n) ans = (ans + (ll)l * modinv(b[i])) % MOD;
  if (ans < 0) ans += MOD;
  // printf("l = %d\n", l);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int N, happiness[100000][3];
int dp[100000][3];//dp[i][j]: i + 1日目に活動j (0 <= j <= 2) をしたときの幸福度の最大値

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> happiness[i][j];
		}
	}

	dp[0][0] = happiness[0][0], dp[0][1] = happiness[0][1], dp[0][2] = happiness[0][2];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k)dp[i][j] = max(dp[i][j], dp[i - 1][k] + happiness[i][j]);
			}
		}
	}

	cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl;


	return 0;
}

Measured memory_bytes: 2560
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.conv;

void main() {
	string[char] d;
	d['a'] = rs;
	d['b'] = rs;
	d['c'] = rs;
	import std.uni;
	solve(d).toUpper.writeln;
}

char solve(string[char] d) {
	if(d['a'].length == 1) return 'a';
	char turn = 'a';
	while(true) {
		if(d[turn].length == 0) return turn;
		char tmp = turn;
		turn = d[turn].front.to!char;
		d[tmp].popFront;
	}
}

// ===================================

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (isBasicType!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

int ri() {
	return readAs!int;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	vector<pair<int, int>>segs;

	int cnt = 1;

	for (int i = 1; i < n; i++) {
		if (s[i] != s[i - 1]) {
			if (cnt) {
				segs.emplace_back(s[i - 1] - '0', cnt);
			}
			cnt = 1;
		}
		else cnt++;
 	}
	if (cnt) segs.emplace_back(s.back() - '0', cnt);

	int l = 0, r = 0;

	cnt = 0;
	int cur = 0;
	int mx = -1;

	cnt += segs[0].second;
	if (segs[0].first == 0) {
		cur++;
	}

	mx = max(mx, cnt);

	while (r + 1 < segs.size()) {
		if (cur < k || (r + 1 < segs.size()) && segs[r + 1].first == 1) {
			r++;
			if (r < segs.size()) {
				cnt += segs[r].second;
				if (segs[r].first == 0) cur++;
				mx = max(mx, cnt);
			}
		}
		else {
			cnt -= segs[l].second;
			if (segs[l].first == 0) cur--;
			l++;
		}
	}
	cout << mx;
 	return 0;
}

Measured memory_bytes: 1528
use std::fmt::Debug;
use std::io::{self, Read};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = StdinScanner::new();
    println!("{}", solve(sc.next(), sc.next(), sc.next()));
}


fn solve(n: u64, a: u64, b: u64) -> u64 {
    if a > b {
        return 0;
    }
    if a == b {
        return 1;
    }
    if a != b && n == 1 {
        return 0;
    }
    let min = a * (n - 1) + b;
    let max = b * (n - 1) + a;
    1 + max - min
}


struct StdinScanner {
    buf: Vec<u8>,
}

impl StdinScanner {
    fn new() -> Self {
        StdinScanner { buf: Vec::with_capacity(256) }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let stdin = io::stdin();
        let mut stdin = stdin.lock().bytes();
        let mut c = stdin.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = stdin.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = stdin.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n,h,w;
  cin >> n>> h>>w;
  ll res = 0;
  REP(i,n){
    ll a,b;
    cin >> a >> b;
    if (a >= h && b >= w) res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

int main() {
	string s;
	bool ret = false;

	cin >> s;

	if (s.length() < 4) {
		cout << "No" << endl;
		return 0;
	}

	if (s.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s)begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) (a).begin(), (a).end()

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#ifdef _DEBUG
#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#else
#define DEBUG(x)
#endif

#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

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

//------------------HEAD---------------------

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;cin>>x;
    ll ans=(x/11)*2;
    if(x%11)ans+=x%11>6?2:1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int saiki(int ima)
{
	if(ima == n)
		return 1;
	if(ima > n)
		return 0;

	int res = 0;
	res += saiki(ima + 1) + saiki(ima + 2) + saiki(ima + 3);
	return res;
}

int main() {
	while (true){
		cin >> n;
		if (n == 0)
		{
			break;
		}
		
		int ans,a;
		ans = saiki(0);
		a = ans;
		ans /= 3650;
		a %= 3650;
		if( a == 0 )
		{
			cout << ans << endl;
		}
		else if( a != 0 )
		{
			ans++;
			cout << ans << endl;
			
		}
	}
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll inf=0xc0c0c0c0c0c0c0c0;
const double pi=acos(-1);
const ll MAX=2e5+7;
ll N,Q;
struct node{
	ll A,B,C;
};
bool operator<(node n1,node n2){return n1.C>n2.C;}
ll fa[MAX];
ll find(ll x){return fa[x]==x?x:fa[x]=find(fa[x]);}
priority_queue<node>que;
int main()
{
	scanf("%lld%lld",&N,&Q);
	for(ll i=0;i<N;i++)
		fa[i]=i;
	while(Q--)
	{
		node n;
		scanf("%lld%lld%lld",&n.A,&n.B,&n.C);
		que.push(n);
		n.A=(n.A+1)%N;n.C++;
		que.push(n);
	}
	ll block=N;
	ll res=0;
	while(block!=1)
	{
		node n=que.top();
		que.pop();
		ll a=find(n.A),b=find(n.B);
		if(a!=b)
		{
			res+=n.C;
			fa[a]=b;
			n.A=(n.A+1)%N;
			n.B=(n.B+1)%N;
			n.C+=2;
			block--;
			que.push(n);
		}
		// prllf("%lld\n",block);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 16108
#include<stdio.h>
#include<string.h>
int main()
{
	int k,n,i;
	char s[101];
	scanf("%d",&k);
    scanf("%s",&s);
    n=strlen(s);
    if(n>k){
        for(i=0;i<k;i++)
    	printf("%c",s[i]);
    	if(i==k) printf("...");
	}
	else puts(s);
	return 0; 
} 

Measured memory_bytes: 3228
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char s[101], p[101];
    int i, j, sn=0, pn=0, t;
    
    scanf("%s", s);
    scanf("%s", p);
    
    while(s[sn] != '\0') sn++;
    while(p[pn] != '\0') pn++;
    
    for (i=0; i<sn; i++) {
        t=1;
        for (j=0; j<pn; j++) {
            if (s[(i+j)%sn]!=p[j]) {
                t=0;
            }
        }
        if (t==1) {
            break;
        }
    }
    
    if (t==1) {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#define MAX 5000


int main(){
	int t[MAX];
	int n;
	int a[MAX];
	int b[MAX];
	int i,j,k;
	int max=-200000000;
	while(scanf("%d",&n)){
		if(n==0){
			break;
		}
		max=-200000000;
		for(i=0;i<n;i++){
				t[i]=b[i]=0;
		}
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
			for(j=i;j<n;j++){
				t[j]+=a[i];
				b[j]=t[j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<i;j++){
				t[i]-=a[j];
				if(t[i]>b[i]){
					b[i]=t[i];
				}
			}
		}
		for(i=0;i<n;i++){
			if(max<b[i]){
				max=b[i];
			}	
		}

		printf("%d\n",max);
	}	
	return 0;

}

Measured memory_bytes: 648
n, k = map(int, input().split())
h = [0] + list(map(int, input().split()))
inf = 10**5
dp = [inf]*(n+1)
dp[1] = 0
dp[2] = abs(h[1] - h[2])
for i in range(3, n+1):
    dp[i] = min(
        [dp[i-j] + abs(h[i-j] - h[i]) for j in range(1, min(k, i)+1)]
    )
print(dp[n])

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

const int N = 110;
const int M = 310;

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

int main(){
	while(~scanf("%d %d", &n, &m)){
		for(int i=1; i<=n; i++){
			scanf("%d %d", w+i, v+i);
		}
		b = w[1];
		int s = 0;
		for(int i=1; i<=n; i++){
			w[i] = w[i] - b;
			s += w[i];
		}
        memset(dp, 0, sizeof(dp));
        for(int i=1; i<=n; i++){
            for(int j=n; j>0; j--){
				for(int k=s; k>=w[i]; k--){
					dp[j][k] = max(dp[j][k], dp[j-1][k-w[i]] + v[i]);
				}
            }
        }
        int ans = 0;
        for(int i=1; i<=n; i++){
			for(int j=0; j<=s; j++){
				int d = m - j;
				d = d / b;
				if(d >= i){
					ans = max(ans, dp[i][j]);
				}
			}
        }
        printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
	unsigned int a, b;
	std::cin >> a >> b;
	const bool even =
		//((a * b) % 2 == 0);         // NOTE: Constant cost, 1 LSB test after 1 multiply.
	 	  (a % 2 == 0 || b % 2 == 0); // NOTE: Worst cost, 2 LSB test w/ logical OR.
	const std::string s = (even) ? "Even" : "Odd";
	std::cout << s << std::endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    int N;
    cin >> N;
    int sum = 0;
    REP(i, N){
        ll a;
        cin >> a;
        while(a%2==0 && a>0){
            sum++;
            a/=2;
        }
    }
    cout << sum << el;
}



Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



D = 10**9+7

def main():
  NM = sorted(list(map(int, input().split())))
  if NM[1]-NM[0] > 1:
    return 0
  elif NM[0]==NM[1]:
    ret = 2*(math.factorial(NM[0])**2) % D
    return ret
  else:
    ret = math.factorial(NM[0])*math.factorial(NM[1]) % D
    return ret

if __name__ == "__main__":
  print(main())

Measured memory_bytes: 54640