akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static long[][] dp;
    public static long f(int[] arr, int[] w, int n, int sum, int W) {
        if(sum<0)
            return 0;
        if (n == arr.length)
            return 0;
        if (dp[n][sum] != -1)
            return dp[n][sum];
        if (w[n] + sum <= W) {
            return dp[n][sum] = Math.max(1l*arr[n] + f(arr, w, n + 1, sum + w[n], W), f(arr, w, n + 1, sum, W));
        }
        return dp[n][sum] = f(arr, w, n + 1, sum, W);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int W = sc.nextInt();
        int[] arr = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            arr[i] = sc.nextInt();
        }
        dp = new long[105][100000 + 5];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[i].length; j++)
                dp[i][j] = -1;
        pw.println(f(arr, w, 0, 0, W));
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 126676
#include <array>
#include <iostream>
#include <vector>

uint32_t count = 0;

void merge_sort(uint32_t start, uint32_t end, std::array<uint32_t, 500000>& A) {
  if (end - start == 1) return;
  uint32_t mid = (end + start + 1) / 2;
  merge_sort(start, mid, A);
  merge_sort(mid, end, A);

  std::vector<uint32_t> L(mid - start + 1);
  std::vector<uint32_t> R(end - mid + 1);
  for (uint32_t i = 0; i < mid - start; i++) L[i] = A[start + i];
  for (uint32_t i = 0; i < end - mid; i++) R[i] = A[mid + i];
  L.back() = -1;
  R.back() = -1;

  auto iter_L = L.begin(), iter_R = R.begin();
  for (uint32_t i = 0; i < end - start; i++) {
    if (*iter_L <= *iter_R) {
      A[start + i] = *iter_L;
      iter_L++;
    } else {
      A[start + i] = *iter_R;
      iter_R++;
    }
    count++;
  }

  return;
}

int main() {
  std::array<uint32_t, 500000> A;

  uint32_t n = 0;
  std::cin >> n;
  for (uint32_t i = 0; i < n; i++) std::cin >> A[i];

  merge_sort(0, n, A);
  for (size_t i = 0; i < n - 1; i++) std::cout << A[i] << " ";
  std::cout << A[n - 1] << std::endl;
  std::cout << count << std::endl;

  return 0;
}


Measured memory_bytes: 6732
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    ll sum = 0;
    ll tmp = n;
    ll base = 1000000000;
    while(base >= 1){
        sum += tmp/base;
        tmp %= base;
        base /= 10;
    }
    if(n%sum == 0)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
n = int(input())
s = input()
s += s[:2]

for ans in ["SS", "SW", "WW", "WS"]:
    for i in range(1,n+1):
        if (ans[-1] == "S" and s[i] == "o") or (ans[-1] == "W" and s[i] == "x"):
            ans += ans[-2]
        else:
            ans += ("S" if ans[-2] == "W" else "W")
        

    if ans[:2] == ans[n:]:
        print(ans[:n])
        exit()

print(-1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int n, a, b;

    cin >> n >> a >> b;

    cout << (n * a <= b ? n * a : b) << endl;

    return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.nextString();
            String[] arr = s.split("/");
            out.println(2018 + "/" + arr[1] + "/" + arr[2]);
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

    }
}



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

