akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 3 != 0 && a % 3 != 0 && b % 3 != 0)
		cout << "Impossible" << endl;
	else cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}
func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return string(str)
}

func round(f float64) float64 {
	return math.Floor(f + .5)
}

func main() {
	defer out.Flush()
	sc.Split(bufio.ScanWords)
	r := nextInt()
	var result float64
	result = float64(r) * float64(2) * 3.14

	fmt.Fprintln(out, fmt.Sprintln(result))
}


Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n,k;
	cin>>n>>k;
	set<ll> s;
	map<ll,ll> m;
	while(k--)
	{
		ll x;
		string st;
		cin>>x>>st;
		if(st=="AC")
		{
			s.insert(x);
		}
		else
		{
			auto it=s.find(x);
			if(it==s.end())
			{
				m[x]++;
			}
		}
	}
	ll out=0;
	for(auto it=s.begin();it!=s.end();it++)
	{
		out+=m[(*it)];
	}
	cout<<s.size()<<" "<<out<<"\n";
}

Measured memory_bytes: 11136
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	int Bucket[N];
	for (int i = 0; i < N; ++i)
		Bucket[i] = 0;
	for (int i = 0; i < N; ++i)	{
		int tmp;
		scanf("%d", &tmp);
		Bucket[tmp - 1]++;
	}
	sort(Bucket, Bucket + N);
	int answer = 0;
	for (int i = distance(Bucket, upper_bound(Bucket, Bucket + N, 0)); i < N - K; ++i)
		answer += Bucket[i];
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;

char c1[100005];
char c2[100005];
int l1,l2,s1[30],s2[30],num1[30][100005];
ll ans=0;

