akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main() {
    int A,B,Ac,Bc;

    std::cin >> A >> B;

    unsigned long long cookie,unit;

    if(A > B){
        cookie = B;
        unit = B;
        while(1){
            Ac = (cookie % A);
            //std::cout << cookie << std::endl;
            if(Ac == 0){
                break;
            }
            cookie += unit;
        }
    }
    else if(A < B){
        cookie = A;
        unit = A;
        while(1){
            Bc = (cookie % B);
            //std::cout << cookie << std::endl;
            if(Bc == 0){
                break;
            }
            cookie += unit;
        }
    }
    else{
        std::cout << A << std::endl;
        return 0;
    }

    std::cout << cookie << std::endl;

    return 0;
}

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

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, K, sum=0, nums[100009];
    cin>>N;
    rep(i,N) cin>>nums[i], sum+=nums[i];
    
    if(sum%(N*(N+1)/2)){
        cout1("NO");
        return 0;
    }else{
        K = sum/(N*(N+1)/2);
    }
    
    nums[N]=nums[0];
    rep(i,N){
        ll n = (nums[i+1]-nums[i])-K;
        if(n>0||n%N){
            cout1("NO");
            return 0;
        }
    }
    cout1("YES");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

// 素因数分解
// 素因数(1は含まない)の値と数をペア型のvectorに入れる
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n,p;
    cin >> n >> p;
    auto pf = prime_factorize(p);
	ll ans=1;
	rep(i,pf.size()){
		while(pf[i].second>=n){
			ans*=pf[i].first;
			pf[i].second-=n;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <set>
#include <queue>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
}


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

int main() {

  int a, b, c;
  cin >> a >> b >> c;
  
  while (!(a <= b && b <= c)){  
    if (a > b) {
	  int x;
      x = a;
      a = b;
      b = x;
    }
    if (b > c) {
	  int x;
      x = b;
      b = c;
      c = x;
    }
  }
  
  cout << a << ' ' << b << ' ' << c << endl;
  
  return 0;
}


Measured memory_bytes: 3088
import sys

s=str(input())
k=int(input())

if len(s)==1:
    print(s)
else:
    if s[0]!='1':
        print(s[0])
    elif set(s)=={'1'}:
        print(1)
    else:
        for i in range(len(s)):
            if s[i]!='1':
                a=i
                if k<=a:
                    print(1)
                else:
                    print(s[i])
                break


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

using namespace std;

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

  string s;
  cin >> s;
  int n = 0;
  for (char c : s) {
    c -= '0';
    n += c;
  }
  cout << (n % 9 == 0 ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 3744
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, x;
	cin >> n >> x;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int ans = abs(a[0]-x);
	for (int i = 1; i < n; i++)
		ans = gcd(ans, abs(a[i]-x));
	cout << ans << endl;
	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    int a = 25 - N;
    string ans = "Christmas";
    REP(i, 0, a) {
        ans += " Eve";
    }
    cout << ans << endl;
}


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

int main(){
  int n;cin>>n;
  for (int i = 0; i < n; i++){
    int k,p;
    cin>>k>>p;
    if (k % p) {
      cout << k % p << endl;
    }else{
      cout << p << endl;
    }
  }
  return 0;
}

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

int n;
int b, r, f, v;

int main()
{
	cin >> n;
	int a[4][3][10] = {};
	for (int i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		 a[b-1][f-1][r-1] += v;
		 

	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				cout << ' ' << a[i][j][k];


			}
			cout << endl;
		}
		if (i == 3){ break; }
		cout << "####################" << endl;

	}
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <string.h>
#include <string>
#include <vector>
#include <array>

int main()
{
    char buffer[10];

    scanf("%s", buffer);

    if ((buffer[2] == buffer[3])
        && (buffer[4] == buffer[5]))
    {
        printf("Yes");
        return 0;
    }

    printf("No");
    return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;




long long int N,M,A[200020],num[200050]={},res=0;
long double L;
string a,b,c;

int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 0; i < N; i++){
        cin>>A[i];
        num[A[i]]++;
    }
    for(long long int i = 1; i <= N; i++){
        res+=num[i]*(num[i]-1)/2;
    }
    for(long long int i = 0; i < N; i++){
        cout<<res-num[A[i]]+1<<endl;
    }
}


