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

#define M 10000000

using namespace std;


void solve(long long N, std::vector<long long> P){
    long long min = M;
    long long count = 0;
    for (int i = 0; i < N; i++) {
        if (min >= P[i]) {
            count++;
            min = P[i];
        }
    }
    cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;


int a[40000],b[40000];

int main(){
	int N;
	while(cin >> N && N){
		for(int i = 0 ; i < N ; i++) scanf("%d",&a[i]);
		for(int i = 0 ; i < N ; i++) scanf("%d",&b[i]);
		sort(a,a+N);
		sort(b,b+N);
		int win = 0;
		int ans = -1;
		
		int ah = N-1 , bh = N-1;
		for(int i = 0 ; i < N-1 ; i++){
			if( a[ah] > b[bh] ){
				ah--;
				win++;
			}else{
				ah--;
				bh--;
			}
			if( win > (i+1) / 2 ){
				ans = i+1;
				break;
			}
		}
		if(ans==-1)puts("NA");
		else printf("%d\n",ans);
		
		
	}
}

Measured memory_bytes: 1560
#!/usr/bin/env python3
import sys, math, heapq,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


ans = -inf
n = int(input())
A = list(map(int, input().split()))
AL, AR = A[:n], A[2*n:]
al,ar=copy.copy(AL),copy.copy(AR)
AN = A[n:2*n]
LS, RS = sum(AL), sum(AR)
AR = list(map(lambda ddd: -ddd, AR))
heapq.heapify(AL)
heapq.heapify(AR)
tmp=LS
ANSR=[0]*n
ANSL=[0]*n

for i in range(n):
    if AN[i]-AL[0] >0:
        LS = LS-heapq.heappop(AL)+AN[i]
        heapq.heappush(AL,AN[i])
    ANSL[i] = LS

LS=tmp
for j in range(n-1,-1,-1):
    if 0 < -AR[0]-AN[j]:
        RS = RS+heapq.heappop(AR)+AN[j]
        heapq.heappush(AR,-AN[j])
    ANSR[j] = RS
ANSR=ANSR+[sum(ar)]
ANSL=[sum(al)]+ANSL
for i in range(n+1):
    ans=max(ans,ANSL[i]-ANSR[i])
print(ans)
# print(ANSL,ANSR)

Measured memory_bytes: 117244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<vi> dp(n + 1, vi(h + 1, 1e9));
  dp[0][0] = 0;
  rep(i, n) rep(j, h + 1) {
    if(j == 0) dp[i][0] = 0;
    int ni = i, nj = min(h, j + a[i]);
    dp[ni][nj] = min(dp[ni][nj], dp[i][j] + b[i]);
    ni++;
    dp[ni][j] = dp[i][j];
  }
  cout << dp[n][h] << endl;
}

Measured memory_bytes: 39424
#include <iostream>
using namespace std;
const int MAX = 100000;