int main(void){
	scanf("%s",c1+1);
	scanf("%s",c2+1);
	l1=strlen(c1+1);
	l2=strlen(c2+1);
	for(int i=1;i<=l1;i++)
	s1[c1[i]-'a'+1]++;
	for(int i=l1;i>=1;i--){
		for(int j=1;j<=26;j++)
		if(c1[i]-'a'+1==j)num1[j][i-1]=i;
		else num1[j][i-1]=num1[j][i];
	}
	for(int i=1;i<=l2;i++)
	s2[c2[i]-'a'+1]++;
	for(int i=1;i<=26;i++)
	if(s2[i]!=0&&s1[i]==0){
		printf("-1");
		return 0;
	}
	int now=1; 
	while(1){
		int i,maxn=0; 
		for(i=num1[c2[now]-'a'+1][0];i<=l1;){
			if(i!=0)maxn=i;
			if(i==0){
				if(now<=l2)maxn=l1;
				break;
			}
			now++;
			if(now>l2)break;
			if(i==l1)break;
			i=num1[c2[now]-'a'+1][i];
		}
		ans+=maxn+0ll;
		if(now>l2)break;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 10496
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 1){
            System.out.println("Hello World");
        }else{
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N, M, K;
	cin >> N >> M >> K;

	vector<bool> can(N*M+1, false);

	for (ll h = 0; h <= M; ++h)
	{
		for (ll w = 0; w <= N; ++w)
		{
			can[h*w + (M-h)*(N-w)] = true;
		}
	}

	std::cout << (can[K] ? "Yes" : "No")<< std::endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define Mod 1000000007
using namespace std;
int n;
int f[5010][5010];
int siz[5010];
int g[5010];
struct Edge{
	int v,nxt;
}e[10010];int tot;
int first[5010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	return ;
}
int tmp[5010];
void dfs(int u,int lst)
{
	f[u][1]=1;
	siz[u]=1;
	for(int i=first[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==lst)continue;
		dfs(v,u);
		for(int j=1;j<=siz[u];j++)
			for(int k=1;k<=siz[v];k++)
			{
				tmp[j]=(tmp[j]-(long long)f[v][k]*g[k]%Mod*f[u][j]%Mod+Mod)%Mod;
				tmp[j+k]=(tmp[j+k]+(long long)f[v][k]*f[u][j])%Mod;
			}
		siz[u]+=siz[v];
		for(int j=1;j<=siz[u];j++)
		{
			f[u][j]=tmp[j];
			tmp[j]=0;
		}
	}
	return ;
}
int main()
{
	scanf("%d",&n);
	g[0]=1;
	for(int i=2;i<=n;i++)
		g[i]=(long long)g[i-2]*(i-1)%Mod;
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	dfs(1,0);
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+(long long)f[1][i]*g[i])%Mod;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> S(n);
  vector<int> count(4);
  rep(i,n){
    cin >> S[i];
    if(S[i]=="AC"){
      count[0]++;
      continue;
    }
    if(S[i]=="WA"){
      count[1]++;
      continue;
    }
    if(S[i]=="TLE"){
      count[2]++;
      continue;
    }
    if(S[i]=="RE"){
      count[3]++;
      continue;
    }
  }
  cout << "AC x "<<count[0]<<endl;
  cout << "WA x "<<count[1]<<endl;
  cout << "TLE x "<<count[2]<<endl;
  cout << "RE x "<<count[3]<<endl;



}


Measured memory_bytes: 6420
//============================================================================
// Name        : sample1.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int S;
	cin >> S;
	int h = S / 3600, ha = S % 3600;
	int m = ha / 60, s = ha % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
import java.util.* ;

public class Main{
  public static void main(String args[]){
   	Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if((A-B)<C){
      System.out.println(C-(A-B));
    }else{
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int X,A,B; cin>>X>>A>>B;
  string ans="dangerous";
  if(B-A<=0)
    ans="delicious";
  else if(B-A<=X)
    ans="safe";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
// ABC069B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int l;
	l = s.size();
	l = l - 2;
	cout << s[0] << l << s[l + 1] << endl;
	
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
using namespace std;

int main() {
	int r, D, x;
	long long S[11];
	cin >> r >> D >> x;
	S[0] = x;
	for (int i = 1; i <= 10; i++) {
		S[i] = r * S[i - 1] - D;
	}
	for (int i = 1; i <= 10; i++) {
		cout << S[i] << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,a[100010],b=0,c=0;
  cin>>n;
  fr(i,n) cin>>a[i];
  sort(a,a+n);
  fr(i,n){
    b+=a[i];
    if(i==n-1) break;
    if(2*b<a[i+1]) c=i+1;
  }
  cout<<n-c<<endl;
}

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

#define ll long long

const int INF = 1000000;

void chmin(ll& a, ll b){ 
  if (a > b) a = b;
}

int main() {
  int H, W;
  cin >> H >> W;
  
  ll cost[10][10];
  
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> cost[i][j];
    }
  }
  
  ll dp[10][10];
  
  
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      dp[i][j] = cost[i][j];
    }
  }

  
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        chmin(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  
  
  
  vector<ll> numcount(10, 0);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int x;
      cin >> x;      
      if (x != -1) numcount[x]++;
    }
  }
  
  
  ll ans = 0;
  for (int i = 0; i < 10; i++) {
    ans += numcount[i] * dp[i][1];
  }
  
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 3628
n = int(input())
s = [0]*n
p = [0]*n
w = [0]*n
for i in range(n):
    s[i], p[i] = input().split()
    p[i] = int(p[i])
    w[i] = [s[i], p[i],i+1]

w = sorted(w, key=lambda x: x[1], reverse=True)
w = sorted(w, key=lambda x: x[0])

for i in range(n):
    print(w[i][2])

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const int mod=1000000007;    
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
  int n;cin>>n;
  ll a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int cnt=0;
  ll sum=0;
  rep(i,n-1){
    sum+=a[i];
    if(2*sum>=a[i+1])cnt++;
    else cnt=0;
    }
  cout<<cnt+1<<endl;
  return 0;
  }
       

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z = 1;
  while(1) {
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    if (x > y) {
      z = x;
      x = y;
      y = z;
    }
    cout << x << " " << y << endl;
  }
}


Measured memory_bytes: 3080
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

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

int const N = 500 + 20 , M = 3e4 + 20 ;
int n , a[N][N] ;
bool np[M] ;
vector <int> vec ;

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

inline void add (int &a , int b) {
	a = a / gcd(a , b) * b ;
}

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

	cin >> n ;

	if (n == 2) {
		cout << "4 7\n23 10\n" ;
		return 0 ;
	}

	np[0] = np[1] = 1 ;
	for (int i = 2 ; i < M ; i ++) {
		if (np[i]) continue ;

		vec.push_back(i) ;

		for (int j = 2 * i ; j < M ; j += i) np[j] = 1 ;
	}

	for (int i = 0 ; i < n ; i ++)
		for (int j = 0 ; j < n ; j ++)
			if (((i + j) & 1) == 0) 
				a[i][j] = vec[(i + j) >> 1] * vec[((i - j + n) >> 1) + n] ;

	for (int i = 0 ; i < n ; i ++)
		for (int j = 0 ; j < n ; j ++)
			if (((i + j) & 1) == 1) {
				a[i][j] = 1 ;
				if (i > 0) add(a[i][j] , a[i - 1][j]) ;
				if (i < n - 1) add(a[i][j] , a[i + 1][j]) ;
				if (j > 0) add(a[i][j] , a[i][j - 1]) ;
				if (j < n - 1) add(a[i][j] , a[i][j + 1]) ;
				a[i][j] += 1 ;
			}

	for (int i = 0 ; i < n ; i ++) {
		for (int j = 0 ; j < n ; j ++) cout << a[i][j] << ' ' ;
		cout << '\n' ;
	}
}

