akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
	ll M, D;
	cin >> M >> D;
	ll ans = 0;
	for(ll d1 = 2; d1 < 10; d1++){
		for(ll d10 = 2; d10 < 10; d10++){
			if(D >= d10*10 + d1 && 1 < d10*10 + d1){
				if(M >= d1 * d10){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAXN = 1000010;

vector<int> g[MAXN];
bool is[MAXN];

LL ret = 0, k;

int dfs(int v) {
	int depth = 1;
	FOR (i, g[v].sz) {
		depth = max(depth, 1 + dfs(g[v][i]));
		if (!is[v] && depth == k) {
			ret++;
			depth = 0;
			ffor (j, i + 1, g[v].sz)
				dfs(g[v][j]);
			break;
		}
	}
	return depth;
}

int main() {
	int n;
	cin >> n >> k;
	SET(is, 0);
	FOR (i, n)
		g[i].clear();
	FOR (i, n) {
		int a;
		cin >> a;
		a--;
		if (!i) {
			if (a)
				ret++;
		}
		else {
			g[a].pb(i);
			if (!a)
				is[i] = true;
		}
	}
	is[0] = true;
	if (k == 1)
		ret += n - 1 - (signed int)g[0].sz;
	else
		int tmp = dfs(0);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 34048
a, b = map(int, input().split())

if a % 2 == 0:
    a_min = int(a * 12.5)
else:
    a_min = int(a * 12.5) + 1

if (a + 1) % 2 == 0:
    a_max = int((a + 1) * 12.5) - 1
else:
    a_max = int((a + 1) * 12.5)

b_min = b * 10
b_max = (b + 1) * 10 - 1

if a_max < b_min:
    print("-1")
elif a_min <= b_min:
    print(int(b_min))
elif b_max >= a_min:
    print(int(a_min))
else:
    print("-1")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s =scan.next();
		scan.close();

		char[] s_char =s.toCharArray();

		if(s_char[2]==s_char[3]&&s_char[4]==s_char[5])System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 35256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e5 + 5 ;
int n , num[maxn] ;
char s[maxn] ;
int main()
{
	int x ;
	for(int i = 1 ; i <= 3 ; i ++)  scanf("%d" , &x) , num[x] ++ ;
	for(int i = 1 ; i <= 9 ; i ++)  if(num[i] == 2){printf("Yes\n") ;
	return 0 ;
	}
	printf("No\n") ;
    return 0 ;
}

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

class Main{
	public static void main(String[] args) {

		int suretu_kazu=0;
		int[] suretu;
		int bubun_nokazu=0;
		int[] bubun;
		String moji="";
		String[] srt;
		String[] bbn;
		int gacchi=0;

		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));

		try {
			moji=bfr.readLine();
			suretu_kazu=Integer.parseInt(moji);
			moji=bfr.readLine();
			srt=moji.split(" ");
			suretu=new int[suretu_kazu];
			for(int i=0; i<suretu_kazu; i++) {
				suretu[i]=Integer.parseInt(srt[i]);
			}
			moji=bfr.readLine();
			bubun_nokazu=Integer.parseInt(moji);
			moji=bfr.readLine();
			bbn=moji.split(" ");
			bubun=new int[bubun_nokazu];
			for(int i=0; i<bubun_nokazu; i++) {
				bubun[i]=Integer.parseInt(bbn[i]);
			}
			
			for(int i=0; i<bubun_nokazu; i++) {
				for(int j=0; j<suretu_kazu; j++) {
					if(bubun[i]==suretu[j]) {
						gacchi++;
						break;
					}
				}
			}
			System.out.println(gacchi);
		}catch(IOException e) {

		}
	}
}


Measured memory_bytes: 27384
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	long long int n,k,i,s=0;
 	cin>>n>>k;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 	for(i=0;i<n;i++)
 		{
 			if(a[i]>=k)
 				s++;
		 }
 		
 	cout<<s<<endl;
 }

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int A[100002];
	A[0] = 0;
	A[N + 1] = 0;
	int goukei = 0;
	rep1(i, N) {
		goukei += abs((A[i] = getint()) - A[i - 1]);
	}
	goukei += abs(A[N]);

	int mae = abs(A[1]);
	rep1(i, N) {
		putint(goukei - mae - (mae = abs(A[i + 1] - A[i])) + abs(A[i + 1] - A[i - 1]));
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

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

typedef long long ll;

int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tot,n;
    cin>>tot>>n;
    ll curr = 0;
    for(ll i=0;i<n;i++)
    {
        ll temp;
        cin>>temp;
        curr +=temp;
    }
    tot = tot - curr;
    if(tot>=0)
        cout<<tot<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 3656
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  n <- readLn
  ps <- readIntsLn
  putStrLn $ if solve n ps then "YES" else "NO"

solve :: Int -> V.Vector Int -> Bool
solve _ ps = l <= 2
  where l = V.length $ V.ifilter (\i x -> (i + 1) /= x) ps

readIntsLn :: IO (V.Vector Int)
readIntsLn = V.unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine


Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
const int maxN = 100100;
long long int grid[101][maxN];
long long int knapsack(int n,int w,vector<int> weight,vector<long long int> price){
	if(n == 0 or w == 0){
		return 0;
	}
	if(grid[n][w] != -1){
		return grid[n][w];
	}
	if(weight[n - 1] > w){
		return grid[n][w] = knapsack(n - 1,w,weight,price);
	}
	return grid[n][w] = max(price[n - 1] + knapsack(n - 1,w - weight[n - 1],weight,price),knapsack(n - 1,w,weight,price));
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,w;
    cin >> n >> w;
    vector<int> weight(n);
    vector<long long int> price(n);
    for(int i = 0;i < n; i++){
		cin >> weight[i] >> price[i];
	}
    memset(grid,-1,sizeof(grid));
    cout << knapsack(n,w,weight,price) << "\n";
}
 


Measured memory_bytes: 82824
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
        String [] str = new String [a];
        for(int i=0;i<a;i++){str[i] = sc.next();
                            }
        Arrays.sort(str);
        int b = 0;
        int c = 1;
        for(int i=0;i<a;i++){if(i>=1 && str[i].equals(str[i-1])){in[b]++;if(in[b]>c){c = in[b];}
                                                 
                                                                }else{b=i;in[i]++;}
                            }
        for(int i=0;i<a;i++){if(in[i]==c){System.out.println(str[i]);}
                              }
		
	}
}


Measured memory_bytes: 78696
N = int(input())
T = list(map(lambda x:int(x), input().split()))
M = int(input())
P = [0]*M
X = [0]*M
for i in range(M):
	p, x = map(lambda x:int(x), input().split())
	P[i] = p
	X[i] = x

sum_origin = sum(T)
for i in range(M):
	sum = sum_origin-T[P[i]-1]+X[i]
	print(sum)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    if (n % 1000 == 0) {
      System.out.println(0);
    } else {
      System.out.println(1000 - n % 1000);
    }
    
  }
}

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