int main() {
	int n, c;
	cin >> n >> c;
	int A[30][MAX+10] = {};
	int imos[MAX+10] = {};
	for (int i = 0; i < n; i++) {
		int s, t, ci;
		cin >> s >> t >> ci;
		ci--;
		A[ci][s]++;
		A[ci][t]--;
	}
	for (int i = 1; i <= MAX; i++) {
		for (int j = 0; j < 30; j++) {
			if (A[j][i] == 1) imos[i-1] += 1;
			else if (A[j][i] == -1) imos[i] -= 1;
		}
	}
	int ans = 0;
	for (int i = 0; i <= MAX; i++) {
		ans = max(ans, imos[i]);
		imos[i+1] += imos[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15300
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    A,B,C,x,y = LI()
    ans = float("inf")
    for c in range(200001)[::2]:
        a = b = c >> 1
        a = max(0,x-a)
        b = max(0,y-b)
        s = A*a+B*b+C*c
        if s < ans:
            ans = s
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    string s, t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    vector<vector<int>> is(26);
    rep(i,n) is[s[i]-'a'].pb(i);
    rep(i,n) is[s[i]-'a'].pb(i+n);
    ll ans = 0;
    int p = 0;//現在位置
    rep(i,m) {
        int c = t[i] - 'a';
        if(sz(is[c])==0){
            cout << "-1" << endl;
            return 0;
        }
        p = *lower_bound(is[c].begin(),is[c].end(),p) + 1;
        if(p >= n){
            p -= n;
            ans += n;
        }
    }
    ans += p;//答えは0-indexedでないのでpを足すだけ。
    cout << ans << endl;
}

Measured memory_bytes: 1724
#include <stdio.h>
int main(void){
 int a,b,c,d;
 scanf("%d %d %d %d",&a,&b,&c,&d);

 while(a>0){
   c=c-b;
   if(c<0||c==0){
     printf("Yes");
     return 0;
   }

   a=a-d;

 }
 printf("No");

  return 0;
  }

Measured memory_bytes: 1712
#include <iostream>
#include <vector>

#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int p[N];
    for (int i=0; i<N; i++) {
        cin >> p[i];
    }

    int psort[N];
    copy(p, p+N, psort);
    sort(psort, psort+N);
  
    int change =0;
    for (int i=0; i<N; i++) {
        if (p[i] != psort[i]) {
            change += 1;
        }
        //cout << i << " " << p[i] << " " << psort[i] << " " << change << "\n";
    }
    if (change == 0 || change == 2) {
        cout << "YES";
        return 0;
    }

    cout << "NO";
    return 0;
}   


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

int main(){
	int n;
	cin >> n;
	int V[n],C[n];
	for(int i = 0;i < n;i++){
		cin >> V[i];
	}
	for(int i = 0;i < n;i++){
		cin >> C[i];
	}
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(V[i] > C[i]){
			ans += V[i];
			ans -= C[i];
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-18 11:08:03
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    string s;
    cin >> s;
    int n = s.length();

    int max_n = 0;
    for (int i = 1; 2*i < n; i++) {
        int ok = 1;
        for (int j = 0; j < i; j++) {
            if (s[j] != s[j+i]) ok = 0;
        }

        if (ok) max_n = 2*i;
    }

    cout << max_n << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#include <stdio.h>
#include <string>
#define INF 1000000007
using namespace std;

double hi_0(int x,int r){
    if (x>-1*r&&x<r) {
        double h = sqrt(r*r-x*x);
        return h-(double)r;
    }else{
        return -1*r;
    }
}


int main(){
    for (;;) {
        int  r,n;
        cin >> r>>n;
        if (r==0&&n==0) break;
        double hist[41];
        for (int i=0; i<41; i++) {
            hist[i] = 0;
        }
        for (int i=0; i<n; i++) {
            int l,rr,h;
            cin >> l >> rr >>h;
            for (int j=l; j<rr; j++) {
                hist[j+20]=max(hist[j+20],(double)h);
            }
        }
        double ans=114514;
        for (int i=-1*r+1; i<r ; i++) {
            double limit = min(hist[i+19]-hi_0(i, r),hist[i+20]-hi_0(i, r));
            ans= min(ans,limit);
        }
        printf("%.4f\n",ans);
    }
}

Measured memory_bytes: 1196
from collections import deque
S = list(map(str, input()))
Q = int(input())

ans_lst = deque(S)
rev = False
for i in range(Q):
  QUERY = list(map(str, input().split()))
  if QUERY[0] == '1':
    if rev:
      rev = False
    else:
      rev = True
  else:
    if rev:
      if QUERY[1] == '1':
        ans_lst.append(QUERY[2])
      else:
        ans_lst.appendleft(QUERY[2])
    else:
      if QUERY[1] == '1':
        ans_lst.appendleft(QUERY[2])
      else:
        ans_lst.append(QUERY[2])    

if rev:
  ans_lst.reverse()
  print(''.join(ans_lst))
else:
  print(''.join(ans_lst))

Measured memory_bytes: 9460
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    string s;
    R(n,s);
    if(n>=3200)W(s);
    else W("red");
    return 0;
}


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

int main() {
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A);
    for(int i=0;i<A;i++) cin >> a.at(i);
    vector<int> b(B);
    for(int i=0;i<B;i++) cin >> b.at(i);
    vector<vector<int>> c(M,vector<int>(3));
    for(int i=0;i<M;i++){
        for(int j=0;j<3;j++) cin >> c.at(i).at(j);
    }
    int cost2=10000000;
    for(int i=0;i<M;i++){
        int cost1=a.at(c.at(i).at(0)-1)+b.at(c.at(i).at(1)-1)-c.at(i).at(2);
        cost2=min(cost2,cost1);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    cout << min(cost2,a.at(0)+b.at(0)) << endl;
}

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

#ifdef LOCAL
  #include "debug.h"
#endif

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string a, b, c;
  cin >> a >> b >> c;
  char turn = 'a';
  while (1) {
    if (turn == 'a') {
      if (a.empty()) break;
      turn = a[0];
      a = a.substr(1);
    } else if (turn == 'b') {
      if (b.empty()) break;
      turn = b[0];
      b = b.substr(1);
    } else {
      if (c.empty()) break;
      turn = c[0];
      c = c.substr(1);
    }
  }
  turn = toupper(turn);
  cout << turn << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200000+10;
int fa[maxn],vis[maxn],du[maxn],bz[maxn];
int i,j,k,l,t,n,m,a,b,c,d,x,y;
bool czy;
int getfa(int x){
	return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,1000) fa[i]=i;
	fo(i,1,n){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		x=c?-c:a;
		y=d?d:-b;
		x+=500;y+=500;
		fa[getfa(x)]=getfa(y);
		du[x]++;du[y]--;
		vis[x]=1;
	}
	czy=1;
	fo(i,1,499)
		if (du[i]>0) czy=0;
	fo(i,501,1000)
		if (du[i]<0) czy=0;
	fo(i,1,1000) vis[getfa(i)]|=vis[i];
	fo(i,1,1000)
		if (du[i]) bz[getfa(i)]=1;
	fo(i,1,1000)
		if (fa[i]==i&&!bz[i]&&vis[i]) czy=0;
	if (czy) printf("YES\n");else printf("NO\n");
}

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

int main(void)
{
	char word[501][33];
	int i, j;
	int c;
	int flag;
	char str[32];
	int  count[501];
	int maxC = 500;;
	char maxL[33] = "\0";

	count[500] = 0;
	c = 0;
	while (scanf("%s", str) != EOF){
		flag = 0;
		for (i = 0; i < c; i++){
			if (strcmp(word[i], str) == 0){
				count[i]++;
				if (count[maxC] < count[i]){
					maxC = i;
				}
				flag++;
			}
		}

		if (!flag){
			strcpy(word[i], str);
			c++;
		}

		if (strlen(maxL) < strlen(str)){
			strcpy(maxL, str);
		}
	}

	printf("%s %s\n", word[maxC], maxL);

	return (0);
}

Measured memory_bytes: 572
#include<stdio.h>
int p,n[6],a[]={1,5,10,50,100,500};
int G(int x)
{
	int i,j,r=0;
	for(i=5;i>=0;--i)
		for(j=1;j<=n[i];++j)
			if(x>=a[i])x-=a[i],++r;
			else break;
	return x?1e9:r;
}
int F(int x)
{
	int r=0,i;
	for(i=5;i>=0;--i)r+=x/a[i],x%=a[i];
	return r;
}
int main()
{
	int i,x,y;
	while(scanf("%d",&p),p)
	{
		for(i=0;i<6;++i)scanf("%d",n+i);
		for(x=1e9,i=p;i<p+501;++i)
		{
			y=G(i)+F(i-p);
			if(x>y)x=y;
		}
		printf("%d\n",x);
	}
	return 0;
}

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

int main()
{
    int n,x,in,times = 1;
    vector<int> v;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>in;
        v.emplace_back(in);
    }
    for(int i=0;i<v.size();i++){
        if(x - v[i] >= 0) times++;
        else break;
        x -= v[i];
    }
    cout<<times<<endl;
    return 0;
}

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