Measured memory_bytes: 5248
on= input()

on = on.split()
 
if (on[0] != on[1] and on[0] != on[2] and on[1] != on[2]):
    print("No")
elif (on[0] == on[1] and on[0] == on[2] and on[1] == on[2]):
    print("No")

else:
  print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;
	double ans = 0;
#define For(N,i) for(int i = 0; i < N; i++)


int main(){
	string S,T;
	cin>>S>>T;
	cout<<T<<S<<endl;






}

Measured memory_bytes: 256
# frozen_string_literal: true

# Generated by AtcoderGreedy on 2018-05-06
# ARC081 C
# Your code here

_ = gets.chomp

$A = gets.chomp.split(' ').map(&:to_i)

$a_hash = {}
$A.each do |i|
  $a_hash[i] ||= 0
  $a_hash[i] += 1
end

long, short = $a_hash.max_by(2) { |k, v| v > 1 ? k : 0 }

if long[1] >= 4
  puts long[0]**2
elsif long[1].to_i > 1 && short[1] > 1
  puts long[0] * short[0]
else
  puts 0
end


Measured memory_bytes: 18576
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    tp = 0
    ans = 1
    
    for i in range(1,n):
        before = a[i-1]
        after = a[i]

        if tp == 0:
            if before < after:
                tp = 1
            elif before > after:
                tp = -1
        elif tp == 1:
            if before > after:
                ans += 1
                tp = 0
        elif tp == -1:
            if before < after:
                ans += 1
                tp = 0
        
    print(ans)



main()            


Measured memory_bytes: 93424
/*input
6
4 2 9 7 1 5
*/
 
// author - Madhav Thakker
 
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace std;
 
#define ll long long
#define ld long double
#define int ll
#define endl '\n'