using namespace std;

void solve() {
    int l; cin >> l;
    int n = 1<<l;
    vector<array<pair<int, int>, 2>> S(n);
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        S[i][0] = {-1, -1};
        S[i][1] = {x, i};
    }

    int mx = 0;
    for (int i = 1; i < n; i++) {
        set<pair<int, int>> tmp;
        tmp.insert(S[i][0]);
        tmp.insert(S[i][1]);
        for (int j = l-1; j >= 0; j--) {
            if (i & (1<<j)) {
                tmp.insert(S[i^(1<<j)][0]);
                tmp.insert(S[i^(1<<j)][1]);
            }
        }
        S[i][1] = *tmp.rbegin();
        tmp.erase(S[i][1]);
        S[i][0] = *tmp.rbegin();
        int sum = S[i][0].first + S[i][1].first;
        mx = max(mx, sum);
        cout << mx << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 7168
import heapq
N,M = [int(i) for i in input().split()]
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort(key=lambda x:x[0])
curpos = 0
Works = []
d = 1#d日後までの支払いが許される
ans = 0
curpos = 0

for d in range(1,M+1):#d日後までの支払いのうち一番高いやつ
    while 1:
        if curpos>=N:break
        if AB[curpos][0]<=d:
            heapq.heappush(Works,-AB[curpos][1])
            curpos += 1
        else:
            break
    if Works:
        ans -= heapq.heappop(Works)
print(ans)

Measured memory_bytes: 25732
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    /*ll t;
    cin>>t;
    while(t--)			
    {
       
    }*/
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    map<int,int>mp;
    mp[1]=0;
    ll pos=1;
    int flag=1,cnt=1;
    vector<int>v;
   // v.push_back(1);
    while(flag==1)
    {
        pos=a[pos-1];
       // cout<<pos<<" ";
        if(mp[pos]!=0)
        {
            //cnt++;
            v.push_back(pos);
            break;
        }
        mp[pos]=cnt;
        v.push_back(pos);
        cnt++;
    }
    ll len=cnt-mp[pos];
    ll ans[len];
    ll j=mp[pos];
   // cout<<"len "<<cnt<<" "<<mp[pos]<<" ";
    
    for(int i=0;i<len;i++,j++)
    {
        ans[(i+1)%len]=v[j-1];
    }
   //for(int i=0;i<len;i++)
    //cout<<ans[i]<<" ";
    if(k<cnt-1)
    {
        cout<<v[k-1]<<endl;
    }
    else
    {
        if(mp[pos]!=1)
        k-=mp[pos]-1;
       // cout<<"K;"<<k<<" ";
        cout<<ans[k%len];
    }
    
}