int main(){
	int N, M;
  	cin >> N >> M;
  	const int NMAX = 50;
  	int A[NMAX], B[NMAX], C[NMAX], D[NMAX];
  	
  	for(int i = 0; i < N; i++){
    	cin >> A[i] >> B[i];
    }
  
  	for(int j = 0; j < M; j++){
    	cin >> C[j] >> D[j];
    }
  
  	for(int i = 0; i < N; i++){
    	int min_dist = abs(A[i]-C[0]) + abs(B[i]-D[0]),checkpoint=1;
      	for(int j = 1; j < M; j++){
        	const int cur_dist = abs(A[i]-C[j]) + abs(B[i]-D[j]);
          	if(min_dist > cur_dist){
            	min_dist = cur_dist;
              	checkpoint = j + 1;
            }
        }
      	cout << checkpoint << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//char a[200000],b[2000000],c[200000];
//char a[1000005],y[1000000],k[300];
char x[400000];
int a[200];
int main()
{
    int i,n,m,j,k=0,l;
    scanf("%s",x);
    for(i=0;i<strlen(x);i++)
    {
        for(j=0;j<26;j++)
        {
            if(x[i]=='a'+j)
            {
                a[j]++;
                break;
            }
        }
    }
    for(i=0;i<26;i++)
    {
        if(a[i]==0)
        {
            k=1;
            printf("%c",'a'+i);
            break;
        }
    }if(k==0)
    {
        printf("None\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)

int main() { 
  int a,b,c,d;cin>>a>>b>>c>>d;
  cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == 5 && b == 5 && c == 7 ||
        a == 5 && b == 7 && c == 5 ||
        a == 7 && b == 5 && c == 5)
            puts("YES");
    else
        puts("NO");
    return 0;
}

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

string subst;
int ca, cc, cg, ct;
int ans = 0;

void solve(std::string S){
    for(int i = 0; i <= S.size(); ++i){
        for(int j = S.size(); j >= 0; --j){
            subst = S.substr(i, j);
            ca = count(subst.begin(), subst.end(), 'A');
            cc = count(subst.begin(), subst.end(), 'C');
            cg = count(subst.begin(), subst.end(), 'G');
            ct = count(subst.begin(), subst.end(), 'T');
            if(ca+cc+cg+ct == subst.size()){
                ans = max(ans, (int)subst.size());
            }
        }
    }
    cout << ans << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb                 push_back
#define bug(x)             cerr<<#x<<" "<<x<<endl;
#define T int time;        scanf("%d", &time); while(time--)
    vector<ll>ar;
  bool check(ll i,ll n){
    if(abs(i-n)<=1)return true;
    for(ll ii=n-1; ii>i; ii--)if(ar[ii]<ar[ii-1])
      cout<<ar[ii]<<" ";
    cout<<endl;
    return true;
  }

   int main(){
       set<ll>s;
      ll n;
      cin>>n;
      for(ll i=0; i<n; i++){
        ll x;
        cin>>x;
        s.insert(x);
      }
      if(s.size()==n)cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
     }
   

Measured memory_bytes: 12932
n = int(input())

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


ans = sum(b)

for i in range(n-1):
    if a[i] == a[i+1]-1:
        ans += c[a[i]-1]
  
print(ans)      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n, a, cnt;
int main()
{
	cin >> n;
	for(int i = 1;i <= n; ++ i){
		cin >> a;
		if(a % 2 == 1)++cnt;
	}
	if(cnt % 2 == 0)cout << "YES";
	else cout << "NO";
    return 0;
}

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

int main() {
  vector<char> a(10);
  for(int i = 0; i < 10; i++){
    cin >> a.at(i);
  }
  a.at(3) = '8';
  for(char x : a){
    cout << x;
  }
  cout << endl;
}


Measured memory_bytes: 256
'use strict';

function Main(input) {
    const tmp = input.trim().split('\n').splice(1);
    const result = {
        AC: 0,
        WA: 0,
        TLE: 0,
        RE: 0,
    };

    for (const v of tmp) {
        result[v]++;
    }
    console.log(`AC x ${result.AC}`);
    console.log(`WA x ${result.WA}`);
    console.log(`TLE x ${result.TLE}`);
    console.log(`RE x ${result.RE}`);

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

Measured memory_bytes: 41852
#include <iostream>
#include <stdlib.h>

using namespace std;

int a, b, c, d;

int main(void)
{
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int mostNearestInt(double num){
	int left = num;
	int right = left + 1;
	if( abs( left - num) < abs(right - num)){
		return left;
	}else{
		return right;
	}
}

int main()
{
	int N;
	double sum1=0,sum2=0,average=0;
	cin>>N;
	int *A = new int[N];
	for(int i =0; i < N; i++){
		double num;
		cin>>A[i];
	}
	unsigned long long int ans = 100*100*100*100*100;
	for(int b = -100; b <=100; b++){
		double cost=0;
		for(int i = 0; i < N; i++){
			cost += (A[i] - b)*(A[i] - b);
		}		
		if(cost < ans) ans = cost;
	}
	cout<<ans<<endl;
	return 0;
}



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

typedef long long int ll;

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

    ll ans = 0;
    for(ll i = 1;i <= n;i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
  long long a,b,x; cin >> a >> b >> x;
  if(a==0) cout << b/x + 1 << endl;
  else{
    if(a%x==0) cout << b/x - a/x + 1 << endl;
    else cout << b/x - a/x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
<?php
    $N = intval(trim(fgets(STDIN)));
    
    $max = 0;
    
    for($i=1;$i<=$N;$i++){
        $line = trim(fgets(STDIN));
        
        if(!isset($array[$line])){
            $array[$line]=1;
        }else{
            $array[$line]++;
        }
        if($max<$array[$line]){
            $max = $array[$line];
        }
    }
    $new_array = array_keys($array,$max);
    asort($new_array);
    // var_dump($new_array);
    //書かれている最大の数
    // echo $max."\n";
    foreach($new_array as $value){
        echo $value."\n";
    }

?>

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

public class Main {
	private static int[] a;
	private static int[][] dp;

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

		int n = sc.nextInt();
		int z = sc.nextInt();
		int w = sc.nextInt();

		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		dp = new int[n + 1][2];
		for (int i = 0; i <= n; i++) {
			Arrays.fill(dp[i], -1);
		}

		System.out.println(dfs(0, 0, z, w));
	}

	private static int dfs(int current, int who, int z, int w) {
		if (current >= a.length) {
			dp[current][who] = Math.abs(z - w);
			return dp[current][who];
		}

		if (dp[current][who] >= 0) return dp[current][who];

		int score;
		if (who == 0) {
			score = Integer.MIN_VALUE;

			for (int k = current; k < a.length; k++) {
				score = Math.max(score, dfs(k + 1, 1, a[k], w));
			}

		} else {
			score = Integer.MAX_VALUE;

			for (int k = current; k < a.length; k++) {
				score = Math.min(score, dfs(k + 1, 0, z, a[k]));
			}
		}

		dp[current][who] = score;
		return dp[current][who];
	}
}


Measured memory_bytes: 26336
N,*L = map(int, open(0).read().split())
ls = [0]*N
for i,c in enumerate(zip(*[iter(L)]*2)):
  ls[i] = c
ls.sort()
pls = []
for i in range(N):
  for j in range(i+1,N):
    a,b = ls[i]
    x,y = ls[j]
    pls += [(x-a,y-b)]
ans = 10**10
for X,Y in pls:
  s = set()
  m = 0
  for x,y in ls:
    if (x-X, y-Y) not in s:
      m += 1
    s.add((x,y))
  ans = min(m,ans)
if N==1:
  ans = 1
print(ans)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
//#include<atcoder/all>
// Begin Header {{{
//using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template<class T, class S> inline bool chmax(T &a, const S &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T, class S> inline bool chmin(T &a, const S &b) { if (a>b) { a = b; return 1; } return 0; }
template<class T> void scan(T &a) { cin >> a; }
void IN() {}
template<class Head, class... Tail> void IN(Head &head, Tail &... tail){ scan(head); IN(tail...); }
// }}} End Header
int main() {
	vector<int> t(4);
	ll n;
	IN(n);
	rep(i,n){
		ll a;
		cin >> a;
		t[a%4]++;
	}
	ll cash = t[1]+t[3];
	bool ok;
	if(t[2] > 0){
		if(t[0] >= cash) ok = true;
		else false;
	}else{
		if(t[0]+1 >= cash) ok = true;
		else ok = false;
	}
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
A,B=map(int, input().split())

ans = 0
for i in range(A,B+1):
    string = str(i)
    mae = string[:2]
    ato = string[3:]
    if mae == ato[::-1]:
        ans += 1

print(ans)

Measured memory_bytes: 78532
N = int(input())
a_list = [int(input()) for _ in range(N)]
a_list2 = sorted(a_list)
max1 = a_list2[-1]
max2 = a_list2[-2]

for a in a_list:
	if a == max1:
		print(max2)
	else:
		print(max1)



Measured memory_bytes: 14112
A, B, C, D = map(int, input().split())

Cprimes = {}
Dprimes = {}

tmpC = C
d = 2
while tmpC > 1:
    if tmpC % d == 0:
        if d in Cprimes:
            Cprimes[d] += 1
        else:
            Cprimes[d] = 1
        tmpC //= d
    else:
        d += 1

tmpD = D
d = 2
while tmpD > 1:
    if tmpD % d == 0:
        if d in Dprimes:
            Dprimes[d] += 1
        else:
            Dprimes[d] = 1
        tmpD //= d
    else:
        d += 1

comPrimes = {}
for k in Cprimes:
    comPrimes[k] = Cprimes[k]
for k in Dprimes:
    if k in comPrimes:
        if comPrimes[k] < Dprimes[k]:
            comPrimes[k] = Dprimes[k]
    else:
        comPrimes[k] = Dprimes[k]

comVal = 1
for k in comPrimes:
    comVal *= k**comPrimes[k]

#print(Cprimes)
#print(Dprimes)
#print(comPrimes)
#print(comVal)

CdivNum = B//C - (A-1)//C
DdivNum = B//D - (A-1)//D
comDivNum = B//comVal - (A-1)//comVal
ans = B-(A-1)
ans -= CdivNum
ans -= DdivNum
ans += comDivNum

print(ans)


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

int main(){
  double W,H,X,Y;
  cin >> W >> H >> X >> Y;
  bool si=(2*X==W&&2*Y==H);
  double ans=W*H/2;
  cout << ans << " " << (si?1:0) << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int h, w;
	cin>>h>>w;
	string a[8];
	for(int i=0; i<h; i++) cin>>a[i];
	int ct=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(a[i][j]=='#') ct++;
		}
	}
	if(ct==h+w-1) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s; cin >> s;
	ll k; cin >> k;
	int n = s.size();
	ll ans = 0;
	int c=1;
	
	bool eql = true;
	rep(i,n-1)if(s[i]!=s[i+1])eql=false;
	if(eql){
		ll ans = (ll(n)*k/2);
		cout << ans << endl;
		return 0;
	}
	
	rep(i,n-1){
		if(s[i]!=s[i+1]){
			ans += c/2;
			c=1;
		}else c++;
	}
	ans += c/2;
	ans *= k;
	if(s[0]==s[n-1]){
		int a=1,b=1;
		for(int i=0; i<n; i++){
			if(s[i]==s[i+1])a++;
			else break;
		}
		for(int i=n-1; i>=0; i--){
			if(s[i]==s[i-1])b++;
			else break;
		}
		ans -= (a/2+b/2-(a+b)/2)*(k-1);
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)5e5 + 3;
const int infint = (int)1e9 + 3;
const ll inf = (ll)2e18;
int n, k, p[MAXN], q[MAXN], oc[MAXN];
set <int> L, R;
vector <int> G[MAXN];
int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i];
		q[p[i]] = i;
	}
	for (int i = 1; i < k; i++)
		R.insert(p[i]);
	for (int i = 1; i <= n; i++) 
	{
		if (i + k - 1 <= n)
			R.insert(p[i + k - 1]);
		if (i)
			R.erase(p[i - 1]);
		L.insert(p[i]);
		if (i > k)
			L.erase(p[i - k]);
		auto it = R.upper_bound(p[i]);
		if (it != R.end())
			G[i].push_back(q[*it]), oc[q[*it]]++;
		it = L.upper_bound(p[i]);
		if (it != L.end())
			G[i].push_back(q[*it]), ++ oc[q[*it]];
	}
	L.clear(); R.clear();
	for (int i = 1; i <= n; ++ i) 
		if (oc[i] == 0)
			L.insert(i);
	int tp = 0;
	while (L.size())
	{
		int pos = (*L.begin());
		p[++tp] = pos;
		L.erase(L.begin());
		for (int i = 0; i < G[pos].size(); ++ i)
		{
			int v = G[pos][i]; -- oc[v];
			if (oc[v] != 0)
				continue;
			L.insert(v);
		}
	}
	for (int i = 1; i <= n; ++ i)
		q[p[i]] = i;
	for (int i = 1; i <= n; ++ i)
		cout << q[i] << "\n";
}


Measured memory_bytes: 60288
N, M = map(int, input().split())

SCS = []
for _ in range(0, M):
    s, c = map(int, input().split())
    SCS.append((s, c))

def candidates():
    SC = [-1, -1, -1]
    for (s, c) in SCS:
        if N > 1:
            if s == 1 and c == 0:
                return -1
        if SC[s-1] == -1:
            SC[s-1] = c
        elif SC[s-1] != c:
            return -1
    return SC

sc = candidates()
if sc == -1:
    print(-1)
else:
    if N == 3:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        b = 0
        if sc[1] != -1:
            b = sc[1]
        c = 0
        if sc[2] != -1:
            c = sc[2]
        print(a * 100 + b * 10 + c)

    if N == 2:
        a = 1
        if sc[0] != -1:
            a = sc[0]
        b = 0
        if sc[1] != -1:
            b = sc[1]
        print(a * 10 + b)

    if N == 1:
        a = 0
        if sc[0] != -1:
            a = sc[0]
        print(a)

Measured memory_bytes: 38492
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



template < typename T >
struct BIT {
  vector< T > data;

  BIT(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret=Madd(ret,data[k]);
    return (ret);
  }

  T get(int x,int y){

    return Msub(sum(y),sum(x));
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k]=Madd(data[k],x);
  }
};



template< typename T >
struct Compress {
  vector< T > xs;

  Compress() = default;

  Compress(const vector< T > &vs) {
    add(vs);
  }

  Compress(const initializer_list< vector< T > > &vs) {
    for(auto &p : vs) add(p);
  }

  void add(const vector< T > &vs) {
    copy(begin(vs), end(vs), back_inserter(xs));
  }

  void add(const T &x) {
    xs.emplace_back(x);
  }

  void build() {
    sort(begin(xs), end(xs));
    xs.erase(unique(begin(xs), end(xs)), end(xs));
  }

  vector< int > get(const vector< T > &vs) const {
    vector< int > ret;
    transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) {
        return lower_bound(begin(xs), end(xs), x) - begin(xs);
        });
    return ret;
  }

  int get(const T &x) const {
    return lower_bound(begin(xs), end(xs), x) - begin(xs);
  }

  int size(){
    return xs.size();
  }

  const T &operator[](int k) const {
    return xs[k];
  }
};


template < typename T > 
int inversionNumber(vector<T> v){
  Compress<T> comp(v);
  comp.build();
  BIT<int> bit(comp.size());

  int res=0;
  rep(i,v.size()){
    int it=comp.get(v[i]);
    res+= i - bit.sum(it);
    bit.add(it,1);
  }

  return res;
}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi v(n),a(n);
  rep(i,n){
    cin>>v[i];
    a[i]=v[i];
  }
  sort(all(a));
  rep(i,n){
    if(i) cout<<' ';
    cout<<a[i];
  }
  cout<<endl;

  cout<<inversionNumber(v)<<endl;


}


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

using namespace std;

typedef long long int lli;

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

    int n, p, sum = 0, big = -1;

    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> p;
        sum += p;
        big = max(big, p);
    }

    cout << sum - big + (big/2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);

