akhauriyash/Code-Regression huggingface dataset:
"当選者を探せ！"

while True:
    flag = True
    n = int(input())
    if n == 0:
        break
    C = list(map(str, input().split()))
    if n == 1:
        print(C[0], 1)
        flag = False

    if flag:
        candidates = {}

        for i, c in enumerate(C, start=1):
            if c in candidates:
                candidates[c] += 1
            else:
                candidates[c] = 1
            # print(candidates)
            candidates_list = sorted(candidates.items(), key=lambda x: x[1], reverse=True)
            # print(candidates_list)
            if len(candidates) > 1:
                if candidates_list[0][1] > (candidates_list[1][1]+n-i):
                    print(candidates_list[0][0], i)
                    flag = False
                    break
            if len(candidates) == 1 and candidates_list[0][1] >= (n//2+1):
                print(candidates_list[0][0], n//2+1)
                flag = False
                break

            candidates = dict(candidates_list)

        if flag:
            candidates_list = sorted(candidates.items(), key=lambda x: x[1], reverse=True)
            if len(candidates_list) != 1:
                if candidates_list[0][1] > candidates_list[1][1]:
                    print(print(candidates_list[0][0], candidates_list[0][1]))
                    flag = False
            elif len(candidates_list) == 1:
                print(candidates_list[0][0], n//2+1)
                flag = False
            if flag:
                print('TIE')



Measured memory_bytes: 5624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static int[] f = new int[1000001];
	static long ans = 0;

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int h = sc.nextInt(), w = sc.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++)
			a[i] = sc.next();
		boolean[] row = new boolean[h], col = new boolean[w];
		Arrays.fill(row, false);
		Arrays.fill(row, false);
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (a[i].charAt(j) == '#') {
					row[i]=true;
					col[j]=true;
				}
		for(int i=0;i<h;i++){
			if(row[i]){
				for(int j=0;j<w;j++){
					if(col[j]){
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}

}


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

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp;
  char com[21];
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      A[++H] = atoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


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

int main() {
  long N;
  cin >> N;
  long ans = 0;
  for (long i = 1; i * i <= N; i++) {
    if (N % i == 0) ans = max(ans, i);
  }
  cout << ans + N / ans - 2 << "\n";
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> ans(M, 1);
    for (int i = 0; i < N; i++) {
        int k;
        cin >> k;
        vector<int> flag(M);
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            a--;
            flag[a] = 1;
        }
        for (int j = 0; j < M; j++) {
            ans[j] &= flag[j];
        }
    }
    int cnt = 0;
    for (int j = 0; j < M; j++) {
        if (ans[j]) cnt++;
    }
    cout << cnt << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

lint mod=1e9+7;

int main()
{
	int N;
	lint A[100010]={};
	
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> A[i];
	
	lint xyz[100010][3]={};
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<3;j++)
			xyz[i][j]=xyz[i-1][j];

		for(int j=0;j<3;j++)
		{
			if(xyz[i][j]==A[i])
			{
				xyz[i][j]++;
				break;
			}
		}
	}

	lint ans=1;
	for(int i=1;i<=N;i++)
	{
		lint cnt=0;
		for(int j=0;j<3;j++)
			if(xyz[i-1][j]==A[i])
				cnt++;

		ans*=cnt;
		ans%=mod;
	}
	
	cout << ans << endl;
	return 0;
}


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

int main()
{
    int n, k;
    string s;
    cin >> n >> s >> k;

    char target = s[k - 1];

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != target)
            s[i] = '*';
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false INT_MAX INT_MIN insert erase clear pop push compare INT64_MAX INT64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const int mod = 1e9 + 7 ;
const int inf =
 1e9 + 5 ;
 //1e18L + 5;
const int nax = 2e5 + 5;
void min_self(int&a , int b){a=min(a,b);}
void max_self(int&a , int b){a=max(a,b);}
void add_self(int&a , int b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int x , n ;cin >>x >> n ; 
unordered_set<int>us;
for(int i = 0 ; i<n ; i++){
	int k ; cin >> k ; 
	us.insert(k) ; 
} 
int ans = INT_MAX ; 
for(int i = 0 ; i<=101 ; i++){
	if(us.find(i) != us.end())continue;
	if(abs(i - x) == abs(x - ans)){
		ans = min(ans , i);
	}
	else if(abs(i- x) < abs(x - ans)){
		ans = i ;
	}
	
}
// if(us.find(x)==us.end())ans=x;
cout<<ans;
	

	
}

Measured memory_bytes: 3656
// C - Exam and Wizard
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}

int main(){
	int N = in<int>();
	vi C(N);
	ll minus = 0, impossible = 0;// <0: impossible
	int ans = 0;

	rp(i, 0, N){
		int a = in<int>();
		impossible += a;
		C[i] = a;
	}

	rp(i, 0, N){
		int b = in<int>();
		impossible -= b;
		C[i] -= b;
		if(C[i] < 0){
			ans++;//変更が必要
			minus += C[i];
		}
	}

	if(impossible < 0){ puts("-1"); return 0; }

	sort(allr(C));

	rp(i, 0, C.size()){
		if(minus >= 0) break;
		if(C[i] <= 0) break;
		ans++;//変更が必要
		minus += C[i];
	}

	cout<< ans <<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
//java11
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();

		int ans = 0;
		for(int i=1; i<=K; i++) {
			for(int j=1; j<=K; j++) {
				for(int k=1; k<=K; k++) {
					ans += gcd(gcd(i, j), k);
				}
			}
		}

		System.out.println(ans);
	}

	//最大公約数
	static int gcd(int a, int b) {
		int big = Math.max(a, b);
		int small = Math.min(a, b);

		if(small == 0) {
			return big;
		}

		return gcd(small, big % small);
	}

}