Measured memory_bytes: 15476
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {




        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int inp = int.Parse(line);
                if (inp == -1) { break; }
                long _4 = 0;
                long bas = 1;
                while (inp > 0) {
                    _4 += inp % 4 * bas;
                    bas *= 10;
                    inp /= 4;
                }
                Console.WriteLine(_4);


            }
        }


    }
}

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

int main()
{
    int round, total;
    cin >> round >> total;

    int house[1000010];
    for(int i =1; i <= total; i++){
        cin >> house[i];
    }

    house[0] = 0; //北端

   //一番長い間隔を探す
    int max_distance = 0;
    for(int i=2; i<=total; i++){
        if(max_distance <= house[i]-house[i-1]){
            max_distance = house[i]-house[i-1];
        }
    }

    int top_distance = round - house[total] + house[1]; //北端を挟んだ家の距離
    if(max_distance <= top_distance){
            max_distance = top_distance;
        }
    
    cout <<  round - max_distance << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vec = vector<int>;
using mat = vector<vec>;

// 行列の階数を求める
// 係数行列と拡大係数行列の階数が異なるときは不能
// 係数行列と拡大係数行列の階数が等しく、係数行列の階数と変数の個数が異なるときは不定
// 係数行列と拡大係数行列の階数と変数の個数がすべて等しいときは一意解が存在
int mat_rank(mat A){
    const int R = A.size(), C = A[0].size();
    int ret = 0;
    for(int i=0; ret<R&&i<C; ++i){
        int pivot = ret;
        for(int j=ret+1; j<R; ++j){
            if(abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
        }
        swap(A[pivot], A[ret]);

        if(A[ret][i] == 0) continue;

        // for(int k=C-1; k>=i; --k) A[ret][k] /= A[ret][i];
        for(int j=ret+1; j<R; ++j){
            for(int k=C-1; k>=i; --k) A[j][k] ^= A[ret][k]&A[j][i];
        }
        ++ret;
    }
    return ret;
}

using pi = pair<int,int>;

int main(){
    int m,n,d;
    while(scanf(" %d %d %d", &m, &n, &d),m){
        auto ID = [&](int y, int x){
            return y*m + x;
        };

        auto get = [&](int idx){
            return pi(idx/m, idx%m);
        };

        auto dist = [&](pi p, pi q){
            return abs(p.fi-q.fi) + abs(p.se-q.se);
        };

        int sz = n*m;

        mat s(n,vec(m));
        mat a(sz, vec(sz));
        vec b(sz);
        rep(i,n)rep(j,m){
            scanf(" %d", &s[i][j]);
            b[ID(i,j)] = s[i][j];
        }

        rep(i,sz)rep(j,sz){
            if(i==j || dist(get(i), get(j)) == d) a[i][j] = 1;
        }

        mat ab(sz, vec(sz+1));
        rep(i,sz){
            rep(j,sz) ab[i][j] = a[i][j];
            ab[i][sz] = b[i];
        }

        printf("%d\n", mat_rank(a) == mat_rank(ab));
    }
    return 0;
}



Measured memory_bytes: 9148
#include <stdio.h>

int main(){
    int i, j, k, N, A[201];
    int count = 0;
    int minimum = 30;
    scanf("%d", &N);
    for (k = 0; k <= N-1; k++){
        scanf("%d", &A[k]);
    }

    for (j=0; j<=N-1; j++){
        for (i=1; i<=30; i++){
            if (A[j] % 2 == 0){
                count += 1;
                A[j] = A[j]/2;
            }
        }
        if (minimum > count){
            minimum = count;
            }
        count = 0;
    }
    printf("%d\n", minimum);
    return 0;
}

Measured memory_bytes: 128
n = gets.chop.to_i
h = gets.chop.split.map(&:to_i)


ans = 0
num = 0

n.times do |index|

  unless index == 0 then

    if h[index] <= h[index-1] then
      num += 1
      ans = [num, ans].max

    else
      ans = [num, ans].max
      num = 0
    end


  end

end

puts ans


Measured memory_bytes: 12292
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n>=1&&n<=9) printf("%d\n",n);
  else if(n>=10&&n<=99) printf("9\n");
  else if(n>=100&&n<=999) printf("%d\n",n-90);
  else if(n>=1000&&n<=9999) printf("909\n");
  else if(n>=10000&&n<=99999) printf("%d\n",n-9090);
  else if(n==100000) printf("90909\n");
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod1=1000033;
long long mod2=1000037;
long long inv(long long x,int t){
	long long ret=1;
	long long now=x;
	long long mod=mod1;
	if(t==2)mod=mod2;
	int pow=mod-2;
	while(pow){
		if(pow%2){
			ret=ret*now%mod;
		}
		now=now*now%mod;
		pow/=2;
	}
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	long long v1=0;
	long long v2=0;
	for(int i=0;i<a;i++){
		int p,q;
		scanf("%d%d",&p,&q);
		if(p==1){
			v1=(v1+mod1+q%mod1)%mod1;
			v2=(v2+mod2+q%mod2)%mod2;
		}
		if(p==2){
			v1=(v1+mod1-q%mod1)%mod1;
			v2=(v2+mod2-q%mod2)%mod2;
		}
		if(p==3){
			v1=(v1*(q%mod1+mod1))%mod1;
			v2=(v2*(q%mod2+mod2))%mod2;
		}
		if(p==4){
			v1=(v1*inv((q%mod1+mod1),1))%mod1;
			v2=(v2*inv((q%mod2+mod2),2))%mod2;
		}
	}
	//printf("%lld %lld\n",v1,v2);
	for(long long x=-1000000;x<=1000000;x++){
		long long N=x*mod1+v1;
		long long M=(N%mod2+mod2)%mod2;
		if(M==v2&&-(1LL<<31)<=N&&N<(1LL<<31)){
			printf("%lld\n",N);return 0;
		}
	}
}

Measured memory_bytes: 1028
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()

a = inlist()

look = 1
removed = 0
for i in range(N):
    if a[i] != look and removed < N-1:
        removed += 1
    else:
        if a[i] == look:
            look += 1
if look == 1:
    print(-1)
else:
    print(removed)


Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int
bool comp(pair<int, int>& a, pair<int, int>& b)
{
    return a.first > b.first;
}
void findAns()
{
    int n;
    cin >> n;

    int a[n];

    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a, a + n, greater<int>());

    // for (auto c : a) cout << c << " ";
    // cout << "\n";

    ll ans = a[0];

    ll count = n - 2;

    for (int i = 1; i < n and count>0; i++)
    {
        if (count >= 2)
        {
            ans += 2 * a[i];
            count -= 2;
        }
        else
        {
            ans += a[i];
            break;
        }
    }

    cout << ans;



}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("out1.txt", "w", stdout);
// #endif

    fastio;

    ll  t = 1;
    //cin >> t;


    while (t--)
        findAns();
    return 0;
}