int main(){

    int a,b;
    cin >> a >> b;

    if(a>12){
        cout << b << endl;
    }else if(a>5){
        cout << b/2 << endl;
    }else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 764
# coding:utf-8
if __name__=='__main__':
  N, M = map(int, input().split())
  L, R = 1, N
  for i in range(M):
    l, r = map(int, input().split())
    if L < l: L = l
    if R > r: R = r
  if L > R:
    print(0)
  else:
    print(R-L+1)

Measured memory_bytes: 3188
n = int(input())
a = list([input() for i in range(n)])
z = 0
ax = 0
for i in range(n):
    a[i] = int(a[i])
    if a[i] > ax:
        z = i
        ax = a[i]
        
print(int(sum(a)-a[z]/2))

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
 
#define ll          int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        200005
#define mod         998244353  
 
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
// abc127_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int r, D, x;
    cin >> r >> D >> x;

    REP(i, 10){
        x = r * x - D;
        print(x);
    }

    return 0;
}


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

int main(void) {
    int N,M,C,A;
    int cnt = 0;
    int sum;

    cin >> N >> M >> C;
    vector<int> B(M);
    for(int j=0;j<M;j++) {
        cin >> B[j];
    }

    for(int i=0;i<N;i++) {
        sum= 0;
        for(int j=0;j<M;j++) {
            cin >> A;
            sum += (A*B[j]);
        }
        if((sum+C) > 0) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    input()
    a = set(input().split())
    input()
    b = set(input().split())
    print(len(a.intersection(b)))


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Measured memory_bytes: 20344
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>

//#include"gap.h"

using namespace std;


int N, M;
vector<int> pass[100000];
int dp[100000];

int dfs(int now){
	int leaf = pass[now].size();

	if(leaf == 0) return 0;

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

	for(int i=0; i<leaf; i++){
		dp[now] = max(dfs(pass[now][i]) + 1, dp[now]);
	}

	return dp[now];
}

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int tmpx, tmpy;
		cin >> tmpx >> tmpy;

		pass[tmpx-1].push_back(tmpy-1);
	}

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

	int ans = 0;
	for(int i=0; i<N; i++){
		ans = max(ans, dfs(i));
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;
public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
}

Measured memory_bytes: 19704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 2e18;
const double PI = acos(-1);

typedef pair<ll, ll> P;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<P> VP;
	REP(i, N)
	{
		ll a, b;
		cin >> a >> b;
		VP.push_back(P(a, b));
	}
	so(VP);
	ll ans = 0;
	ll cur = M;
	REP(i, N)
	{
		ans += min(cur, VP[i].second) * VP[i].first;
		cur -= min(cur, VP[i].second);
		if (cur == 0)
			break;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int gcd(int a, int b) {
  if (a < b) swap(a, b);

  while (a % b > 0) {
    swap(a, b);
    b = b % a;
  }

  return b;
}

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

  cout << gcd(a, b) << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
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; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    queue<int>v;
    vector<vector<int>>v2(h, vector<int>(w));
    rep(i,1, n+1){
        int a;
        cin >> a;
        rep(j, 0, a){
            v.push(i);
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            int p = v.front();
            v.pop();
            v2[i][j] = p;
        }
        if(i%2==1)reverse(v2[i].begin(),v2[i].end());
    }
    rep(i, 0, h){
        rep(j, 0, w){
            cout << v2[i][j] << " ";
        }
        cout << endl;
    }
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int res = 0;
	for (int i = 1; i < N; i++) {
		if (a[i] == a[i - 1]) {
			++res;
			a[i] += 10000;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m, a[112345];
    cin >> n >> m;
    REP(i, n)
    cin >> a[i];

    priority_queue<P> q;

    REP(i, n)
    q.push({a[i], i});

    while (m)
    {
        P p = q.top();
        q.pop();

        a[p.second] /= 2;

        q.push({a[p.second], p.second});

        m--;
    }

    ll res = 0;
    REP(i, n)
    res += a[i];

    cout << res << endl;

    return 0;
}

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

using namespace std;

bool check(int, int);

int main() {
	int x;
	cin >> x;
	double level = sqrt(x);
	for (int i = 1;i <= level;i++) {
		if (x % i == 0) {
			if (check(i, x / i))return 0;
		}
	}
}

bool check(int x, int y) {
	double level = sqrt(y);
	int b;
	for (int a = 0;a <= level;a++) {
		b = a - x;
		if (a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b == y) {
			cout << a << " " << b << endl;
			return true;
		}
	}
	return false;
}

Measured memory_bytes: 3196
import java.util.*;
import java.io.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int[][][] num = new int[4][3][10];
		for(int[][] a: num){
			for(int[] b: a){
				Arrays.fill(b, 0);
			}
		}
		int n = sc.nextInt();
		for(int i = 0; i < n; ++i){
			int b = sc.nextInt() - 1;
			int f = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			int v = sc.nextInt();
			num[b][f][r] += v;
		}
		
		for(int i = 0; i < 4; ++i){
			if(i != 0) System.out.println("####################");
			for(int j = 0; j < 3; ++j){
				for(int k = 0; k < 10; ++k)
					System.out.printf(" %d", num[i][j][k]);
				System.out.println();
			}
			
		}
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


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

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

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

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	//vector<string> vs(n)
	string pt="MARCH";
	VI ct(5);
	rep(i,n){
		string s;
		cin >> s;
		rep(j,5){
			if(s[0]==pt[j]){ ct[j]++; break;}
		}
	}
	//for(auto x :ct) printf("%d, ",x); puts("");
	
	ll sm = accumulate(all(ct), 0LL);
	
	int qc=0;
	rep(i,5) if(ct[i]>0) qc++;
	if(qc<3) {puts("0"); return 0;}
	
	ll ans =0;
	rep(i,5) rep2(j,i+1,5) rep2(k,j+1,5){
		if(ct[i]<1 || ct[j]<0 || ct[k]<0) continue;
		ans += (ll)ct[i] * (ll)ct[j] * (ll)ct[k];
	}
	cout << ans <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
object Main extends App {
  val s = scala.io.StdIn.readLine()
  var ans = 999

  for(i <- 0 to s.length - 3){
  	if(ans > Math.abs(s.substring(i, i+3).toInt - 753)){
  		ans = Math.abs(s.substring(i, i+3).toInt - 753)
  	}
  }

  println(ans)
}

Measured memory_bytes: 25412
#include<stdio.h>

void swap(int* x,int* y){
	int tmp;
	tmp=*x;
	*x=*y;
	*y=tmp;
}

void insert_sort(int array[1000], int array_size){
	int j=0;
	for(int i=0; i<array_size; i++){
		j=i;
		while((j>0)&&(array[j-1]>array[j])){
			swap(&array[j-1],&array[j]);
			j--;
		}
		for(int j=0; j<array_size; j++){
			if(!(j==array_size-1)){
				printf("%d ",array[j]);
			}else{
				printf("%d\n",array[j]);
			}
		}
	}
}

int main(){
	int array_size=0;
	scanf("%d",&array_size);
	int array[1000]={};
	for(int i=0; i<array_size; i++){
		scanf("%d",&array[i]);
	}
	insert_sort(array,array_size);
	return 0;
}



Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int a,b,k;
      cin>>a>>b>>k;

      if(k-a >= 0)
      {
        k=k-a;
         a=0;
           if(k - b >= 0)
            b=0;

            else
           b=b-k;
      }
      else
         a=a-k;

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<cstring>
#include<string>
#include<deque>
#include<map>
#include<cmath>
#include<stack>
#include<vector>
#include<queue>
#include<cstdlib>
using namespace std;
#define lck_max(a,b) ((a)>(b)?(a):(b))
#define lck_min(a,b) ((a)<(b)?(a):(b))
typedef long long LL;
const int maxn=1e6+7;
const int mod=998244353;
LL hash[maxn];
char s[maxn];
struct hh
{
	LL first,second;
}t;
inline void Hash()
{
	hash[0]=1;
	for(LL i=1;i<=maxn-1000;i++)
	{
		hash[i]=hash[i-1]*13%mod;
	}
}
inline LL read()
{
	LL kr=1,xs=0;
	char ls;
	ls=getchar();
	while(!isdigit(ls))
	{
		if(!(ls^45))
			kr=-1;
		ls=getchar();
	}
	while(isdigit(ls))
	{
		xs=(xs<<1)+(xs<<3)+(ls^48);
		ls=getchar();
	}
	return xs*kr;
}
inline void out(LL xs)
{
	if(!xs) {putchar(48); return;}
	if(xs<0) putchar('-'),xs=-xs;
	int kr[57],ls=0;
	while(xs) kr[++ls]=xs%10,xs/=10;
	while(ls) putchar(kr[ls]+48),ls--;
}
inline void change(LL len)
{
	for(LL i=0;i<len;i++)
	{
		if(s[i]=='b') {s[i]='d';continue;}
		if(s[i]=='d') {s[i]='b';continue;}
		if(s[i]=='q') {s[i]='p';continue;}
		if(s[i]=='p') {s[i]='q';continue;}
	}
}
int main()
{
	Hash();
	scanf("%s",s);
	LL len=strlen(s);
	for(LL i=0;i<len;i++) t.first=(t.first+s[i]*hash[i])%mod;
	change(len);
	for(LL i=len-1;~i;i--) t.second=(t.second+s[i]*hash[len-i-1])%mod;
	if(t.first==t.second) puts("Yes");
	else puts("No");
return 0;
}


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (long long i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (long long j = i * i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }

  bool isPrime(int x) { return f[x] == x; }

  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  vector<pair<int, int>> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  Sieve s(1000001);

  ll all = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) all = gcd(all, a[i]);

  bool pc = true;
  map<int, int> mp;
  rep(i, n) {
    auto f = s.factor(a[i]);

    for (auto x : f) {
      if (x.first == 1) continue;
      mp[x.first]++;
      if (mp[x.first] > 1) {
        pc = false;
        break;
      }
    }
    if (!pc) break;
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
  } else if (!pc && all == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


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

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
}


Measured memory_bytes: 3192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    private 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;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int n = in.nextInt();
        Set<Integer> a = new HashSet<>();
        for (int i = 0; i < n; i++) {
            a.add(Integer.valueOf(in.nextInt()));
        }
        String answer = n == a.size() ? "YES" : "NO";
        out.println(answer);
    }
}


Measured memory_bytes: 56920
/*input
100 0

*/

#include <bits/stdc++.h>
using namespace std;

#define int long long int


signed main(){

    int x , n ; 
    cin >> x >> n ; 
    vector<int> v(n);
    for ( int i = 0 ; i < n ; i++ )cin >> v[i];
    sort(v.begin(),v.end());
    int index = lower_bound( v.begin(), v.end() ,x) -v.begin();
    if ( index == n ) {
        cout << x; return 0;
    }
    if ( v[index] != x){
        cout << x; return 0;
    }
    int mn=INT_MAX;
    int ans;
    for ( int i =x -1 ; ; i --){
        if (*lower_bound( v.begin(), v.end() ,i) != i ){
            mn = min( mn , abs(i-x));
            ans = i;
            break;
        } 

    }
    for ( int i =x +1 ; ; i ++){
        if (*lower_bound( v.begin(), v.end() ,i) != i ){
            if ( mn > abs( i -x )){
                ans = i ;
            }
            break;
        } 

    }
    cout << ans;



}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

//????????????
//test?????£???wrong answer????????£??????

int ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) {
	can = true;
	return;
  }
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
  }

}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S, T; cin >> S >> T;
    cout << T << S << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cout << boolalpha;

    solve();

    return 0;
}