Measured memory_bytes: 35884
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int>v(n);
  for (int i=0;i<n;++i){cin>>v[i];}
  vector<int>c(n);
  for (int i=0;i<n;++i){cin>>c[i];}
  

  
  int s=0;
  for (int i=0;i<n;++i)
  {
      if (v[i]>c[i]){
      s+=v[i]-c[i];
      }
  }
    cout<<s<<endl;
}
     

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

void printRect(int w, int h)
{
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if (y == 0 || y == (h-1) || x == 0 || x == (w-1))
                cout << '#';
            else
                cout << '.';
        }
        cout << endl;
    }
}

int main(void)
{
    while (1)
    {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
            break;
        printRect(w, h);
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	x_i := 100
	x_r := 100.0
	for i := 1; i < x; i++ {
		x_i = int(1.01 * x_r)
		x_r = float64(x_i)
		if x_i >= x {
			fmt.Println(i)
			return
		}
	}
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 50;

int mod_pow(int a, int b) {
	if (!b) return 1;
	if (b % 2) return a * mod_pow(a, b - 1) % MOD;
	int q = mod_pow(a, b / 2);
	return q * q % MOD;
}

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(all(a));

	if (k == 1) {
		cout << 0;
		return;
	}

	vector<int> pref(n);
	for (int i = 0; i < n; i++) {
		pref[i] = ((i ? pref[i - 1] : 0) + a[i]) % MOD;
	}

	vector<int> fact(n + 1);
	fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	int ans = 0;
	for (int i = k; i <= n; i++) {
		int c = fact[i - 2] * mod_pow(fact[k - 2], MOD - 2) % MOD;
		c = c * mod_pow(fact[i - k], MOD - 2) % MOD;
		int sum = ((pref[n - 1] - pref[i - 2] + MOD) % MOD - pref[n - i] + MOD) % MOD;
		ans = (ans + c * sum % MOD) % MOD;
	}

	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 2560
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


ll dp[210000][40];

main(){
    ios
    int n=in();
    ll t=in();
    vecll a,b,b2;
    rep(i,n){
        int A=in(),B=in()+1;
        if(A==0)b2.pb(B);
        else a.pb(A),b.pb(B);
    }
    int m=a.size();
    vec id;
    rep(i,m)id.pb(i);
    sort(all(id),[&](int x,int y){
        return (a[x])*b[y] > (a[y])*b[x];
    });
    vec id2;
    rep(i,n-m){
        id2.pb(i);
    }
    sort(all(id2),[&](int x,int y){
        return b2[x]<b2[y];
    });
    rep(i,n+1)rep(j,40)dp[i][j]=INT_MAX;
    dp[0][0]=1;
    rep(i,m){
        rep(j,31){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][j+1],dp[i][j]+dp[i][j]*a[id[i]]+b[id[i]]);
        }
    }
    t++;
    int ans=0;
    rep(j,31){
        ll T=dp[m][j];
        if(T>t)continue;
        int now=j;
        int p=0;
        while(p<n-m and T+b2[id2[p]]<=t){
            T+=b2[id2[p]]; p++;
        }
        chmax(ans,p+(int)j);
    }
    cout<<ans<<endl;
        
}