Measured memory_bytes: 4440
fun main(args: Array<String>) {
    val (N, P) = readInputLine().split(" ").map { it.toInt() }
    val S = readInputLine().reversed().toCharArray()

    var ans = 0L

    if (P == 2 || P == 5) {
        for ((i, c) in S.withIndex()) {
            if ((c - '0') % P == 0) {
               ans += (N - i).toLong()
            }
        }
        println(ans)
        return
    }

    val modCnt = LongArray(P)
    modCnt[0]++

    var current = 0
    var digitFactor = 1
    for (c in S) {
        current = ((c - '0') * digitFactor + current) % P
        digitFactor = (digitFactor * 10) % P
        modCnt[current]++
    }

    repeat(P) {
        ans += modCnt[it] * (modCnt[it] - 1L) / 2L
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 41212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,a,b,ans;
  cin>>n>>a>>b;
  ans=0;
  if(n%(a+b)>a){
    ans=(n/(a+b)*a)+a;
  }else{
    ans=(n/(a+b)*a)+n%(a+b);
  }
  cout<<ans;
}

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

int main(){
	
	int p, q, r, max;
	
	scanf("%d %d %d", &p, &q, &r);
	
	if(p > q)
		max = p;
	else
		max = q;
	
	if(r > max)
		max = r;
	
	
	printf("%d", p + q + r - max);
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
using namespace std;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a == b && a ==5)|| (a == c && a == 5)||(b == c && b == 5)){
		if(a + b + c == 17) printf("YES\n");
	}
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,X,Y; cin>>N>>X>>Y;
  vii A(N);
  rep(i,1,N){
    A[i].pb(i-1);
    A[i-1].pb(i);
  }
  A[X-1].pb(Y-1);
  A[Y-1].pb(X-1);
  vii F(N,vi(N,INF));
  rep(i,0,N){
    priority_queue<pii,vector<pii>,greater<pii>> Q;
    Q.push(mp(0,i));
    F[i][i]=0;
    while(Q.size()>0){
      int B=Q.top().first,C=Q.top().second; Q.pop();
      if(F[i][C]<B) continue;
      rep(j,0,A[C].size()){
        int D=A[C][j];
        if(F[i][D]>B+1){
          F[i][D]=B+1;
          Q.push(mp(B+1,D));
        }
      }
    }
  }
  vi ans(N);
  rep(i,0,N-1){
    rep(j,i+1,N){
      ans[F[i][j]]++;
    }
  }
  rep(i,1,N) cout<<ans[i]<<endl;
  }



