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

using namespace std;
#define Sheep true
#define Wolf false

int n;
string s;

bool func(bool z, bool o) {
	bool a[100000] = {};
	a[0] = z;
	a[1] = o;
	for (int i = 1; i != s.size() - 1; i++) {
		if (s[i] == 'o') {//s[i]が○だったら
			if (a[i] && a[i - 1])a[i + 1] = Sheep; //a[i]とa[i-1]が羊
			else if (a[i] && !a[i - 1])a[i + 1] = Wolf;//a[i]が羊,a[i-1]が狼
			else if (!a[i] && a[i - 1])a[i + 1] = Wolf;//a[i]が狼、a[i-1]が羊
			else if (!a[i] && !a[i - 1])a[i + 1] = Sheep;//a[i]とa[i-1]が狼				
		}
		else { //s[i]が×だったら
			if (a[i] && a[i - 1])a[i + 1] = Wolf; //a[i]とa[i-1]が羊
			else if (a[i] && !a[i - 1])a[i + 1] = Sheep;//a[i]が羊,a[i-1]が狼
			else if (!a[i] && a[i - 1])a[i + 1] = Sheep;//a[i]が狼、a[i-1]が羊
			else if (!a[i] && !a[i - 1])a[i + 1] = Wolf;//a[i]とa[i-1]が狼				
		}
	}
	if (s[n - 1] == 'o') { //n-1番目の証言があってるかチェック
		if (a[n - 1] && a[n - 2] != a[0])return false;
		else if (!a[n - 1] && a[n - 2] == a[0])return false;
	}
	else {
		if (a[n - 1] && a[n - 2] == a[0])return false;
		else if (!a[n - 1] && a[n - 2] != a[0])return false;
	}

	if (s[0] == 'o') { //上と同様に0番目の証言があってるかチェック
		if (a[0] && a[n - 1] != a[1])return false;
		else if (!a[0] && a[n - 1] == a[1])return false;
	}
	else {
		if (a[0] && a[n - 1] == a[1])return false;
		else if (!a[0] && a[n - 1] != a[1])return false;
	}

	for (int i = 0; i < n; i++) {
		if(a[i]==Sheep)cout << 'S';
		else cout << 'W';
	}
	cout << endl;
	return true;
}

int main() {

	cin >> n >> s;
	for (int x = 1; x >= 0; x--) {
		for (int y = 1; y >= 0; y--) {
			if (func(x, y))return 0;
		}
	}
	if (func(Sheep, Sheep))return 0;
	if (func(Sheep, Wolf))return 0;
	if (func(Wolf, Sheep))return 0;
	if (func(Wolf, Wolf))return 0;

	cout << -1 << endl;
	return 0;
}

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

ll minimum(ll a,ll b,ll c,ll d,ll e){
  return min(min(a,min(b,c)),min(d,e));
}

int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll time=4;
  ll data=minimum(a,b,c,d,e);
  time+=(n/data);
  if(n%data!=0){
    time++;
  }
  cout << time << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		ans += ((x & 1) && (i & 1));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        long a = cin.nextLong();
        long b = cin.nextLong();
        if (a <= 0 && b >= 0)
        {
            Console.WriteLine("Zero");
        }
        else if (a > 0 || (b - a) % 2 == 1)
        {
            Console.WriteLine("Positive");
        }
        else
        {
            Console.WriteLine("Negative");
        }
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
double pi = 3.1415926535898;
int main()
{
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      double n;
      cin >> n;
      n = 2*n*pi;
      cout << n << endl;
      return 0;
}


Measured memory_bytes: 3772
N, M = map(int, input().split())
par = [i for i in range(N)]
rank = [0 for _ in range(N)]

def root(x):
  if par[x] == x:
    return x
  else:
    par[x] = root(par[x])
    return par[x]
def unite(x, y):
  s, t = root(x), root(y)
  if s != t:
    if rank[s] < rank[t]:
      par[s] = t
    else:
      par[t] = s
      if rank[s] == rank[t]:
        rank[s] += 1
        
p = list(map(int, input().split()))
for i in range(N):
  p[i] -= 1