Measured memory_bytes: 256
// rawatabhi14@gmail.com
// Abhinav Rawat
#include<bits/stdc++.h>
using namespace std;

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    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...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, n, x) for(int i=n; i>x; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector< vector <ll> > matrix;
typedef vector<ll> vll;

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int32_t main() {
    fast_io();
    int x, n; cin >> x >> n;
    vll p(102);
    int temp;
    f(i, 0, n){
        cin >> temp;
        p[temp] = 1; 
    }
    int left = x, right = x;
    while(true){
        if(p[left] == 0){
            cout << left << endl;
            return 0;
        }else left --;
        if(p[right] == 0){
            cout << right << endl;
            return 0;
        }else right++;
    }
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;
 
public class Main{
    void run(){
 
	Scanner sc = new Scanner(System.in);
	while(sc.hasNext()){
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    if(A==0 && B==0) break;
	    //100 500 1000
 
	    int remaining = B-A;
 
	    int m1000 = 0;
	    int m500 = 0;
	    int m100 = 0;
	    while(remaining - 1000 >=0){
		m1000++;
		remaining -= 1000;
	    }
 
	    while(remaining - 500 >=0){
		m500++;
		remaining -= 500;
	    }
 
	    while(remaining - 100 >=0){
		m100++;
		remaining -= 100;
	    }
 
	    System.out.printf("%d %d %d\n",m100,m500,m1000);
 
	}
    }
     
    public static void main(String args[]){
	new Main().run();
    }
}

Measured memory_bytes: 31408
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String read = scan.nextLine();
    int N = Integer.parseInt(read);
    int R = N % 1000;
    
    if (R == 0) {
      System.out.println(0);
    }
    else {
      System.out.println(1000 - R);
    }
  }
}