Measured memory_bytes: 31744
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

#define int long long

const int MAX_N = 100005;

//[1, n]
int bit[MAX_N + 1] = {0};

int sum(int i){
    int s = 0;
    while(i > 0){
        s = max(s,bit[i]);
        i -= i & -i;
    }
    return s;
}

void add(int i, int x){
    while(i <= MAX_N){
        //bit[i] += x;
        bit[i] = max(bit[i], x);
        i += i & - i;
    }
}

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

    rep(i,n){
        int a;
        cin >> a;
        add(a, sum(a) + a);
    }
    cout << ((n * n + n) / 2) - sum(MAX_N) << endl;
}

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

int main(){

    long int N,M;
    cin >> N >> M;

    //奇数なら表 偶数なら裏

    long int cnt = 0;

    if(N == 1 && M == 1) cnt = 1;
    else if(N == 1) cnt = M-2;
    else if(M == 1) cnt = N-2;
    else cnt = N*M - N*2 -(M-2)*2;

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    PUTS(max(0,c - (a-b)));
}

Measured memory_bytes: 256
use std::io;

fn main() {
    // 一行目を取得、分割
    let mut one_line_buffer = String::new();

    io::stdin().read_line(&mut one_line_buffer).unwrap();
    let one_line_vec: Vec<i64> = one_line_buffer
        .trim()
        .split_whitespace()
        .map(|c| c.parse().unwrap())
        .collect();

    let popular_product_num = one_line_vec[1]; //M

    // 二行目を取得、分割
    let mut two_line_buffer = String::new();
    io::stdin().read_line(&mut two_line_buffer).unwrap();

    let mut vote_nums: Vec<i64> = two_line_buffer
        .trim()
        .split_whitespace()
        .map(|c| c.parse().unwrap())
        .collect();

    // 処理

    let total_vote_num = {
        let mut total: i64 = 0;
        for i in &vote_nums {
            total = total + i;
        }
        total
    };

    let judge_line_num = total_vote_num as f64 / (4 * popular_product_num) as f64;

    vote_nums.sort_by(|a, b| b.cmp(a));

    // for i in &vote_nums {
    //     println!("{}", i);
    // }

    let popular_product_votes: Vec<i64> = vote_nums[..(popular_product_num as usize)].to_vec();

    // println!("productVotes");
    // for i in &popular_product_votes {
    //     println!("{}", i);
    // }

    let mut is_yes = true;
    for i in popular_product_votes.iter() {
        if (*i as f64) < judge_line_num {
            is_yes = false;
        }
    }
    if is_yes {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int convdir(int direction, int width){
    switch(direction){
        case 0:
            return -4;
        case 1:
            return 0-4*width;
        case 2:
            return 4;
        default:
            return 4*width;
    }
}

int main(void){
    int H, W, K, x1, y1, x2, y2;
    char cbuf;
    cin >> H >> W >> K;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    vector<vector<char>> c(H,vector<char>(W, ' '));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> cbuf;
            c[i][j] = cbuf;
        }
    }
    vector<int> Cost(H*W*4, -1);
    Cost[4*(x1*W+y1)]=0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    que.push(pair<int, int>(0, 4*(x1*W+y1)));
    que.push(pair<int, int>(0, 4*(x1*W+y1)+2));
    while(!que.empty()){
        pair<int, int> curPoint = que.top();
        que.pop();
        if(curPoint.first > Cost[curPoint.second])continue;
        int turnbuf = (Cost[curPoint.second]+K-1)/K*K;
        int pointbuf = curPoint.second/4*4;
        int dirbuf = curPoint.second-pointbuf;
        for(int direction=0; direction<4; direction++){
            if((Cost[pointbuf+direction] == -1)||(Cost[pointbuf+direction] > turnbuf))Cost[pointbuf+direction] = turnbuf;
            int nxtPoint = pointbuf + direction + convdir(direction, W);
            if((nxtPoint < 0)||(nxtPoint >= H*W*4))continue;
            if(abs(nxtPoint/4/W - pointbuf/4/W)+abs(nxtPoint/4%W - pointbuf/4%W)!=1)continue;
            if(c[nxtPoint/4/W][nxtPoint/4%W]=='@')continue;
            if(abs(direction-dirbuf) == 2)continue;
            if(direction == dirbuf){
                if((Cost[nxtPoint] > Cost[curPoint.second]+1)||(Cost[nxtPoint] == -1)){
                    Cost[nxtPoint] = Cost[curPoint.second]+1;
                    que.push(pair<int, int>(Cost[nxtPoint], nxtPoint));
                }
            }else{
                if((Cost[nxtPoint] > turnbuf+1)||(Cost[nxtPoint] == -1)){
                    Cost[nxtPoint] = turnbuf+1;
                    que.push(pair<int, int>(Cost[nxtPoint], nxtPoint));
                }
            }
        }
    }
    int res = 100000000;
    for(int i=0; i<4; i++)if(Cost[4*(x2*W+y2)+i]!=-1)res = min(res, Cost[4*(x2*W+y2)+i]);
    cout << (res == 100000000 ? -1 : (res+K-1)/K) << endl;
    return 0;
}

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

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


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