typedef pair<int, int> pii; 
typedef pair<ld, ld> pdd;
 
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define all(c) c.begin(), c.end() 
#define tr(container, it )\
for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(aint(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 
#define all(c) c.begin(), c.end() 
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
const int MOD = 1e9+7;
 
 
int fast_pow(int a, int b){
	int res = a, ret = 1;
	while(b>0){
		if(b%2)
			ret = (ret*res)%MOD;
		res = (res*res)%MOD;b/=2;
	}
	return ret;
}
 
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';
// str = to_string(n)
// stoi , stoll, stol
// sort(arr, arr+n, greater<int>());
// fill(prefix.begin(), prefix.end(), 0);
// 
// 
 
 
 
////
const int maxN = 3e3+7;
int arr[maxN];
int dp[maxN][maxN][2];  // 0 - max X - Y

////

int n;
int getans(int l, int r, int turn){
	if(l == r){
		return arr[l];
	}
	if(l > r or r < 0){
		return 1e10;
	}
	if(dp[l][r][turn]!=-1){
		return dp[l][r][turn];
	}
	if(turn==1){
		dp[l][r][1] =  max(arr[l] - getans(l+1, r, turn*1), arr[r] - getans(l, r-1, turn*1));
	}
	else if(turn == -1){
		dp[l][r][0] =  max(arr[l] - getans(l + 1, r, turn*1), arr[r] - getans(l, r-1, turn*1));
	}
	return dp[l][r][turn];
}

signed main(){
 
	fastio;
	time_t time_t1, time_t2;
	time_t1 = clock();
 
	////////////////////////////////

	int t = 1;
	// cin >> t ;

	while(t--){
		memset(dp, -1, sizeof dp);
		cin >> n;
		for (int i = 0; i < n; ++i){
			cin >> arr[i];
		}
		int ans = getans(0, n-1, 1);
		cout << ans << endl;
	}
 	
	///////////////////////////////
	// 
 
	time_t2 = clock();
	// cerr << "time taken :" << time_t2 - time_t1 << endl;
 
	return 0;
}


Measured memory_bytes: 141696
K,A,B=map(int,input().split())

if A>=B:
    print(1+K)

else:
    if K<=A-1:
        print(1+K)

    else:
        x=K-(A-1)

        if x%2==0:
            ANS=A+(B-A)*(x//2)
        else:
            ANS=A+(B-A)*(x//2)+1

        print(max(ANS,1+K))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if(op == '?') break;
    switch(op){
    case '+':
      cout << a+b;
      break;
    case '-':
      cout << a-b;
      break;
    case '*':
      cout << a*b;
      break;
    case '/':
      cout << a/b;
      break;
    default:
      break;
    }
    cout << '\n';
  }
}

Measured memory_bytes: 1160
using System;
using System.Linq;

class Program
{
    static int N;
    static int Ma;
    static int Mb;
    static int[] a;
    static int[] b;
    static int[] c;

    static void Main()
    {
        /*入力を受け取る*/
        int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = inputs[0];
        Ma = inputs[1];
        Mb = inputs[2];
        a = new int[N];
        b = new int[N];
        c = new int[N];
        for (int i = 0; i < N; i++)
        {
            inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a[i] = inputs[0];
            b[i] = inputs[1];
            c[i] = inputs[2];
        }

        /*
            DP[i][p,q] : i番目までの商品で、Aをp(g),Bをq(g)買う最小金額(不可能なら∞)
        というDPを行う
         */
        int[][,] DP = new int[N + 1][,];
        int a_sum = a.Sum();
        int b_sum = b.Sum();
        for (int i = 0; i <= N; i++)
            DP[i] = new int[a_sum + 1, b_sum + 1];
        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= a_sum; j++)
                for (int k = 0; k <= b_sum; k++)
                    DP[i][j, k] = (int)1e8;
        DP[0][0, 0] = 0;
        for (int i = 1; i <= N; i++)
        {
            int ai = a[i - 1];
            int bi = b[i - 1];
            int ci = c[i - 1];
            for (int p = 0; p <= a_sum; p++)
            {
                for (int q = 0; q <= b_sum; q++)
                {
                    try
                    {
                        DP[i][p, q] = Math.Min(DP[i - 1][p, q], DP[i - 1][p - ai, q - bi] + ci);
                    }
                    catch
                    {
                        DP[i][p, q] = DP[i - 1][p, q];
                    }
                }
            }
        }

        /*DP[N][Ma * i,Mb * i] (i = 1,2,3,...)の中の最小値が答え*/
        int ans = int.MaxValue;
        for (int i = 1; ; i++)
        {
            try
            {
                ans = Math.Min(ans, DP[N][Ma * i, Mb * i]);
            }
            catch { break; }
        }
        Console.WriteLine(ans >= (int)1e5 ? -1 : ans);
    }
}

Measured memory_bytes: 21344
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,cev,b,a[li],k;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	if(n>=9 || m>=9){printf(":(\n");return 0;}
	printf("Yay!");
	return 0;
}


Measured memory_bytes: 256
// ABC052B - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A * B >= C * D) {
		cout << A * B << endl;
	} else {
		cout << C * D << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int n, a;
	cin >> n >> a;
	int max_num = 51;
	int max_card = 51;
	int max_price = max_num * max_card;
	vector<vector<int64_t>> dp(max_card, vector<int64_t>(max_price,0));
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		int64_t xi;
		cin >> xi;
		for (int card = i; card >=0; --card) {
			for (int price = 0; price < max_price; ++price) {
				if (price + xi >= max_price)break;
				dp[card + 1][price + xi] += dp[card][price];
			}
		}
	}
	int64_t sum = 0;
	for (int card = 1; card <= n; ++card) {
		sum += dp[card][card*a];
	}
	cout << sum << endl;
	return 0;
}


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

ll power(ll x,ll n)
{
	ll res =1;
	while(n>0)
	{
		if(n%2==1)
	res=res*x;
	x=x*x;
	n=n/2;
	}
	return res;
	
}
int main(){
 
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i,j;
    cin>>n;
    int x=log10(n);
    int x1=n/power(10,(int)log10(n)),x2=n%10;
    ll a[10][10]={0};
    for(i=1;i<=n;i++)
    {
    	a[i/power(10,(int)log10(i))][i%10]++;
    	
    	
	}
	ll sum=0;
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=9;j++)
		{
			sum=sum+a[i][j]*a[j][i];
		}
	}
	cout<<sum<<"\n";
    
    
    
    
    
    
    
    
}


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