Measured memory_bytes: 68708
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    s = set(P)

    diff = INF
    ans = X if X not in s else None
    for i in range(-1, 102):
        if i in s:
            continue

        tmp = abs(X - i)
        if tmp < diff:
            diff = tmp
            ans = i

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	if (N == 1) cout << "Hello World" << "\n";
	else {
		int A, B;
		cin >> A >> B;
		cout << A + B << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=300005;
int n,m,ans,cnt,ok;
int x[N],t[N],l[N],r[N];
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%d",&x[i]);
	For(i,1,n) scanf("%d",&t[i]);
	ans=1;
	For(i,1,n){
		int k=(t[i]+2ll*m-1)/(2*m),v=t[i]%(2*m);
		ans+=k;
		l[i]=(0<v&&v<=2*x[i]);
		r[i]=(0<v&&v<=2*(m-x[i]));
	}
	For(i,1,n-1)
		if (cnt&&r[i]){
			if (l[i]) ++ok;
			--ans; --cnt;
		}
		else if (!l[i]&&r[i]){
			if (ok) ok--,cnt++;
		}
		else if (l[i]) cnt++;
	if (r[n]) ans--;
	printf("%lld",1ll*ans*2*m);
}

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

int main()
{
	int H, W;
	int i,j = 0;
	while(1) {
		cin >> H >> W;
		if (H == 0 || W == 0) {
			break;
		}
		else {
			for (j = 0; j < H; j++) {
				for (i = 0; i < W; i++) {
					cout << "#";
				}
				cout << endl;
			}
			cout << endl;
		}
 }
    
return	 0;
}

Measured memory_bytes: 3076
n, m = gets.split.map(&:to_i)
if m == 1 || n >= m
  puts '0'
else
  nums = gets.split.map(&:to_i).sort
  gaps = []
  (0..(nums.size-2)).each do |i|
    gaps << nums[i+1] - nums[i]
  end
  omit = gaps.sort.reverse[0...n-1].inject(:+)
  omit = 0 if omit.nil?
  puts (nums.max - nums.min) - omit
end


Measured memory_bytes: 11248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    int ans=0;
    while (N>0)
    {
        ans++;
        N/=K;
    }
    cout << ans << endl;
    
    return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int MAX_N = 205;

int M, N;

bool bpGraph[MAX_N][MAX_N];
  
bool bpm(bool bpGraph[MAX_N][MAX_N], int u, 
         bool seen[], int matchR[]) 
{ 
    for (int v = 0; v < N; v++) 
    { 
        if (bpGraph[u][v] && !seen[v]) 
        { 
            seen[v] = true;  
  
            if (matchR[v] < 0 || bpm(bpGraph, matchR[v], 
                                     seen, matchR)) 
            { 
                matchR[v] = u; 
                return true; 
            } 
        } 
    } 
    return false; 
} 
  
int maxBPM(bool bpGraph[MAX_N][MAX_N]) 
{ 
    int matchR[N]; 
  
    memset(matchR, -1, sizeof(matchR)); 
  
    int result = 0;  
    for (int u = 0; u < M; u++) 
    { 
        bool seen[N]; 
        memset(seen, 0, sizeof(seen)); 
  
        if (bpm(bpGraph, u, seen, matchR)) 
            result++; 
    } 
    return result; 
} 
  
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n;
    cin >> n;
    vector<PII> R(n), B(n);
    REP(i, n) cin >> R[i].first >> R[i].second;
    REP(i, n) cin >> B[i].first >> B[i].second;
    M = n;
    N = n;
    REP(i, N) {
        REP(j, N) {
            if (R[j].first < B[i].first && R[j].second < B[i].second) {
                bpGraph[j][i] = 1;
            }
        }
    }
    cout << maxBPM(bpGraph) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
   ll n;
   cin>>n;
   ll a[n];
    bool pot[n];
   for(ll i=0;i<n;i++)
    {cin>>a[i];
    pot[i]=0;}
  sort(a,a+n);
  ll mx=0;
  for(ll i=0;i<n;i++)
  {
    if(a[i]>2*mx)
      pot[i]=1;
     mx+=a[i];
  }
  for(ll i=n-1;i>=0;i--)
  {
    if(pot[i])
    {
      cout<<n-i<<endl;
      return 0;
    }
  }
  cout<<n<<endl;
 


}