Measured memory_bytes: 35640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);

int main() {
    ll n,k; cin >> n >> k;
    ll out = k*pow(k-1,n-1);
    cout << out << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

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

int N;
vector<int> A;

int main() {
  cin >> N;
  rep (i, N) {
    int a;
    cin >> a;
    if (i%2==0) {
      A.insert(A.end(), a);
    } else {
      A.insert(A.begin(), a);
    }
  }
  rep(i, N) {
    if (N%2 == 0) {
      cout << A.at(i);
    } else {
      cout << A.at(N-1-i);
    }
    if (i != N-1) {
      cout << ' ';
    }
  }
  cout << endl;
}


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

// {{{
func MaxInts(nums []int) (int, int) {
	var maxIdx, maxVal int
	for i, e := range nums {
		if i == 0 || e > maxVal {
			maxIdx = i
			maxVal = e
		}
	}
	return maxVal, maxIdx
}

func MinInts(nums []int) (int, int) {
	var minIdx, minVal int
	for i, e := range nums {
		if i == 0 || e < minVal {
			minIdx = i
			minVal = e
		}
	}
	return minVal, minIdx
}

func SumInts(nums []int) int {
	s := 0
	for _, v := range nums {
		s += v
	}
	return s
}

func ReverseInts(nums []int) []int {
	rnums := make([]int, len(nums))
	for i := 0; i < len(nums); i++ {
		rnums[len(nums)-1-i] = nums[i]
	}
	return rnums
}

func ExtendInts(nums1 []int, nums2 []int) []int {
	for _, v := range nums2 {
		nums1 = append(nums1, v)
	}
	return nums1
}

func Ints2d(n_rows, n_cols int) [][]int {
	ints := make([][]int, n_rows)
	for i := 0; i < n_rows; i++ {
		ints[i] = make([]int, n_cols)
	}
	return ints
}

func MemsetInts1d(nums []int, val int) {
	for i := range nums {
		nums[i] = val
	}
}

func MemsetInts2d(nums [][]int, val int) {
	for i := range nums {
		for j := range nums[i] {
			nums[i][j] = val
		}
	}
}

func ContainsInt(nums []int, num int) bool {
	sort.Ints(nums)

	s, e := 0, len(nums)
	for {
		if s >= e {
			break
		}

		m := (e + s) / 2
		if nums[m] == num {
			return true
		} else if num > nums[m] {
			s = m + 1
		} else {
			e = m
		}
	}

	return false
}

func ReadInt(f *os.File) int {
	var n int
	fmt.Fscanf(f, "%d", &n)
	return n
}

func ReadInts(f *os.File, n int) []int {
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%d", &nums[i])
	}
	return nums
}