int main(void){
  int k;
  while(cin>>k,k){
    vector<int> c(k*(k-1)/2);
    int sum=0;
    for(int i=0;i<k*(k-1)/2;++i){
      cin>>c[i];
      sum+=c[i];
    }
    cout<<sum/(k-1)<<endl;
  }
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int k, n;
    cin >> k >> n;
    int maior = 0;
    int ant;
    cin >> ant;
    int prim = ant;
    fo(i, n - 1) {
        int a;
        cin >> a;
        maior = max(a - ant, maior);
        ant = a;
    }
    
    maior = max(maior, (k - ant) + prim);

    cout << k - maior << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
score = sum(c) - max(c)
num = [-1] * N
que = deque()
que.append(0)
i = 0
while que:
    v = que.pop()
    if num[v] != -1:
        continue
    num[v] = c[i]
    i += 1
    for nv in adj[v]:
        que.append(nv)
print(score)
print(*num)


Measured memory_bytes: 12040
class Store(val a : Long, val b : Long)

fun main(args: Array<String>){
    var(n, m) = readLine()!!.split(" ").map(String::toLong)
    var l = mutableListOf<Store>()
    for(i in 1..n){
        val (a, b) = readLine()!!.split(" ").map(String::toLong)
        l.add(Store(a, b))
    }
    l.sortBy { it.a }
    var sum = 0L
    l.forEach{
        sum += it.a * listOf(it.b, m).min()!!
        m = listOf(0, m - it.b).max()!!
    }
    println(sum)
}


Measured memory_bytes: 82332
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();

        long res = 0;
        if(A%2 ==1){
            if(B%2 == 1){
                res =  ((B -(A+1) +1)/2) % 2;
                res ^= A;
            }else{
                res =  ((B-1 -(A+1) +1)/2) % 2;
                res ^= A;
                res ^= B;
            }
        }else{
            if(B%2 == 1){
                res =  ((B -A +1)/2) % 2;
            }else{
                res =  ((B-1 -A +1) / 2) %2;
                res += B;
            }
        }

        System.out.println(res);

    }

}


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

void copyStringArray(char **, char **, int);

