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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];

    ll ans = 1;
    if(N%2){
        VI n((N+1)/2,0);
        REP(i,N){
            if(A[i]%2 == 1){
                cout << 0 << endl;
                return 0;
            }
            n[A[i]/2]++;
        }
        if(n[0] != 1){
            cout << 0 << endl;
            return 0;
        }
        REP(i,(N+1)/2-1){
            if(n[i+1] != 2){
                cout << 0 << endl;
                return 0;
            }
        }
        REP(i,(N+1)/2) ans = ans*n[i]%MOD;
    }
    else{
        VI n(N/2,0);
        REP(i,N){
            if(A[i]%2 == 0){
                cout << 0 << endl;
                return 0;
            }
            n[A[i]/2]++;
        }
        REP(i,N/2-1){
            if(n[i+1] != 2){
                cout << 0 << endl;
                return 0;
            }
        }
        REP(i,N/2) ans = ans*n[i]%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
import math
import itertools

n = int(input())
x, y = [], []
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    y.append(j)

ans = []
for i in itertools.permutations([i for i in range(n)]):
    length = 0
    for j in range(n-1):
        length += math.sqrt((x[i[j]] - x[i[j+1]])**2 + (y[i[j]] - y[i[j+1]])**2)
    ans.append(length)
print(sum(ans)/len(ans))


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

public class Main {
    private static Scanner in;

    private static int n, k;
    private static int[] h;
    private static int[] dp;

	public static void main(String[] args) {
        in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        h = new int[n];
        for(int i=0; i<n; i++) h[i] = in.nextInt();

        dp = new int[n-1];

        Arrays.fill(dp, -1);

        System.out.println(solve(0));

	}

    public static int solve(int i) {
        if (i==n-1) return 0;

        if (dp[i]!=-1) return dp[i];


        int ans = (int)1e9;

        for(int j=i+1; j<=i+k && j<n; j++) {
            ans = Math.min(ans, Math.abs(h[j]-h[i])+solve(j));
        }

        return dp[i] = ans;

    }

}


Measured memory_bytes: 60884
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

struct segment_tree {
  using T = i64;
  T ope(const T& a, const T& b) {
    return max(a, b);
  }
  T ide() { return -1e18; }

  i64 n;
  vector<i64> node;

  segment_tree(vector<i64> init) {
    n = 1;
    while(n < init.size()) n *= 2;
    node.resize(2 * n);
    rep(i, 0, init.size()) node[i + n] = init[i];
    for(int i = n - 1; i >= 1;i--) node[i] = ope(node[i * 2], node[i * 2 + 1]);
  }

  void update(i64 i, i64 x) {
    i += n;
    node[i] = x;
    while(i > 1) {
      i = i / 2;
      node[i] = ope(node[i * 2], node[i * 2 + 1]);
    }
  }

  T get(i64 l, i64 r) {
    T lx = ide();
    T rx = ide();
    l += n;
    r += n;
    while(l < r) {
      if(l & 1) { lx = ope(lx, node[l]); }
      if(!(r & 1)) { rx = ope(node[r], rx); }
      l = (l + 1) >> 1;
      r = (r - 1) >> 1;
    }
    if(l == r) { lx = ope(lx, node[l]); }
    return ope(lx, rx);
  }
};

int main() {
  i64 N;
  cin >> N;
  vector<i64> h(N + 1), a(N + 1);
  rep(i, 1, N + 1) cin >> h[i];
  rep(i, 1, N + 1) cin >> a[i];
  vector<i64> vec(N + 1, -1e18);
  vec[0] = 0;
  segment_tree seg(move(vec));
  rep(i, 1, N + 1) {
    seg.update(h[i], seg.get(0, h[i] - 1) + a[i]);
  }

  cout << seg.get(0, N) << endl;
}


Measured memory_bytes: 9088
from scipy.misc import comb
N, A, B = map(int, input().split())
V = list(map(int, input().split()))


V.sort(reverse=True)
print(sum(V[:A]) / A)


Ath_CNT = V.count(V[A - 1])
V_than_Ath_CNT = len([v for v in V if v > V[A - 1]])
if max(V) == V[A - 1]:
    ans = 0
    for k in range(A, B + 1):
        ans += comb(Ath_CNT, k, 1)
else:
    ans = comb(Ath_CNT, A - V_than_Ath_CNT, 1)
print(ans)


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  bool result = false;
  if(A==B && A!=C) result = true;
  if(B==C && B!=A) result = true;
  if(C==A && C!=B) result = true;
  if(result){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
      
   
 
  
}

Measured memory_bytes: 256
import java.util.*;

class FenwickTree{
    private int _n;
    private long[] data;

    public FenwickTree(int n){
        this._n = n;
        data = new long[n];
    }

    public void add(int p, long x){
        assert(0<=p && p<_n);
        p++;
        while(p<=_n){
            data[p-1] += x;
            p += p&-p;
        }
    }
    public long sum(int l, int r){
        assert(0<=l && l<=r && r<=_n);
        return sum(r)-sum(l);
    }

    private long sum(int r){
        long s = 0;
        while(r>0){
            s += data[r-1];
            r -= r&-r;
        }
        return s;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int Q = sc.nextInt();
        FenwickTree fw = new FenwickTree(N);
        for(int n=0; n<N; n++){
            long a = sc.nextLong();
            fw.add(n, a);
        }
        for(int q=0; q<Q; q++){
            int t = sc.nextInt();
            if(t==0){
                int p = sc.nextInt();
                long x = sc.nextLong();
                fw.add(p, x);
            }else{
                int l = sc.nextInt();
                int r = sc.nextInt();
                System.out.println(fw.sum(l, r));
            }
        }
        
        
    }
}


Measured memory_bytes: 63264
#include <cstdio>
#include <cstring>

int main(){
	char input[10001];
	while(~scanf("%s", input)){
		int ioi = 0, joi = 0;
		char *p = input;
		while((p = strstr(p, "JOI")) != NULL){ joi++; p++; }
		p = input;
		while((p = strstr(p, "IOI")) != NULL){ ioi++; p++; }
		printf("%d\n%d\n", joi, ioi);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    string str;
    cin >> str;
    int n;
    cin >> n;
    bool flag = true;
    for(int i = 0; i < n; ++i)
    {
        int t1,t2;
        char c;
        scanf("%d",&t1);
        switch(t1)
        {
            case 1:
                flag = !flag;
            break;
            case 2:
                scanf("%d %c",&t2,&c);
                if(!flag)
                {
                    if(t2==1)t2=2;
                    else if(t2==2)t2=1;
                }
                if(t2==1)
                    {
                        str.insert(str.begin(),c);
                    }
                    else if(t1==2)
                    {
                        str.insert(str.end(),c);
                    }
            break;
            default:
            break;
        }
    }
    if(!flag)
    {
        reverse(str.begin(),str.end());
    }
    cout << str << endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> n && n)
	{
		map<char, char> table;
		for (int i = 0; i < n; i++)
		{
			char c; cin >> c;
			cin >> table[c];
		}

		string ans;
		int m = getInt();

		for (int i = 0; i < m; i++)
		{
			char c; cin >> c;
			if(table.count(c)) ans += table[c];
			else ans += c;
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
const int maxn=3e5+10;
multiset<int> s;
vector<int> ve[maxn];
int c[maxn];
int n,m,k;

void add(int x){
	s.erase(s.find(c[x]));
	c[x]++;
	s.insert(c[x]);
}

void delet(int x){
	s.erase(s.find(c[x]));
	c[x]--;
	s.insert(c[x]);
}

int main(){
	io;
	cin>>n>>m>>k;
	while(k--){
		int x,y;cin>>x>>y;
		ve[x].pb(y);
		c[y]++;
	}
	for(int i=1;i<=m;i++)s.insert(c[i]);
	s.insert(0);
	int ans=0;
	for(int i=1;i<=n;i++){
		int xx=sz(ve[i]);
		for(int x:ve[i])delet(x);
		ans=max(ans,xx+(int)(*s.rbegin()));
		for(int x:ve[i])add(x);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, double> pd;
typedef pair<int, int> pi; typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;  typedef pair<ll, pi> plp;
typedef pair<int, pi> pip; typedef tuple<int, int, int> ti;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

char S[100]; int N;
int main() {
	scanf("%s", S);
	N = strlen(S);
	bool isGood = false;
	for(int i=0; i<N-1; i++) if(S[i] == 'A' && S[i+1] == 'C') isGood = true;
	puts(isGood?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, c;
  in(n);
  vector<ll> a(n), b(n, 1);
  rep(i, n)
    in(a[i]);
  sort(all(a));
  rep(i, n - 1){
    if(a[i] == a[i + 1])
      b[i + 1] = b[i] + 1;
  }
  c = 0;
  rep2(i, 1, n){
    if(b[i - 1] % 2 == 1 && b[i] == 1)
      c++;
  }
  if(b[n - 1] % 2 == 1)
    c++;
  out(c);
  memi;
}

Measured memory_bytes: 1792
class imosOneDimension:
    def __init__(self, size):
        self.table = [0 for i in range(size)]

    def setTable(self):
        for i in range(len(self.table) - 1):
            if self.is_prime(i) and self.is_prime(int((i + 1) / 2)):
                self.table[i] = 1
                # self.table[i] += self.table[i - 1]

    def cumulativeSum(self):
        for i in range(1, len(self.table)):
            self.table[i] += self.table[i - 1]

    def is_prime(self, n):
        if n == 1:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        i = 3
        while i ** 2 <= n:
            if n % i == 0:
                return False
            i += 2
        return True


imos = imosOneDimension(size=10 ** 5 + 1)
imos.setTable()
imos.cumulativeSum()
q = int(input())
for i in range(q):
    l, r = [int(i) for i in input().split()]
    print(imos.table[r] - imos.table[l - 1])


Measured memory_bytes: 6424
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int n;
  cin >>n; 
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  
  cout << d[n/2]-d[n/2-1] << endl;
}

Measured memory_bytes: 640
import sys
def input():
	return sys.stdin.readline().strip()


N, M = list(map(int, input().split()))

edge_list = []
for _ in range(M):
	a, b, c = list(map(int, input().split()))
	a -= 1
	b -= 1
	edge_list.append((a, b, c))
dist = [-(10**20) for _ in range(N)]
dist[0] = 0

for times in range(N):
	for edge in edge_list:
		if dist[edge[0]] > -(10**20):
			if dist[edge[1]] == -(10**20):
				dist[edge[1]] = dist[edge[0]] + edge[2]
			else:
				dist[edge[1]] = max(dist[edge[1]], dist[edge[0]] + edge[2])
score = dist[N - 1]

for times in range(N):
	for edge in edge_list:
		if dist[edge[0]] > -(10**20):
			if dist[edge[1]] == -(10**20):
				dist[edge[1]] = dist[edge[0]] + edge[2]
			else:
				dist[edge[1]] = max(dist[edge[1]], dist[edge[0]] + edge[2])

if score < dist[N - 1]:
	print("inf")
else:
	print(dist[N - 1])

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

int main(){

    int e1,e2,e3,e4;
    cin>>e1>>e2>>e3>>e4;
    if(e1==e2&&e3==e4){
       cout<<"yes"<<endl;
    } else if (e2==e3&&e1==e4){
       cout<<"yes"<<endl;
    } else if (e1==e3&&e2==e4){
       cout<<"yes"<<endl;
    } else {
       cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())
    ans = 2 * (x // 11)
    if x % 11 == 0:
        pass
    elif x % 11 <= 6:
        ans += 1
    else:
        ans += 2

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61872
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int ASC(const int *a,const int *b){
	return (*a - *b);
}

int main(int argc, char const *argv[])
{
	int n,w[107];
	int min = 0x3FFF;
	int lsum = 0,rsum = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		scanf("%d",&w[i]);
		rsum += w[i];
	}
	// qsort(w,n,sizeof(int),ASC);
	for (int i = 0; i < n; ++i)
	{
		lsum += w[i];
		rsum -= w[i];
		if(abs(lsum - rsum) < min)	min = abs(lsum - rsum);
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n, m, a;
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	int p = 0, q = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) p++;
		else q++;
	}
	long long ret = 1;
	for (int i = 0; i < q - 1; i++) ret *= 2;
	if (q == 0 && m == 1) ret = 0;
	for (int i = 0; i < p; i++) ret *= 2;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 764
import sys
from functools import lru_cache

sys.setrecursionlimit(2 ** 20)

INF = sys.maxsize

N = int(input())
bars = list(map(int, input().split()))

@lru_cache(maxsize=None)
def min_cost(start, goal):
  if start == goal:
    return 0
  else:
    return min(
      min_cost(start, goal - 1) + abs(bars[goal] - bars[goal - 1]) if goal - 1 >= 0 else INF,
      min_cost(start, goal - 2) + abs(bars[goal] - bars[goal - 2]) if goal - 2 >= 0 else INF      
    )


print(min_cost(0, N - 1))

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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------


int main(){
    int a, b;
    double t;
    cin >> a >> b >> t;
    int ans = 0, tmp = a;
    while((double)tmp < t + 0.5){
        ans += b;
        tmp += a;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    string x,y;
    x = "";
    for(int i=0; i<w; i++){
        if(i<a){
            x += "1";
            y += "0";
        }else{
            x += "0";
            y += "1";
        }
    }
    for(int i=0; i<h; i++){
        if(i<b){
            cout << x << endl;
        }else{
            cout << y << endl;
        }
    }
}

Measured memory_bytes: 1280
#include <stdio.h>

int dp[1000100];

int main(){
    int x;
    scanf("%d", &x);
    dp[0] = 1;
    for (int i = 100; i <= 105; i++) {
        for (int j = i; j <= 1000005; j++) {
            dp[j] |= dp[j - i];
        }
    }
    printf("%d\n", dp[x]);
}

Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
    string ans = "Yay!";
    if(e-a > k) ans = ":(";
    
    cout << ans << ln;
    return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {

	static char[] xx = new char[] {'S','H','C','D'};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		System.out.printf("%.8f", Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));

	}
}

Measured memory_bytes: 19128
n = gets.to_i
as = gets.split.map(&:to_i)
as.sort!
x = as[n - 1]
if x % 2 == 0
  y = as.min_by{|a| (x / 2 - a).abs}
else
  y = as.min_by{|a| (x / 2 + 1 - a).abs}
end
print x, ' ', y, "\n"

Measured memory_bytes: 9328
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int sum = 0;
    int temp;
    int i;
    for(i=0;i<n;i++){
        scanf("%d", &temp);
        sum += temp;
    }
    sum -= n;
    
    printf("%d", sum);

    return 0;
}

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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=1e5+5,MOD=100;

using namespace std;
int n,k;
string a;
int howmany(int x){
	int ret = 0;
	while(x<k){
		x*=2;
		ret++;
	}
	return ret;
}
double power(int x){
	double ret = 0.5;

	for(int i=1;i<x;i++)ret*=0.5;
	return ret;
}
char s[5];
int main(){
	
    bool YYMM=false,MMYY=false;
	scanf("%s",s);
	int m=(s[0]-'0')*10+s[1]-'0',y=(s[2]-'0')*10+s[3]-'0';
	if (m>0 && m<=12)
        MMYY=true;
    if (y>0 && y<=12)
        YYMM=true;
    if (YYMM && MMYY)
        printf("AMBIGUOUS");
    else if (YYMM)
        printf("YYMM");
    else if (MMYY)
        printf("MMYY");
    else
        printf("NA");
	return 0;
}


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

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

int	main(void)
{
	int		N;
	double	D;
	long	X[200010], Y[200010];
	int		i;
	int		res;

	scanf("%d %lf", &N, &D);
	for (i = 0; i < N; i++)
		scanf("%ld %ld", &X[i], &Y[i]);
	res = 0;
	for (i = 0; i < N; i++)
	{
		if (sqrt((X[i] * X[i]) + (Y[i] * Y[i])) <= D)
			res++;
	}
	printf("%d\n", res);
	return (0);
}


Measured memory_bytes: 5260
A,B=map(int,input().split())
strong=[2,3,4,5,6,7,8,9,10,11,12,13,1]
if strong.index(A)>strong.index(B):
    print('Alice')

elif strong.index(A)==strong.index(B):
    print('Draw')
else:
    print('Bob')


Measured memory_bytes: 2940
// ------------------------------------
// Date:2018/ 3/ 4
// Problem:ABC 089 _ b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  char ch;
  int cnt = 0;
  bool p, w, g, y;
  p = w = g = y = false;
  REP(i, N) {
    cin >> ch;
    switch (ch) {
      case 'P':
        p = true;
        break;
      case 'W':
        w = true;
        break;
      case 'G':
        g = true;
        break;
      case 'Y':
        y = true;
        break;
    }
  }
  if (p) ++cnt;
  if (w) ++cnt;
  if (g) ++cnt;
  if (y) ++cnt;
  
  if (cnt == 3) {
    cout << "Three" << endl;
  } else if (cnt == 4) {
    cout << "Four" << endl;
  }
  return 0;
}



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

int main(){
  long a,b,k;
  cin >> a >> b >> k;
  if(a-k>0){
    a = a-k;
  }else if(a+b>=k){
    b = b + a -k;
    a = 0;
  }else{
    a = b = 0;
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
import Data.List

g1 = [2]
g2 = [1,3,5,7,8,10,12]
g3 = [4,6,9,11]

main = do
    [a,b]  <- map read.words<$>getLine :: IO [Int]
    putStrLn $ case (a,b) of
        (a,b) | a `elem` g1 && b `elem` g1 -> "Yes"
        (a,b) | a `elem` g2 && b `elem` g2 -> "Yes"
        (a,b) | a `elem` g3 && b `elem` g3 -> "Yes"
        otherwise -> "No"


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int A,B,C;
int main(){
    cin>>A>>B>>C;
    int ans=A^B^C;
    cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools
import itertools


def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29


def mk1d(n, val=INF):
    return [val for i in range(n)]

def mk2d(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]

DIV = 998244353


def convolve(a, b):
    p, g = 1107296257, 5
    n0, n1 = len(a), len(b)
    n = 1 << (max(n0, n1) - 1).bit_length() + 1
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)
    w = pow(g, (p - 1) // n, p)
    invw = pow(w, p-2, p)

    def fft(f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2

    def ifft(f):
        d = 1
        while d < n:
            v = pow(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2

    fft(a), fft(b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(a)
    invn = pow(n, p - 2, p)
    return [a[i] * invn % p for i in range(n0 + n1 - 1)]


def main():
    N = iRaw()
    Ps = tuple(isRaw())
    Qs = tuple(isRaw())
    idxP = -1
    idxQ = -1
    permN = itertools.permutations(range(1,N+1),N)
    for idx,perm in enumerate(permN):
        if  idxP==-1 and perm == Ps:
            idxP = idx
        if idxQ == -1 and perm == Qs:
            idxQ = idx
    return abs(idxP-idxQ)

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 39408
h, w, k = map(int, input().split())
c = [list(input()) for _i in range(h)]

x = [i.count('#') for i in c]
y = [[i[j] for i in c].count('#') for j in range(w)]
z = sum(x)
r = 0
for i in range(2**h):
    s = []
    num = i
    for _i in range(h):
        if num%2==1:
            s.append(_i)
        num >>= 1
    for j in range(2**w):
        num = j
        t = []
        for _j in range(w):
            if num%2==1:
                t.append(_j)
            num >>= 1
        if s==[] and t==[]:
            if k == z:
                r += 1
        elif s == []:
            counter = sum(y[n] for n in t)
            if z-counter == k:
                r += 1
        elif t == []:
            counter = sum(x[n] for n in s)
            if z-counter == k:
                r += 1
        else:
            counter = sum(x[n] for n in s) + sum(y[m] for m in t)
            for nn in s:
                for mm in t:
                    if c[nn][mm] == '#':
                        counter -= 1
            if z-counter == k:
                r += 1

print(r)

Measured memory_bytes: 9288
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,x,t;
int main()
{
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
    return 0;
}



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

#define N 200020

using namespace std;

struct EDGE {
	int adj, next;
} edge[N * 2];

int n, gh[N], sg[N], top;

void addedge(int x, int y) {
	edge[++top].adj = y;
	edge[top].next = gh[x];
	gh[x] = top;
}

void dfs(int x, int root = 0) {
	sg[x] = 0;
	for (int p = gh[x]; p; p = edge[p].next)
		if (edge[p].adj != root) {
			dfs(edge[p].adj, x);
			sg[x] ^= sg[edge[p].adj];
		}
	sg[x] += 1;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		addedge(x, y);
		addedge(y, x);
	}
	dfs(1);
	puts(sg[1] != 1 ? "Alice" : "Bob");
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int N; cin >> N;
    vec L(N); readv(L);
    bool ans = true;
    int s = 0; REP(i, N) s += L[i];
    REP(i, N) if(L[i] >= s - L[i]) ans = false;
    Ans(ans, "Yes", "No");

    return 0;
}


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


int main() {

//変数の宣言

	int i,j,n,debt;
	
	cin >> n;
	debt = 100000;
	
	for(j=0;j<n;j++){
		debt = debt * 1.05;
		i = 0;
		while(1){
			if (((100000+i*1000)<debt)&&((100000+(i+1)*1000)>=debt)){
				debt = (100000+(i+1)*1000);
				break;
			}
			i++;
		}
	}
	
	cout << debt <<endl;
		
	return 0;
}

Measured memory_bytes: 1160
import itertools
K = int(input())
ans = 0
S = list(range(1,K+1))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
for v in itertools.combinations_with_replacement(S, 3):
  if v[0] == v[1] == v[2]:
    ans += v[0]
  elif v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
    ans += gcd(gcd(v[0],v[1]),v[2])*6
  else:
    ans += gcd(gcd(v[0],v[1]),v[2])*3

print(ans)

Measured memory_bytes: 9144
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&c^-1;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
string a,ans="";
cin>>a;
for (char c:a){
  if (c=='B'){
    if (ans.size()) ans.pop_back();
	}else{
	ans.push_back(c);    
	}
  }
cout<<ans<<endl;
}

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

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

void m(ld s) 
{ 
    
    ld length = s / 3; 
  
    s -= length; 
  
 
    ld breadth = s / 2; 
  ld height = s - breadth; 
    cout<<fixed<<sp(10)<< (length * breadth * height); 
} 

int32_t main()
{
    speed upp
    ld n;
    cin>>n;
    m(n);
}

Measured memory_bytes: 256
cnt=0
def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    l=a[left:mid]
    r=a[mid:right]
    l.append(float("inf"))
    r.append(float("inf"))
    i=0
    j=0
    for k in range(left,right):
        global cnt
        cnt+=1
        if(l[i] <= r[j]):
            a[k] = l[i]
            i+=1
        else:
            a[k]=r[j]
            j+=1
 
def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
 
 
 
n=int(input())
s=input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(cnt)
    


Measured memory_bytes: 69564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  int N = s.length();
  int count = 0;
  rep(i,N/2){
    if(s[i] != s[N-1-i]) ++count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int age;
	int a_g[7] = {0};
	int i;
	
	while (1) {
		
		scanf("%d", &n);
		
		if (n == 0) {
			break;
		}
		else {
			for (i = 0; i < n; i++) {
				
				scanf("%d", &age);
				
				if ((age >= 0) && (age <= 9)) {
					a_g[0]++;
				}
				
				else if ((age >= 10) && (age <= 19)) {
					a_g[1]++;
				}
				
				else if ((age >= 20) && (age <= 29)) {
					a_g[2]++;
				}
				
				else if ((age >= 30) && (age <= 39)) {
					a_g[3]++;
				}
				
				else if ((age >= 40) && (age <= 49)) {
					a_g[4]++;
				}
				
				else if ((age >= 50) && (age <= 59)) {
					a_g[5]++;
				}
				
				else if (age >= 60) {
					a_g[6]++;
				}
			}
		}
		
		printf("%d\n", a_g[0]);
			a_g[0] = 0;
		printf("%d\n", a_g[1]);
			a_g[1] = 0;
		printf("%d\n", a_g[2]);
			a_g[2] = 0;
		printf("%d\n", a_g[3]);
			a_g[3] = 0;
		printf("%d\n", a_g[4]);
			a_g[4] = 0;
		printf("%d\n", a_g[5]);
			a_g[5] = 0;
		printf("%d\n", a_g[6]);
			a_g[6] = 0;
		
	}
	
	return (0);
}

Measured memory_bytes: 600
import sys
sys.setrecursionlimit(10**6)
from collections import Counter

def dfs(nw):
    for nx in F[nw]:
        if V[nx]==-1:
            V[nx] = cnt
            dfs(nx)

n, m, k = list(map(int, sys.stdin.readline().split()))
F = [[] for _ in range(n)]
B = [[] for _ in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    F[a].append(b)
    F[b].append(a)
for i in range(k):
    c,d = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    B[c].append(d)
    B[d].append(c)

V = [-1]*n
cnt = 1
for i in range(n):
    if V[i]==-1:
        V[i] = cnt
        dfs(i)
        cnt += 1
cV = Counter(V)
ans = []
for i in range(n):
    ans.append(cV[V[i]]-1 - len(F[i]) - sum([V[b]==V[i] for b in B[i]]))

print(*ans)

Measured memory_bytes: 64744
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
long long sum[maxn];
int a[maxn];
int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++)
			scanf("%d",a+i);
		sort(a,a+n);
		sum[0]=a[0];
		for(int i=1;i<n;i++)
			sum[i]=sum[i-1]+a[i];
		long long ans;
		if(n&1){
			if(n==3)
				ans = max(abs(2*a[2]-a[1]-a[0]), abs(2*a[0]-a[1]-a[2]));
			else
				ans = max(abs(2*(sum[n-1]-sum[n/2])-2*(sum[n/2-2])-(a[n/2]+a[n/2-1])), abs(2*(sum[n-1]-sum[n/2+1])-2*(sum[n/2-1])+(a[n/2]+a[n/2+1])));
		}
		else
			ans =abs(2*(sum[n-1]-sum[n/2])-2*(sum[n/2-2])+abs(a[n/2]-a[n/2-1]));
		printf("%lld\n",ans);
	}
}

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

int main() {
  int a,b,c,d; cin >> a >> b>> c >> d;
  while(true) {
    c -= b;
    if(c <= 0) { cout << "Yes\n"; break; }
    a -= d;
    if(a <= 0) { cout << "No\n"; break; } 
  }
  
  return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if (A==0 && B==0)
    {
        printf("0\n");
    }
    else if (A+B>=A-B && A+B>A*B)
    {
        printf("%d",A+B);
    }
    else if (A-B>A+B && A-B>A*B)
    {
        printf("%d",A-B);
    }
    else if (A*B>A+B && A*B>A-B)
    {
        printf("%d",A*B);
    }
}


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

int main(){
  	int N;
  	int sum=0;
  	cin>>N;
  	vector<int> A(N),B(N-1);
  	for(int k=0;k<N-1;k++)cin>>B.at(k);
  	A.at(0)=B.at(0);
  	A.at(N-1)=B.at(N-2);
  
	for(int i=0;i<N-2;i++){
      if(B.at(i)<B.at(i+1)) {A.at(i+1)=B.at(i);}
      else {A.at(i+1)=B.at(i+1);}
    }

//  	for(auto it=A.begin();it!=A.end();++it)cout<<*it<<" - ";
  	for(int k=0;k<N;k++) sum+=A.at(k);
  	cout<<sum<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N, temp;
  std::cin >> N;
  std::vector<std::pair<int,int>> A;
  
  for (int i=0; i<N; ++i) {
    std::cin >> temp;
    A.emplace_back(temp, i+1);
  }
  
  std::sort(A.begin(), A.end(), [](const auto &a, const auto &b) {return a.first < b.first;});

  for (int i=0; i<N; ++i) {
    std::cout << A.at(i).second;
    if (i != N-1)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
}

Measured memory_bytes: 1780
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  int n; cin >> n;
  int a[3],result,i;
  
  for ( i = 2; i>=0;i--){
    a[2-i] = n / pow(10,i);
    n -= a[2-i]*pow(10,i);
  }

  if ( a[2] == a[1] && a[1] == a[0]){
    result = a[0]*111;
  }
  else if ( a[0] > a[1]){
    result = 111*a[0];
  }
  else if ( a[0] == a[1]){
    if( a[2] > a[1]){
      result = 111*(a[0]+1);
    }
    else{
      result = 111 * a[0];
    }
  }
  else result = 111* (a[0]+1);

  cout << result<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int A, B, M;
	cin >> A >> B >> M;

	vector<int> a(A, 100000), b(B, 100000);

	repeat(i, A) {
		cin >> a[i];
	}

	repeat (i, B) {
		cin >> b[i];
	}

	int min_a = *min_element(a.begin(), a.end());	
	int min_b = *min_element(b.begin(), b.end());	

	int min = min_a + min_b;

	repeat(i, M) {
		int x, y, c;
		cin >> x >> y >> c;

		if ((a[x-1] + b[y-1] - c) < min) min = (a[x-1] + b[y-1] - c);
	}

	cout << min << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N,M;
	cin >> N >> M;
	map<int,vector<int>> ma;
	for(int i = 0;i < M;i++) {
		int A,B;
		cin >> A >> B;
		ma[A].push_back(B);
		ma[B].push_back(A);
	}
	bool answer = false;
	for(auto x:ma[1]) {
		for(auto y:ma[x]) {
			if(y == N) {
				answer = true;
			}
		}
	}
	if(answer == true) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 23656
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] dp = new int[n+1];

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

		for (int i=0; i<m; i++){
			int a = Integer.parseInt(sc.next());
			dp[a] = 0;
		}

		dp[1] = dp[1] != 0 ? dp[0] : 0;

		for (int i=2; i<n+1; i++){
			dp[i] = dp[i] != 0 ? (dp[i-1] + dp[i-2])%1000000007 : 0;
		}
//		System.out.println(Arrays.toString(dp));
		System.out.println(dp[n]%1000000007);
	}
}

Measured memory_bytes: 44204
#include <iostream>
#include <vector>
#include <stack>

using std::cin;
using std::cout;
using std::endl;

int check_start(std::vector<int> t, int ts) {
	for (int i = t.size()-1; i > 0; i--) {
		if (t[i] <= ts) {
			return i;
		}
	}
	return 0;
}

int check_end(std::vector<int> t, int te) {
	for (int i = 0; i < t.size(); i++) {
		if (t[i] >= te) {
			return i;
		}
	}
	return t.size()-1;
}

int main(void) {
	int N,M;
	cin >> N >> M;

	while( N != 0 || M != 0 ) {
		int r,q;
		int t,n,m,s;
		cin >> r;

		std::vector< std::stack<int> > l(M);
		std::vector<int> time(r);
		std::vector< std::vector<bool> > use(r, std::vector<bool>(M,false));
		for (int i = 0; i < r; i++) {
			cin >> time[i] >> n >> m >> s;
			if (s == 0) {
				l[m-1].pop();
			}
			else {
				l[m-1].push(n);
			}

			for (int j = 0; j < M; j++) {
				if (!(l[j].empty())) {
					use[i][j] = true;
				}
			}

		}

		cin >> q;
		int ts,te;
		int si,ei;
		for (int i = 0; i < q; i++) {
			cin >> ts >> te >> m;
			si = check_start(time,ts);
			ei = check_end(time,te);
			int sdt = ts - time[si];
			int edt = time[ei] - te;
			int ret = 0;
			int st = 0;
			bool start = false;
			bool end = false;
			bool freq = false;
			for (int j = si; j < ei+1; j++) {
				if (use[j][m-1]) {
					if (j == si) {
						start = true;
					}
					if (j == ei-1) {
						end = true;
					}
					if (!freq) {
						st = time[j];
					}
					freq = true;
				}
				if (!use[j][m-1] || j == ei) {
					if (freq) {
						ret += time[j] - st;
						freq = false;
					}
				}
			}
			if (start && sdt > 0) {
				ret -= sdt;
			}
			if (end && edt > 0) {
				ret -= edt;
			}
			cout << ret << endl;
		}
		cin >> N >> M;
	}

	return 0;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  long long a, b;
  cin >> a >> b;
  if ((a+b)%2 == 0){
      cout << (a+b)/2;
  }else{
      cout << "IMPOSSIBLE";
  }
  return 0; 
 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long A = s.nextInt();
		long B = s.nextInt();
		long C = s.nextInt();
		long K = s.nextInt();
		
		long ans =0;
		
		if(K <= A) {ans =K;}
		else if(K <= A+B) {ans = A;}
		else {ans = A-(K-A-B);}
		
		System.out.println(ans);
	}

}


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

struct StQuery
{
  StQuery() : m_nLeft(0), m_nRigt(0) { }

  int m_nLeft;
  int m_nRigt;
};

void fnInput(string& rsStr, vector<StQuery>& rvoQuery)
{
  int nStrSiz, nQuerySiz;
  cin >> nStrSiz >> nQuerySiz;
  rvoQuery.resize(nQuerySiz);

  cin >> rsStr;
  
  for (StQuery& roQuery : rvoQuery)
    cin >> roQuery.m_nLeft >> roQuery.m_nRigt;
}

void fnSubStrACCnt(string sStr, const vector<StQuery>& cnrvoQuery)
{
  vector<int> vnCumlSum(sStr.size() + 1);      // 累積和

  //累積和index 0 1 2 3 4 5 6 7 8
  //文字列位置   1 2 3 4 5 6 7 8
  //文字列       A C A C T A C G
  //文字列index  0 1 2 3 4 5 6 7
  for (int nBgn = 0; nBgn < vnCumlSum.size() - 1; nBgn++)
  {
    vnCumlSum[ nBgn + 2 ] = vnCumlSum[ nBgn + 1 ];
    if (sStr[nBgn] == 'A' && sStr[nBgn + 1] == 'C')
      vnCumlSum[ nBgn + 2 ] = vnCumlSum[ nBgn + 1] + 1;
  }

 for (int i = 0; i < cnrvoQuery.size(); i++)
  {
    cout << vnCumlSum[ cnrvoQuery[i].m_nRigt ] - vnCumlSum[ cnrvoQuery[i].m_nLeft ];
    cout << endl; 
  }
}
 
int main()
{
  string sStr;
  vector<StQuery> voQuery;

  fnInput(sStr, voQuery);
  fnSubStrACCnt(sStr, voQuery);

  return 0;
}

Measured memory_bytes: 4572
#include<bits/stdc++.h>
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i, a, b) for(int i=(int)(a); i>=(int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
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;}

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A;
    int x=0;
    REP(i, 0, N){
        int Ai;
        cin >> Ai;
        x*=-1;
        x+=Ai;
        A.push_back(Ai);
    }

    REP(i, 0, N){
        cout << x << "\n";
        x = 2*A[i]-x;
    }
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
const int MAX = 1e2;
int a[MAX] , b[MAX] , n , mx = 0 , k;
int main() {
    cin >> n;
	for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		k += b[i];
	}
	k += a[0];
	mx = k;
	for (int i = 1; i < n; ++i) {
		k += a[i] - b[i - 1];
		if (k > mx) mx = k;
	}
	cout << mx << endl;
}

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

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

	int N = scan.nextInt();
	int K = scan.nextInt();

	int[] A_ = new int[N];
	for(int i = 0; i < N; i++){
	    A_[i] = scan.nextInt();
	}

	int[] map_ = new int[N+1];
	int kind = 0;
	for(int i = 0; i < N; i++){
	    if(map_[A_[i]] == 0){
		kind++;
	    }
	    map_[A_[i]]++;
	}

	Arrays.sort(map_);

	int num = 0;
	for(int i = 0; i <= N; i++){
	    if(kind > K){
		if(map_[i] != 0){
		    num += map_[i];
		    kind--;
		}
	    }else{
		break;
	    }
	}

	System.out.println(num);
    }
}


Measured memory_bytes: 87128