akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  int a, b, c;
  a = b = c = 0;
  char turn = 'a';
  while (1) {
    switch(turn) {
      case 'a':
        if (a == s1.size()) {
          cout << 'A' << endl;
          return 0;
        }
        turn = s1[a++];
        break;
      case 'b':
        if (b == s2.size()) {
          cout << 'B' << endl;
          return 0;
        }
        turn = s2[b++];
        break;
      case 'c':
        if (c == s3.size()) {
          cout << 'C' << endl;
          return 0;
        }
        turn = s3[c++];
        break;
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    A = [list(reversed(a)) for a in A]

    s1 = set()
    s2 = set()

    def update(i):
        if not A[i-1]:
            return

        d = A[i-1][-1]
        n = (min(i, d), max(i, d))
        if n not in s1:
            s1.add(n)
        else:
            s2.add(n)
            s1.remove(n)

    for i in range(1, N+1):
        update(i)

    while s2:
        ans += 1
        s2_, s2 = s2, set()
        for k in s2_:
            a, b = k
            A[a-1].pop()
            A[b-1].pop()
            update(a)
            update(b)


    for a in A:
        if a:
            return -1
    return ans


def main():
    N = read_int()
    A = [read_int_n() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 46448
n = int(input())
A = list(map(int,input().split()))
dp = [0]*n
for i in range(n):
    dp[A[i]-1] += 1
sub = 0
for i in range(n):
    if dp[i] != 0:
        sub += dp[i]*(dp[i]-1)//2
for i in range(n):
    ans = sub
    k = A[i]
    ans -= dp[k-1]*(dp[k-1]-1)//2
    if dp[k-1] == 1:
        print(ans)
    else:
        print(ans+(dp[k-1]-1)*(dp[k-1]-2)//2)


Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;

ll n, m, h[nax], a, b;
vector<vector<ll>> v(nax);

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	
	cin >> n >> m;
	for(ll i = 1; i <= n; i++){
		cin >> h[i];
	}
	for(ll i = 1; i <= m; i++){
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	ll cnt = 0;
	for(ll i = 1; i <= n; i++){
		bool bl = 1;
		for(ll j = 0; j < v[i].size(); j++){
			if(h[i] <= h[v[i][j]]){
				bl = 0;
				break;
			}
		}
		if(bl){
			cnt++;
		}
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 9804
// https://atcoder.jp/contests/abc075/tasks/abc075_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c;

  cin >> a >> b >> c;

  cout << (a == b ? c : a == c ? b : a) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int>a(n),b(n);
    REP(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b.begin(),b.end());
    int med1=b[n/2-1],med2=b[n/2];
    REP(i,n) cout<<((a[i]<med2)?med2:med1)<<endl;


}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define ll long long int
#define forr(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define oo 2000000000000000000LL
using namespace std;


void _sol(){
    ll x,k,d; cin >> x >> k >> d;
    x = abs(x);
    ll cnt = x/d;
    if( cnt > k ){
        cout << x - k*d;
    }
    else{
        if(cnt == k){
            cout << x - cnt*d;
        }
        else{
            x = x - cnt*d;
            k -= cnt;
            if(k%2){
                x = min( abs( x - d ) , abs(x+d) );
            }
            cout << x;
        }
    }

}

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


Measured memory_bytes: 3640
N, A=map(int, input().split())
x=list(map(int, input().split()))

dp=[[[0]*2501 for j in range(N+1)] for i in range(N)]

dp[0][0][0]=1
dp[0][1][x[0]]=1
for i in range(1, N):
  dp[i][0][0]=1
  for j in range(1, i+2):
    for k in range(2501):
      if k-x[i]>=0:
        dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k]
      else:
        dp[i][j][k]=dp[i-1][j][k]
        
print(sum([dp[-1][j][A*j] for j in range(1, N+1)]))

Measured memory_bytes: 91356
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, sx; readV(n, sx);
  int[] x; readA(n, x);

  auto y = x.map!(xi => (xi-sx).abs);

  auto g = y[0];
  foreach (i; 1..n) g = gcd(g, y[i]);

  writeln(g);
}


Measured memory_bytes: 4476
H,W,K = map(int,input().split())
grid = [input() for _ in range(H)]
N = H+W
ans = 0
start = 0
for i in grid:
    start += i.count('#')

for i in range(2**N):
    tmp = start
    painted = []
    for j in range(H):
        if (i>>j)&1:
            tmp -= grid[j].count('#')
            painted.append(j)
    for j in range(W):
        if (i>>j+H)&1:
            for k in range(H):
                if '#' == grid[k][j]:
                    if k in painted:
                        continue
                    else:
                        tmp -= 1
    if tmp == K:
        ans += 1
print(ans)

Measured memory_bytes: 74100
#include <algorithm>
#include <iomanip>
#include <iostream>

using namespace std;

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  string X;
  cin >> N >> X;

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt += (X[i] == '1');
  }

  long long A = 0, B = 0;
  for (int i = 0; i < N; i++) {
    if (X[i] == '1') {
      if (cnt - 1 > 0) {
        A = (A + mod_pow(2, N - i - 1, cnt - 1)) % (cnt - 1);
      }
      B = (B + mod_pow(2, N - i - 1, cnt + 1)) % (cnt + 1);
    }
  }

  for (int i = 0; i < N; i++) {
    long long ans = 0, t = 0;
    if (X[i] == '1') {
      if (cnt != 1) {
        t = ((A - mod_pow(2, N - i - 1, cnt - 1)) + (cnt - 1)) % (cnt - 1);
        ans++;
      }
    } else {
      t = (B + mod_pow(2, N - i - 1, cnt + 1)) % (cnt + 1);
      ans++;
    }
    while (t != 0LL) {
      t %= __builtin_popcountll(t);
      ans++;
    }
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 3764
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int[] ball={1,0,0};
while((line=br.readLine())!=null){
char[] c=line.toCharArray();
reverse(c[0],c[2],ball);
}
for(int i=0;i<ball.length;i++){
if(ball[i]==1){
switch(i){
case 0:System.out.println("A");
       break;
case 1:System.out.println("B");
       break;
case 2:System.out.println("C");
       break;
}
}
}
}
private static void reverse(char c1,char c2,final int[] ball){
int a=ball[c1-'A'];
ball[c1-'A']=ball[c2-'A'];
ball[c2-'A']=a;
}
}

Measured memory_bytes: 17032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

vector<ll> G[100100];
ll dp[100100];
bool used[100100];

ll dijkstra(ll s){
  if(used[s]) return dp[s];
  for(auto e:G[s]){
    dp[s]=max(dp[s],dijkstra(e)+1);
  }
  used[s]=true;
  return dp[s];
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  int x,y;
  for(int i=0;i<M;i++){
    cin >> x >>y;
    x--;
    y--;
    G[x].push_back(y);
  }
  for(int i=0;i<N;i++){
    dp[i]=0;
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    ans = dijkstra(i);
  }
  for(int i=0;i<N;i++){
    ans=max(ans,dp[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int ans=0;
	rep(i,5){
		int a; cin>>a;
		ans+=a;
	}
	cout << 15-ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 160000
#define B 100
#define dpb push_back
#define fi first
#define se second
typedef pair<int, int> P;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const int size = 504;
//__gcd(a,b), __builtin_popcount(a);

int r, h1, w1, X1, Y1, h2, w2, X2, Y2;
int dy[4] = {0, 0, -1, 1}, dx[4] = {-1, 1, 0, 0};
int a[size][size], b[size][size];
int an[250010], bn[250010];

int to_n(int y, int x, int w){
	return (w*(y-1)+x);
}
int to_y(int n, int w){
	return ((n-1)/w+1);
}
int to_x(int n, int w){
	return (n-(to_y(n, w)-1)*w);
}
int main(){
	while(1){
	fill((int*)a, (int*)(a+size), inf);
	fill((int*)b, (int*)(b+size), inf);
	fill(an, an+250010, 0);
	fill(bn, bn+250010, 0);
	scanf("%d", &r);
	if(!r)break;
	scanf("%d%d%d%d", &w1, &h1, &X1, &Y1);
	rrep(i,h1)rrep(j,w1)scanf("%d", &a[i][j]);
	scanf("%d%d%d%d", &w2, &h2, &X2, &Y2);
	rrep(i,h2)rrep(j,w2)scanf("%d", &b[i][j]);
	
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(a[Y1][X1], to_n(Y1, X1,w1)));
	a[Y1][X1] = inf;
	int acnt = 1;
	while(!q.empty()){
		P p = q.top();q.pop();
		int y = to_y(p.se, w1), x = to_x(p.se, w1);
		an[acnt++] = p.fi;
		for(int i = 0;i < 4;i++){
			int yy = y+dy[i], xx = x+dx[i];
			if(a[yy][xx] != inf){
				q.push(P(a[yy][xx], to_n(yy, xx,w1)));
				a[yy][xx] = inf;
			}
		}
	}
	
	q.push(P(b[Y2][X2], to_n(Y2, X2,w2)));
	b[Y2][X2] = inf;
	int bcnt = 1;
	while(!q.empty()){
		P p = q.top();q.pop();
		int y = to_y(p.se, w2), x = to_x(p.se, w2);
		bn[bcnt++] = p.fi;
		for(int i = 0;i < 4;i++){
			int yy = y+dy[i], xx = x+dx[i];
			if(b[yy][xx] != inf){
				q.push(P(b[yy][xx], to_n(yy, xx,w2)));
				b[yy][xx] = inf;
			}
		}
	}
	
	int t1 = 0, t2 = 0;
	for(int i = 0;i < acnt;i++){
		t1 = max(t1, an[i]);
		an[i] = t1;
	}
	for(int i = 0;i < bcnt;i++){
		t2 = max(t2, bn[i]);
		bn[i] = t2;
	}
	
	int ans = inf;
	for(int i = 0;i < acnt;i++){
		if(r-i < bcnt)ans = min(ans, an[i]+bn[r-i]);
		if(r == i)break;
	}
	
	printf("%d\n", ans);
	}
	return 0;
}






Measured memory_bytes: 7244
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 105, W = 1e5+10;

int n, totw;
int w[N], v[N];
ll dp[W];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> totw;
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = totw; j >= w[i]; j--) {
      dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
    }
  }
  cout << *max_element(dp, dp + W) << nl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int x,n,p[101];
int main(){
	ios::sync_with_stdio(0);
	cin>>x>>n;
	rep(i,n)
	cin>>p[i];
	int ans=-1;
	sort(p,p+n);
	int now=0;
	rep(i,n){
		while(now<p[i]){
			if(abs(now-x)<abs(x-ans))
			ans=now;
			now++;
		}
		now++;
	}
	while(now<=x*2){
		if(abs(now-x)<abs(x-ans))
			ans=now;
		now++;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define push_back pb
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; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int H,M;
    cin >> H >> M;
    int D[1010][1010];
    char A[H][M];
    queue<pair<int,int>> Q;
    REP(i,H){
      REP(j,M){
        cin >> A[i][j];
        if(A[i][j] == '#'){
          Q.push(make_pair(i,j));
        }
      }
    }
    
    int a = 0;  //dの値を外に持っていくために作った
    while(!Q.empty()){
        int x = Q.front().first, y = Q.front().second;
        Q.pop();
        int d = D[x][y];
        a = d;
        int dx[4] = {0,1,0,-1};  //xの動く向き
        int dy[4] = {1,0,-1,0};  //yの動く向き（xと連動している）
        REP(i,4){
            int px = x + dx[i];
            int py = y + dy[i];
            //盤外に行った場合はcontinue
            if(px < 0 || px >= H || py < 0 || py >= M) continue;
            if(A[px][py] == '.'){
                Q.push(make_pair(px,py));  //26,27行目同様＃の時queueにpush
                A[px][py] = '#';  //白から黒へと色を変える
                D[px][py] = d+1;  //一つずれるので距離を＋１
            }
        }
    }
    cout << a << endl;
}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

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

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){

    bool flag=false;

    ll ans=1e13,sum=0;
    
    ll n;
    cin >>n;

    for (int i = 1; i <= (int)sqrt(n); i++){
        if(n%i == 0){
            ll p = i;
            ll q = n/i;
            ans = min(p+q-2,ans);
        }
    }
    
    ans = min(n-1,ans);

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

using namespace std;

int main(){
	int X, Y, Z; cin >> X >> Y >> Z;
	int ans = 0;
	int now = Z;
	while(1){
		if(now + Y + Z <= X){
			now += Y + Z;
			ans++;
		}else{
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#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>;

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

    vector<string> s(n);
    
    rep(i,n){
        cin >> s.at(i);
    }

    ll count=n;

    sort(s.begin(),s.end());
    rep(i,n-1){
        if(s.at(i)==s.at(i+1)){
            count -= 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 9596
def bisect(ng, ok, judge):
    while abs(ng-ok) > 1:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

def solve(S):
    d = {'0':0,'1':1,'?':2}
    S = tuple(d[c] for c in S)
    lookup = ((-1,-1),(1,1), (-1,1))

    def judge(target_lo, target_hi):
        lo,hi = 0,0
        pl = target_lo%2 == 0
        ph = target_hi%2 == 0
        for s in S:
            a,b = lookup[s]
            lo = max(lo+a, target_lo+pl)
            hi = min(hi+b, target_hi-ph)
            if hi < lo:
                return False
            pl = not pl
            ph = not ph
        return True

    best = 10**6*2
    n0,n1,n2 = S.count(0), S.count(1), S.count(2)
    lo = -n0-n2
    hi = n1+n2
    while True:
        hi = bisect(-1, hi, lambda x: judge(lo, x))
        lo = bisect(1, lo, lambda x: judge(x, hi))
        if hi-lo >= best:
            break
        else:
            best = hi-lo
    hi += 1
    lo = bisect(1, lo, lambda x: judge(x, hi))
    return min(best, hi-lo)

# from itertools import product, accumulate
# from random import shuffle

# def naive(S):
#     d = {'0':(-1,), '1':(1,), '?': (-1,1)}
#     return min(max(0,max(accumulate(X)))-min(0,min(accumulate(X))) for X in product(*(d[c] for c in S)))

if __name__ == '__main__':
    S = input()
    print(solve(S))

    # for _ in range(50):
    #     S = ['0']*15+['1']*15+['?']*14
    #     shuffle(S)
    #     S = ''.join(S)
    #     print(S, naive(S), solve(S))

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int N,Q;
string s;
char t[200010],d[200010];

bool outL(int x){//x番目のゴーレムが左からはみ出るか
  if(x>=N+1)return 0;
  rep(i,Q){
    if(s[x] == t[i]){
      if(d[i]=='L')x--;
      else x++;
    }
    if(x==0)return 1;
    if(x==N+1) return 0;
  }
  return 0;
}

bool outR(int x){//右からはみ出るか
  if(x<0)return 0;
  rep(i,Q){
    if(s[x] == t[i]){
      if(d[i]=='L')x--;
      else x++;
    }
    if(x==N+1)return 1;
    if(x==0) return 0;
  }
  return 0;
}

int main(){
  cin >> N >> Q >> s;
  s = " "+s;
  rep(i,Q){
    cin >> t[i] >> d[i];
  }

  int okL=0,ngL=1e9;
  while(abs(ngL-okL)>1){
    int mid = (okL+ngL)/2;
    if(outL(mid)){
      okL = mid;
    }else{
      ngL = mid;
    }
  }

  int okR=N+1,ngR=0;
  while(abs(ngR-okR)>1){
    int mid = (okR+ngR)/2;
    if(outR(mid)){
      okR = mid;
    }else{
      ngR = mid;
    }
  }

  cout << okR-okL-1 << endl;
}

Measured memory_bytes: 984
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>

using namespace std;
int main()
{
  unsigned long long R;
  cin >> R;
  string ret = "";
  if (R < 1200) ret = "ABC";
  else if (R < 2800) ret = "ARC";
  else ret = "AGC";
  std::cout << ret << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

void dump(vector<char>& arr) {
  string res = "";
  for (auto c : arr) {
    res += c;
  }
  cout << res << endl;
  return;
}

void rec (int idx, int N, vector<char>& arr, char max_c) {
  if (idx == N - 1) {
    dump(arr);
    for (int i = 1; i < N; i++) {
      arr[idx]++;
      if (arr[idx] > max_c + 1) {
        break;
      }
      dump(arr);
    }
    arr[idx] = 'a';
  } else if (idx == 0) {
    rec(idx + 1, N, arr, 'a');
  }else {
    rec(idx + 1, N, arr, max_c);
    for (int i = 1; i < idx + 1; i++) {
      arr[idx] = 'a' + i;
      if (arr[idx] > max_c + 1) {
        break;
      } else if (arr[idx] > max_c) {
        rec(idx + 1, N, arr, arr[idx]);
      } else {
        rec(idx + 1, N, arr, max_c);
      }
    }
    arr[idx] = 'a';
  }
  return;
}

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

  int32_t N;
  cin >> N;
  vector<char> arr(N, 'a');
  rec(0, N, arr, 'a');
  return 0;
}


Measured memory_bytes: 1536
// author: gary
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ( (int) (x).size() )
typedef pair<int, int> pii;
typedef long long ll;

int a, b, c, d, e, f;

pii best(pii a, pii b) {
  return 1LL * a.first * b.second < 1LL * a.second * b.first ? b : a;
}

int main() {
  cin >> a >> b >> c >> d >> e >> f;

  pii ans = {0, 100 * a};

  for(int i = 0; i * a <= f; i++) {
    for(int j = 0; j * b <= f; j++) {
      int water = 100 * (i * a + j * b);
      if(water > f) break;
      for(int k = 0; k * c <= f; k++) {
        for(int l = 0; l * d <= f; l++) {
          int sugar = (k * c + l * d);
          if(sugar * 100 <= water * e && sugar + water <= f) {
            // printf("i=%d j=%d k=%d l=%d\n", i, j, k, l);
            ans = best(ans, {sugar, (water + sugar)});
          }
        }
      }
    }
  }
  printf("%d %d\n", ans.second, ans.first);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
int A,B;
cin>>A>>B;
if(A==1 && B==1){cout<<"Draw";}
else if(A==1 && B!=1){cout<<"Alice";}
else if(A!=1 && B==1){cout<<"Bob";}
else if(A>B){cout<<"Alice";}
else if (B>A){cout<<"Bob";}
else if(A==B){cout<<"Draw";}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    int n, k;
    cin >>  n>> k;
    if (n < 10) cout << k + 100*(10 - n) << endl;
    else {
        cout << k << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from collections import *
import math
from bisect import *
import functools
INF = float('inf')
mod = 10**9+7

def mat(A, B):
    n = len(A)
    C = [[0] * n for i in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                C[i][j] += A[i][k]*B[k][j]
            C[i][j] %= mod
    return C

N, K = map(int, input().split())
a = [[int(x) for x in input().split()] for i in range(N)]
b = [[0] * N for i in range(N)]
for i in range(N):
    b[i][i] = 1
while K > 0:
    if K % 2:
        b = mat(b, a)
    a = mat(a, a)
    K //= 2
print(sum([sum(_b) for _b in b])%mod)


Measured memory_bytes: 69596
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;  
typedef vector<ll> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef vector<vi> vvi;
#define F first
#define S second
#define pb emplace_back
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for(int i = a; i<= b; i++)
#define ws " "
#define all(c) c.begin(), c.end()
#define ln "\n" 
 
void printarray(int ar[], int n) {
    for (int i = 0; i < n; i++) {
        cout << ar[i] << ws;
    }
    cout << ln;
}

int dp[3001][3001];

void init(int n, int m) {
    for (int i = 0; i < n + 1; i++) {
        dp[i][0] = 0;
    }
    for (int i = 0; i <= m; i++) {
        dp[0][i] = 0;
    }
}

main() {
    IOS;

    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    init(n, m);
    // n - string s
    // m - string t

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    int i = n, j = m;
    int val = dp[n][m];
    string str = "";

    while (i >= 1 and j >= 1) {
        if (s[i - 1] == t[j - 1]) {
            str.push_back(s[i-1]);
            i--, j--;
        } else {
            if (dp[i - 1][j] > dp[i][j - 1]) {
                i = i - 1;
            } else {
                j = j - 1;
            }
        }
    }
    reverse(all(str));
    cout << str;



}
 
/*  Check for base cases such as n == 1
    and cases like it where code can fail */

Measured memory_bytes: 70656
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

struct Point { double x, y; };


void Coh(int c_, Point a, Point b) {
	if (c_ == 0)return;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0; // 60deg [rad]
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	Coh(c_ - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	Coh(c_ - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	Coh(c_ - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	Coh(c_ - 1, t, b);
}

int main() {
	int n;
	cin >> n;
	Point a, b;
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x, a.y);
	Coh(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);

	return 0;
	}


Measured memory_bytes: 3164
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int            take()
#define  Dnt            ttake()
#define  LL             takes()
#define  done           {return 0;}
#define  fr(i,x,n,a)    for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)      for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)   for(int i=x;i>=n;i--)
int      cas;
#define  print          printf("Case %d:",++cas)
#define  vi             vector<int>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace      std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR            {struct info}
#define  dbg(x)         {cout<<"ekhane"<<x<<endl;}
#define  SS             second
#define  FF             first
#define  PQ             priority_queue
#define  great          greatest
#define  less           lesser
#define  mii            map<int,int>
#define  mil            map<int,ll>
#define  mll            map<ll,ll>
#define  msb            map<string,bool>
#define  V              vector
#define  M              100005
#define  pf             printf
//////////////////////////////////////////


int main(){

    string s ; cin>>s ;
    int k = Int ;
    set<string>s1 ;

    fr( i , 0 , s.size() , 1 ){
        string up ="" ;
        fr( k , i , s.size() - 1 , 1 ){
            up += s[k ] ;
            s1.insert( up ) ;
            if( s1.size() > 5 ){
                auto it = s1.end() ; it-- ;
                s1.erase( it ) ;
            }
        }
    }
    auto it = s1.begin() ;
    while( it != s1.end() ){
        k-- ;
        if( k == 0 ){
            cout<<*it ;done ;
        }
        it++ ;
    }
    done;
}




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

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

    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin>>v.at(i);
    }

    sort(v.begin(),v.end());

    for(int i=1; i<n; i++){
        v.at(i)=(v.at(i-1)+v.at(i))/2;
    }

    cout<<v.at(n-1)<<endl;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7

S = input()
len_S = len(S)

set_map = []
state = 0
st = 0
en = 0

for i in range(len_S):
    s = S[i]
    if state == 0:
        if s == 'A':
            state = 1
            st = i
    elif state == 1:
        if s == 'B':
            state = 2
        elif s == 'C':
            state = 0
    elif state == 2:
        if s == 'A':
            state = 1
            st = i
        elif s == 'B':
            state = 0
        elif s == 'C':
            state = 3
            en = i
    elif state == 3:
        if s == 'A':
            state = 5
        elif s == 'B':
            state = 4
        elif s == 'C':
            set_map.append([st,en])
            state = 0
    elif state == 4:
        if s == 'A':
            set_map.append([st,en])
            state = 1
            st = i
        elif s == 'B':
            set_map.append([st,en])
            state = 0
        elif s == 'C':
            state = 3
            en = i
    elif state == 5:
        if s == 'B':
            state = 6
        elif s == 'C':
            set_map.append([st,en])
            state = 0
    elif state == 6:
        if s == 'A':
            set_map.append([st,en])
            state = 1
            st = i
        elif s == 'B':
            set_map.append([st,en])
            state = 0
        elif s == 'C':
            state = 7
            en = i
    elif state == 7:
        if s == 'A':
            state = 5
        elif s == 'B':
            state = 8
        elif s == 'C':
            set_map.append([st,en])
            state = 0
    elif state == 8:
        if s == 'A':
            set_map.append([st,en])
            state = 1
            st = i
        elif s == 'B':
            set_map.append([st,en])
            state = 0
        elif s == 'C':
            state = 7
            en = i

if state >= 3:
    set_map.append([st,en])

ans = 0
for st,en in set_map:
    cnt = 0
    for i in range(st,en):
        if S[i] == 'A':
            cnt += 1
        elif S[i] == 'B':
            ans += cnt

print(ans)


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

int main() {
  int x; cin >> x;
  int ans = 1;
  for (int i=2; i<=sqrt(x); ++i) {
    int n = i*i;
    while (n*i <= x) n *= i;
    ans = max(ans, n);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int n,s,a;

void dfs(int i,int sum,int m){
	if(m==0 && sum==s){a++;return;}
	if(i==10 || m==0)return;
	dfs(i+1,sum+i,m-1);
	dfs(i+1,sum,m);
}
int main(){
	while(scanf("%d%d",&n,&s)!=EOF){
		if(n==0 && s==0)break;
		a=0;
		dfs(0,0,n);
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 0
import re
key = list(str(input()))
keyence = list('^keyence$')
flag = 0

keylist = []
for i in range(1, len(keyence)):
    keyence.insert(i, r'\w*')
    
    key = ''.join(key)
    keyence = ''.join(keyence)
    result = re.match(keyence, key)
    if result:
        print("YES")
        quit()
    
    key = list(str(key))
    keyence = list(str(keyence))
    
    for s in r'\w*':
        keyence.remove(s)

print("NO")

Measured memory_bytes: 3188
N = int(input())

cnt = [0] * (6 * 10000 + 1)

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            cnt[x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x] += 1

for i in range(1, N + 1):
    print(cnt[i])


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

int main(){
    long N=0,M=0;
    cin >> N >> M;
    if(2*N>=M){
        cout << M/2 << endl;
    }
    else{
        M -= N*2;
        M /= 4;
        cout << N+M << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1e9+7
using namespace std;
#define  pp push_back
#define  po pop_back
#define  mp make_pair
#define clr(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,-1,sizeof(a))
#define fas(a) memset(a,false,sizeof(a))
#define debug(x) cout<<#x<<": "<<x<<endl
#define debug1(x) cout<<#x<<": "<<x<<" "
#define rev(x) reverse(x.begin(), x.end())
#define int long long 
#define F first
#define S second
//int a[2000];
void printvector(std::vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<""<<endl;}
void printarray(int a[],int n){for (int i = 0; i < n; ++i){cout<<a[i]<<" ";}cout<<""<<endl;}
 
 

 

void  solve()
{
   int a,b,c;cin>>a>>b>>c;
   cout<<min(a+b+1,c)+b<<endl; 

}




 int32_t main() 
{

  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    
   solve();

return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,gosa,ans,a,i,b,k,nagasa;
  gosa=0;
  string str;
  ans=0;
  nagasa=str.size();
  cin>>n>>k>>str;
  nagasa=str.size();
  for(i=0; i<nagasa-1; i++){
    if(str.at(i)==str.at(i+1)){
      ans=ans+1;
     
    }
    else{
      gosa=gosa+1;
      
     
      
    }
  }
  
  
  if(k*2<=gosa){
    ans=ans+k*2;
  }
  else{
    ans=ans+gosa;
  }
  cout<<ans;
}

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

typedef struct Node {
    int value;
    struct Node *prev;
    struct Node *next;
} Node;

Node *sentinel;
int size;

Node* search(int keyValue) {
    Node *target = sentinel->next;

    while (target != sentinel && target->value != keyValue) {
        target = target->next;
    }

    return target;
}

// initialize first Node
void initSentinel() {
    sentinel = (Node *)malloc(sizeof(Node));
    sentinel->next = sentinel;
    sentinel->prev = sentinel;
    size = 1;
}

void insert(int value) {
    Node *node = (Node *)malloc(sizeof(Node));
    node->value = value;

    if (sentinel->next == sentinel) {
        sentinel->prev = node;
        node->next = sentinel;

    } else {
        node->next = sentinel->next;
        sentinel->next->prev = node;
    }

    node->prev = sentinel;
    sentinel->next = node;

    size++;
}

void deleteNode(Node *target) {
    if (target == sentinel) { return; }

    target->prev->next = target->next;
    target->next->prev = target->prev;
    free(target);

    size--;
}

void delete(int keyValue) {
    deleteNode(search(keyValue));
}

void deleteFirst() {
    deleteNode(sentinel->next);
}

void deleteLast() {
    deleteNode(sentinel->prev);
}

void printList() {
    Node *target = sentinel->next;
    while(target != sentinel) {
        if (target->next == sentinel) {
            printf("%d\n", target->value);
        } else {
            printf("%d ", target->value);
        }

        target = target->next;
    }
}

int main() {

    // command count
    int N;
    scanf("%d", &N);

    // initialize
    initSentinel();

    char command[100];
    int value = 0;

    for (int i = 0; i < N; i++) {
        scanf("%s", command);

        if (strlen(command) > 6) {
            if (command[6] == 'F') {
                deleteFirst();

            } else {
                deleteLast();
            }

        } else {
            scanf("%d", &value);
            if (command[0] == 'i') {
                insert(value);

            } else {
                delete(value);
            }
        }
    }

    printList();

    return 0;
}



Measured memory_bytes: 32936
from collections import deque
from itertools import chain
H, W = map(int, input().split(' '))
Maze = [list(input()) for _ in range(H)]
White = list(chain.from_iterable(Maze)).count('.')
Maze[0][0] = 1
q = deque([])
current = [0, 0]
q.append(current)

dir_x = [1, -1, 0, 0]
dir_y = [0, 0, 1, -1]
while len(q) > 0:
    now_y, now_x = q.popleft()
    if now_y == H-1 and now_x == W-1 : break
    for (dx, dy) in zip(dir_x, dir_y):
        if 0 <= now_y + dy <= H-1 and 0 <= now_x + dx <= W-1 and Maze[now_y + dy][now_x + dx] == '.':
            Maze[now_y + dy][now_x + dx] = Maze[now_y][now_x] + 1
            q.append([now_y + dy, now_x + dx])


if Maze[H-1][W-1] == '.': print(-1)
else: print(White - Maze[H-1][W-1])

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

ans = 0

if n%2 == 0:
    a = list(s[0:n//2])
    b = list(s[(n//2):n+1])
    if a == b:
        ans = 1

if ans == 1:
    print("Yes")
else:
    print("No")

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535 
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{ 
    string s;
    cin>>s;
    int a=(s[0]-'0')*10+(s[1]-'0');
    int b=(s[2]-'0')*10+(s[3]-'0');
    if((a>12||a<1)&&(b>12||b<1)) cout<<"NA";
    else if((a>12||a<1)&&!(b>12||b<1)) cout<<"YYMM";
    else if(!(a>12||a<1)&&(b>12||b<1)) cout<<"MMYY";
    else cout<<"AMBIGUOUS";
    return 0;
}

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

const int INF = 1000000;

int main() {
	int n, m;
	cin >> n >> m;
	if (n <= 9 && m <= 9)cout << n * m;
	else cout << -1 << endl;
}





Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long X, Y;
    scan(X, Y);
    writeln(X % Y == 0 ? -1 : X);
}


Measured memory_bytes: 3668
N,Y=[int(s) for s in input().split()]
##N枚でY円
flag=0
i10=0
while i10*10000<=Y and i10<=N:
  i5=0
  while i10*10000+i5*5000<=Y and i10+i5<=N :
    i1=N-i10-i5
    if i10*10000+i5*5000+i1*1000==Y:
      print(*[i10,i5,i1])
      flag=1
      break
    i5+=1
  if flag==1 : break
  i10+=1
else:
  print(*[-1,-1,-1])


Measured memory_bytes: 3060
goods = [105, 104, 103, 102, 101]


def calc(n: int) -> list:
    n = n % 100
    res = []
    for c in goods:
        c = c % 100
        q = n // c
        n = n % c
        res.append(q)
    return res


def main():
    x = int(input())
    num = calc(x)
    y = 0
    for p, q in zip(goods, num):
        y += p*q
    if y <= x:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
A,B = map(int,input().split())
count = 0
for i in range(A,B+1):
	a = i // 10000
	b = i // 1000 - a*10
	c = i % 10
	e = i // 100 - a*100 - b * 10
	d = i // 10 - a*1000 - b * 100 - e *10
	if a == c and b == d :
		count+=1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

using namespace std;
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];

  int sum=0;
  int ans1=0;
  rep(i,n){
    sum+=a[i];
    if(i%2==0){
      if(sum>0)continue;
      else{
        ans1+=1-sum;
        sum=1;
      }
    }else{
      if(sum<0)continue;
      else{
        ans1+=sum+1;
        sum=-1;
      }
    }
  }
  //cout<<ans1<<endl;
  int ans2=0;
  sum=0;
  rep(i,n){
    sum+=a[i];
    if(i%2==1){
      if(sum>0)continue;
      else{
        ans2+=1-sum;
        sum=1;
      }
    }else{
      if(sum<0)continue;
      else{
        ans2+=sum+1;
        sum=-1;
      }
    }
  }
  //cout<<ans2<<endl;
  cout<<min(ans1,ans2)<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 5;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

	int N, M;
	cin >> N >> M;
	int A[M], B[M], C[M]{};
	rep(i,M){
		cin >> A[i] >> B[i];
		rep(j,B[i]){
			int tmp;
			cin >> tmp;
			--tmp;
			C[i] += (1<<tmp);
		}
	}
	int dp[M+1][1<<N];
	rep(i,M+1){
		rep(j,1<<N){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i,M){
		rep(j,(1<<N)){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			int nj = (j | C[i]);
			dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + A[i]); 
		}
	}
	if(dp[M][(1<<N)-1] == INF) cout << -1 << endl;
	else cout << dp[M][(1<<N)-1] << endl;
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 1e9+7;
 
string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    cout << (a+b-1)/b;
}

Measured memory_bytes: 256
function myOut(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.split(" ");
	//input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	input = input.split("\n").map((a)=>Number(a));
  input.sort(function(a,b){
  	return b % 10 - a % 10;
  });
  var zero = [];
  var output = 0;
  
  for(var i = 0; i < input.length; i++){
    if(input[i] % 10 == 0){
       zero.push(input[i]);
      input.splice(i,1);
      i--;
       }
  }
  
  var last = 0;
  if(input.length != 0){
  	last = input[input.length - 1];
     }
  
  for(var i = 0; i < input.length - 1; i++){
    output += input[i] + (10 - input[i] % 10);
  }
  for(var i = 0; i < zero.length; i++){
    output += zero[i];
  }
  
  //myOut(output);
  myOut(output + last);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    // 問題:
    class A_165_We_Love_Golf
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int k = int.Parse(Console.ReadLine());

            // 整数配列の入力
            var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int a = inputintArray[0];
            int b = inputintArray[1];

            //for (int i = a; i < b + 1; i++)
            //{
            //    if (i % k == 0)
            //    {
            //        Console.WriteLine("OK");
            //        break;
            //    }
            //    else if (i == b)
            //    {
            //        Console.WriteLine("NG");
            //    }
            //}
            for (int i = 1; i < b + 1; i++)
            {
                int keisan = k * i;

                if (keisan >= a && keisan <= b)
                {
                    Console.WriteLine("OK");
                    break;
                }
                else if (i == b)
                {
                    Console.WriteLine("NG");
                }
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28260