Measured memory_bytes: 1152
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n;
    cin >> n;

    cout << n * n * n << "\n";

    return 0;
}

Measured memory_bytes: 256
function main(arg) {
	arg = arg.trim().split("\n")
	arg.shift()
	var s = arg.shift()
	arg = arg.map(e => e.split(" ").map(Number).map(e => e -1))
	var result = new Array(arg.length).fill(0)
	var count = 0
	var indexs = new Array(arg.length)
	for (var i = 0; i < arg.length; i++) {
		indexs[i] = i
	}
	for (var i = 0; i < s.length - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			count++
		}
		result[i + 1] = count
	}
	for (var i = 0; i < arg.length; i++) {
		var l = arg[i][0]
		var r = arg[i][1]
		console.log(result[r] - result[l])
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 56160
#include <bits/stdc++.h>
using namespace std;
int s[100005];
int cnt[100005];
int ans[100005];
int main() {
    int n,k;
    cin >> n >> k;
    s[0] = 100;
    int res = 0;
    string str;
    cin >> str;
    for(int i = 1;i <= n;++i) s[i]=str[i-1]-'0';
    for(int i = 1;i <= n;++i) {
        if(s[i] == 1){
            cnt[i] = cnt[i-1];
            if(s[i-1] == 0) {
                ans[cnt[i]] = i-1;
            }
        }
        else {
            if(s[i-1] == 0) cnt[i] = cnt[i-1];
            else{
                cnt[i] = cnt[i-1]+1;
            }
        }
        res = max(res,i-ans[max(0,cnt[i]-k)]);
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  int n, t, a, ans;
  double temp=1000;
  cin >> n >> t >> a;
  rep(i, n){
    int j;
    cin >> j;
    double x = t - j * 0.006;
    if(temp > abs(a - x)){
      temp = abs(a - x);
      ans = i + 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {

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

		val x1 = sc.nextInt
		val y1 = sc.nextInt
		val x2 = sc.nextInt
		val y2 = sc.nextInt

		val dx = x2 - x1
		val dy = y2 - y1

    val x3 = x2 - dy
    val y3 = y2 + dx

    val x4 = x1 - dy
    val y4 = y1 + dx

		println(s"$x3 $y3 $x4 $y4")

	}


}


Measured memory_bytes: 25536
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n, m = LI()
a = LI()
b = n - sum(a)
print(b if b>=0 else -1)

Measured memory_bytes: 9888
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<math.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10007
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

double Xs, Ys, Xt, Yt;
int N;
double X[1010], Y[1010], R[1010];

double dist[1012][1012];

double yosupot(double a, double b)
{
	return sqrt(a * a + b * b);
}

double dij[1020];
bool vis[1020];
int main()
{
	scanf("%lf%lf%lf%lf", &Xs, &Ys, &Xt, &Yt);
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lf%lf%lf", X + i, Y + i, R + i);

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			double d = yosupot(X[i] - X[j], Y[i] - Y[j]);
			dist[i][j] = max(0.0, d - R[i] - R[j]);
		}
		dist[i][N] = dist[N][i] = max(0.0, yosupot(X[i] - Xs, Y[i] - Ys) - R[i]);
		dist[i][N + 1] = dist[N + 1][i] = max(0.0, yosupot(X[i] - Xt, Y[i] - Yt) - R[i]);
	}
	dist[N][N + 1] = yosupot(Xs - Xt, Ys - Yt);
	for (int i = 0; i < N + 2; ++i) dij[i] = 1e18;
	for (int i = 0; i < N + 2; ++i) vis[i] = false;
	dij[N] = 0;
	for (int i = 0; i < N + 2; ++i) {
		int bp = -1;
		for (int j = 0; j < N + 2; ++j) {
			if (!vis[j] && (bp == -1 || dij[bp] > dij[j])) bp = j;
		}
		vis[bp] = true;
		for (int j = 0; j < N + 2; ++j) dij[j] = min(dij[j], dij[bp] + dist[bp][j]);
	}
	printf("%.10f\n", dij[N + 1]);
	return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>
int Yakusuu(int);
int main(){
  int x,n,i,count=0;

  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d",&x);
    if(Yakusuu(x)){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}                                                                   
int Yakusuu(int x){
  int i,a;
  if(x < 2)return 0;
  else if(x == 2)return 1;
  if(x % 2 == 0) return 0;
  for(i=3;i*i <= x;i+=2){
    if(x%i == 0)return 0;
  }
  return 1;
}



Measured memory_bytes: 2084
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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

		// 計算
		String result = "Yes";
		int[] arrayS = new int[26];
		int[] arrayT = new int[26];
		Arrays.fill(arrayS, -1);
		Arrays.fill(arrayT, -1);
		for(int i = 0; i < s.length(); i++){
		    char x = s.charAt(i);
		    char y = t.charAt(i);
		    if(arrayS[x - 'a'] == -1){
		        arrayS[x - 'a'] = y;
		    }else{
		        if(arrayS[x - 'a'] != y) result = "No";
		    }
		    if(arrayT[y - 'a'] == -1){
		        arrayT[y - 'a'] = x;
		    }else{
		        if(arrayT[y - 'a'] != x) result = "No";
		    }
		}
		
		// 出力
		System.out.println(result);
		
	}
}


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

int main(){
    string S; cin >> S;
    float sum = 0;
    float length = S.length();
    for(int i = 0; i<length;i++){
        char Zero = '0',One = '1';
        if(i%2 == 0){
            if(S[i] != Zero){
                sum++;
            }
        }else{
            if(S[i] != One){
                sum++;
            }
        }
    }
        if(sum > length/2){
        sum = abs((int)(sum-=length));
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 512
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int dp[9 + 1][2][2][2][2][2];

signed main() {
    string S;
    cin >> S;
    int n = S.size();

    dp[0][0][0][0][0][0] = 1;

    // i: 注目している桁のidx
    // j: A未満であることが確定しているか
    // a: すでに7を選んでいるか
    // b: すでに5を選んでいるか
    // c: すでに3を選んでいるか
    // e: すでに0以上がでているか

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            int lim = j ? 9 : S[i] - '0';

            for (int d = 0; d < lim + 1; d++) {
                if (!(d == 7 || d == 5 || d == 3 || d == 0)) continue;
                for (int a = 0; a < 2; a++) {
                    for (int b = 0; b < 2; b++) {
                        for (int c = 0; c < 2; c++) {
                            for (int e = 0; e < 2; e++) {
                                if (e && d == 0) continue;
                                dp[i+1][j || d < lim][a || d == 7][b || d == 5][c || d == 3][e || d > 0] += dp[i][j][a][b][c][e];
                            }
                        }
                    }
                }
            }
        }
    }

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

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	long long int num[100001] = {};
	long long int bene[200001] = {};
	long long int mi[200001] = {};
	long long int beg[200001] = {};
	long long sum[200001] = {};
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		if (i) {
			ans += (num[i] - num[i - 1] + M) % M;
			if (num[i] > num[i - 1]) {
				if (num[i] - num[i - 1] > 1) {
					bene[num[i - 1] + 2]++;
					bene[num[i] + 1]--;
					beg[num[i - 1] + 2]++;
					mi[num[i] + 1] += (num[i] - num[i - 1]) - 1;
				}
			}
			else {
				if (num[i] + M - num[i - 1] > 1) {
					bene[num[i - 1] + 2]++;
					bene[num[i] + M + 1]--;
					beg[num[i - 1] + 2]++;
					mi[num[i] + M + 1] += (num[i] + M - num[i - 1]) - 1;
				}
			}
		}
	}
	for (int i = 1; i <= M * 2; i++) {
		bene[i] += bene[i - 1];
	//	cout << i << " " << bene[i] << endl;
	}
	for (int i = 1; i <= M * 2; i++) {
		sum[i] = sum[i - 1] + (bene[i] - beg[i]) - mi[i] + beg[i];
	//	cout << i << " " << sum[i] << endl;
	}
	long long int box = 0;
	for (int i = 1; i <= M; i++) {
		sum[i] += sum[i + M];
	//	cout << sum[i] << endl;
		box = max(box, sum[i]);
	}
	cout << ans - box << endl;
	return 0;
}

Measured memory_bytes: 7296
n,x = map(int,input().split())

# a : レベルlでの長さ
# p : レベルlでのP数
a,p = [1], [1]
for i in range(n):
    a.append(2*a[-1]+3)
    p.append(2*p[-1]+1)

# f(l,x) : レベルlでの下からxまでのP数
def f(l, x):
    if l==0:
        if x>0:
            return 1
        else:
            return 0
    
    elif x<=a[l-1]+1:
        return f(l-1, x-1)

    else:
        return p[l-1] + 1 + f(l-1, x-a[l-1]-2)

print(f(n,x))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define lb lower_bound
using namespace std;
void solve()
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll x=a/n;
    x = x*n;
    if(x == a)
    {
        cout << "OK";
        return;
    }
    else if(x+n >= a and x+n <= b)
    {
        cout << "OK";
        return;
    }
    cout << "NG";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3652
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    dishes = []
    for _ in range(N):
        a, b = map(int, input().split())
        dishes.append((a, b))
    
    dishes = sorted(dishes, key=lambda x: x[0])
    
    ans = 0
    dp = np.zeros(T, dtype=int)
    for a, b in dishes:
        ans = max(ans, dp.max() + b)
        np.maximum(dp[:-a] + b, dp[a:], out=dp[a:])

    return ans

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

Measured memory_bytes: 12512
def main()
  n,m = gets.chomp.split(' ').map(&:to_i)
  table = Array.new(n).map{Array.new}
  for i in 0..m-1
    a,b = gets.chomp.split(' ').map(&:to_i)
    table[a] << b
  end
  flag = false
  table[1].each{|t| flag = true if table[t].include?(n)}
  if flag
    puts "POSSIBLE"
  else
    puts "IMPOSSIBLE"
  end
end

main()

Measured memory_bytes: 20612
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,p=0,i;
	char s[11],x[11];
	scanf("%s", s);
	n=strlen(s);
	for(i=0; i<n; i++){
		if(s[i]=='1'){
			x[p]='1';
			p++;
		}
		if(s[i]=='0'){
			x[p]='0';
			p++;
		}
		if(s[i]=='B'&&p>0){
			p--;
		}
	}
	for(i=0; i<p; i++){
		printf("%c", x[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<unordered_map>

using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof a)

const  int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int t, n, m;
vector<int> v;
int minn = inf;

int main()
{
	ll l, r;
	cin >> l >> r;
	r = min(l + 2018, r);
	fo(i, l, r)
		v.push_back(i % 2019);
	int len = v.size();
	fo(i, 0, len - 1)
		fo(j, i + 1, len - 1)
		minn = min(minn, v[i] * v[j] % 2019);
	cout << minn << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(){
 int n;
 scanf("%d",&n);
 for(int a=1;a<=9;a++)for(int b=1;b<=9;b++){
 	if(a*b==n){
 		puts("Yes");
 		return 0;
 	}
 }
 puts("No");
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, x;
    cin >> n >> x;
    int ans[2*n-1];
    rep(i, 2 * n - 1) ans[i] = 0;
    if (x > 1 && x < 2 * n - 1){
        ans[n-1] = x;
        int idx = 1;
        if (x < n){
            for (int i = 1; i < x; i++){
                if (idx % 2 == 0){
                    ans[n-1-idx] = i;
                }else{
                    ans[n-1+idx] = i;
                }
                idx++;
            }
            idx = 0;
            for (int i = x + 1; i <= 2 * n - 1; i++){
                while(ans[idx] != 0){
                    idx++;
                }
                ans[idx] = i;
                idx++;
            }
        }else{
            for (int i = x + 1; i <= 2 * n - 1; i++){
                if (idx % 2 == 0){
                    ans[n-1-idx] = i;
                }else{
                    ans[n-1+idx] = i;
                }
                idx++;
            }
            idx = 0;
            for (int i = 1; i < x; i++){
                while(ans[idx] != 0){
                    idx++;
                }
                ans[idx] = i;
                idx++;
            }
        }
        cout << "Yes" << endl;
        rep(i, 2 * n - 1) cout << ans[i] << endl;
    }else cout << "No" << endl;
    
    
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
int n;
cin>>n;
double x1,y1,x2,y2,x3,y3,x4,y4;
while(n--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
P a(x2-x1,y2-y1);
P b(x4-x3,y4-y3);
double cr = imag(conj(a)*b);
if(abs(cr)<1e-11){
  cout<<"YES"<<endl;
}else{
  cout<<"NO"<<endl;
}
}
  return 0;
}

Measured memory_bytes: 1268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
class Program
{
   private static int largeV = 9999999;
   static void Main(string[] args)
   {
    var list = new List<int[]>();
            int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            int n = arr[0];
            int m = arr[1];
            int minValue = arr[2];
            int min = largeV;
            for (int i = 1; i <= n; i++)
            {
                list.Add(Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
            }
            for (int bit = 0; bit < (1 << n); bit++)
            {
                var sumList = new List<int[]>();
                for (int i = 0; i < n; i++)
                {
                    if ((bit & (1 << i)) > 0)
                    {
                        sumList.Add(list[i]);
                    }
                }
                if (sumList.Count == 0) continue;
                var ansE = new ctrlSum(sumList, minValue);
                if (ansE.line)
                {
                    if (ansE.sumV < min) min = ansE.sumV;
                }
            }
            if (min == largeV) Console.WriteLine(-1);
            else Console.WriteLine(min);
   }
}
  
   class ctrlSum
    {
        public int sumV;
        public bool line = true;
        public ctrlSum(List<int[]> sumList, int minValue)
        {           
            int len = sumList[0].Length;
            int[] sumA = new int[len-1];
            foreach(int[] eleA in sumList)
            {
                int ind = 1;
                this.sumV += eleA[0];
                while(ind < len)
                {
                    sumA[ind - 1] += eleA[ind];
                    ind++;
                }
            }
            foreach (int ele in sumA)
            {
                if (ele < minValue) this.line = false;
            }
        }
    }

Measured memory_bytes: 20048
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, C;
	cin >> N >> C;
	vector<unsigned long long> val(N), vc; // Upper bound: N * (C * max(p) + 1) - 1
	for (int i = 0; i < N; ++i) {
		val[i] = N - i - 1;
		vc.push_back(val[i]);
	}
	vector<int> tp(C), a(C), b(C);
	for (int i = 0; i < C; ++i) {
		cin >> tp[i] >> a[i]; --a[i];
		if (tp[i] == 0) {
			cin >> b[i];
			val[a[i]] += 1LL * N * b[i];
			vc.push_back(val[a[i]]);
		}
	}
	sort(vc.begin(), vc.end());
	for (int i = 0; i < N; ++i) {
		val[i] = N - i - 1;
	}
	int sz = 1;
	while (sz < vc.size()) sz *= 2;
	vector<int> bit(sz + 1);
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j <= sz; j += j & (-j)) {
			++bit[j];
		}
	}
	for (int i = 0; i < C; ++i) {
		if (tp[i] == 0) {
			int ptr_old = lower_bound(vc.begin(), vc.end(), val[a[i]]) - vc.begin();
			val[a[i]] += 1LL * N * b[i];
			int ptr_new = lower_bound(vc.begin(), vc.end(), val[a[i]]) - vc.begin();
			for (int j = ptr_old + 1; j <= sz; j += j & (-j)) {
				--bit[j];
			}
			for (int j = ptr_new + 1; j <= sz; j += j & (-j)) {
				++bit[j];
			}
		}
		else {
			int cur = 0, pos = 0;
			for (int j = sz / 2; j >= 1; j >>= 1) {
				if (cur + bit[pos + j] < N - a[i]) {
					pos += j;
					cur += bit[pos];
				}
			}
			cout << N - vc[pos] % N << ' ' << vc[pos] / N << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 7292
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL por(LL x,LL y){
	LL ans = 1;
	while(y){
		if(y & 1) ans = ans * x;
		x = x * x;
		y >>= 1;
	}
	return ans;
}

int main(){
	LL x,y,sum = 0;
	cin >> x >> y;
	for(LL i = 0;;i++){
		if(x * por(2,i) > y){
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int visited[1005];
V<V<int>> graph;
int cnt,memo;
V<int> res;
bool make(int now,int cn){
    if(cn==cnt&&now==memo)return true;
    if(cn>cnt)return false;
    for(int v: graph[now]){
        if(make(v,cn+1)){res.push_back(now);return true;}
    }
    return false;
}
int main(){
ll ma=10000;
int n,m;
cin>>n>>m;
V<int> ans;
graph.resize(n);
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
}
queue<P> q;
for(int i=0;i<n;i++){
   int c=10001;
   V<int> v(n,10000);
   v[i]=0;
   q.push(P(i,0));
   while(!q.empty()){
     P now=q.front();
     q.pop();
     for(int d:graph[now.fi]){
       if(d==i)chmin(c,now.se+1);
       else if(v[d]>now.se+1){
         v[d]=now.se+1;
         q.push(P(d,now.se+1));
         }
         }
         }
         if(ma>c){
           cnt=c;memo=i;
           bool e=make(i,0);
           ans=res;
           res.clear();
           ma=c;
           }
}
if(ans.size()){
reverse(all(ans));
   cout<<ans.size()<<endl;
       for(int v: ans)cout<<v+1<<endl;}
else cout<<-1<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
  long long  n,a,m,M,c,b,i;
  c = 0;
  m = 100000000;
  M =-100000000;
  scanf("%lld",&n);

  for(i=1; i<=n; i++){
    scanf("%lld",&a);
    if(a>M) {
      M = a;
    } 
    if(a < m){
      m = a;
    }
    c = c+a;
  }
    printf("%lld %lld %lld\n",m,M,c);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c >=22) cout << "bust" << endl;
  else cout << "win" << endl;

}


Measured memory_bytes: 3624
n = gets.to_i

sp = []
n.times do |i|
  sp << [i + 1] + gets.strip.split(" ")
end

sp.sort! do |a, b|
  if a[1] != b[1]
    a[1] <=> b[1]
  else
    -a.last.to_i <=> -b.last.to_i
  end
end

sp.each do |t|
  puts t.first
end



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

using namespace std;

const int nmaxn=105;
const int wmaxn=10005;
const int diagnoal=1;
const int top=0;

struct item{
    int value,weight;
};

int n,m;
item items[nmaxn+1];
int c[nmaxn][wmaxn],g[nmaxn][wmaxn];

void compute(int &maxvalue,vector<int>&selection)
{
    for(int w=0;w<=m;w++){
        c[0][w]=0;
        g[0][w]=diagnoal;
    }
    for(int i=1;i<=n;i++){
        c[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int w=1;w<=m;w++){
            c[i][w]=c[i-1][w];
            g[i][w]=top;
            if(items[i].weight>w){
                continue;
            }
            if(items[i].value+c[i-1][w-items[i].weight]>c[i-1][w]){
                c[i][w]=items[i].value+c[i-1][w-items[i].weight];
                g[i][w]=diagnoal;
            }
        }
    }
    maxvalue=c[n][m];
    selection.clear();
    for(int i=n,w=m;i>=1;i--){
        if(g[i][w]==diagnoal){
            selection.push_back(i);
            w-=items[i].weight;
        }
    }
    reverse(selection.begin(),selection.end());
}

void input()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>items[i].value>>items[i].weight;
    }
//    for(int i=1;i<=n;i++){
//        cout<<items[i].value<<" "<<items[i].weight<<endl;
//    }
//    cout<<endl;
}

int main()
{
    int maxvalue;
    vector<int>selection;
    input();
    compute(maxvalue,selection);
    cout<<maxvalue<<endl;
    return 0;
}



Measured memory_bytes: 11044
n = gets.chomp.to_i
n.times do
  balls = gets.chomp.split.map(&:to_i)
  a,b = 0,0
  10.times do |i|
    if balls[i] > a || balls[i] > b
      if balls[i] < a
        b = balls[i]
      elsif balls[i] < b
        a = balls[i]
      elsif balls[i] > a && balls[i] > b
        if a > b
          a = balls[i]
        else
          b = balls[i]
        end
      end
    else
      puts "NO"
      break
    end
    puts "YES" if i == 9
  end
end

Measured memory_bytes: 6108
/* 
STATUS :>	ac
PROBLEM LINK:>	https://atcoder.jp/contests/abc175/tasks/abc175_a
LINKDIN PROFILE :>	linkedin.com/in/dheerajpoonia29/
*/

// #include "macro.h"
// #include "../../macro.h"


#include <bits/stdc++.h>
using namespace std;
#define ll long long int


void inline cp();

int main(){
	cp();
	int t=1;	
	//cin>>t;
	while(t--){
		string s;
		cin>>s;
		if(s=="SSS")
			cout<<0;
		else if(s=="RRR")
			cout<<3;
		else if(s=="RSR" || s=="SRS")
			cout<<1;
		else if(s=="SRR" || s=="RRS")
			cout<<2;
		else if(s=="SSR" || s=="RSS")
			cout<<1;
		else
			cout<<0;
	}
	return 0;
}

void inline cp(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE	
	freopen("../../input.txt", "r", stdin);
	freopen("../../output.txt", "w", stdout);
#endif 
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
typedef long long ll;
using namespace std;

int main() {
	int X,Y,Z; cin >> X >> Y >> Z;
	cout << (X - Z) / (Y + Z) << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int x,n;
    cin>>x>>n;
    set<int> s;
    rep(i,n){
        int p;
        cin>>p;
        s.insert(p);
    }
    int ans=0;
    rep(i,102){
        if(s.find(i)!=s.end())continue;
        if(abs(x-ans)>abs(x-i))ans=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616