int main() {
  	int n;
  	cin>>n;
  	vector<vector<ll> > arr(n, vector<ll>(3, 0));
  	for( int i=0;i<n;i++ ) {
  		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
  	}

  	for( int i=1;i<n;i++ ) {
  		arr[i][0] = arr[i][0] + max(arr[i-1][1], arr[i-1][2]);
  		arr[i][1] = arr[i][1] + max(arr[i-1][0], arr[i-1][2]);
  		arr[i][2] = arr[i][2] + max(arr[i-1][0], arr[i-1][1]);
  	}

  	cout<<max(arr[n-1][0], max(arr[n-1][1], arr[n-1][2]));

  	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)

using namespace std;

int i,j,k;

int main(){
    int k,n,ans,mini;
    ans=0;
    cin >>k>>n;
    int a[n];
    REP(i,n)cin>>a[i];
    mini=k+a[0]-a[n-1];
    REP(i,n-1){
        mini=max(mini,a[i+1]-a[i]);
    }
    ans=k-mini;

    cout<<ans<<endl;
    

    
    
    return 0;
}

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

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
//#define MOD 1000000007 //10^9+7
#define MOD 2019

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

int main(void){

  ll k, t;
  cin>>k>>t;
  vector<ll> a(t);
  ll max = 0;
  REP(i, t){
    ll x;
    cin>>x;
    a[i] = x;
    if(max < x) max = x;
  }

  if(k%2==0 && max < k/2){
    cout<<"0"<<endl;
  }else if(k%2==1 && max < (k/2 +1)){
    cout<<"0"<<endl;
  }else{
    cout<<max - (k- max) -1<<endl;
  }
  
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  int a=0,k;
  cin>>k;
  bool ok=0;
  for(int i=1;i<=k;i++) {
  a=(a*10+7)%k;
  if(a==0) { a=i; ok=1; break; }
  }
  if(ok) { cout<<a; }
  else { cout<<-1; }
  //} 
  return 0;
}

Measured memory_bytes: 3572
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] p = new int[n];

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    int c = 0;
    int min = p[0];

    for (int i = 0; i < n; i++) {
      min = Math.min(min,p[i]);
      if (min >= p[i]) {
        c++;
      }
    }

    System.out.println(c);

  }

}


Measured memory_bytes: 76232
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int l, r, d;
    cin >> l >> r >> d;
    int c = 0;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0) c++;
    }
    cout << c;
    cout << '\n';
    return 0;
}

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