Measured memory_bytes: 4736
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 1:
    if a[0] != 0:
        print(0)
        exit()
    a = a[1:]

for idx, i in enumerate(a):
    if n % 2 == 0:
        if (idx//2)*2 + 1 != i:
            print(0)
            exit()
    else:
        if ((idx//2)+1)*2 != i:
            print(0)
            exit()
    
print(divmod(pow(2, n//2),(10**9)+7)[1])

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
   string str="";
 string a,b;
   cin>>a>>b;
   int sa=a.length();
   int sb=b.length();
  int dp[sb+1][sa+1];
   for(int i=0;i<sa+1;i++)
     dp[0][i]=0;
     for(int i=0;i<sb+1;i++)
     dp[i][0]=0;
   for(int i=1;i<sb+1;i++)
   for(int j=1;j<sa+1;j++)
   {
     if(b[i-1]==a[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=sb;
   int j=sa;
   while(i>0&&j>0)
   {
   if(a[j-1]==b[i-1])
   {
   str+=a[j-1];
     i--;
     j--;
       continue;
   }
     if(dp[i-1][j]>dp[i][j-1])
       i--;
     else
       j--;

   }
   reverse(str.begin(), str.end());
   cout<<str;
 }


Measured memory_bytes: 35456
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def main():
    s = sys.stdin.readline().rstrip()
    if (s[0] == s[-1]) == (len(s) % 2 == 1):
        print "Second"
    else:
        print "First"

if __name__ == '__main__':
    main()


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

int main(){
    ll n;   cin >> n;
    map<string, ll> mp;
    for(int i=0; i<n; i++){
        string s;   cin >> s;
        sort(s.begin(), s.end());
        mp[s] += 1;
    }
    ll ans = 0;
    for(auto x: mp)
        ans += x.second*(x.second-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int main() {
	int c[3][3];
	int a[3];
	int b[3];
	int min;
	bool flag = false;
	for (int a = 0;a < 3;a ++) {
		for (int b = 0;b < 3;b++)
			cin >> c[a][b];
	}//数値の格納
	min = c[0][0];
	for (int d = 1;d < 3;d++) {
		if (c[0][d] < min)
			min = c[0][d];
	}//minを定義
	for (a[0] = 0;a[0] <= min;a[0]++) {
		for (int i = 0;i < 3;i++) {
			b[i] = c[0][i] - a[0];
		}
		a[1] = c[1][0] - b[0];
		a[2] = c[2][0] - b[0];
		if (a[1] + b[1] == c[1][1] && a[1] + b[2] == c[1][2] && a[2]+b[1]==c[2][1] && a[2]+b[2]==c[2][2]) {
			flag = true;
			break;
		}
		

	}
	if (flag)
		cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3668
#include <stdio.h>

int main(void){
  int a,b,c;

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

Measured memory_bytes: 2016
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		
		if (set.size() == n) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 98632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;

signed main() {
	cin >> s;
	if ((int)s.size() % 2) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 1; i < (int)s.size(); i += 2) {
		if (s[i - 1] != 'h' || s[i] != 'i') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main() {
  int s,s1,s2,s3;
  cin >> s;
  s1 = s / 100;
  s2 = (s-s1*100) / 10;
  s3 = s - s1*100 - s2*10; 
  cout << s1 + s2 + s3 << endl;
}


Measured memory_bytes: 256
'use strict'
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var k=input.pop();
  var result=(input.pop()-input.shift()<=k);
  var ans=result?'Yay!':':(';
  console.log(ans);
}

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


Measured memory_bytes: 7372
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
# include <stdio.h>
#include <bits/stdc++.h>

const int maxn = 3e5 + 111;

using namespace std;        

const int mod = 1e9 + 7;

long long n, ans;

set <long long> q;
int cntn;

void rec(int pos, long long last){
    if(last > n) return;
    int cnt = 0, cnt3 = 0, cnt5 = 0, cnt7 = 0;
    long long llast = last;
    
    while(llast){
        cnt3 |= (llast % 10 == 3);
        cnt5 |= (llast % 10 == 5);
        cnt7 |= (llast % 10 == 7);
        llast/=10;
        cnt++;
        
    }
    if( cnt3 && cnt5 && cnt7)
    q.insert(last);
    rec(pos + 1, last * 10 +7);
    rec(pos + 1, last * 10 +3);
    rec(pos + 1, last * 10 +5);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin>>n;
    long long nn = n;
    while(nn){
        nn/=10;
        cntn++;
    }
    //cout<<cntn;
	rec(1, 7);
	rec(1, 5);
	rec(1, 3);
	cout<<q.size();
}

Measured memory_bytes: 1536
import Control.Applicative ((<$>))
import Control.Monad
import Control.Monad.RWS.Strict
import qualified Data.IntMap as IM
import qualified Data.Set as S

type Time = Int

type AdjG = IM.IntMap [Int]
type State = (Time, IM.IntMap Bool)
type Log = S.Set (Bool, Int, Time)

main :: IO ()
main = do
  n <- readLn
  adjG <- fmap IM.fromList $ replicateM n $ do
    (u:_:vs) <- map read . words <$> getLine :: IO [Int]
    return (u,vs)
  let res = S.toList $ snd $ evalRWS (dfs n) adjG (1, IM.fromList $ zip [1..n] $ repeat False)

  forM_ [1..n] $ \i -> do
    putStrLn $ unwords $ map show $ (i:) $ map (\(_,_,t) -> t) $ filter (\(_,v,_) -> v == i) res

dfs :: Int -> RWS AdjG Log State ()
dfs n = forM_ [1..n] $ \v -> do
  fls <- snd <$> get
  when (not $ fls IM.! v) $ rec v

rec :: Int -> RWS AdjG Log State ()
rec v = do
  (t, fls) <- get

  when (not $ fls IM.! v) $ do
    us <- asks (IM.!v)
    tell $ S.singleton (False, v, t)
    put (t+1, IM.alter (fmap (const True)) v fls)
    mapM_ rec us
    (t, fls) <- get
    tell $ S.singleton (True, v, t)
    put (t+1, fls)
    return ()

Measured memory_bytes: 4676
#include <bits/stdc++.h>
//#define int long long
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

signed main()
{
    FAST_IO;

    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 1; j < m + 1; 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;
    string s1 = "";
    while (i > 0 && j > 0)
    {
        if (s[i - 1] == t[j - 1])
        {
            s1 = s1 + s[i - 1];
            i--;
            j--;
        }
        else
        {
            if (dp[i - 1][j] > dp[i][j - 1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    reverse(s1.begin(), s1.end());

    cout << s1;
    return 0;
}

Measured memory_bytes: 38872
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    
    if(k <= a){
        cout << 1 << endl;
        return 0;
    }
    
    if(a > b){
        cout << (((k - a) % (a - b) != 0)? k / (a - b) * 2 + 1 : (k - a) / (a - b) * 2 + 1) << endl;
    }
    else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

/*
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;cin>>n;
    cout<<ceil((double)n/2);
    return 0;
}
*/
/*
int a[4][4];
int mark[4][4];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(mark , 0 , sizeof(mark));
    for (size_t i = 0; i < 3; i++) {
        for (size_t j = 0; j < 3; j++) {
            cin>>a[i][j];
        }
    }
    int n,k;cin>>n;
    for (size_t i = 0; i < n; i++) {
        cin>>k;
        for (size_t i = 0; i < 3; i++) {
            for (size_t j = 0; j < 3; j++) {
                if(a[i][j] == k){
                    mark[i][j] = 1;

                }
            }
        }
    }
    ll int sum = 0;
    for (size_t i = 0; i < 3; i++) {
        sum = 0;
        for (size_t j = 0; j < 3; j++) {
            sum += mark[i][j];
        }
        if(sum == 3){
            cout<<"Yes";
            return 0;
        }
    }
    sum = 0;
    for (size_t i = 0; i < 3; i++) {
        sum = 0;
        for (size_t j = 0; j < 3; j++) {
            sum += mark[j][i];
        }
        if(sum == 3){
            cout<<"Yes";
            return 0;
        }
    }
    sum = mark[0][0] + mark[1][1] + mark[2][2];
    if(sum == 3 ){
        cout<<"Yes";
        return 0;

    }
    else if(mark[2][0] + mark[1][1] + mark[0][2] == 3){
        cout<<"Yes";
        return 0;
    }

    cout<<"No";
    return 0;
}
*/
int a[4];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;
    memset(a,-1,sizeof(a));
    int s[m+2],c[m+2];
    for (size_t i = 0; i < m; i++) {
        cin>>s[i]>>c[i];
        s[i]--;
        if(a[s[i]] != -1 && a[s[i]] != c[i] ){
            cout<<-1;
            return 0;
        }
        else{
            a[s[i]] = c[i];
        }

    }
    if(n==1 ){
        if(a[0] == -1){
            cout<<0;
        }
        else{
            cout<<a[0];
        }
    }
    else{
        if(a[0] == 0 ){
            cout<<-1;
            return 0;
        }
        else{
           for (size_t i = 0; i < n; i++) {
               if(a[i] == -1 &&  i != 0){
                   cout<<0;
               }
               else if(a[i] == -1 &&  i == 0){
                   cout<<1;
               }
               else{
                   cout<<a[i];
               }
           }
       }
    }
    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    elem_num = int(input())
    elems = list(map(lambda x: int(x), input().split()))
    print(" ".join([str(elem) for elem in elems]))  # Initial state.
    for i in range(1, elem_num):
        key = elems[i]
        j = i - 1
        while j >= 0 and elems[j] > key:
            elems[j + 1] = elems[j]
            j -= 1
        elems[j + 1] = key
        print(" ".join([str(elem) for elem in elems]))  # Each sorting steps.



Measured memory_bytes: 5608
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion

typedef long double ld;
const ld eps = 5e-7;
vector<pair<ld,ld>> XY;
ld g(ld x, ld y){
    ld res = 0;
    for(auto e:XY){
        chmax(res, hypot(e.first-x, e.second-y));
    }
    return res;
}

//xが決められた時、yの位置を三分探索で決め、そのときの半径を返す
ld f(ld x){
    ld up = 0, bot = 1000;
    ld up_val = g(x,up), bot_val = g(x,bot);
    REP(i,100){
    // while(abs(up_val-bot_val) > eps){
        ld mu = (up*2 + bot) / 3, mb = (up + bot*2) / 3;
        ld mu_val = g(x,mu), mb_val = g(x,mb);

        if(mu_val < mb_val) bot = mb, bot_val = mb_val;
        else up = mu, up_val = mu_val;

    }
    return up_val;
}

//xの位置を三分探索で決める
ld TsearchX(){
    ld left = 0, right = 1000;
    ld left_val = f(left), right_val = f(right);
    REP(i,100){
    // while(abs(left_val-right_val) > eps){
        ld ml = (left*2+right)/3, mr = (left+right*2)/3;
        ld ml_val = f(ml), mr_val = f(mr);

        if(ml_val < mr_val) right = mr, right_val = mr_val;
        else left = ml, left_val = ml_val;
    }
    return left_val;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i,N){
        ld x,y; cin >> x >> y;
        XY.emplace_back(x,y);
    }

    auto ans = TsearchX();

    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

int N;

int idx = 0;
long long all_value[199368];

long long process(int curr, int last_value, string curr_digit)
{
	if (curr == N)
	{
		all_value[idx] = stoll(curr_digit);
		idx++;
		return 1;
	}

	long long left = 0;
	long long right = 0;
	long long center = process(curr + 1, last_value, curr_digit + to_string(last_value));
	if (last_value > 0) left = process(curr + 1, last_value - 1, curr_digit + to_string(last_value - 1));
	if (last_value < 9) right = process(curr + 1, last_value + 1, curr_digit + to_string(last_value + 1));

	return left + right + center;
}

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

	//long long all_count = 0;
	for (int n = 1; n <= 10; n++)
	{
		N = n;
		//long long curr_cnt = 0;
		for (int i = 1; i <= 9; i++)
		{
			process(1, i, to_string(i));
		}

		//cout << curr_cnt << "\n";
		//all_count += curr_cnt;
	}

	//cout << all_count << "\n";

	sort(begin(all_value), end(all_value));

	int K;
	cin >> K;

	cout << all_value[K - 1];

	return 0;
}

Measured memory_bytes: 1920
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[M];
		int[] b = new int[M];
		int count = 0;
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i = 1; i <= N; i++) {
			for(int j = 0; j < M; j++) {
				if(a[j] == i) count++;
				else if(b[j] == i) count++;
			}
			System.out.println(count);
			count = 0;
		}

	}

}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>

#define swap(a, b) {int tmp;tmp = a;a=b;b=tmp;}

int main(){
	char str[1001];
	char cmd[100];
	int n;
	int i;
	int m,a,b;
	char p[1001];
	char *ptr;
	gets(str);
	scanf("%d", &n);
	for(i = 0;i < n; i++){
		scanf("%s", cmd);
		if(strcmp(cmd, "print")==0)m = 0;
		if(strcmp(cmd, "reverse")==0)m = 1;
		if(strcmp(cmd, "replace")==0)m = 2;
		switch(m){
			case 0:
				scanf("%d %d", &a, &b);
				for(;a<=b;a++){
					putchar(str[a]);
				}
				puts("");
			break;
			case 1:
				scanf("%d %d", &a, &b);
				for(;a<b;a++,b--){
					swap(str[a],str[b]);
				}
			break;
			case 2:
				scanf("%d %d %s", &a, &b, &p);
				for(ptr = p;a<=b;a++,ptr++){
					str[a] = *ptr;
				}
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 588
import fractions

a, b, c, d = map(int, input().split())

# cとdの最大公約数
g = fractions.gcd(c, d)

# cとdの最小公倍数
l = c * d // g

# cとdで割り切れないb以下の数の個数
# (全体) - (cの倍数の個数) - (dの倍数の個数) + (cの倍数かつdの倍数の個数)
x = b - b // c - b // d + b // l

# cとdで割り切れない(a-1)以下の数の個数
y = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // l
    
print(x - y)

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

int main() {
	string s;
	int maxi = 0, between, ans = 100000;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		between = 0;
		maxi = 0;
		for (int j = 0; j< s.size(); j++) {
			if (s[j] == s[i]) {
				maxi = max(maxi, between);
				between = 0;
			}
			else between++;
		}
		maxi = max(maxi, between);
		ans = min(maxi, ans);
	}
	cout << ans << endl;
}

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

int main(){
	int n, m,a,b,ans[50];
	cin >> n >> m;

	for (int i = 0; i < 50; i++) {
		ans[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		ans[a]++;
		ans[b]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  string s;
  cin >> N >> s;
  int cnt = 0;
  for(int i = 0; i < s.size() - 2; i++){
  if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
 
int binarySearch(int *,int,int);
int main(){   
  int i,n,q,S[N],T,c=0;
   
  scanf("%d",&n);
   
  for (i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
 
  scanf("%d",&q);
   
  for (i=0;i<q;i++){
    scanf("%d",&T);
    if (binarySearch(S,n,T)){
      c++;
    }
  }
   
  printf("%d\n",c);
  return 0;
}

int binarySearch(int S[],int n,int T){
    int left = 0;
    int right = n;
    int mid;
while(left < right){
  mid = (left + right) / 2;
  if(S[mid] == T) return mid;
  else if(T < S[mid]) right = mid;
  else left = mid + 1;
 }
  return 0;
}

Measured memory_bytes: 988
N = input()

ans = 0
all_nine_flg = True

for i in range(1,len(N)):
  if N[i] == "9":
    continue
  else:
    all_nine_flg = False
    break

sub = 0 if all_nine_flg else 1
print( int(N[0]) + 9*(len(N)-1) - sub)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat& A, mat& B){
    mat C(A.size(), vec(B[0].size(), 0));
    for(int i = 0; i < A.size(); ++i){
        for(int k = 0; k < B.size(); ++k){
            for(int j = 0; j < B[0].size(); ++j){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] % mod) % mod;
                while(C[i][j] < 0)  C[i][j] += mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size(), 0));
    for(int i = 0; i < A.size(); ++i){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1)   B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

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

    int n;
    ll k;
    cin >> n >> k;
    mat a(n, vec(n));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
    }

    a = pow(a, k);
    
    ll res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            res = (res + a[i][j]) % mod;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<typename Mono,typename Ope>
struct LazySegmentTree{
    using F = function<Mono(Mono,Mono)>;
    using G = function<Mono(Mono,Ope)>;
    using H = function<Ope(Ope,Ope)>;
    int n,height;
    F f; G g; H h; Mono tu; Ope eu;
    vector<Mono> node;
    vector<Ope> lazy;

    LazySegmentTree(F f,G g,H h,Mono tu,Ope eu):f(f),g(g),h(h),tu(tu),eu(eu){}

    void init(vector<Mono> v){
        int n_ = (int)(v.size());
        n = 1;height = 0;
        while(n < n_) n <<= 1,++ height;
        node.assign(2*n,tu);
        lazy.assign(2*n,eu);
        for(int i=0;i<n_;i++) node[i+n] = v[i];
        for(int i=n-1;i>0;i--) node[i] = f(node[i<<1],node[i<<1|1]);
    }

    Mono eval(int k){
        return (lazy[k]==eu)?node[k]:g(node[k],lazy[k]);
    }

    void prop(int k){
        if(lazy[k]==eu) return;
        lazy[k<<1] = h(lazy[k<<1],lazy[k]);
        lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        node[k] = eval(k);
        lazy[k] = eu;
    }

    void prop_above(int k){
        for(int i=height;i>0;i--) prop(k>>i);
    }

    void recalc_above(int k){
        while(k>0){
            k >>= 1;
            node[k] = f(eval(k<<1),eval(k<<1|1));
        }
    }

    void set_val(int k,Mono x){
        k += n;
        prop_above(k);
        node[k] = x;
        lazy[k] = eu;
        recalc_above(k);
    }

    void update(int l,int r,Ope x){
        if(l >= r) return;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);
        int a = l,b = r;
        ++ r;
        while(l < r){
            if(l&1) lazy[l] = h(lazy[l],x), ++l;
            if(r&1) --r, lazy[r] = h(lazy[r],x);
            l >>= 1;r >>= 1;
        }
        recalc_above(a);
        recalc_above(b);
    }

    Mono query(int l,int r){
        if(l >= r) return tu;
        l += n;r += n-1;
        prop_above(l);
        prop_above(r);++r;
        Mono vl = tu,vr = tu;
        while(l < r){
            if(l&1) vl = f(vl,eval(l)), ++l;
            if(r&1) --r, vr = f(eval(r),vr);
            l >>= 1;r >>= 1;
        }
        return f(vl,vr);
    }
};


int main(){
    auto f = [](int a,int b){
        return min(a,b);
    };
    auto g = [](int a,int x){
        if(x==INT_MAX) return a;
        else return x;
    };
    auto h = [](int x,int y){
        if(y==-1) return x;
        else return y;
    };
    LazySegmentTree<int,int> seg(f,g,h,INT_MAX,-1);

    int n;
    cin >> n;
    vector<int> a(n,INT_MAX);
    seg.init(a);

    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t==0){
            int l,r,x;
            cin >> l >> r >> x;
            seg.update(l,r+1,x);
        }else{
            int l,r;
            cin >> l >> r;
            cout << seg.query(l,r+1) << endl;
        }
    }


    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

template<typename T> class SegmentTree {
private:
	typedef function<T(T, T)> F;
	int n;
	T d0;
	vector<T> vertex;
	F f;
	F g;
public:

	SegmentTree(int sourceN, F f, F g, T d = 0) :d0(d), f(f), g(g) {
		init(sourceN);
	}
	void init(int sourceN) {
		n = 1;
		while (n < sourceN) n *= 2;
		vertex.resize(2 * n - 1, d0);
	}
	void update(int i, T x) {
		int k = i + n - 1;
		vertex[k] = g(vertex[k], x);
		while (k > 0) {
			k = (k - 1) / 2;
			vertex[k] = f(vertex[2 * k + 1], vertex[2 * k + 2]);
		}
		return;
	}
	T query(int l, int r) {
		T vl = d0, vr = d0;
		l += n - 1;
		r += n - 1;
		for (; l <= r; l /= 2, r = r / 2 - 1) {
			if (l % 2 == 0) vl = f(vl, vertex[l]);
			if (r & 1) vr = f(vr, vertex[r]);
		}
		return f(vl, vr);
	}
};


static SegmentTree<ll> SegmentTreeMax(int n) {
	SegmentTree<ll> t(n, [=](ll left, ll right) {return max(left, right); },
		[=](ll _, ll value) {return value; });
	return t;
}

static SegmentTree<ll> SegmentTreeRangeMinimumQuery(int n) {
	SegmentTree<ll> t(n, [=](ll left, ll right) {return min(left, right); },
		[=](ll _, ll value) {return value; },
		1e18);
	return t;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> cs(n,0), ss(n,0), fs(n,1);
	rep(i, n-1) {
		cin >> cs[i] >> ss[i] >> fs[i];
	}
	vector<ll> ans;
	rep(i, n) {
		ll t = 0;
		for (int j = i; j < n-1; j++) {
			chmax(t, ss[j]);
			if (t % fs[j]) {
				t = (t / fs[j] + 1) * fs[j];
			}
			t += cs[j];
		}
		ans.push_back(t);
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int k;
   cin >> k;
   string s;
   int count = 0;
   s = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
   vector<int> vec;
   for(int i = 0;i < s.length();i++) {
       if(s[i]==',') {
        int j = i-1;
        int count = 1;
        int num = 0;
        while(j!=-1&&s[j]!=',') {
            num += (s[j]-'0')*count;
            j--;
            count*=10;
        }
        vec.push_back(num);
       }
   }
   vec.push_back(51);

   cout << vec[k-1] << endl;
}

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

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

int main() {
  ll S;
  cin >> S;
  vector<ll> fac(MAX,1), inv(MAX,1), finv(MAX,1);
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
  ll p = S/3;//最大項数
  ll q = S;//余剰
  ll ans = 0;
  for (int i = 1; i <= p; i++) {
    q -= 3;
    ll a = fac[i+q-1] * (finv[q] * finv[i-1] % MOD);
    ans = (ans+a) % MOD;
  }
  cout << ans%MOD << endl;
}

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

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

string S;
int Q;

void solve() {
    bool isRev = false;
    vector<char> left, right;
    REP (q, Q) {
        int T, F;
        char C;
        cin >> T;
        if (T == 1) {
            isRev ^= 1;
            continue;
        } else {
            cin >> F >> C;
            if (isRev ^ (F == 2)) { // ひっくり返っている xor 先頭
                right.push_back(C);
            } else {
                left.push_back(C);
            }
        }
    }
    if (isRev) {
        swap(left, right);
        reverse(ALL(S));
    }
    reverse(ALL(left));
    FORE (c, left) cout << c;
    cout << S;
    FORE (c, right) cout << c;
    cout << endl;
}

int main() {
    cin >> S >> Q;
    solve();
}

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

int data[2][33];//0:light, 1:push
int n, c;
int memo[33][1<<17];

int input(int p ,int q){
  for(int i=15, a; i>-1; i--) cin >> a, data[p][q] |= a<<i;
}

int solve(int p, int bit){
  
  if(p == n) return 0;
  if(~memo[p][bit]) return memo[p][bit];

  int ans = 0;
  for(int i=0;i<c;i++){
    int cnt = __builtin_popcount(bit&data[1][i]);
    int next = (bit^data[1][i])&bit;
    ans = max(solve(p+1, next|data[0][p+1])+cnt, ans);
  }

  return memo[p][bit] = ans;
}

int main(){

  while(cin >> n >> c){
    if(!n && !c) break;

    memset(data, 0, sizeof(data));
    memset(memo, -1, sizeof(memo));

    for(int i=0;i<n;i++) input(0, i);
    for(int i=0;i<c;i++) input(1, i);
    
    cout << solve(0, data[0][0]) << endl;
  }

}

Measured memory_bytes: 18068
#include<cstdio>

using namespace std;

int N, M;
int a[100100];
int Q;

int ids[100100];
int cnts[100100];
int num;
int rev_ids[100100];

void init(){
	for(int i = 0; i < N; ++i){
		ids[i] = -1;
		cnts[i] = 0;
	}
	num = 0;
}

bool used[100100];

void restore(int *a, int L, int N){
	for(int i = 0; i < N; ++i) used[i] = false;
	for(int i = 0; i < L; ++i) used[a[i]] = true;
	int c = L;
	for(int i = 0; i < N; ++i){
		if(!used[i]) a[c++] = i;
	}
}

int fi[100100];
int la[100100];

bool solve(){
	init();
	for(int i = Q - 1; i >= 0; --i){
		int x = a[i];
		if(ids[x] == -1){
			ids[x] = num++;
			rev_ids[ids[x]] = x;
		}
		int id = ids[x];
		//printf("%d\n", id);
		if(id > 0 && cnts[id - 1] == cnts[id]){
			//nothing
		} else {
			if(cnts[id] < M){
				cnts[id]++;
			}
		}
	}
	bool flg = true;
	for(int i = 0; i < N; ++i){
		if(cnts[i] != 0 && cnts[i] != M){
			flg = false;
			break;
		}
	}
	if(flg) return true;
	/*for(int i = 0; i < N; ++i){
		printf("%d %d\n", rev_ids[i], cnts[i]);
	}
	printf("\n");*/
	int l1 = 0, l2 = 0;
	for(int i = 0; i < N; ++i){
		if(cnts[i] > 0){
			fi[i] = rev_ids[i];
			l1++;
		}
		
		if(cnts[i] == M){
			la[i] = rev_ids[i];
			l2++;
		}
	}
	restore(fi, l1, N);
	restore(la, l2, N);
	/*for(int i = 0; i < N; ++i){
		printf("%d %d\n", fi[i], la[i]);
	}*/
	for(int i = 0; i < N; ++i){
		if(fi[i] != la[i]) return false;
	}
	return true;
}

void input(){
	scanf("%d%d", &M, &N);
	scanf("%d", &Q);
	for(int i = 0; i < Q; ++i){
		scanf("%d", a + i);
		a[i]--;
	}
}

int main(){
	input();
	bool flg = solve();
	if(flg) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    sort(ALL(v));
    OUT(v.back() - v.front())

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
        int i,x,y;
        i = 1;
        while(i <= 3000){
                scanf("%d %d",&x,&y);
                if(x == 0 && y == 0)
                        break;
                else if(x >= y)
                        printf("%d %d\n",y,x);
                else
                        printf("%d %d\n",x,y);
                i++;
        }
        return 0;
}


Measured memory_bytes: 2036
import bisect
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
r=[0]*(10**5+2)
for i in range(n):
    r[l[i]]+=1
for i in range(10**5+1):
    r[i+1]+=r[i]
ok=10**6
ng=0
while ok-ng>1:
    x=(ok+ng)//2
    k=0
    for i in range(n):
        if x-l[i]<0:
            k+=n
        elif x-l[i]>10**5+1:
            k+=0
        else:
            k+=n-r[x-l[i]]
    if k>=m:
        ng=x
    else:
        ok=x
#print(ok)
p=[0]*(n+1)
for i in range(n):
    p[i+1]=p[i]+l[i]
ans=0
mi=0
for i in range(n):
    li=bisect.bisect_left(l,ok-l[i])
    ans+=l[i]*(n-li)+p[n]-p[li]
    mi+=n-li
print(ans-(mi-m)*ok)


Measured memory_bytes: 15824
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
using ll = long long;
using namespace std;
constexpr int MAX = 14000;

int h, w, a[88][88], b[88][88], c[88][88];
bitset<MAX * 2> dp[88][88];

int main()
{
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) cin >> a[i][j];
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) cin >> b[i][j];
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) c[i][j] = abs(a[i][j] - b[i][j]);
	
	dp[1][1][MAX + c[1][1]] = 1;
	dp[1][1][MAX - c[1][1]] = 1;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			dp[i][j] |= dp[i - 1][j] << c[i][j];
			dp[i][j] |= dp[i - 1][j] >> c[i][j];
			dp[i][j] |= dp[i][j - 1] << c[i][j];
			dp[i][j] |= dp[i][j - 1] >> c[i][j];
		}
	}
	
	int ans = MAX * 2;
	for (int i = 0; i < MAX * 2; ++i) if (dp[h][w][i]) {
		ans = min(ans, abs(i - MAX));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 24448
X, N = map(int, input().split())
p = list(map(int, input().split()))
P = set(p)

dif = 10**18
for d in range(1000):
    tmp = X - d
    if not tmp in P:
        print(tmp)
        exit()
    tmp = X + d
    if not tmp in P:
        print(tmp)
        exit()

Measured memory_bytes: 9188