for i in range(M):
  x, y = map(int, input().split())
  unite(x-1, y-1)
for i in range(N):
  par[i] = root(i)
cnt = 0
for i in range(N):
  if par[i] == par[p[i]]:
    cnt += 1
print(cnt)

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

void solve() 
{
    int a,b;cin>>a>>b;cout<<a*b<<endl;
}

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

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int N,a[110],min1=100,max1=-100,ans=99999999,temp;
	
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(a[i]>max1)
			max1=a[i];
		if(a[i]<min1)
			min1=a[i];
	}
	for(int i=min1;i<=max1;i++){
		temp=0;
		for(int j=0;j<N;j++){
			temp+=(a[j]-i)*(a[j]-i);
		}
		if(temp<ans)
			ans=temp;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

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

  int ans = 1;
  for (int i=0; i<3; i++)
    ans *= n;
  cout<<ans<<endl;
 
  return 0;
}


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

public class Main {

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

    String d = t.substring(0,s.length());

    if (s.equals(d)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }


  }

}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int md = (int)1e9+7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	int d, n;
	cin >>d >>n;
	ll w =0;
	if(d==0){
		w = n;
		if(n==100) w++;
	}else if(d==1){
		 w=100LL*n;
		if(n==100) w+=100;
	}else{
		w=10000LL *n;
		if(n==100) w+=10000;
	}
	cout << w <<"\n";
	return 0;
}


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

int main(){
    //あり本では，w，vの順に入力しているが，このコードは逆である
    int n;
    cin >> n;
    int W;
    cin >> W;
    vector<int> v(n);
    vector<int> w(n);
    rep(i, n){
        cin >> v[i] >> w[i];
    }
    
    int dp[1001][10001];
    rep(i, 1001){
        rep(j, 1001){
            dp[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= W; j++){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]  +v[i]);
            }
        }
    }
    cout << dp[n][W] << endl;
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll A, ll B) {
  ll ans = 0;
  ll c = 1;

  while (c < B) {
    c += (A - 1);
    ans++;
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3752
import sys
input = sys.stdin.readline


def main():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))
    ans = 0
    x = X[0]
    for i in range(1, N):
        if (X[i] - x)*A <= B:
            ans += (X[i] - x)*A
        else:
            ans += B
        x = X[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58864
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
int n;
int v[30],c[30];
cin>>n;
REP(i,n){
    cin>>v[i];
}
REP(i,n) cin>>c[i];
int cnt=0;
for(int i=0;i<n;i++){
    if(v[i]-c[i]>=0) cnt+=v[i]-c[i];

}
cout<<cnt<<endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    map<ll,pair<ll,ll>> dic;
    ll h,w,d;
    cin>>h>>w>>d;
    ll a[h+1][w+1];
    rep(i,h){
        rep(j,w){
            cin>>a[i+1][j+1];
            dic[a[i+1][j+1]]=make_pair(i+1,j+1);
        }
    }
    ll a1[d+1][(h*w)/d+10];
    //a1[i][j]はiからd*j+iまでの魔力
    for (int i=1;i<d+1;i++){
        for (int j=0;d*j+i<=h*w;j++){
            if (j==0){
                a1[i][j]=0;
            }
            else{
                ll num=d*j+i;
                ll x,y;
                x=dic[num].first;
                y=dic[num].second;
                ll x1,y1;
                x1=dic[num-d].first;
                y1=dic[num-d].second;
                a1[i][j]=a1[i][j-1]+abs(x-x1)+abs(y-y1);
            }
        }
    }
    ll q;
    cin>>q;
    rep(i,q){
        ll l,r;
        cin>>l>>r;
        ll d1=(l-1)%d+1;
        ll d2=(l-1)/d;
        ll d3=(r-1)/d;
        cout<<a1[d1][d3]-a1[d1][d2]<<endl;
    }





    return 0;
}

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

int main() {

  int a, b, c;
  cin >> a >> b;
  
  int d, r;
  double f;
  
  d = a/b;
  r = a%b;
  f = (double)a/b;
  
  printf("%d %d %f\n", d, r, f);
  
  return 0;
}