int main() {
  const string COLOR = "RGBY";
  ios::sync_with_stdio(false), cin.tie(0);
  int h, w, d; cin >> h >> w >> d;
  int dd = d * 2;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      int y = i + j, x = i - j;
      y = (y % dd + dd) % dd;
      x = (x % dd + dd) % dd;
      cout << COLOR[((y < d) << 1) | (x < d)];
    }
    cout << endl;
  }

}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[n], max = 0;
  for (int i=0; i<n; i++) scanf("%d", a+i);
  for (int i=0; i<n-1; i++) for (int j=i+1; j<n; j++) max = (abs(a[i]-a[j]) > max) ? abs(a[i]-a[j]) : max;
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int MAX_RESULT = 1000000;
std::unordered_set<int> primeset;
int Solve(int a, int d, int n) {
  int primecount = 0;
  while (primecount < n) {
    // cerr << "\033[93m" << primecount << " " << a << "\033[m" << endl;
    if (primeset.find(a) != primeset.end()) {
      // cerr << "\033[93m" << a << "is prime"
      //      << "\033[m" << endl;
      primecount++;
    }
    a += d;
  }
  return a - d;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  bool searchset[MAX_RESULT + 1] = {};
  for (int i = 2; i <= MAX_RESULT; i++) {
    searchset[i] = true;
  }

  for (int top = 2; top <= 1000; top++) {
    if (!searchset[top]) continue;
    primeset.insert(top);
    for (int i = top; i <= MAX_RESULT; i += top) {
      searchset[i] = false;
    }
  }

  for (int i = 2; i <= MAX_RESULT; i++) {
    if (searchset[i]) {
      primeset.insert(i);
    }
  }

  while (1) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) break;
    cout << Solve(a, d, n) << endl;
  }

  return 0;
}



Measured memory_bytes: 7100
#include <bits/stdc++.h>
using namespace std;
int main(){
  set<int> S;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int x;
      cin >> x;
      S.insert(x);
      cout << S.size() << endl;
    }
    if (t == 1){
      int x;
      cin >> x;
      if (S.count(x)){
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
    if (t == 2){
      int x;
      cin >> x;
      S.erase(x);
    }
  }
}


Measured memory_bytes: 12388
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

long long dp[110][100010];
int main() {
	int n, W;
	cin >> n >> W;
	long long *w = new ll[n];
	long long *v = new ll[n];
	for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {
			if (j - w[i] >= 0) {
				chmax(dp[i + 1][j], dp[i][j - w[i]]+v[i]);
			}
			chmax(dp[i + 1][j], dp[i][j]);
		
		}
	}
	cout << dp[n][W];
	return 0;
}


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

vector<bool> IsPrime(MAX_N+1,true);

void sieve(int max){
  IsPrime.at(0)=IsPrime.at(1)=false;
  for(int i=2;i*i<=max;++i) if(IsPrime.at(i)){
    for(int j=2;i*j<=max;++j) IsPrime.at(i*j)=false;
  }
}

int main(){
  int n,ans=0;cin>>n;
  vector<int> x(MAX_N+2,0);
  sieve(MAX_N);
  REP(i,MAX_N+1) x.at(i+1)=x.at(i)+(IsPrime.at(i)&&IsPrime.at((i+1)/2)?1:0);
  REP(i,n){
    int l,r;cin>>l>>r;
    cout<<x.at(r+1)-x.at(l)<<endl;
  }
}

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

int main(){
  int n;
  cin>>n;
  
  int cnt = 0;
  
  for(int i=0;i<n;++i){
    int a;
    cin>>a;
    if(i%2 == 0 && a%2 == 1){
      cnt++;
    }
  }
  
  cout<<cnt<<endl;
  return 0;
}

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

#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define BUFF ios::sync_with_stdio(false);

typedef long long int ll;
typedef long double ld;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > ii;
typedef vector < ii > vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9+7;
const ld pi = acos(-1);