#define l_ength size

ll MOD;

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll rwpw(ll q, ll p = MOD-2){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,q);
		}
		mul_mod(q,q);
		p /= 2;
	}
	return ret;
}

int m = (1<<18);
ll x[1<<18]={1ll},rev;
vector<ll> a(1<<18),b(1<<18);

vector<ll> fft(vector<ll> f){
	int i,n,t;
	n = f.l_ength();
	if(n==1){
		return f;
	}
	vector<ll> g[2]; t = m/n;
	for(i=0; i<n; ++i){
		g[i%2].push_back(f[i]);
	}
	for(i=0; i<2; ++i){
		g[i] = fft(g[i]);
	}
	for(i=0; i<n; ++i){
		f[i] = g[1][i%(n/2)];
		mul_mod(f[i],x[i*t]);
		add_mod(f[i],g[0][i%(n/2)]);
	}
	return f;
}

int main(void){
	int n,i,j,p;
	ll t,ans=0ll;
	for(i=0; i<m; ++i){
		a[i] = 0ll; b[i] = 0ll;
	}
	cin >> n >> t;
	for(i=0; i<n; ++i){
		cin >> p;
		++a[p]; ++b[p];
	}
	MOD = 998244353ll;
	rev = rwpw(m);
	x[1] = rwpw(3ll,(MOD-1)/m);
	for(i=2; i<m; ++i){
		x[i] = x[i-1];
		mul_mod(x[i],x[1]);
	}
	a = fft(a);
	for(i=0; i<m; ++i){
		mul_mod(a[i],a[i]);
	}
	reverse(&x[1],&x[m]);
	a = fft(a);
	for(i=m-1; i>=0; --i){
		mul_mod(a[i],rev);
	}
	MOD = 985661441ll;
	rev = rwpw(m);
	x[1] = rwpw(3ll,(MOD-1)/m);
	for(i=2; i<m; ++i){
		x[i] = x[i-1];
		mul_mod(x[i],x[1]);
	}
	b = fft(b);
	for(i=0; i<m; ++i){
		mul_mod(b[i],b[i]);
	}
	reverse(&x[1],&x[m]);
	b = fft(b);
	for(i=m-1; i>=0; --i){
		mul_mod(b[i],rev);
		for(j=0; j<11; ++j){
			if(a[i]%MOD==b[i]){
				break;
			}
			a[i] += 998244353ll;
		}
		ans += min(a[i],t)*i;
		t -= min(a[i],t);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16728
#include<iostream>

using namespace std;
int n, s, ans;
void solve(int v, int sum, int num){
    if(sum==s&&num==n){
        ans++;
        return;
    }
    if(v>=10||num>=n) return;

    solve(v+1, sum+v, num+1);
    solve(v+1, sum, num);
}


int main(){

    while(1){
        cin>> n>> s;
        if(n==0&&s==0) break;
        ans=0;
        solve(0, 0, 0);
        cout<< ans<< endl;
    }

    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll n,t[100010],a[100010];
  cin>>n;
  for(int i=0;i<n;i++)cin>>t[i];
  for(int i=0;i<n;i++)cin>>a[i];
  ll p=1e9+7;


  ll fixh[100010]={};
  ll fixt[100010]={};
  ll fixa[100010]={};
  fixt[0]=t[0];
  fixa[n-1]=a[n-1];
  for(int i=1;i<n;i++){
    if(t[i-1]<t[i])fixt[i]=t[i];
    if(a[i-1]>a[i])fixa[i-1]=a[i-1];
  }
  
  bool is_miss=false;
  for(int i=0;i<n;i++){
    fixh[i]=max(fixa[i],fixt[i]);
    if(fixh[i]==0)continue;
    if(fixa[i]&&fixt[i]&&fixa[i]!=fixt[i])is_miss=true;
    if(fixh[i]>a[i])is_miss=true;
    if(fixh[i]>t[i])is_miss=true;
  }
  if(is_miss){
    cout<<0<<endl;
    return 0;
  }

  ll ans=1;
  for(int i=0;i<n;i++){
    if(fixh[i])continue;
    ans*=min(a[i],t[i]);
    ans%=p;
  }

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


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

using namespace std;



int main(){
 int a,b,c,k;
  cin>>a>>b>>c>>k;
  
  int d=max(a,b);
  int e=max(d,c);
  int sum2=a+b+c-e;
  int ebai=e;
  for(int i=1;i<=k;i++) ebai*=2;
  
  cout<<sum2+ebai<<endl;
   
  
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        for (int i = 0; i < 5; i++)
        {
            if (input[i] == "0")
            {
                Console.WriteLine(i + 1);
                break;
            }
        }
    }
}


Measured memory_bytes: 25816
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe
import Debug.Trace

solve :: Int -> Int -> B.ByteString -> Int
solve n k ss = maximum
  [ accums
    VU.! ((i + k') `min` (gn - 1))
    -    (if i - k' - 1 >= 0 then accums VU.! (i - k' - 1) else 0)
  | i <- [0 .. gn - 1]
  , let k' =
          if is0AtNthGroup i then ((k - 1) `div` 2) * 2 + 1 else (k `div` 2) * 2
  ]
 where
  (_, istream, gn) = fix
    ( \f (bs, acc, g) -> if B.length bs == 0
      then (bs, acc, g)
      else if B.last bs == '0'
        then
          let (other, zeros) = B.spanEnd (== '0') bs
          in  f (other, B.length zeros : acc, g + 1)
        else
          let (other, ones) = B.spanEnd (== '1') bs
          in  f (other, B.length ones : acc, g + 1)
    )
    (ss, [], 0)

  accums :: VU.Vector Int
  accums = unsafePerformIO $ VU.freeze $ (\(x, _, _) -> x) $ foldl'
    ( \(acc, i, prev) k ->
      let cur = prev + k
      in  cur
            `seq` ( unsafePerformIO $ (VM.write acc i cur >> return acc)
                  , i + 1
                  , cur
                  )
    )
    (unsafePerformIO $ VM.new gn, 0, 0)
    istream

  is0AtNthGroup n = if B.head ss == '0' then even n else odd n

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nk <- V.unfoldrN 2 readInt <$> B.getLine
  ss <- B.getLine
  print $ solve (nk V.! 0) (nk V.! 1) ss


Measured memory_bytes: 11900
#include<bits/stdc++.h>
using namespace std;
const int inf=2147483647,N=50050;
struct edge{
	int to,nxt,w;
}e[N<<1];
int head[N],cnt,cur[N],deep[N],pos[N];
int n,m,s,t,ans,tot,even,a[N];
void add(int u,int v,int w)
{
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	e[cnt].w=w;
	head[u]=cnt;
}
bool dinic_bfs(){
	queue<int> q;
	memset(deep,0,sizeof(deep));
	deep[s]=1;
	q.push(s);
	while (!q.empty()){
		int x=q.front();
		q.pop();
		for (int i=head[x];~i;i=e[i].nxt)
			if (e[i].w>0 && deep[e[i].to]==0){
				deep[e[i].to]=deep[x]+1;
				q.push(e[i].to);
			}
	}
	return deep[t];
}
 int dinic_dfs(int u,int now){
        if(u==t)
            return now;
        int ret=0;
        for(int i=cur[u];~i;i=e[i].nxt) {
            cur[u]=i;
            if(deep[e[i].to]==deep[u]+1 && e[i].w){
                int di=dinic_dfs(e[i].to,min(e[i].w,now-ret)); 
                if(di){     
                    e[i].w-=di;
                    e[i^1].w+=di;
                    ret+=di;
                    if(ret==now)
                        break;
                    
				}
            }
		} 
		deep[u]=-1;
        return ret;
    }
int dinic(){
    int ret=0;
    while(dinic_bfs()){    
            memcpy(cur,head,sizeof(head));      
            ret+=dinic_dfs(s,inf);      
        }
      return ret; 
}
bool pd(int n) {
	if (n==1||n==2) return false;
	for (int i=2;i*i<=n;i++)
		if (!(n%i)) return false;
	return true;
}
int main(){
	memset(head,-1,sizeof(head));
    cnt=-1;
	scanf("%d",&n);
    for (int i=1;i<=n;++i){
        scanf("%d",&a[i]);  
    }
	pos[++tot]=a[1];
	for (int i=2;i<=n;++i)
		if(a[i-1]<a[i]-1) {
        	pos[++tot]=a[i];
        	pos[++tot]=a[i-1]+1;
		}
    pos[++tot]=a[n]+1;
    s=0,t=tot+1;
    for(int i=1;i<=tot;++i){
    	if(!(pos[i]&1)) {
    		++even;
    		add(s,i,1);
			add(i,s,0); 
		}else{
			add(i,t,1);
			add(t,i,0);
		}
	}
    for(int i=1;i<=tot;++i)
		if(!(pos[i]&1)){
       		for(int j=1;j<=tot;++j)
				if((pos[j]&1)&&pd(abs(pos[j]-pos[i]))){
					add(i,j,1);
					add(j,i,0);
				}
					
    }
    int ans=dinic();
    printf("%d\n",tot-ans+((even-ans)&1));	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
int main(void) {
	cin >> n;
	set<int> se;
	rep(i, n) {
		int a; cin >> a;
		if(se.count(a)) se.erase(a);
		else se.insert(a);
	}
	printf("%d\n", se.size());
	return 0;
}

Measured memory_bytes: 4864
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Repsept
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_K = 1000000;

/* typedef */

/* global variables */

bool used[MAX_K];

/* subroutines */

/* main */

int main() {
  int k;
  scanf("%d", &k);

  int c = 1, r = 7 % k;
  used[r] = true;

  for (; r > 0; c++) {
    r = (r * 10 + 7) % k;
    if (used[r]) {
      puts("-1");
      return 0;
    }
    used[r] = true;
  }

  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 4156
n = int(input())
s = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0
for ss in s:
    if ss == 'AC':
        ac+=1
    elif ss == 'WA':
        wa+=1
    elif ss == 'TLE':
        tle+=1
    elif ss == 'RE':
        re+=1
    
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

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

using namespace std;

const int N = 50000;

int r, c, q, a[N], b[N], o[N], d[2];
bool used[2][N];

main(){
  while(cin >> r >> c >> q && (r|c|q)){
    for(int i=q-1;i>=0;i--) cin >> a[i] >> b[i] >> o[i];
    fill(used[0], used[2], false);
    d[0] = d[1] = 0;
    int ans = 0;
    for(int i=0;i<q;i++){
      if(!used[a[i]][b[i]]){
        used[a[i]][b[i]] = true;
        ans += ((a[i] ? r : c) - d[1-a[i]]) * o[i];
        d[a[i]]++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1844
#include <stdio.h>
#define MAX 100

int
bubbleSort(int [], int);

void
print(int [], int);

int
main(void)
{
    int arr[MAX], n, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    int cnt = bubbleSort(arr, n);

    print(arr, n);
    printf("%d\n", cnt);

    return 0;
}

int
bubbleSort(int arr[], int n)
{
    int i, j, v, cnt;
    cnt = 0;

    for (i = 0; i < n; i++)
        for (j = n - 1; j > i; j--)
            if (arr[j] < arr[j - 1]) {
                v = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = v;
                cnt++;
            }
    return cnt;
}

void
print(int arr[], int n)
{
    int i = 0;
    printf("%d", arr[i++]);
    for ( ; i < n; i++)
        printf(" %d", arr[i]);
    putchar('\n');
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}
 

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    double r;
    cin>>r;
    double ans = 2*(M_PI)*(r);
    cout<<ans<<"\n";

    return 0;
}
 

Measured memory_bytes: 3228
/* 
	今日も一日がんばるぞい
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n];//ソートするやつ
    vector<int> v;
    REP(i,n){
        scanf("%d",&a[i]);
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    int num1 = v[(n-1)/2];
    int num2 = v[n/2];
    REP(i,n){
        if(a[i]<=num1)COUT(num2);
        else COUT(num1);
    }
    return 0;
}

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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main(){
    IOS 
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<' '<<y<<' '<<z<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L, R;
    cin >> L >> R;
    if (L % 2019 == 0 || R % 2019 == 0) {
        cout << 0 << endl;
        return 0;
    } else if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    int res = 2018;
    for (ll i = L; i < R; i++) {
        for (ll j = i + 1; j <= R; j++) {
            int r = i * j % 2019;
            amin(res, r);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;

typedef long long LL;

struct graph{
	int V;
	vector<char> used;
	vector<int> vs, cmp;
	vector<vector<int> > G, rG;

	graph(int n)
	: V(n), used(n), cmp(n), G(n), rG(n)
	{ }
	
	void add_edge(int a, int b){
		G[a].push_back(b);
		rG[b].push_back(a);
	}
	
	void dfs(int v){
		used[v] = 1;
		for(int i = 0; i < G[v].size(); ++i){
			if(!used[G[v][i]]){ dfs(G[v][i]); }
		}
		vs.push_back(v);
	}
	
	void rdfs(int v, int k){
		used[v] = 1;
		cmp[v] = k;
		for(int i = 0; i < rG[v].size(); ++i){
			if(!used[rG[v][i]]){ rdfs(rG[v][i], k); }
		}
	}
	
	int scc(){
		fill(used.begin(), used.end(), 0);
		vs.clear();
		for(int v = 0; v < V; ++v){
			if(!used[v]){ dfs(v); }
		}
		fill(used.begin(), used.end(), 0);
		int k = 0;
		for(int i = vs.size() - 1; i >= 0; --i){
			if(!used[vs[i]]){ rdfs(vs[i], k++); }
		}
		return k;
	}
};


struct restype{
	int left, is_or, right;
};

const char *p;
map<string,int> vars;

restype expr();
restype factor();

restype expr(){
	restype r = factor();
	if(*p == '|' || *p == '&'){
		r.is_or = (*p++ == '|');
		r.right = factor().left;
	}
	return r;
}


restype factor(){
	restype r;
	if(*p == '~'){
		++p;
		r = factor();
		r.left ^= 1;
		r.is_or ^= 1;
		r.right ^= 1;
	}
	else if(*p == '('){
		++p;
		r = expr();
		++p;
	}
	else{
		char buf[16];
		int d = 0;
		sscanf(p, "%[a-zA-Z]%n", buf, &d);
		p += d;

		int k = vars.insert(make_pair(buf, vars.size())).first->second;
		r.left = r.right = k * 2;
		r.is_or = 0;
	}
	return r;
}


int main(){
	int n, m;
	cin >> n >> m;
	cin.get();

	string s;
	graph G(m * 2);
	for(int i = 0; i < n; ++i){
		getline(cin, s);
		p = s.c_str();
		restype r = expr();

		if(r.is_or){
			G.add_edge(r.left ^ 1, r.right);
			G.add_edge(r.right ^ 1, r.left);
		}
		else{
			G.add_edge(r.left ^ 1, r.left);
			G.add_edge(r.right ^ 1, r.right);
		}
	}

	G.scc();

	const char *ans = "accept";
	for(int i = 0; i < m; ++i){
		if(G.cmp[i*2] == G.cmp[i*2+1]){
			ans = "reject";
		}
	}
	puts(ans);
}

Measured memory_bytes: 1380
import java.util.Scanner;

fun main (args: Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val order = IntArray(N + 1)
    
    for (i in 1..N) {
      order[input.nextInt()] = i
    }
    
    print(order[1])
    for(i in 2..N) {
      print(" ${order[i]}")
    }
    println()
  }
}

Measured memory_bytes: 60924
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
   	ll N;
    cin >> N;
  	ll a[3 * N];
  	ll sum = 0;
  	ll count = 0;
    for(ll i = 0; i < 3 * N; ++i){
      cin >> a[i];
    }
  	sort(a, a + 3 * N, greater<int>());
  	for(ll i = 0; i < 3 * N; ++i){
     	if(i % 2 != 0) {
          sum += a[i];
          count++;
        }
      if(count == N) break;
    }
  	
   
    cout << sum << endl;
}

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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

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


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int a[11000];
int field[110][110];

int dxy[5]={-1,0,1,0,-1};
int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int H,W; cin >> H >> W;
    int N; cin >> N;

    for(int i=1; i<=N; ++i) cin >> a[i];

    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            field[i][j] = -1;
        }
    }int idx = 1;
    int y = 1, x = 1;
    int stmt = 0;
    field[y][x] = 1;
    a[1]--;
    if(a[1]==0) idx++;
    
    while(idx<N+1){
        if(stmt == 0){
            if(field[y][x+1] != -1){
                stmt++;
            }else{
                x++;
            }
        }
        if(stmt == 1){
            if(field[y+1][x] != -1){
                stmt++;
            }else{
                y++;
            }
            
        }else if(stmt == 2){
            if(field[y][x-1] != -1){
                stmt++;
            }else{
                x--;
            }
        }else if(stmt == 3){
            if(field[y-1][x] != -1){
                stmt++;
            }else{
                y--;
            }
        }
        if(field[y][x] == -1 ) {
            field[y][x] = idx;
            a[idx]--;
            if(a[idx]==0) idx++;
        }
        stmt = stmt%4;
    }

    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            if(j-1)cout << " ";
            cout << field[i][j];
        }
        cout << endl;
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[100005];
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		if(a[i]%2 == 1){
			cout<<"first"<<endl;
			return 0;
		}
	}
	cout<<"second"<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int n, k, s; /* 入力 */

/* 合計がsになるk個のn以下の正整数の組を総当たりで探す */
/* i番目の文字をm以上n以下の範囲でとる */
int search(int i, int m, int sum) {
	/* これが最後の数の場合 */
	if (i == k - 1) {
		if (s - sum >= m && s - sum <= n) return 1; /* 最後の数は s - sum */
		else return 0; /* 条件の中で s - sum を取れない */
	}
	/* 枝刈り */
	if (m >= s - sum) return 0; /* この時点でsumが大きすぎる */
	if (n * (k - i) < s - sum) return 0; /* この時点でsumが小さすぎる */

	/* 以降の数について探索する */
	int count = 0;
	int j;
	for (j = m; j <= n; j++) {
		count += search(i + 1, j + 1, sum + j);
	}
	return count;
}

int main(void) {
	/* データセット毎の処理 */
	while (scanf("%d%d%d", &n, &k, &s) == 3 && n >= 1 && n <= 20 && k >= 1 && k <= 10 && s >= 1 && s <= 155) {
		printf("%d\n", search(0, 1, 0));
	}
	return 0;
}

Measured memory_bytes: 600
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

u=input()

for i in range(0,len(u)):
    print("x",end="")


N=int(100005)
a=[int(0) for i in range(N)]



Measured memory_bytes: 4332