Measured memory_bytes: 3184
N, K = map(int, input().split())

result = ''
if N == 0:
    result += str(N)

while( N != 0 ):
    q, mod = divmod(N, K)
    # print(q,mod)
    result += str(mod)
    N = q

# print(''.join(list(reversed(result))))
print(len(list(reversed(result))))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int main()
{
    string s,t;
    cin >> s>>t;
    int a=0,i;
    rep0(i,s.size()){
        if(s[i]!=t[i])a++;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3924
def vector_u(vc_p1 = [], vc_p2 = []):
    vc_p1s = [(vc_p2[0] - vc_p1[0])/3.0, (vc_p2[1] - vc_p1[1])/3.0]
    vc_su  = [vc_p1s[0]*0.5 - vc_p1s[1]*0.866025, vc_p1s[0]*0.866025 + vc_p1s[1]*0.5]
    vc_u   = [vc_p1[0] + vc_p1s[0] + vc_su[0], vc_p1[1] + vc_p1s[1] + vc_su[1]]
    return vc_u

def vector_s(vc_p1 = [], vc_p2 = []):
    vc_s = [(2.0*vc_p1[0] + vc_p2[0])/3.0, (2.0*vc_p1[1] + vc_p2[1])/3.0]
    return vc_s

def vector_t(vc_p1 = [], vc_p2 = []):
    vc_t = [(vc_p1[0] + 2.0*vc_p2[0])/3.0, (vc_p1[1] + 2.0*vc_p2[1])/3.0]
    return vc_t

def koch_curve(p1 = [0.00000, 0.00000], p2 = [100.00000, 0.00000], n = 0):
    s = vector_s(p1, p2)
    u = vector_u(p1, p2)
    t = vector_t(p1, p2)
    
    if n == 0:
        print(str( s[0]) + " " + str( s[1]))
        print(str( u[0]) + " " + str( u[1]))
        print(str( t[0]) + " " + str( t[1]))
        print(str(p2[0]) + " " + str(p2[1]))
    else:
        koch_curve(p1,  s, n-1)
        koch_curve( s,  u, n-1)
        koch_curve( u,  t, n-1)
        koch_curve( t, p2, n-1)

n = int(raw_input())

p1 = [  0.0, 0.0]
p2 = [100.0, 0.0]

print(str(p1[0]) + " " + str(p1[1]))
if n == 0:
    print(str(p2[0]) + " " + str(p2[1]))
else:
    koch_curve(p1, p2, n-1)

Measured memory_bytes: 6496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int const INF = 1 << 30;
int const MAX = 405;
int dp[45][450][450];

int main()
{
    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i] >> b[i] >> c[i];

    Fill(dp, INF);
    dp[0][0][0] = 0;
    rep(i,n) rep(j,MAX) rep(k,MAX) {
        if(dp[i][j][k] >= INF) continue;
        chmin(dp[i+1][j][k], dp[i][j][k]);
        chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
    }

    int res = INF;//j = k = 0のときに注意
    for(int j = 1; j <= MAX; ++j) {
        for(int k = 1; k <= MAX; ++k) {
            if(mb*j == ma*k) chmin(res, dp[n][j][k]);
        }
    }
    cout << (res < INF?res:-1) << endl;
    return 0;
}

Measured memory_bytes: 39192
#include<stdio.h>
#include<math.h>

int main() {
	long long S, s, sum = 0;
	int len = 0, p, q;

	scanf("%lld", &S);
	for (int i = 0; i <= 10; i++) {
		if (S <= pow(10, i)) {
			len = i;
			break;
		}
	}

#ifdef DEBUG
	printf("%d\n", len);
#endif DEBUG

	for (int mask = 0; mask < pow(2, len - 1); mask++) {
		s = S;
		for (int i = len - 2; i >= 0; i--) {
			p = (int)pow(2, i);
			if (mask & p) {
				q = (int)pow(10, i+1);
				sum += s / q;
				s %= q;
			}
		}
		sum += s;
	}
	printf("%lld", sum);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
int main(){

    int n;

    cin >> n;

    int boss[n-1];
    int ans[n];

    for (int i = 0; i < n; i++)
    {
        ans[i] = 0;
    }

    for (int i = 0; i < n-1; i++)
    {
        cin >> boss[i];
    }

    for (int i = 0; i < n-1; i++)
    {
        ans[boss[i] - 1] = ans[boss[i] - 1] + 1;
    }

    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }

	return 0;
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  rep(i, 10000) {
    if (a == int(i * 0.08) && b == int(i * 0.1)) {
      ans = i;
      break;
    }
    ans = -1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int a[10000];
int main() {
  int n;
  while(cin >> n) {
    REP(i,n) scanf("%d", a+i);
    sort(a,a+n);
    vector<int> v;
    REP(i,min(4,n)) REP(j,min(4,n)) {
      if (i==j) continue;
      char t[100];
      sprintf(t,"%d%d",a[i],a[j]);
      v.push_back(atoi(t));
    }
    sort(ALL(v));
    cout << v[2] << endl;
  }
}

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

int main(){
    bool f = true;
    int n, tmp;
    cin >> n;
    vector<pair<int, int>> p(n);
    for(int i = 0; i < n; i++){
        cin >> tmp;
        p[i] = make_pair(tmp, i + 1);
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < n; i++){
        if(f == false) cout << ' ';
        cout << p[i].second;
        f = false;
    }
    cout << endl;
    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int64 comb(int32 n, int32 r){
    int64 retval = 1;
    r = min(r, n - r);
    REP(i,r){
        retval *= n - i;
    }
    REP(i,r){
        retval /= i + 1;
    }
    return retval;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    map<vector<int32>, int32> cnt;
    REP(i,n){
        vector<int32> c(26, 0);
        string s;
        cin >> s;
        REP(j, 10){
            c[s[j] - 'a']++;
        }
        cnt[c]++;
    }
    int64 ans = 0;
    for(auto p : cnt){
        // ostream_iterator<int32> out_it(cout, " ");
        // copy(ALL(p.first), out_it);
        // cout << " " << p.second << endl;
        int32 x = p.second;
        if(x <= 1)continue;
        ans += comb(x, 2);
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 29952
n, m = gets.chomp.split.map(&:to_i)
sc = []
m.times do |i|
  sc[i] = gets.chomp.split.map(&:to_i)
end

max = 10 ** n - 1
min = if n == 1
        0
      else
        10 ** (n-1)
      end
min.upto(max) do |i|
  flag = true
  arr = i.to_s.split('').map(&:to_i)
  sc.each do |s, c|
    if arr[s-1] != c
      flag = false
      next
    end
  end
  if flag
    puts arr.join
    exit
  end
end
puts '-1'


Measured memory_bytes: 3964
import java.util.*;

public class Main{
	
	class C implements Comparable<C>{
		int d,p;

		public C(int d, int p) {
			this.d = d;
			this.p = p;
		}

		@Override
		public int compareTo(C o) {
			if(this.p < o.p) return 1;
			if(this.p > o.p) return -1;
			return 0;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			C [] data = new C[n];
			for(int i = 0; i < n; i++){
				int d = sc.nextInt();
				int p = sc.nextInt();
				data[i] = new C(d, p);
			}
			Arrays.sort(data);
			int ind = 0;
			while(true){
				int res = m - data[ind].d;
				if(res >= 0){
					m = res;
					data[ind].d = 0;
					ind++;
					if(ind == n) break;
				}
				else {
					data[ind].d = data[ind].d - m;
					break;
				}
			}
			int sum = 0;
			for(int i = 0; i < n; i++){
				sum += data[i].d * data[i].p;
			}
			System.out.println(sum);
		}
	}

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

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
 
#define int  long long
const int MOD = 1e9 + 7;

void solve(){
	int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int cnt = 0;
    for (auto it : v)
      cnt += it >= k;
    cout << cnt << endl;
}

int32_t main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     solve();	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> a(n);
    double s = 0;
    rep(i, n) { cin >> a[i]; s += (double)(a[i]); }
    s /= (double)(4 * m);
    int cnt = 0;
    rep(i, n) if (a[i]>=s) cnt++;
    (cnt>=m) ? puts("Yes") : puts("No");
    return 0;
}

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

int solve(string &in){
  int ret = 0;
  int p = 0;
  char which[3]={'A','A','A'};
  int cnt[3]={0};
  while(p < in.size()){
    which[0] = in[p];
    while(p < in.size() && in[p] == which[0])cnt[0]++,p++;
    if (which[0] == 'I' && which[1] == 'O' && which[2] == 'J' && 
	cnt[0] >= cnt[1] && cnt[2] >= cnt[1])ret = max(ret,min(cnt[1],cnt[2]));
    for(int i=2;i>0;i--){
      cnt[i] = cnt[i-1];
      which[i] = which[i-1];
    }
    cnt[0] = 0;
  }
  return ret;
}


main(){
  string in;
  while(cin>>in){
    cout << solve(in) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double x[n],y[n];
    for(int i=0;i<n;i++){
    	cin>>x[i]>>y[i];
    }
    double ans=0;
    for(int i=0;i<n;i++){
    	for(int j=i+1;j<n;j++){
    		ans+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    	}
    }
    double a=1;
    double m=double(n);
    for(double i=1;i<=n;i++){
    	a*=i;
    }
    doublecout(ans*2/m);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
set <int >a[26], b[26];
 
int main()
{
	int n;
	string y,x;
	cin >> x >> y;
	for (int i = 0; i < x.size(); i++)
	{
		a[x[i] - 'a'].insert(y[i] - 'a');
		b[y[i] - 'a'].insert(x[i] - 'a');
	}
	for (int i = 0; i <= 25; i++)
	{
		if (a[i].size() > 1 || b[i].size() > 1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int a, b, c, x;
int gen(int x){
  return (a * x + b) % c;
}

int main(){
  int n;
  while(cin >> n >> a >> b >> c >> x, n || a || b || c || x){
    int cnt = 0;
    int y;
    bool ok = true;
    for(int i = 0; i < n; i++){
      cin >> y;
      
      if(i > 0){
        x = gen(x);
        cnt++;
      }
      while(x != y){
        x = gen(x);
        cnt++;
        if(cnt > 10000)break;
        if(x == y)break;
      }
    }
    cout << ((cnt > 10000) ? -1 : cnt) << endl;
  }
}

Measured memory_bytes: 2912
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
int A1,i;
scanf("%d",&A1);
char S1[A1],S2[A1],S3[2*A1];
scanf("%s" "%s",S1,S2);
for(i=0;i<2*A1;i++){
	S3[2*i]=S1[i];
	S3[2*i+1]=S2[i];
}
printf("%s",&S3);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int h,w,m;
	cin>>h>>w>>m;
	vector<int> vh(h+1,0);
	vector<int> vw(w+1,0);
	unordered_map<string,int> u;
	for(int i=0;i<m;i++)
	{
		int l,r;
		cin>>l>>r;
		vh[l]++;
		vw[r]++;
		string temp=to_string(l)+" "+to_string(r);
		u[temp]++;
	}
	int m1=0;
	int m2=0;
	for(int i=0;i<=h;i++)
	{
		if(vh[i]>m1)
		{
			m1=vh[i];
		}
	}
	for(int i=0;i<=w;i++)
	{
		if(vw[i]>m2)
		{
			m2=vw[i];
		}
	}
  vector<int> l1;
  vector<int> r1;
  for(int i=0;i<=h;i++)
	{
		if(vh[i]==m1)
		{
			l1.push_back(i);
		}
	}
	for(int i=0;i<=w;i++)
	{
		if(vw[i]==m2)
		{
			r1.push_back(i);
		}
	}
  int ans=0;
  for(int i=0;i<l1.size();i++)
  {
    for(int j=0;j<r1.size();j++)
    {
      
    	string temp=to_string(l1[i])+" "+to_string(r1[j]);
    	if(u.find(temp)!=u.end())
    	{
    		ans=max(ans,m1+m2-1);
    	}
    	else
    	{
    		ans=max(ans,m1+m2);
          break;
    	}
    	
    }
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 32884
#include<stdio.h>

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

 while(1){
  int i=10;
  int count=1;

  if(scanf("%d %d",&a,&b)<2) break;
  
  sum=a+b;

  if(a<0 || b<0) break;

  while(1){
   if(sum<i){
   printf("%d\n" ,count);
   break;
   }else{
   i=i*10;
   count++;
   }
  }
 }
 return 0;
}

Measured memory_bytes: 0
#include <cstdio>

int main(void)
{
	int x, y, z, ans;
	scanf("%d%d%d", &x, &y, &z);
	for (ans = 0; z * (ans + 1) + y * ans <= x; ans++) ;
	printf("%d\n", ans - 1);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

void solve() {
    int n;
    cin >> n;
    if (n < 1000) cout << "ABC" << endl;
    else  cout << "ABD" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <cstdlib>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define forv(i,m,n) for (int i=(m); i>=(n); i--)
#define forall(it,p) for (auto it = p.begin(); it != p.end(); ++it)
#define DBG 0
#define R 1000000007

#define MAXN 3001
long a[MAXN][MAXN];

int main() {
  int n;
  long sum;
  string s;
  cin >> n >> s;
  a[0][0] = 1;
  forr(i,1,n-1) {
    sum = 0;
    if (s[i-1] == '>') {
      a[i][i] = 0;
      forv(j,i-1,0) {
        sum = (sum + a[i-1][j]) % R;
        a[i][j] = sum;
      }
    } else {
      a[i][0] = 0;
      forr(j,1,i) {
        sum = (sum + a[i-1][j-1]) % R;
        a[i][j] = sum;
      }
    }
    if (DBG) {
      cout << "i " << i << ")" << endl;
      forr(jj,0,i)
        cout << a[i][jj] << " ";
      cout << endl;
    }
  }
  sum = 0;
  forr(i,0,n-1)
    sum = (sum + a[n-1][i]) % R;
  cout << sum;

}


Measured memory_bytes: 68992
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int a, b;

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

  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << ((a + b) / 2) + 1 << endl;
  }

  return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int d[n];
  rep(i, n) d[i] = i + 1;

  int dif = 0;
  rep(i, n) {
    int p;
    cin >> p;
    if (p != d[i]) ++dif;
  }

  if (dif <= 2)
    puts("YES");
  else
    puts("NO");
  return 0;
}


Measured memory_bytes: 3532
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String edit = "";
		for(int i = 0; i < s.length(); i++) {
			if(edit.length() != 0 && s.charAt(i) == 'B')
				edit = edit.substring(0, edit.length() - 1);
			else if(s.charAt(i) != 'B')
				edit = edit + String.valueOf(s.charAt(i));
		}
		System.out.println(edit);
	}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <ctype.h>
#define MAX 1202
#define alphaNum 26
  
int main(void){
    int i;
    char str[MAX];
    int count[alphaNum] = {0};
  
    while(fgets(str, MAX, stdin) != NULL){
        for(i = 0; str[i] != '\n'; i++){
            if(isalpha(str[i])){
                if(isupper(str[i])){
                    count[str[i] - 'A']++;
                }
                if(islower(str[i])){
                    count[str[i] - 'a']++;
                }
            }
        }
    }
  
    for(i = 0; i < alphaNum; i++){
        printf("%c : %d\n", i + 'a', count[i]);
    }
    return 0;
}

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

int main()
{
  int N;
  vector<string> w;
  bool rule=true;
  cin >> N;

  rep(i,N) {
    string s;
    cin >> s;
    if(find(w.begin(),w.end(),s)!=w.end()){
      rule = false;
    }
    w.push_back(s);
  }

  for(int i=1;i<N;i++){
    if(w[i][0]!=w[i-1][w[i-1].size()-1]){
      rule = false;
    }
  }
  
  if(rule) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    ll n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vl don(2 * n + 3);
    rrep (i, n) {
        if (s[i] == 'x') {
            don[i] = don[i + 1];
        }
        else {
            don[i] = 1 + don[i + 1 + c];
        }
    }
    assert(don[0] >= k);

    int now = 0;
    vi ans;
    int zisyuku = 0;
    rep (i, n) {
        if (s[i] == 'x') {
            zisyuku = max(zisyuku - 1, 0LL);
            continue;
        }
        if (zisyuku > 0) {
            zisyuku--;
        }
        else {
            int can = now + don[i + 1];
            if (can < k) {
                ans.push_back(i + 1);
            }
            zisyuku = c;
            now++;
        }
    }
    rep (i, ans.size()) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6536
#include<iostream>
#include<complex>
#include<cstdio>
using namespace std;
int main(){
  int x,a,b;
  scanf("%d%d%d",&x,&a,&b);
  if(abs(x-a)<abs(x-b)){
    printf("A");
  }else{
    printf("B");
  }
  return 0;
}

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

int main()
{
	int m,d,a,b,c;

   cin >> m >> d;

   c=0;
   for(int i=1; i<=m; i++){
    for(int j=10; j<=d; j++){
      a=j%10;
      b=j/10;
      if(a*b == i && a>=2 && b>=2){
        c++;
      }
    }
   }

   cout << c << endl;

	return 0;
}

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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     pii              pair<int, int>
#define     pll             pair<long long int, long long int>
#define     vll             vector<long long int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()
//__builtin_popcount(n)

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

unsigned int logn(unsigned int n, unsigned int r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }

ll pw[32];

void cal(){ pw[0] = 1; rep(i, 1, 32)pw[i] = 2*pw[i-1]; }


void solve()
{
    ll s, w; cin>>s>>w;
    cout<<(s>w?"safe\n":"unsafe\n");
}


int main()
{
    // boost;
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	string ans = "Yes";
	REP(i, s.length()) {
		if (i != a) {
			if (!isdigit(s[i])) {
				ans = "No";
				break;
			}
		}
		else {
			if (s[i] != '-') {
				ans = "No";
				break;
			}
		}

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

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int m[100010],p[100010];

int main(void){
	int i;

	int N,M;
	cin >> N >> M;
	vector<int>v(N);
	for(i=0;i<N;i++) cin >> v[i];
	sort(v.begin(),v.end());
	for(i=0;i<N-1;i++){
		if(v[i]==v[i+1]){
			p[v[i]%M]++;
			i++;
		}
	}

	for(i=0;i<N;i++){
		m[v[i]%M]++;
	}

	if(M==1){
		cout << m[0]/2 << endl;
		return 0;
	}
	if(M==2){
		cout << m[0]/2+m[1]/2 << endl;
		return 0;
	}

	int ans=0;
	if(M%2==1){
		for(i=1;i<=(M-1)/2;i++){
			int x=min(m[i],m[M-i]);
			m[i]-=x;
			m[M-i]-=x;
			ans+=x;
		}

		ans+=m[0]/2;
		for(i=1;i<M;i++){
			if(2*p[i]<=m[i]) ans+=p[i];
			else ans+=m[i]/2;
		}

	}else{

		for(i=1;i<=M/2-1;i++){
			int x=min(m[i],m[M-i]);
			m[i]-=x;
			m[M-i]-=x;
			ans+=x;
		}

		ans+=m[0]/2;
		for(i=1;i<M;i++){
			if(i==M/2){
				ans+=m[i]/2;
				m[i]=0;
				continue;
			}

			if(2*p[i]<=m[i]) ans+=p[i];
			else ans+=m[i]/2;
		}

	}


	cout << ans << endl;


	return 0;
}


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

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

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

int main(void){

    ll x;
    cin >> x;

    int a = -120, b = -120;

    ll ans = 0;

    for(int i = a;i < 118;i++){
        for(int j = b;j < 118;j++){
            ans = (i*i*i*i*i)-(j*j*j*j*j);
            if(ans <= 0 || 1000000000 < ans) continue;
            if(ans == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
A.sort()
check = -1
for i in range(N):
    if A[i] > 0:    
        break
    check += 1

ans = 0
if 0 <= check < N-1:
    ans = 0
    for i in range(N):
        if i <= check:
            ans -= A[i]
        else:
            ans += A[i]
else:
    ans = abs(sum(A)) - 2*min(abs(A[0]),abs(A[N-1]))
print(ans)
tmp = A[0]
i = 0
while N-i-2 > max(0,check):
    print(str(tmp) + " " + str(A[N-i-1]))
    tmp -= A[N-i-1]
    i += 1
if N-i-2 <= check or N-i-2 == 0:
    print(str(A[N-i-1]) + " " + str(tmp))
    tmp = A[N-i-1] - tmp
    i += 1
while N-i-1 > 0:
    print(str(tmp) + " " + str(A[N-i-1]))
    tmp -= A[N-i-1]
    i += 1

Measured memory_bytes: 14024
w,h,*L=map(int,open(0).read().split())
P=L[:w];Q=L[w:]
x,y=w,h
sss=[]
for i,pi in enumerate(P):
	sss.append((pi,1))
for j,qj in enumerate(Q):
	sss.append((qj,0))
sss.sort()
ans=0
for c,f in sss:
	if f and x:
		x-=1
		ans+=c*(y+1)
	elif not f and y:
		y-=1
		ans+=c*(x+1)
print(ans)





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

int binarysearch(int key, int A[], int n){
    int left = 0;
    int right = n;
    int mid;

    while(left != right){
        mid = (left + right) / 2;
        if (key == A[mid]){
            return 1;
        }else if (key < A[mid]){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    return 0;
}

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

  int S[n];
  rep(i, n) cin >> S[i];

  int q;
  cin >> q;

  int T[q];
  rep(i, q) cin >> T[i];
  
  int cnt = 0;

  rep(i, q){
    cnt += binarysearch(T[i], S, n);
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define st first
#define nd second 

using  namespace std;
using pii = pair<int, int>;
using ll = long long;
const  int N = 3e3 + 10;
const int mod = 998244353;
int dp[N];
int add(int a, int b){
	a += b;
	a %= mod;
	return a;
}
int main(){
	int n, k, x, ans = 0;
	scanf("%d %d",&n, &k);
	dp[0] = 1;
	for(int i =1; i <= n; i++){
		scanf("%d", &x);
		if(x <= k){
			for(int j = k; j >= x; j--){
				dp[j] = add(dp[j], dp[j - x]);
			}
		}
		dp[0]++;
		ans = add(ans, dp[k]);
	}
	printf("%d", ans);
}


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

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

  vector<int> c(4);
  string tmp;
  for(int i=0;i<n;i++){
    cin >> tmp;
    if(tmp=="AC")c[0]+=1;
    if(tmp=="WA")c[1]+=1;
    if(tmp=="TLE")c[2]+=1;
    if(tmp=="RE")c[3]+=1;
  }
  
  cout << "AC x " << c[0] << endl;
  cout << "WA x " << c[1] << endl;
  cout << "TLE x " << c[2] << endl;
  cout << "RE x " << c[3] << endl;
  return 0;
}


Measured memory_bytes: 3592
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define MOD 1000000007

int main(){
	string S;
	cin >> S;

	int ans1 = 0;
	for(int i=0; i<S.size(); i++){
		if(i%2 == 0 && S[i] == '1') ans1++;
		if(i%2 == 1 && S[i] == '0') ans1++;
	}

	int ans2 = 0;
	for(int i=0; i<S.size(); i++){
		if(i%2 == 0 && S[i] == '0') ans2++;
		if(i%2 == 1 && S[i] == '1') ans2++;
	}

	cout << min(ans1, ans2) << endl;

	return 0;
}


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

int w[110];
int n;

int min(int a, int b){
	return (a < b ? a : b);
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		if(i == 0) w[i] = x;
		else w[i] = w[i - 1] + x;
	}
	int mn = 100000000;
	for(int i = 0; i < n; i++){
		mn = min(mn, abs(w[n - 1] - 2 * w[i]));
	}
	printf("%d\n", mn);
}

Measured memory_bytes: 128