int main() { BUFF
  int a, b;
  cin >> a >> b;
  if(b % a == 0)
    cout << a + b;
  else
    cout << b - a;

  return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define size(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, pair<int,int>>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

const int N=1e6;
vector<vector<int>> dis;
// vector<pii> pre[N];
char a[N+5];
int n,m,k;
const vector<pair<int,int>> dir{{1,0,},{-1,0},{0,1},{0,-1}};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    scanf("%d%d%d",&n,&m,&k);
    dis=vector(n,vector(m,(int)-1));
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    forn(i,n){
        scanf("%s",a+i*m);
    }
    x1--,y1--,x2--,y2--;
    auto dijkstra=[&](int sx,int sy){
        queue<pii> q;
        dis[sx][sy]=0;
        q.push({0,{sx,sy}});
        while(!q.empty()){
            auto tmp=q.front();
            q.pop();
            auto [x,y]=tmp.S;
            for(auto [dx,dy]:dir){
                for(int i=1;i<=k;i++){
                    int nx=x+dx*i,ny=y+dy*i;
                    if(unsigned(nx)>=n||unsigned(ny)>=m||a[nx*m+ny]=='@'||(dis[nx][ny]!=-1&&dis[nx][ny]<=dis[x][y])) break;
                    if(dis[nx][ny]==-1){
                        dis[nx][ny]=dis[x][y]+1;
                        // pre[v].clear();
                        // pre[v].pb({cost,u});
                        q.push({dis[nx][ny],{nx,ny}});
                    }
                    // else if(dis[v]==dis[u]+cost)
                    // 	pre[v].pb({cost,u});
                }
            }
        }
    };
    dijkstra(x1,y1);
    cout<<(dis[x2][y2]);
    return 0;
}



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

typedef long long ll;

ll gcd (ll a, ll b) {
	if (!b)return a;
	else return gcd(b, a%b);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll N, X; cin >> N >> X;
	cout << 3 * (N - gcd(N,X));

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N, K;
	cin >> N >> K;

	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	for (ll i = K - 1; i < N - 1; ++i)
	{
		ll l = A[i - K + 1];
		ll r = A[i + 1];

		if (l < r)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  char input(a);
  if ('a' <= a && a <= 'z') {
    cout << 'a' << endl;
  } else {
    cout << 'A' << endl;
  }
}


Measured memory_bytes: 3636
n = int(input())
s =[input() for _ in range(n)]
ans =0
if len(s) != len(set(s)):
  ans = 1
for i in range(1,n):
  if s[i-1][-1] != s[i][0]:
    ans =1
print('No' if ans ==1 else 'Yes')

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

bitset<2000*2000+2> bit;

int main(void) {
	int N, A;
	cin >> N;

	bit[0] = 1;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A;
		sum += A;
		bit = bit | (bit << A); // VC2012だと落ちる
	}
	int half = (sum+1)/2;
	
	for (int ans = half; ans <= 2000*2000; ans++) {
		if (bit[ans]) {
			cout << ans << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import deque
mod=10**9+7
n=int(input())
edges=[[] for _ in range(n)]
for _ in range(n-1):
    x,y=map(int,input().split())
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)
children=[[] for _ in range(n)]
V=[]
q=deque([0])
used=[False]*n
used[0]=True
while q:
    par=q.popleft()
    C=children[par]
    V.append(par)
    for v in edges[par]:
        if used[v]:
            continue
        C.append(v)
        used[v]=True
        q.append(v)
DP=[None for _ in range(n)]
for par in V[::-1]:
    white,black=1,1
    for v in children[par]:
        w,b=DP[v]
        white*=w+b
        white%=mod
        black*=w
        black%=mod
    DP[par]=(white,black)
print(sum(DP[0])%mod)

Measured memory_bytes: 49224
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u)
{
   int v;

   color[u] = GRAY;
   d[u] = ++tt;

   for (v=0; v<n; v++){
      if (M[u][v]==0)
         continue;
      if (color[v]==WHITE)
         dfs_visit(v);
   }

   color[u] = BLACK;
   f[u] = ++tt;
}

void dfs()
{
   int u;

   for (u=0; u<n; u++)
      color[u] = WHITE;

   tt = 0;

   for (u=0; u<n; u++){
      if (color[u]==WHITE)
         dfs_visit(u);
   }

   for (u=0; u<n; u++)
      printf("%d %d %d\n", u+1, d[u], f[u]);
}

int main()
{
   int u, v, k, i, j;

   scanf("%d", &n);
   for (i=0; i<n; i++){
      for (j=0; j<n; j++)
         M[i][j] = 0;
   }

   for (i=0; i<n; i++){
      scanf("%d %d",  &u, &k);
      u--;

      for (j=0; j<k; j++){
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   dfs();

   return 0;
}

Measured memory_bytes: 1820
#include <cstdio>
int t,n;
int main(){
	while(scanf("%d",&t)){
		if(t==0)break;
		scanf("%d",&n);
		int sum=0;
		for(int i=0;i<n;++i){
			int s,f;
			scanf("%d %d",&s,&f);
			sum+=f-s;
		}
		if(sum>=t)printf("OK\n");
		else printf("%d\n",t-sum);
	}
}

Measured memory_bytes: 1040
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll a, b;
  cin >> a >> b;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  ll n = log2(1e12 + 1);
  auto sum = [&](ll c) -> ll {
    ll res = 0LL;
    REP(i, n + 1) {
      ll tmp = 1LL << (i + 1);
      ll tmp2 = 1LL << (i);
      ll num = tmp2 * (c / tmp) + max(c % tmp - tmp / 2LL + 1LL, 0LL);
      // cout << c << endl;
      // cout << i << " " << c / tmp << " " << c % tmp << " " << num << endl;
      if (num % 2LL == 1) {
        res += tmp2;
      }
    }
    return res;
  };
  // cout << sum(a - 1) << endl;
  // cout << sum(b) << endl;
  cout << (sum(a - 1LL) ^ sum(b)) << endl;
}


Measured memory_bytes: 256