func ReadLines(f *os.File, n int) []string {
	var lines []string
	reader := bufio.NewReader(f)
	for i := 0; i < n; i++ {
		bytes, _, err := reader.ReadLine()
		if err != nil {
			break
		}
		lines = append(lines, string(bytes))
	}

	return lines
}

func ReadWords(f *os.File, n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%s", &strs[i])
	}
	return strs
}

func Pow(a, n int) int {
	c := 1
	for i := 0; i < n; i++ {
		c *= a
	}
	return c
}

// }}}

func main() {
	N := ReadInt(os.Stdin)
	act := Ints2d(N, 3)
	for i := 0; i < N; i++ {
		act[i] = ReadInts(os.Stdin, 3)
	}

	dp := Ints2d(N, 3)
	dp[0] = act[0]
	for i := 0; i < N-1; i++ {
		for j := 0; j < 3; j++ {
			v := make([]int, 2)
			for k := 0; k < 3; k++ {
				if j != k {
					v = append(v, dp[i][k]+act[i+1][j])
				}
			}
			dp[i+1][j], _ = MaxInts(v)
		}
	}

	ans, _ := MaxInts(dp[N-1])
	fmt.Println(ans)
}

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

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

  long long max = 1000000000000000000LL;

  long long ans = 1;
  bool overflow_flag = false;
  bool zero_flag = false;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    long long result = ans * a;

    if (result < ans) {
      overflow_flag = true;
    }
    if (a == 0) {
      zero_flag = true;
    }

    ans = result;
  }

  if (zero_flag == false && (ans > max || overflow_flag == true)) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    s = 5 * (10 ** 8)
    for i in range(N-K+1):
        if x[i] * x[K - 1 + i] < 0:
            s = min(s, min(x[K - 1 + i], abs(x[i])) * 2 + max(x[K - 1 + i], abs(x[i])))
        else:
            s = min(s, max(abs(x[K - 1 + i]), abs(x[i])))
    print(s)
main()


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

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

	// int res = 0;
	// int count = 1,i = 1;

	// for(i = 1; i*10 <= n; i*=10){
	// 	 if(count%2){
	// 	 	res+=(i*10) - i;
	// 	    //cout<<count<<" "<<i*10<<" "<<i<<endl;

	// 	 }
	// 	 count++;
	// }

	// if(count%2){
	// 	res+=(n-i+1);
	// }
	// cout<<res;
	int res = 0;
	for(int i = 1; i <= n; i++){
		string tmp = to_string(i);
		if((int)tmp.length() % 2) res++;
	}
	cout<<res;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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 (b < a) { a = b; return 1; } return 0; }

lli GCD(lli x, lli y)
{
       if(x<y)swap(x,y);
        if (y == 0) {
                return x;
        } else {
                return GCD(y, x % y);
        }
}

lli lcm(lli a,lli b)
{
   return a/GCD(a,b)*b;
}


void func(long long N, std::vector<long long> T){

    sort(T.rbegin(),T.rend());

    lli ans=T[0];
    REP(i,0,N)ans = lcm(ans,T[i]);

    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> T(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&T[i]);
    }
    func(N, std::move(T));
    return 0;
}


Measured memory_bytes: 256