akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {
    int s;
    cin>>s;
    int* a = {};
    a=(int*)malloc(1000000);
    if(!a) return 1;
    a[0]=s;
    int tmp;
    int cnt1=0;
  	int cnt2=0;
    int cnt4=0;
    int i=0;
    while(cnt1!=2||cnt2!=2||cnt4!=2) {
        if(a[i]%2==0) a[i+1]=a[i]/2;
        else if(a[i]%2!=0) a[i+1]=3*a[i]+1;

        if(a[i]==4) {
            cnt4++;
        }
        if(a[i]==2) {
              cnt2++;
          }
        if(a[i]==1) {
              cnt1++;
          }
        if(cnt1==2||cnt2==2||cnt4==2) {
            cout<<i+1<<endl;
            break;
        }
        i++;
    }
    free(a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k,d[10];
bool c[10];
int main(void){
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>d[i];
        c[d[i]]=true;
    }
    while(true){
        ll m=n;
        bool x=true;
        while(m!=0){
            ll D=m%10;
            m=m/10;
            if(c[D]){
                x=false;
            }
        }
        if(x){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }

}


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

int main(){
    string s, t;
    cin >> s >> t;
    int N = s.size(), M = t.size();
    s += s;
    bool ok;
    for(int i = 0; i <= 2*N - M; i++){
        ok = true;
        for(int j = 0; j < M; j++){
            if(s[i+j] != t[j]) ok = false;
        }
        if(ok) break;
    }    
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m,h[310];
ll f[310][310];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	m=n-m;
	rep(i,1,n) h[i]=read();
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	rep(i,1,n)
	{
		rep(j,1,min(i,m))
		{
			rep(k,0,i-1)
				f[i][j]=min(f[i][j],f[k][j-1]+max(0,h[i]-h[k]));
		}
	}
	ll ans=1e18;
	rep(i,1,n) ans=min(ans,f[i][m]);
	if (ans>=1e18) ans=0;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int a[300010];
bool check(int l,int r){
	int maxx=0,minn=0x7fffffff,i,j;
	for(i=l;i<=r;++i){maxx=max(a[i],maxx);minn=min(a[i],minn);}
	if(maxx!=r || minn!=l)  return false;
	int x=0,y=0;
	for(i=l;i<=r;i=i+2){
		if(x<a[i] && y<a[i])  y=a[i];
		else{
			if(x<a[i])  x=a[i];
			else  return false;
		}
	}
	return true;
}
int main(){
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;++i)  scanf("%d",&a[i]);
	for(i=1;i<=n;++i){
		if((i&1)^(a[i]&1)){printf("No\n");return 0;}
	}
	for(i=1;i<=n-2;++i){
		if(a[i]==i)  continue ;
		j=i;
		while(j<=n-2){
			if(a[j+1]!=j+1)  break ;
			if(a[j+2]==j+2)  break ;
			j+=2;
		}
		if(!check(i,j)){printf("No\n");return 0;}
		i=j;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)


//ABC048_a
int main() {
	string A[10];

	rep(i, 3) {
		cin >> A[i];
	}
	cout << "A" << A[1][0] << "C" << endl;

}


Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline())

s = []
for _ in range(n):
    s.append(int(stdin.readline()))

s.sort()

s_without_10s = list(filter(lambda x: x % 10 != 0, s))

maximum_result = sum(s)
if maximum_result % 10 == 0:
    if s_without_10s:
        maximum_result -= s_without_10s[0]
    else:
        maximum_result = 0

print(maximum_result)


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

int main(){
    int a, b;
    cin >> a >> b;

    int A, B;
    A = a;
    B = b;

    for (int i = 0; i < b-1; i++){
        A = A * 10 + a;
    }

    for (int i = 0; i < a-1; i++){
        B = B * 10 + b;
    }

    string X = to_string(A);
    string Y = to_string(B);

    cout << min(X, Y) << endl;
}


Measured memory_bytes: 256
var primeNxt = new Array(1000000);

function primeGenerator()
{
    var p, fact, m;
    var maxN = 1002001;
    var primePrv = new Array(1000000);

    // Initial
    for(p=2;p<=maxN;++p){
        primeNxt[p] = p + 1;
        primePrv[p] = p - 1;
    }
    primePrv[2] = 0;
    primeNxt[maxN] = 0;
    
    // Make prime table (primeNxt)
    for(p=2;p*p<=maxN;p=primeNxt[p]){
        for(fact=p;p*fact<=maxN;fact=primeNxt[fact]){
            for(m=p*fact;m<=maxN;m*=p){
                primeNxt[primePrv[m]] = primeNxt[m];
                primePrv[primeNxt[m]] = primePrv[m];
            }
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function(input){
    primeGenerator();
    input.trim().split('\n').forEach(function(val){
        var N = parseInt(val);
        var cnt = 1;
        if( N == 1 ){
            console.log(0);
        }
        else if( N == 2 ){
            console.log(1);
        }
        else{
            for(var i=3;i<=N;i=primeNxt[i]){
               ++cnt;
            }
            console.log(cnt);
        }
    });
});

Measured memory_bytes: 72144
#include<iostream> 
#include<string>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
using namespace std;

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

    if((abs(a-b)<= d) && (abs(b-c)<=d)){
        cout<<"Yes"<<endl;
    }else if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

const int N = 2005;
int A[N];
ll dp[N][N][2];

ll solveDp(int ind,int prev,int bit,int n) {
    if(ind==n) {
        int r = 1;
        if(bit==0) {
            r = -1;
        }
        return r*abs(A[ind]-A[prev]);
    }
    ll &ret= dp[ind][prev][bit];
    if(ret!=-1) {
        return ret;
    }

    ret = solveDp(ind+1,prev,bit,n);
    ret= max(ret, -solveDp(ind+1,ind,bit^1,n));
    return ret;
}

void solve() {
    int n;
    scanf("%d",&n);
    n+=2;
    for(int i=1;i<=n;++i) {
        scanf("%d",&A[i]);
    }
    memset(dp,-1,sizeof(dp));
    printf("%lld\n", solveDp(3,2,1,n));
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

Measured memory_bytes: 63104
s = input()
n = len(s)
cnt= 0
for i in range(2**(n-1)):
    done = 0
    for j in range(n-1):
        if bin(i)[2:].zfill(n-1)[j] == '1':
            cnt += int(s[done:j+1])
            done = j+1
    cnt += int(s[done:n])
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<int> nodeCount;


// 木上の探索
// v: 現在探索中の頂点、p: v の親 (v が根のときは -1)
void dfs(const Graph &G, int v, int p=-1) {
	for (auto new_v : G[v]) {
		if (new_v == p) continue; // nv が親 p だったらスルー
		nodeCount[new_v] += nodeCount[v];
		dfs(G, new_v, v); // v は新たに new_v の親になります
	}
}


int main() {

	// 頂点数 (木なので辺数は N-1 で確定)
	int n; cin >> n;
	
	nodeCount.assign(n, 0);

	int q; cin >> q;
	
	Graph G(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	for (int i = 0; i < q; ++i) {
		int p, x;
		cin >> p >> x;
		nodeCount[--p] += x;
	}

	int root = 0;
	dfs(G, root);


	for (int i = 0; i < n; ++i)
		cout << nodeCount[i] << " ";
	return 0;
}

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

int main()
{
  	int n,x,cnt;
  
 	cin >> n >> x;

  	while(n != 0 || x != 0){
      cnt = 0;
      for(int i = 1;i <= n;i++){
       for(int j = i + 1;j <= n;j++){
        for(int k = j + 1;k <= n;k++){
          if(i + j + k == x)cnt++;
        }
       }
      }
      cout << cnt << endl;
      
      cin >> n >> x;
    }
  	
}


Measured memory_bytes: 3088
n=gets.strip.to_i
ll=gets.strip.split.map(&:to_i).sort

result=0
(0..n-2).each do |i|
  k=i+2
  a=ll[i]
  (i+1..n-1).each do |j|
    b=ll[j]
    while (k<n && ll[k]<a+b)
      k+=1
    end

    result += (k-j-1)
  end
end

p result



Measured memory_bytes: 2040
num = input()
num_ABCD = num.split()
num_A = int(num_ABCD[0])
num_B = int(num_ABCD[1])
num_C = int(num_ABCD[2])
num_D = int(num_ABCD[3])
if num_B <= num_C or num_D <= num_A:
    print(0)
else:
    if num_A <= num_C and num_B <= num_D:
        print(num_B - num_C)
    elif num_A <= num_C and num_B >= num_D:
        print(num_D - num_C)
    elif num_A >= num_C and num_B <= num_D:
        print(num_B - num_A)
    elif num_A >= num_C and num_B >= num_D:
        print(num_D - num_A)

Measured memory_bytes: 3064
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[10005][105][2],d;
void llialize(){
	for(ll i=0;i<10005;i++){
		for(ll j=0;j<105;j++){
			dp[i][j][0]=-1;
			dp[i][j][1]=-1;
		}
	}
}
ll digit(ll inx,ll sum,ll tem,vector<ll> &v){
	if(inx<0){
		if(sum%d==0)return 1LL;
		return 0LL;
	}
	if(dp[inx][sum][tem]!=-1&&tem==0)
	return dp[inx][sum][tem];
	ll k,res=0;
	k=(tem==1?v[inx]:9);
	for(ll dig=0;dig<=k;dig++){
		ll ntem=(dig==v[inx])?tem:0;
		res=(res+digit(inx-1,(sum+dig)%d,ntem,v))%hell;
	}
	if(!tem)dp[inx][sum][tem]=res;
	return res;
}
ll solve(string &x){
	vi v;
	for(ll i=x.size()-1;i>=0;i--){
		v.pb(x[i]-'0');
	}
	return digit(v.size()-1,0,1,v);
}
int main(){
	ios;
	ll t=1;
	llialize();
	while(t--){
		string r;cin>>r>>d;
		cout<<(solve(r)-1+hell)%hell<<endl;
	}
}

Measured memory_bytes: 17792
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int k;cin >> k;bool good=false;bool check=true;
vector<int> r(k);
vector<int> c(k);
for(int i=0;i<k;i++)cin >> r[i] >> c[i];
vector<int> row(8);vector<int> column(8);
for(int i=0;i<8;i++){row[i]=i;column[i]=i;}
do{
check=true;good=true;
for(int i=0;i<k;i++){if(!check)break;check=false;for(int j=0;j<8;j++)if(r[i]==row[j]&&c[i]==column[j]){check=true;break;}}
if(!check)continue;
for(int i=0;i<8;i++)for(int j=i+1;j<8;j++)if(abs(row[i]-row[j])==abs(column[i]-column[j])){good=false;break;}
if(good)break;
}while(next_permutation(column.begin(),column.end()));
vector<vector<char>> board(8,vector<char>(8,'.'));
for(int i=0;i<8;i++)board[row[i]][column[i]]='Q';
for(int i=0;i<8;i++){for(int j=0;j<8;j++)cout << board[i][j];cout << endl;}
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    int n;
    cin >> n;
    multiset<double> left;
    multiset<double> right;
    rep(i, n){
        double a, b;
        cin >> a >> b;
        left.insert(a);
        right.insert(b);
    }
    if(n % 2 == 0){
        auto itr = left.begin();
        for(int i=0; i<n/2-1; i++) ++itr;
        double l = *itr;
        ++itr;
        l = l + *itr;
        l = l/2;
        itr = right.begin();
        for(int i=0; i<n/2-1; i++) ++itr;
        double r = *itr;
        ++itr;
        r = r + *itr;
        r = r/2;
        double res = (r-l)*2+1;
        cout << (ll)res << endl;
    }else{
        auto itr = left.begin();
        for(int i=0; i<n/2; i++) ++itr;
        double l = *itr;
        itr = right.begin();
        for(int i=0; i<n/2; i++) ++itr;
        double r = *itr;
        double res = r-l + 1;
        cout << (ll)res << endl;
    }
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int a,b,k;
  cin >> a >> b >> k;

  REP(i,k) {
    if (i%2 == 0) {
      if(a%2 == 1) {
        a--;
      }
      b += a/2;
      a /= 2;
    } else {
      if(b%2 == 1) {
        b--;
      }
      a += b/2;
      b /= 2;
    }
  }

  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
<?php
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);

$n = $s[0];

$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);

$p_list = $s;

$findnum = 0;
for ($i = 1; $i < $n - 1; $i++) {
    $pib = $p_list[$i-1];
    $pi = $p_list[$i];
    $pia = $p_list[$i+1];
    if ($pib < $pi && $pi < $pia) {
        $findnum++;
    } else if ($pia < $pi && $pi < $pib) {
        $findnum++;
    }
}

echo($findnum);

Measured memory_bytes: 4728
#include <stdio.h>
#include <stdlib.h>
 
int main(){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
 
  if( abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d) ){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
 
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans=0;
  map<string,int> d;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(d.count(s)){
      continue;
    }
    else{
      d[s]=1;
      ans+=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 19176
n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=100000000000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-2*absmin)
  else:
    print(sum)

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;

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

int x[100005];

int main()
{
    int n;
    cin>>n;
    if(n<1200){
        cout<<"ABC"<<endl;
    }
    else {
        cout<<"ARC"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        long ans = (h * w + 1) / 2;
        if (h == 1 || w == 1) {
            ans = 1;
        }
        System.out.println(ans);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23636
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

ll area(int x1, int y1, int x2, int y2, int x3, int y3) {
  int a = x2 - x1, b = y2 - y1;
  int c = x3 - x1, d = y3 - y1;
  return abs(a * (ll) d - b * (ll) c);
}

ll f(int a, int b) {
  a = abs(a), b = abs(b);
  while (b) {
    int ret = a % b;
    a = b;
    b = ret;
  }
  return a;
}

ll cost(int x1, int y1, int x2, int y2, int x3, int y3) {
  ll a = area(x1, y1, x2, y2, x3, y3);
  ll g = f(x2 - x1, y2 - y1) + f(x3 - x1, y3 - y1) + f(x3 - x2, y3 - y2);
  return a - g + 2;
}

ll bad_consider = 0;

ll solve(int w, int h, int k) {
  ll sum = 0;
  int t = min(w, h);
  int z = max(w, h);
  for (int x1 = 1; x1 < w; x1++) {
    for (int y = h - 1; y >= 1; y--) {
      if (x1 * (ll) (h - y) > k + 3 * z) {
        break;
      }
      ll val = x1 * (ll) (h - y) - f(y, x1);
      ll mx = min((ll) w - 1, max(0ll, (k - val) / y));
      sum += 2 * mx;
      auto eval = [&] (int x2) {
        if (val + x2 * (ll) y - f(h - y, x2) - f(x2 - x1, h) <= k) {
          sum += 2;
        }
      };
      if (x1 > mx) {
        eval(x1);
      }
      for (int x2 = mx + 1; x2 < w; x2++) {
        if (val + x2 * (ll) y - 2 * t > k) {
          break;
        }
        if (x2 != x1)
          eval(x2);
      }
    }
  }
  return sum;
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int w, h, k;
  cin >> w >> h >> k;
  k = 2 * (k - 1);
  cout << solve(w, h, k) + solve(h, w, k) << '\n';
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<pair<ll,ll>> LR(N);
  rep(i,N) cin >> LR[i].first >> LR[i].second;
  sort(all(LR));
  //rep(i,N) cout << LR[i].first << " " << LR[i].second << endl;
  vector<pair<ll,ll>> up(N+1);
  vector<pair<ll,ll>> down(N+1);
  up[0] = {1, 1e9};
  ll L=1, R=1e9;
  rep(i,N){
    L = max(L, LR[i].first);
    R = min(R, LR[i].second);
    up[i+1] = {L,R};
  }
  down[N] = {1, 1e9};
  L = 1; R = 1e9;
  rep(i,N){
    L = max(L, LR[N-i-1].first);
    R = min(R, LR[N-i-1].second);
    down[N-i-1] = {L,R};
  }
  //rep(i,N+1) cout << up[i].first << " " << up[i].second << " " << down[i].first << " " << down[i].second << endl;
  ll ans = 0;
  rep(i,N-1){
    ans = max(ans, max((ll)0, up[i+1].second-up[i+1].first+1)+max((ll)0, down[i+1].second-down[i+1].first+1));
  }
  //cout << ans << endl;
  rep(i,N){
    ans = max(ans, max((ll)0, min(up[i].second, down[i+1].second)-max(up[i].first, down[i+1].first)+1)+LR[i].second-LR[i].first+1);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
N, Y = map(int, input().split())

tf = False

for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y:
            print(i, j, k)
            tf = True
            break
    else:
        continue
    break

if tf is False:
    print(-1,-1,-1)


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a=n%3;
  int ans;
  
  if(a!=3){
    ans=(n-(n%3))/3;
  }
  else{
    ans=n%3;
  }
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
//atoi() = char to int
// stoi() = int to char
//string g(1,"1"); char to string
//f[stoi(g)] = '0';
//cout.precision(14);
//
ll power(ll x,ll y);

int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
	    {
			string s; cin >> s;
			if(s[2]==s[3] and s[4]==s[5])
			cout <<"Yes\n";
			else cout <<"No\n";		
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    cin >> N;
    vector<int> b(N);
    REP(i, N) {
        cin >> b[i];
    }
    vector<int> res;
    int n = N;
    REP(i, N) {
        FORR(j, -1, n) {
            if (j == -1) {
                cout << -1 << endl;
                return 0;
            }
            if (b[j] == j + 1) {
                b.erase(b.begin() + j);
                res.emplace_back(j + 1);
                --n;
                break;
            }
        }
    }
    REV(res);
    for (auto &i : res) {
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;
string a;
void replace(int m,int n,string b)//m????§???????n?????¢???,??????????????????????????¨?????¨??´?????????????\????????????¶?????±????????\????????\

{
	int k=0;
	for(int i=m;i<=n;i++)//??±??????????????????????????§?????\???????????????????????????.
		a[i]=b[k++];




}
	
	
	
	void reverse(int m,int n)
{
	for(int i=n;i>m;i--)
	{		char b;
			b=a[i];//????????°?????¬??????????????¨char

			a[i]=a[m];//??????????????????????????¶????????¬?????¬?????????????????\m??????,??????????????§?????????.
			a[m]=b;//???????????¬??\?°±?????????????¬???????????¬?????????¬
			m++;
	}
			

			




}
void print(int m,int n)
{
	for(int i=m;i<=n;i++)
		cout<<a[i];
	cout<<endl;



}










int main()
{
	string b,c;
	int m,n,k;
	cin>>a;
	cin>>k;
	for(int i=0;i<k;i++)//k?¬???????
	{
		cin>>c;
		if(c=="replace")//????????¨switch????????????
			{
				cin>>m>>n>>b;
			replace(m,n,b);
			
		}
		if(c=="reverse")
			{
				cin>>m>>n;
			reverse(m,n);
		
		}
		if(c=="print")
		{
			cin>>m>>n;
			print(m,n);
			
		}

	
	
	
	}
	
	
}
	

Measured memory_bytes: 3204
#include <stdio.h>

int main(void){
    int m,f,r;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        if(m == -1 || f == -1 || m+f < 30){
            printf("F\n");
        }else if(m + f >= 80){
            printf("A\n");
        }else if(m+f >= 65 && m+f < 80){
            printf("B\n");
        }else if(m+f >= 50 && m+f <65){
            printf("C\n");
        }else if(m+f >= 30 && m+f < 50){
            if(r >= 50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int num=0,pos=0;
    while(s.find("ABC",pos)!=s.npos){
        pos=s.find("ABC",pos)+1;num++;
    }
    cout<<num<<endl;
}

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

vector<int>pes,color,ces,sz;
vector<ll>points;

void dfs(int u, int z){
	color[u]=z;
	sz[color[u]]++;
	points[color[u]]+=ces[u];
	int v = pes[u];
	if(color[v]==-1)dfs(v,z);
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;ll k;
	cin>>n>>k;
	pes=ces=sz=vector<int>(n+1);
	color.resize(n+1,-1);
	points.resize(n+1);

	for(int i=1;i<=n;i++){
		cin>>pes[i];
	}
	for(int i=1;i<=n;i++){
		cin>>ces[i];
	}
	int z = 0;
	for(int i=1;i<=n;i++){
		if(color[i]==-1){
			dfs(i,++z);
		}
	}
	ll ans=-1e10;
	for(int i =1;i<=n;i++){
		int u=i;
		u=pes[u];
		ll tmp=0;
		for(int len=1;len<=sz[color[i]];len++){
			if(len>k)break;

			u=pes[u];
			tmp+=ces[u];
			ans=max(ans,tmp);
			ll foo=(k-len)/sz[color[i]];
			ans=max(ans,tmp+foo*points[color[i]]);
		}
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define ll  long long
#define ld  long double
#define endl "\n"
#define ull  unsigned long long
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define vi   vector<ll>
#define INF 1000000000
#define M ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
	M
	ll n,k,dp[100001]={};
	vi v;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll in; cin>>in; v.pb(in);
	}
	dp[0]=0;
	for(int i=1;i<=n;i++)
		dp[i]=INF;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
		if(i+j<n) dp[i+j]=min(dp[i+j],dp[i]+abs(v[i]-v[i+j]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 2168
#!/usr/bin/env python3
def main():
    _ = int(input())
    P = [int(x) for x in input().split()]

    res = P[0]
    ans = 0
    for p in P:
        if p <= res:
            ans += 1
            res = p
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32232
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let (n, a, b) = {
        let line = read_vec::<usize>();
        (line[0], line[1], line[2])
    };
    let vec: Vec<usize> = read_vec();
    let mut result = 0 as usize;
    let mut prev = vec[0];
    for i in 1..n {
        let current = vec[i];
        if (current - prev) * a <= b {
            result += (current - prev) * a;
        } else {
            result += b;
        }
        prev = current;
    }
    println!("{}", result);
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 6396
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))

import numpy as np
import math

n = ii()

sq = math.ceil(math.sqrt(n))

ans = n+1
for i in range(1, sq+1):
    if n%i==0 and i+n//i < ans:
        ans = i+n//i


print(ans-2)

Measured memory_bytes: 13488
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long i,j,t,a,b,n,c,x,y,m,prev,sum;
    t=1;
    // cin>>t;
    while(t--)
    {
       string s;
       cin>>a>>b;
       cout<<max(0L,a-b);
    }
}

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

int main(){
	int ans=0,a=0;
	rep(i,3){
		char k; cin>>k;
		if(k=='R'){
			a++; 
			//cout<<a<<endl;
		}
		else{ ans=max(a,ans); a=0;}
	}
	ans=max(a,ans);
	cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cassert>
#define F first
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef pair<int,bool> IB;
typedef pair<IB,int> P;//P(IB(cnt,1 or 0),prev)

int main(){
  int n;
  while(true){
    scanf("%d",&n);
    if(n == 0)break;
    P p[n+2];
    int now = 1,cnt = 0;
    rep(i,n+2)p[i] = P(IB(-1,false),-1);
    bool deb[n+2];

    for(int i=1;i<=n;i++){


      //cout << "print ---- "  << i-1  <<", now = " << now<< endl;
      // for(int j=1;j<=n;j++){
      //cout  << "P("<<p[j].F.F << ","<<p[j].F.S <<"," <<p[j].S <<")" << endl;
      // }


      bool input;
      cin >> input;
      deb[i] = input;
      if(i == 1){
	p[i] = P(IB(1,input),-1);
	now = 1;
	continue;
      }
      
      /* odd */
      if(i%2 != 0){
	if(input == p[now].F.S){
	  //cout << "IN!-rev " << i << " " << now << endl;
	  p[now].F.F++;
	}	
	else{
	  p[i] = P(IB(1,input),now);
	  //cout << "IN!" << i << " - now " << now<< endl;
	  now = i;
	}
	continue;
      }

      /* even */
     
      if(input == p[now].F.S){
	p[now].F.F++;
	//cout << "IN!-even1 " << i << endl;
      }
      else {
	//cout << "IN!-even2 " << i << ", now= "<< now << endl;
	p[now].F.F++;
	p[now].F.S = input;

	if(-1 != p[now].S){
	  //cout <<"phowaaaaaaaaaaaaaaaaa" << i << endl;
	  p[p[now].S].F.F += p[now].F.F;	  
	  int post = p[now].S;
	  p[now] = P(IB(-1,false),-1);
	  now = post;
	}

      }

    

    }

   
    //cout << "print ---- last"   << endl;
    //for(int i=1;i<=n;i++){
    //cout << "color = " << deb[i] << ", P("<<p[i].F.F << ","<<p[i].F.S <<"," <<p[i].S <<")" << endl;
    //}

    for(int i=1;i<=n;i++)if(!p[i].F.S && p[i].F.F != -1)cnt += p[i].F.F;
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <array>

#define MAX 100

using namespace std;


void printary( array< int, MAX > ary, int N )
{
	for ( int i = 0 ; i < N ; i++ ) {
		if ( i == N-1 ) {
			cout << ary[i] << endl;
		} else {
			cout << ary[i] << " ";
		}
	}
}

void insertionSort( array< int, MAX >ary, int N )
{
	int val, i, j;

	printary( ary, N );
	for ( i = 1 ; i < N ; i++ ) {
		val = ary[i];
		j = i - 1;
		while ( j >= 0 && ary[j] > val ) {
			ary[j+1] = ary[j];
			j--;
		}
		ary[j+1] = val;
		printary( ary, N );
	}
}

int main()
{
	int N, val, i;
	array< int, MAX > ary;

	cin >> N;
	for ( i = 0 ; i < N ; i++ ) {
		cin >> ary[i];
	}
	insertionSort( ary, N );

	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int t, n;
  cin >> t >> n;
  int i = 0;
  while (t != 0) {
    int td = t / n;
    int k = t % n;
    t = td;
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

            int n = sc.nextInt();
            int hoge = 1;
            for(int i = 0; i <= Math.pow(n,0.5); i++){
                if(i * i <= n){
                    hoge = i  * i;
                }
            }            
            System.out.println(hoge);
            sc.close();
		  }
}

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H + 2);
  FOR(i, 1, H) {
    cin >> s[i];
  }
  REP(i, H + 2) {
    REP(j, W + 2) {
      if(i == 0 || i == H + 1) {
        s[i].push_back('.');
      }
    }
    if(i != 0 && i != H + 1) {
      s[i] = "." + s[i] + ".";
    }
  }
  FOR(i, 1, H) {
    FOR(j, 1, W) {
      if(s[i][j] == '#') {
        bool flag = true;
        REP(k, 4) {
          if(s[i + dy[k]][j + dx[k]] == '#') {
            flag = false;
            break;
          }
        }
        if(flag == true) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

const int Maxn=2e3+10;

int n,x,y;
int cnt[Maxn];

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>x>>y;
    for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++)
    {
    	if(i<=x&&j>=y)
		{
			cnt[x-i+j-y+1]++;
		}
    	else if(i<=x&&j<y&&j>x) 
		{
			cnt[x-i+min(j-x,1+y-j)]++;
		}
    	else if(i>x&&i<y&&j>=y) 
		{
			cnt[j-y+min(y-i,1+i-x)]++;
		}
		else if(i>x&&i<y&&j>x&&j<y)
		{
			cnt[min(j-i,i-x+1+y-j)]++;
		}
    	else 
		{
			cnt[j-i]++;
		}
	}
	for(int k=1;k<n;k++) cout<<cnt[k]<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
  
    int X,A,B;
    cin>>X>>A>>B;
    if(B<=A){
        cout<<"delicious"<<endl;
    }
    else if(B<X+A+1){
        cout<<"safe"<<endl;
    }
    else{
        cout<<"dangerous"<<endl;
    }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
D=[]
for n in range(N):
    a,b=map(int,input().split())
    D.append((a,b))
D.sort()
c=0
m=0
for n in range(N):
    a,b=D[n]
    if m+b<M:
        m+=b
        c+=b*a
    else:
        bb=M-m
        m+=bb
        c+=bb*a
print(c)


Measured memory_bytes: 16892
def main():
    import math
    n = int(input())
    a = sorted(list(map(int,input().split())))
    g=a[0]
    for i in range(1,n):
        g = math.gcd(g,a[i])
    if g > 1:
        print('not coprime')
        return
    d = [1 for i in range(a[-1])]
    for i in range(2,a[-1]+1):
        if d[i-1] == 1:
            for j in range(1,a[-1]//i+1):
                if d[i*j-1] == 1:
                    d[i*j-1] = i
    prm = {}
    for i in range(n):
        p = []
        while a[i] != 1:
            p.append(d[a[i]-1])
            a[i] = a[i] // d[a[i]-1]
        p = set(p)
        for p_ in p:
            if prm.get(p_)==None:
                prm[p_] = 1
            else:
                print('setwise coprime')
                return
    print('pairwise coprime')

if __name__ == "__main__":
    main()


Measured memory_bytes: 126940
# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, raw_input().split())
    print "YES" if abs(((y2-y1)*(x4-x3) - (x2-x1)*(y4-y3))) < 1e-10 else "NO"

Measured memory_bytes: 6388
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int sum(int pos, vector<int> &fenv) {
	int res = 0;
	for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
		res += fenv[pos];
	return res;
}

void upd(int pos, int val, vector<int> &fenv) {
	int n = fenv.size();
	for (; pos < n; pos = (pos | (pos + 1)))
		fenv[pos] += val;
}

void solve() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	vector<queue<int>> col(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		col[a[i]].push(i + 1);
	}
	vector<pair<pair<int, int>, int>> que(q);
	for (int i = 0; i < q; i++) {
		cin >> que[i].first.first >> que[i].first.second;
		que[i].second = i;
	}
	sort(que.begin(), que.end());
	vector<int> ans(q);
	vector<int> fenv(n + 1);
	for (int i = 1; i <= n; i++) {
		if (!col[i].empty())
			upd(col[i].front(), 1, fenv);
	}
	int u = 0;
	for (int i = 0; i < n; i++) {
		while (u < q && que[u].first.first == i + 1) {
			ans[que[u].second] = sum(que[u].first.second, fenv) - sum(que[u].first.first - 1, fenv);
			u++;
		}
		upd(i + 1, -1, fenv);
		col[a[i]].pop();
		if (!col[a[i]].empty())
			upd(col[a[i]].front(), 1, fenv);
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 352920
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def p_d():
    from collections import Counter
    N = int(input())
    li = []
    for i in range(1, N + 1):
        li.extend(prime_factorize(i))
    prime_list = Counter(li).values()

    def num(m):
        return len(list(filter(lambda x: x >= m - 1, prime_list)))

    print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) // 2)


if __name__ == '__main__':
    p_d()


Measured memory_bytes: 38384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.next());
		int total = 0;
		for (int i = 1; i <= num; i++) {
			for (int j = 1; j <= num; j++) {
				for (int k = 1; k <= num; k++) {
					total += calc3GCD(i, j, k);
				}
			}
		}
		System.out.println(total);
	}

	public static int calc3GCD(int a, int b, int c) {
		int tempGCD = calcGCD(a, b);

		return calcGCD(tempGCD, c);
	}

	public static int calcGCD(int a, int b) {
		int[] numArray = { a, b };
		Arrays.sort(numArray);
		int x;
		int y;
		x = numArray[1];
		y = numArray[0];

		int tmp;
		while ((tmp = x % y) != 0) {
			x = y;
			y = tmp;
		}
		return y;
	}
}


Measured memory_bytes: 53876
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  rep(i,M) cin >> s[i] >> c[i];
  vector<char> number(N);
  rep(i,N) number[i] = 'A';
  rep(i,M) {
    if (number[s[i]-1] == 'A') number[s[i]-1] = c[i];
    else if (number[s[i]-1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (number.size() != 1 && number[0] == '0') {
    cout << -1 << endl;
    return 0;
  };
  rep(i,N) {
    if (number[i] == 'A') number[i] = '0';
  }
  if (number.size() != 1 && number[0] == '0') number[0] = '1';


  rep(i,N) cout << number[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 3128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>  // abs() for integer
#include <math.h>     // math.h をインクルードする！
#include <iomanip> // 小数点以下のやつ
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<int> ans;
    bool ok = false;
    for(int i = -110; i < 211; i++) {
        ok = false;
        rep(j,n) {
            if(p[j] == i) {
                ok = true;
                break;
            }
        }
        if(ok) continue;
        ans.push_back(i);
    }
    // rep(i, ans.size()) cout << ans[i] << ' ';
    vector<int> Abs;
    int Min = 110;
    int Ans;
    rep(i, ans.size()) {
        Abs.push_back(abs(x - ans[i]));
        if(Abs[i] < Min) {
            Min = Abs[i];
            Ans = ans[i];
        }
    }
    // rep(i, Abs.size()) cout << Abs[i] << ' ';
    cout << Ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n,h,w; cin >>n >>h >>w;
  int res = 0;
  rep(i, n){
    int a,b; cin >>a >>b;
    if (h <= a && w <= b) res++;
  }
  cout <<res <<endl;
}


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

int main() {
  int n;
  int a[100], b[100];
  int dp[100][100];
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> a[i] >> b[i];
  }
  if (n == 1) {
    cout << 0 << endl;
  } else {
    for (int i=0; i<n; i++) {
      dp[0][i] = 0;
    }
    for (int i=1; i<n; i++) {
      for (int j=0; j<n; j++) {
        dp[i][j] = INT_MAX;
      }
    }
    for (int i=1; i<n; i++) {
      for (int j=0; j<n-i; j++) {
        for (int k=0; k<i; k++) {
          dp[i][j] = min(dp[i][j], dp[k][j]+dp[i-k-1][j+k+1]+a[j]*b[j+k]*a[j+k+1]*b[i+j]);
        }
      }
    }
    cout << dp[n-1][0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
N,M,X,Y = map(int,input().split())
x =  list(map(int,input().split()))
y =  list(map(int,input().split()))
ans = 'No War'
max = X
for i in range(N):
    if x[i]>max:
        max = x[i]
min = Y
for i in range(M):
    if y[i]<min:
        min = y[i]

if max>=min:
    ans = 'War'
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
int main()
{
    int n;
    long long int h;
    cin>>n>>h;
    vector <pair <long long int,long long int> > ba;
    pair<long long int, long long int> p;
    long long int k;
    for(int i=0;i<n;i++){
        cin>>k;
        p.second=k;
        cin>>k;
        p.first=k;
        ba.push_back(p);
    }
    sort(ba.begin(),ba.end());
    long long int sum=0;
    long long int max=0;
    bool flag=true;
    long long int ans=0;
    while(flag){
        p=ba.back();
        ba.pop_back();
        if(ba.empty()){flag=0;}
        
        if(p.second>max){
            max=p.second;
        }
        if(p.first<max){flag=0;}
        else{
            sum=sum+p.first;
            ans++;
            if(sum>=h){
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    h=h-sum;
    if(h%max==0){
        ans=ans+h/max;
    }
    else{
        ans=ans+h/max+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val _ = sc.nextLine()
    val S = sc.nextLine()

    def zip(zipped: List[Char], lst: List[Char]): List[Char] = {
      lst match {
        case Nil => zipped.reverse
        case h :: t =>
          zipped match {
            case Nil => zip(h :: Nil, t)
            case zh :: _ =>
              if (h == zh) {
                zip(zipped, t)
              } else {
                zip(h :: zipped, t)
              }
          }
      }
    }

    println(zip(Nil, S.toList).size)
  }

}

Measured memory_bytes: 40276
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

bool match(const string& str, const string& pat) {
  if (str.size() != pat.size()) { return false; }
  REP(i, str.size()) {
    if (pat[i] == '?') { continue; }
    if (str[i] != pat[i]) { return false; }
  }
  return true;
}

int main() {
  int n, m;
  while (cin >> n >> m, n|m) {
    vector<bool> permits(n);
    vector<string> srcs(n);
    vector<string> dsts(n);
    string keyword;
    REP(i, n) {
      cin >> keyword >> srcs[i]>> dsts[i];
      permits[i] = (keyword == "permit");
    }

    string src, dst, msg;
    vector<string> ans;
    REP(j, m) {
      cin >> src >> dst >> msg;
      bool ok = false;
      REP(i, n) {
        if (match(src, srcs[i]) && match(dst, dsts[i])) {
          ok = permits[i];
        }
      }
      if (ok) {
        ans.push_back(src + " " + dst + " " + msg);
      }
    }

    cout << ans.size() << endl;
    FOREACH(it, ans) { cout << *it << endl; }
  }
}

Measured memory_bytes: 1020