main() {

  int n;
  char **o; //入力された配列
  char **b; //BubbleSort
  char **s; //SelectionSort
  char *tmp;

  int i, j, minj;



  scanf("%d", &n);

  o = (char **)malloc(sizeof(char *) *n);
  for( i=0; i<n; i++) {
    o[i] = (char *)malloc(sizeof(char) *3);
  }
  b = (char **)malloc(sizeof(char *) *n);
  for( i=0; i<n; i++) {
    b[i] = (char *)malloc(sizeof(char) *3);
  }
  s = (char **)malloc(sizeof(char *) *n);
  for( i=0; i<n; i++) {
    s[i] = (char *)malloc(sizeof(char) *3);
  }

  for( i=0; i<n; i++) {
    scanf("%s", o[i]);
  }

  for( i=0; i<n; i++) { 
    strcpy(b[i], o[i]);
    strcpy(s[i], o[i]);
  }

  
  //BubbleSort
  for( i=0; i<n; i++) {
    for( j=n-1; j>i; j--) {
      if( b[j][1] < b[j-1][1] ) {
	tmp = b[j];
	b[j] = b[j-1];
	b[j-1] = tmp;
      }
    }
  }
  
  //SelectionSort
  for( i=0; i<n; i++) {
    minj = i;
    for( j=i; j<n; j++) {
      if( s[j][1] < s[minj][1] ) {
	minj = j;
      }
    }
    if(s[i][1] != s[minj][1]) {
      tmp = s[i];
      s[i] = s[minj];
      s[minj] = tmp;
    }
  }


  for( i=0; i<n-1; i++) {
    printf("%s ", b[i]);
  }
  printf("%s\nStable\n", b[n-1]);


  for( i=0; i<n-1; i++) {
    printf("%s ", s[i]);
  }
  printf("%s\n", s[n-1]);
  for( i=0; i<n; i++) {
    if(strcmp(b[i], s[i]) != 0) {
      printf("Not stable\n");
      break;
    }
  }
  if(i == n){
    printf("Stable\n");
  }


  for( i=0; i<n; i++) {    
    free(o[i]);
    free(b[i]);
    free(s[i]);
  }
  free(o);
  free(b);
  free(s);
  
  return 0;

}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    ll n,k;
    cin >> n >> k;
    vl a;
    a = vl(n);
    rep(i,n) cin >> a[i];
    ll s = accumulate(all(a), 0ll);

    vl div;
    for(ll x=1; x*x <= s; x++){
        if(s % x == 0){
            div.push_back(x);
            if(x*x != s) div.push_back(s/x);
        }
    }

    ll ans = 1;
    for(auto d : div){
        vl r(n), rr(n);
        rep(i,n) r[i] = a[i] % d;
        sort(all(r));
        rep(i,n) rr[i] = d-r[i];
        rep(i,n-1) r[i+1] += r[i];
        rrep(i,n-1) rr[i] += rr[i+1];
        rep(i,n-1){
            if(max(r[i], rr[i+1]) <= k){
                ans = max(ans, d);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

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

int Q, DP[1005][1005];
string X, Y;

int Solve(){
  int N = X.length(), M = Y.length();
  fill((int*)DP, (int*)(DP + N + 1), 0);

  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= M; j++){
      if (X[i - 1] == Y[j - 1]){
        DP[i][j] = DP[i - 1][j - 1] + 1;
      }else{
        DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
      }
    }
  }
  cout << DP[N][M] << endl;
  return 0;
}

int main(){
  cin >> Q;
  for (int i = 0; i < Q; i++){
    cin >> X >> Y;
    Solve();
  }

  return 0;
}



Measured memory_bytes: 7060
class AtCoDeer:
    def __init__(self):
        self.pos = {"x": 0, "y": 0}
        self.time = 0

    def move(self, to_x, to_y):
        self.pos = {"x": to_x, "y": to_y}
        return self.pos

    def can_move(self, t, to_x, to_y):
        dx = abs(to_x-self.pos.get("x"))
        dy = abs(to_y-self.pos.get("y"))
        total_move = dx + dy
        dt = t - self.time

        if dt < total_move:
            return False
        elif (dt-total_move) % 2 != 0:
            return False
        else:
            self.move(to_x, to_y)
            self.time = t
            return True


def main():
    n = int(input())
    at_co_deer = AtCoDeer()

    while(at_co_deer.can_move(*[int(x) for x in input().split()])):
        n -= 1
        if n == 0:
            break
    
    # 計画破綻判明後のデータ読み捨て
    for i in range(n-1):
        input()

    if n == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*
願はくは花の下にて春死なんそのきさらぎの望月のころ（西行 1118-1190）
--This is old Japanese poem expressing the desire to die under tree on the full moon night.(written by Saigyo)
In my research, there is possibility that the tree may be seg-tree.
*/

/*Coding Space*/
int main(){
  int n; cin >> n;
  vi in(n);
  rep(i,n)  cin >> in[i];
  int now_pos = 0;
  ll ans = 0;
  for(int k = 1;now_pos != n;){
       if(now_pos == 0){
        ans += in[now_pos] - 1;
        now_pos++;
        k++;
       }else if(in[now_pos] < k){
         now_pos++;
       }else if(in[now_pos] == k){
         k++; now_pos++;
       }else{
         ans += (in[now_pos]-1)/k;
         now_pos++;
       }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=200005;
int n,k;
char ch[N];
int main(){
	n=read(); k=read();
	if(k>(2*n))k=2*n+((k&1)?1:2);
	scanf("%s",ch);
	int pos=0,flag=1;
	for(int i=0;i<n;i++)ch[i]-='A';
	while(k--){
		if(ch[pos]^flag){ch[pos]^=1; } else{pos=(pos+1)%n; flag^=1; }
	}
	for(int i=pos;i<n;i++)putchar((ch[i]^flag^1)+'A');
	for(int i=0;i<pos;i++)putchar((ch[i]^flag^1)+'A');
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define ill long long
#define rep(i, a, b) for(ill i = (ill)(a); i < (ill)(b); i++)
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  string s, t, r;
  cin >> s >> t >> r;
  if(s[(int)s.size()-1] == t[0] && t[(int)t.size()-1] == r[0]) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 3628
n = int(input())
k = int(input())
res = 10**10
for i in range(1 << n):
    total = 1
    for j in range(n):
        if (i >> j) & 1 == 1:
            total *= 2
        else:
            total += k
    if res > total:
        res = total
print(res)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int K,X;
	cin >> K >> X;
	int left = X - K + 1;
	if(left < (-1000000))left = -1000000;
	int right= X + K - 1;
	if(right> 1000000)right = 1000000;
	for(int i = left ;i<=right;i++){
		cout << i << " ";
	}
	cout << endl;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;
  ll n = s.size();

  vvll dp(n + 1, vll(2, 0));
  rep(i, n) {
    ll d = s[i] - '0';
    dp[i + 1][0] = dp[i][0] + d;
    if (d > 0) dp[i + 1][1] = dp[i][0] + d - 1;
    if (i > 0) chmax(dp[i + 1][1], dp[i][1] + 9);
  }
  ll ans = max(dp[n][0], dp[n][1]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int a = 0,b = 0,c = 0;
int d = 0;
int main(){
    scanf("%d %d %d", &a, &b, &c);
 for (a;a <= b;a++) {
		if (c % a == 0) {
			d++;
		}
	}
	printf("%d\n",d);
}


Measured memory_bytes: 2764
from collections import defaultdict

縦, 横, _, *点 = map(int, open(0).read().split())

あー = defaultdict(int)
for y, x in zip(*[iter(点)]*2):
    y -= 1; x -= 1
    for i in range(9):
        あー[y - 1 + i//3, x - 1 + i%3] += 1

答 = [0] * 10
for [y, x], c in あー.items():
    答[c] += 横 - 1 > x > 0 < y < 縦 - 1
答[0] = (縦 - 2) * (横 - 2) - sum(答)
print(*答)

Measured memory_bytes: 178444
def is_prime(n):
    '''
    素数判定する
    '''
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True


Q = int(input())
prime_list = [False] * 100001
L = []
R = []
for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
a = [0] * 100001
prime_list[2] = True
for i in range(1, 100001):
    prime_list[i] = is_prime(i)
    if prime_list[i] and prime_list[(i+1)//2]:
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
for i in range(Q):
    ans = a[R[i]] - a[L[i]-1]
    print(ans)


Measured memory_bytes: 13528
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;

int main(void){
	int n, m;
	cin >> n >> m;
	int out[3];
	vector<int> s, c; 
	REP(i, 3) out[i] = -1;
	int keta, num;
	REP(i, m){
		cin >> keta >> num;
		s.push_back(keta);
		c.push_back(num);
	}
	REP(i, m){
		keta = s[i];
		num = c[i];
		if (keta == 1 && num == 0){
			if (n == 1){
				out[2] = 0;
			}else{
				cout << -1 << endl;
				return 0;
			}
		}
		else if (out[2-n+keta] == -1){
			out[2-n+keta] = num;
		}
		else if(num != out[2-n+keta]){
			cout << -1 << endl;
			return 0;
		}else{

			out[2-n+keta] = num;
		}
	}
	FOR(i, 3 - n, 3){
		num = out[i];
		if (num == -1){
			if (i == 3-n){
				if (n > 1){
					cout << 1;
				}else{
					cout << 0;
				}
			}else{
				cout << 0;
			}
		}else{
			cout << num;
		}
	}
	cout << endl;
	return 0;


}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int ans[100000] = {0};
  int st = 0;
  int la = 0;
  char now = 'R';
  int mid = 1;
  for(int i = 0; i < s.length(); i++){
    if(i == s.length()-1 || now != s[i+1]){
      if(i!= s.length()-1 && s[i+1] == 'L'){
        mid = i+1;
        now = 'L';
      }
      else{
        la = i;
        if((mid-st)%2){
          ans[mid-1] += (mid-st+1)/2;
          ans[mid] += (mid-st-1)/2;
        }
        else{
          ans[mid-1] += (mid-st)/2;
          ans[mid] += (mid-st)/2;
        }
        if((la-mid+1)%2){
          ans[mid-1] += (la - mid)/2;
          ans[mid] += (la - mid+2)/2;
        }
        else{
          ans[mid-1] += (la-mid+1)/2;
          ans[mid] += (la - mid+1)/2;
        }
        now = 'R';
        st = i+1;
      }
    }

  }
  for(int i = 0 ; i < s.size(); i++) cout << ans[i] << " ";
  cout << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        String s=Integer.toString(Integer.parseInt(String.valueOf(a),10),b);
        System.out.println(s.length());
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int N, M, K, Q, W, H, R, C;
string S;
char table[100][100];
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;

    REP(i, 50) {
        REP(j, 100) {
            table[i][j] = '.';
            table[i + 50][j] = '#';
        }
    }
    A--, B--;

    for (int i = 0; i < 50; i += 2) {
        if (B == 0) break;
        for (int j = 0; j < 50; j += 2) {
            if (B == 0) break;
            table[i][j] = '#';
            B--;
        }
    }

    for (int i = 0; i < 49; i += 2) {
        if (A == 0) break;
        for (int j = 0; j < 50; j += 2) {
            if (A == 0) break;
            table[i + 51][j] = '.';
            A--;
        }
    }

    cout << "100 100\n";
    REP(i, 100) {
        REP(j, 100) { cout << table[i][j]; }
        cout << endl;
    }
    return 0;
}


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

int n , d , x , y , ans;

int main(){
	scanf("%d %d" , &n , &d);
	while(n--){
		scanf("%d %d" , &x , &y);
		if(sqrt(1.0 * x * x + 1.0 * y * y) <= d) ans++;
	}
	printf("%d" , ans);
	return 0;
}

Measured memory_bytes: 3824
import java.util.*;

public class Main{

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    int x = sc.nextInt();
	    int y = sc.nextInt();
	    if(x==0 && y==0) break;

	    int[] appear = new int[1000001];
	    Arrays.fill(appear, -1);
	    int a = 0, b = 0;
	    for(int i=0;;i++){
		x = x%y;
		if(appear[x]!=-1){
		    a = appear[x];
		    b = i-appear[x];
		    if(x==0) b = 0;
		    break;
		}else{
		    appear[x] = i;
		}
		x *= 10;
	    }

	    System.out.println(a+" "+b);
	}
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

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

using ll = long long int;
using vec = vector<ll>;

int n;

vec add(vec a, vec b){
    for(int i=0;i<n;i++){
        a[i] += b[i];
    }
    return a;
}

vec mul(vec a, ll k){
    for(auto &x : a){
        x *= k;
    }
    return a;
}

vec solve(ll a, ll b, int p){
    if(a==0 || b==0) return vec(n,0);
    if(a>=n) return add(vec(n,b*(a/n)), solve(a%n, b, p));
    else if(b>=n) return add(vec(n,a*(b/n)), solve(a, b%n, p));
    vec imos(n*3+1), res(n);
    for(int i=0;i<b;i++){
        imos[p+i]++;
        imos[p+a+i]--;
    }
    for(int i=0;i<n*3;i++){
        imos[i+1] += imos[i];
    }
    for(int i=0;i<n;i++){
        res[i] = imos[i]+imos[i+n]+imos[i+n*2];
    }
    return res;
}

void print_v(vec v){
    for(int i=0;i<n;i++){
        cout << v[i] << " \n"[i==n-1];
    }
}

vector<vec> layer;

int main(){
    ll X, Y, Z, A, B, C;
    cin >> X >> Y >> Z >> A >> B >> C >> n;
    layer.resize(n+1);
    layer[0] = vec(n,0);
    for(int i=0;i<n;i++){
        vec sum(n);
        sum = add(sum, solve(X-A-1, Y-B, (i+1)%n));
        sum = add(sum, solve(A+1, Y-B-1, (i+1)%n));
        sum = add(sum, solve(A, B+1, (i+1)%n));
        sum = add(sum, solve(X-A, B, (i+1)%n));
        sum[i]++;
        layer[i+1] = add(layer[i], sum);
    }
    vec ans;
    ans = mul(layer[n], (Z-C)/n);
    ans = add(ans, layer[(Z-C)%n]);
    ans = add(ans, mul(layer[n],C/n));
    ans = add(ans, add(layer[C%n+1], mul(layer[1],-1)));
    print_v(ans);
    return 0;
}


Measured memory_bytes: 10792
fn input1<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn main() {
    let n: usize = input1().unwrap();
    let s: String = input1().unwrap();
    let mut count = 0;
    let mut prev = ' ';
    for c in s.chars() {
        if c == prev {
            continue;
        } else {
            count += 1;
        }
        prev = c;
    }
    println!("{}", count);
}


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

using namespace std;

int main(){
    int N,check1=0,count=0;
    int d[100000];
    cin>>N;
    int halfN=N/2-1;
    for(int i=0;i<N;i++) cin >>d[i];
    sort(d,d+N);
    cout<<d[N/2]-d[N/2-1]<<endl;
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

typedef long long ll;

ll n,m,k;
ll a,b;

int main() {
    fast;
    cin >> n;
    if (n % 10 == 9 or n / 10 == 9) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if 13 <= a:
        print(b)
    elif 6 <= a <= 12:
        print(b // 2)
    elif a <= 5:
        print(0)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main()
{
	int m, n, r, t, u, i, j;
	cin >> m >> n;
	for (i = r = 0; i < m; i++)
	{
		for (j = u = 0; j < n; j++)
		{
			cin >> t;
			if (t == 1)
				u++;
		}
		if (r < u)
			r = u;
	}
	cout << r << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int dp[105][100005];
int w[10000],v[10000];
signed main(){
  int a,b;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>w[i]>>v[i];
  }
  for(int i=1;i<=a;i++){
    for(int j=0;j<=b;j++){
      if(w[i-1]<=j) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  cout<<dp[a][b]<<"\n";
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    vector<bool> v(n, 1);
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        v[a] = 0;
    }
    while(v.size() != 1){
        vector<bool> u = v;
        v.clear();
        for(int i = 0; i < u.size(); i += 2){
            if(u[i] & u[i + 1]) ans++;
            v.push_back(u[i] | u[i + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3112