akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> arr;
  for(int i=0;i<n;++i){
    int tmp;cin>>tmp;
    bool f = true;
    
    if(arr.size()==0 || tmp <= arr[arr.size()-1]){
      arr.push_back(tmp);
      continue;
    }
    
    for(int j=0;j<arr.size();++j){
      if(tmp > arr[j]){
        arr[j] = tmp;
        break;
      } 
    }
    
  }
  cout<<arr.size()<<endl;
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define SEKAI_NO_OWARI return 0;
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

void solve() {
	int n; cin >> n;
	vector<double> v(n);
	rep(i, n) scanf("%lf", &v[i]);

	sort(v.begin(), v.end());

	double res = 0;
	rep(i, n - 1) {
		v[i + 1] = (v[i] + v[i + 1]) / 2.0;
	}
	cout << v[n-1] << endl;
}

int main(void) {
	solve();
	SEKAI_NO_OWARI
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,q;
    cin >> n >> q;
    if(n==0) return 0;
    vector<int> count(101,0);
    int m,c;
    for(int i=0;i<n;i++){
      cin >> m;
      for(int j=0;j<m;j++){
        cin >> c;
        count[c]++;
      }
    }
    int ma=0,id=0;
    for(int i=1;i<101;i++){
      if(count[i]>ma){
        ma=count[i];
        id=i;
      }
    }
    if(ma>=q) cout << id << endl;
    else cout << 0 << endl;
  }
  return 0;
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using ll=long long;
using namespace std;
const auto mod=1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int a,b,ans=-1; cin >> a >> b;
  if(1<=a and a<=9 and 1<=b and b<=9) ans=a*b;
  cout << ans << endl;
}






Measured memory_bytes: 256
%:pragma GCC optimize("Ofast", "inline")
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
#define int long long
const int N = 1e5 + 233;
const int inf = -5e17;
int n, x[N], y[N], qy;

signed main(void) {
  srand(20021214);
  read(n);
  rep (i, n) read(x[i]), read(y[i]);
  auto isBlack = [&](int o) {
    bool pa = 0;
    rep (i, n) if (y[i] <= o && o <= x[i] + y[i] - inf) {
      int nc = x[i] - inf;
      int mc = o - y[i];
      pa ^= nc == (nc | mc);
    }
    return pa;
  };
  while (!isBlack(qy = rand() % 10));
  for (int k = 61; k >= 0; k--) {
    if (isBlack(qy + (1ll << k))) {
      qy |= 1ll << k;
    }
  }
  cout << qy + inf << "\n";
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,m,cnt,ans;
bool vis[200005];
vector<int>vec[200005];
void dfs(int i)
{
	vis[i]=1;
	cnt++;
	forn(j,vec[i].size())
	{
		int to=vec[i][j];
		if(!vis[to])dfs(to);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	forn(i,m)
	{
		int x,y;
		cin>>x>>y;
		vec[x].pb(y);
		vec[y].pb(x);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			cnt=0;
			dfs(i);
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 20948
#include <stdio.h>
int t[100001];
int f(int k){
    if(k<0) return 0;
    if(k%2==0) return k;
    return k+1;
}
main(){
    int a;
    scanf("%d",&a);
    for(int i=0;i<a;++i){
        int k;
        scanf("%d",&k); t[k]++;
    }
    int mi=1,ma=100000;
    while(mi<ma){
        while(t[mi]<2&&mi<100001) mi++;
        while(t[ma]<2&&ma>0) ma--;
        if(mi>ma) break;
        t[mi]--; t[ma]--;
        a-=2;
    }
    if(mi==ma) a-=f(t[mi]-1);
    printf("%d\n",a);
}


Measured memory_bytes: 512
from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

lsloop = []
used = [False for i in range(n+1)]

for j in range(1,n+1):
    if used[j]:
        continue        
    ii = 1
    d = deque()
    d.append(j)
    used[j] = True
    while d:
        v = d.popleft()
        for i in graph[v]:
            if used[i]:
                continue
            ii += 1
            d.append(i)
            used[i] = True
    lsloop.append(ii)
print(max(lsloop))

Measured memory_bytes: 45004
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

if p == q:
  print(0)
  exit()

temp = [i for i in range(1,n+1)]
v= [list(v) for v in itertools.permutations(temp)]

print(abs(v.index(p)-v.index(q)))

Measured memory_bytes: 10228
n=int(input())
x=list(map(int,input().split()))
m=int(input())
a=list(map(int,input().split()))

for v in a:
    if x[v-1]+1 in x or x[v-1]==2019:
        x[v-1]=x[v-1]
    else:
        x[v-1]+=1
for i in range(n):
    print(x[i])


Measured memory_bytes: 5608
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int n,m; 
vector <int> g[200005];
int  boat[200005] ; 
bool  vis[200005] , ok=false; 

void bfs(){ 
    queue <int> q;
    q.push(1);
    while (q.size()){
        int u=q.front();
        q.pop(); 
        vis[u] = true ; 
        for (auto &it: g[u]){
            boat[it]=min(boat[it],boat[u]+1);
            if (!vis[it]) q.push(it);
        }
    }
} 
 
signed main() 
{ 
    cin>>n>>m; 
    for (int i=0;i<m;i++){ 
        int u,v; 
        cin>>u>>v; 
        g[u].pb(v); 
        g[v].pb(u); 
    } 
    for (int i=2;i<=n;i++) boat[i] = 1000000000 ; 
    boat[0]=boat[1]=0; 
    bfs();
    if (boat[n]==2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}
/*
5 5
1 3
4 5
2 3
2 4
1 4
    1 -> 3
    1 -> 4 -> 5
    2 -> 3
    2 -> 4
*/


Measured memory_bytes: 18236
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    s = sc.strarr()[0]
    s1 = s[0:(n//2)]
    s2 = s[(n//2):]
    if s1 == s2:
        print('Yes')
    else:
        print('No')


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;




int main(){
	while (1) {
		long long n, k, now = 0, m = 0, i;
		long long a[100009];
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (i = 1; i <= k; i++) {
			now += a[i];
		}
		m = now;
		for (i = 1; i <= n - k; i++) {
			now = now - a[i] + a[i + k];
			if (now > m) m = now;
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 3784
def main():
    H, W = map(int, input().split())
    c = [
        list(map(int, input().split()))
        for _ in range(10)
    ]

    # c から最小魔力テーブルの算出
    for k in range(10):
        for i in range(10):
            for j in range(10):
                c1 = c[i][j]
                c2 = c[i][k] + c[k][j]
                if c1 > c2:
                    c[i][j] = c2

    ans = 0
    for _ in range(H):
        for a in map(int, input().split()):
            if a != -1:
                ans += c[a][1]

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
int main(){
    int a,b,c,d,e,ans=0;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
  ans=c*60+d-a*60-b-e;
  if(ans<0)
    ans=0;
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 1732
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
V_odd = V[::2]
V_eve = V[1::2]
odd_max = Counter(V_odd).most_common(1)
even_max = Counter(V_eve).most_common(1)

result = n - odd_max[0][1] - even_max[0][1]
if odd_max[0][0] == even_max[0][0]:
    odd_least,even_least = 0,0
    if Counter(V_odd).most_common(1) != Counter(V_odd).most_common(2):
        odd_least = (Counter(V_odd).most_common(2))[1][1]
    if Counter(V_eve).most_common(1) != Counter(V_eve).most_common(2):
        even_least = (Counter(V_eve).most_common(2))[1][1]
    if Counter(V_odd).most_common(1) == Counter(V_odd).most_common(2) and Counter(V_eve).most_common(1) == Counter(V_eve).most_common(2):
        result = int(n/2)
    else:
        result = min(n - odd_least - even_max[0][1],n - even_least - odd_max[0][1])

print(result)

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

using namespace std;

int main() {

	int N;
	cin >> N;
	vector<int> vNum(N, 0);

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

	total /= 2;

	int counter = 0;
	int left = 0;
	int right = 0;
	bool onlyAdd = false;
	for (int i = 0; i < N; i++)
	{
		if (onlyAdd)
		{
			counter += vNum[i];
		}
		else if (counter + vNum[i] < total)
		{
			counter += vNum[i];
		}
		else
		{
			if (abs(counter - total) < abs(counter + vNum[i] - total))
			{
				// たさないほうがいい
				left = counter;

				// right を求める
				counter = vNum[i];
			}
			else
			{
				counter += vNum[i];
				left = counter;

				counter = 0;
			}
			onlyAdd = true;
		}
	}




	cout << abs(counter - left) << endl;
	
	return 0;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from itertools import*
n=int(input())
con=[[]for _ in range(n)]
col=[-1]*n
G=[]
for i in range(n):
	x=input()
	for j,c in enumerate(x):
		if c=="1":
			con[i].append(j)
			con[j].append(i)
	G.append([c=="1" or float("inf") for c in x])
q=[0]
col[0]=0
while q:
	cur=q.pop(0)
	for nxt in con[cur]:
		if col[nxt]==col[cur]:
			print(-1)
			exit()
		if col[nxt]<0:
			col[nxt]=1-col[cur]
			q.append(nxt)
print(int(np.amax(floyd_warshall(G,0)+1)))

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

#define ll long long 
#define pb push_back
#define pu push
#define in insert
#define f(s,e) for(i=s;i<e;i++)
#define loop(i) while(i--)
#define bg(v) v.begin()
#define ed(v) v.end()
#define sz(v) v.size()
#define len(v) v.length()

int main(){
    ll t,op,i,j,k,n,m,h;
    cin>>n;
    set<string>s;
    while(n--)
    {
        string ss;
        cin>>ss;
        s.insert(ss);
    }
    cout<<s.size();
	return 0; 
} 

Measured memory_bytes: 19224
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int x,y,z;cin>>x>>y>>z;
    int a = x;
    int b = y;
    int c = z;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  val n = readInt
  val arr = readLine.split(" ").map(_.toInt)
  val cnt = mergeSort(arr, left=0, right=arr.length - 1, cnt=0)
  println(arr.mkString(" "))
  println(cnt)

  def mergeSort(arr: Array[Int], left: Int, right: Int, cnt: Int): Int = {
    if (left == right) {
      return 0
    }
    var count = 0
    val mid = (left + right) / 2
    count += mergeSort(arr, left, mid, cnt)
    count += mergeSort(arr, mid + 1, right, cnt)
    count += merge(arr, left, mid, right, cnt)
    count
  }

  def merge(arr: Array[Int], left: Int, mid: Int, right: Int, cnt: Int): Int = {

    val len1 = (mid + 1) - left
    val len2 = right - mid
    val L: Array[Int] = new Array[Int](len1 + 1)
    val R: Array[Int] = new Array[Int](len2 + 1)
    for (i <- 0 until len1) L(i) = arr(left + i)
    for (i <- 0 until len2) R(i) = arr((mid + 1) + i)
    L(len1) = Integer.MAX_VALUE
    R(len2) = Integer.MAX_VALUE

    var count = cnt
    var i = 0
    var j = 0
    var k = left
    while (k <= right) {
      if (L(i) < R(j)) {
        arr(k) = L(i)
        i += 1
      } else {
        arr(k) = R(j)
        j += 1
      }
      k += 1
      count += 1
    }
    count
  }
}



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

using namespace std;

int main()
{
    long long x;
    cin>>x;
    long long y=100;
    int ans=0;
    while(y<x)
    {
        y=y*(1.01);
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
N = input().strip()

maxn = ()
base = set(['357', '375', '537', '573', '735', '753'])

if int(N) < 357:
  print(0)
else:
  for n in range(len(N) - 3):
    newb = set()
    for b in base:
      new3b = set([b[:i] + '3' + b[i:] for i in range(len(b) + 1)])
      new5b = set([b[:i] + '5' + b[i:] for i in range(len(b) + 1)])
      new7b = set([b[:i] + '7' + b[i:] for i in range(len(b) + 1)])
      newb |= new3b | new5b | new7b
    base |= newb
  print(len([i for i in base if int(i) <= int(N)]))


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

char buf[1<<15],*fs,*ft;
inline char getc() { return (ft==fs&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),ft==fs))?0:*fs++; }
template<typename T>inline void read(T &x)
{
	x=0;
	T f=1, ch=getchar();
	while (!isdigit(ch) && ch^'-') ch=getchar();
	if (ch=='-') f=-1, ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x*=f;
}

char Out[1<<24],*fe=Out;
inline void flush() { fwrite(Out,1,fe-Out,stdout); fe=Out; }
template<typename T>inline void write(T x)
{
	if (!x) *fe++=48;
	if (x<0) *fe++='-', x=-x;
	T num=0, ch[20];
	while (x) ch[++num]=x%10+48, x/=10;
	while (num) *fe++=ch[num--];
	*fe++='\n';
}

inline int s(int x,int y)
{
    if (x<=y) return y-x;
    else return x-y+2;
}

int main()
{
    int x,y;read(x);read(y);
    write(min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));
    flush();
    return 0;
}

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

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

using namespace std;
using lint=long long;

template<class T> T gcd(const T& a,const T& b){ return b==0?a:gcd(b,a%b); }

template<class T>
T xgcd(T a,T b,T& x,T& y){
	if(b==0){ x=1; y=0; return a; }
	T g=xgcd(b,a%b,y,x);
	y-=a/b*x;
	return g;
}

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

	int ans=0;
	rep(i,q){
		lint a,k; scanf("%lld%lld",&a,&k);

		while(a%k!=0){
			lint x=a/k+1,y=k,z=a%k;
			lint g=gcd(x,y);

			if(z%g==0){
				// find (m, n) s.t. m*x + n*y = z
				lint m,n;
				xgcd(x,y,m,n);
				m*=z/g;
				n*=z/g;
				assert(m*x+n*y==z);

				// find the smallest positive m
				if(m>0){
					lint l=m/(y/g);
					m-=l*(y/g);
					n+=l*(x/g);
				}
				else{ // m<0
					lint l=(-m)/(y/g)+1;
					m+=l*(y/g);
					n-=l*(x/g);
				}
				assert(m>0);

				lint a2=a-m*x;
				if(a2>=0 && a2/k+1==x){
					a=a2;
					assert(a%k==0);
					break;
				}
			}

			lint lo=0,hi=2*a;
			while(hi-lo>1){
				lint mi=(lo+hi)/2;
				lint a2=a-mi*x;
				if(a2>=0 && a2/k+1==x) lo=mi;
				else                   hi=mi;
			}
			a-=hi*x;
		}

		ans^=a/k;
	}
	puts(ans>0?"Takahashi":"Aoki");

	return 0;
}


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

int main() {

	string s, t;
	cin >> s >> t;

	int ans = 1001;
	for (int si = 0; si < s.size(); si++) {
		int cnt = 0;
		if (si + t.size() > s.size()) break;
		else {
			for (int ti = 0; ti < t.size(); ti++) {
				if (s[si + ti] != t[ti]) cnt++;
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
class Baseball:

  def __init__(self, score, first, second, third, out_counter):
    self.score = score
    self.first = first
    self.second = second
    self.third = third
    self.out_counter = out_counter

  def hit(self):
    if self.third == 1:
      self.score += 1
    if self.second == 1 and self.third == 0:
      self.third = 1
    if self.first == 1 and self.second == 0:
      self.second = 1
    if self.first == 0:
      self.first = 1

  def homerun(self):
    self.score += self.first + self.second + self.third + 1
    self.first = 0
    self.second = 0
    self.third = 0

  def out(self):
    self.out_counter += 1


for i in range(int(input())):
  baseball = Baseball(0, 0, 0, 0, 0)
  while 1:
    event = input()
    if event == "HIT":
      baseball.hit()
    elif event == "HOMERUN":
      baseball.homerun()
    else:
      baseball.out()
      if baseball.out_counter == 3:
        print(baseball.score)
        del baseball
        break



Measured memory_bytes: 5600
#include<stdio.h>
#include<stdlib.h>
#define INF 100000000
int s[1000];
int g[1000];
int sx,sy,gx,gy;
typedef struct{
	int x,y;
}pair;
pair p[5][1000];
int cp[5];
int d[2][1000];
int min(int a,int b){return a<b?a:b;}
int main(){
	while(1){
	int w,h;
	int i,j,k;
	int ans1=INF;
	int ans2;
	char c;
	scanf("%d %d",&w,&h);
	if(w==0&&h==0)return 0;
	for(i=0;i<5;i++)cp[i]=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf(" %c",&c);
			if(c=='S'){sx=j;sy=i;}
			if(c=='G'){gx=j;gy=i;}
			if(c=='1'){p[0][cp[0]].x=j;p[0][cp[0]].y=i;cp[0]++;}
			if(c=='2'){p[1][cp[1]].x=j;p[1][cp[1]].y=i;cp[1]++;}
			if(c=='3'){p[2][cp[2]].x=j;p[2][cp[2]].y=i;cp[2]++;}
			if(c=='4'){p[3][cp[3]].x=j;p[3][cp[3]].y=i;cp[3]++;}
			if(c=='5'){p[4][cp[4]].x=j;p[4][cp[4]].y=i;cp[4]++;}
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<cp[(i+1)%5];j++){
			s[j]=abs(sx-p[(i+1)%5][j].x)+abs(sy-p[(i+1)%5][j].y);
		}
		for(j=0;j<cp[(i+4)%5];j++){
			g[j]=abs(gx-p[(i+4)%5][j].x)+abs(gy-p[(i+4)%5][j].y);
		}
		for(j=0;j<cp[(i+1)%5];j++){
			d[0][j]=s[j];
		}
		for(j=0;j<cp[(i+2)%5];j++)d[1][j]=INF;
		for(j=0;j<3;j++){
			for(k=0;k<cp[(i+j+1)%5];k++){
				for(int l=0;l<cp[(i+j+2)%5];l++){
					d[1][l]=min(d[1][l],d[0][k]+abs(p[(i+j+2)%5][l].x-p[(i+j+1)%5][k].x)+abs(p[(i+j+2)%5][l].y-p[(i+j+1)%5][k].y));
				}
			}
			for(k=0;k<cp[(i+j+2)%5];k++){
				d[0][k]=d[1][k];
			}
			for(k=0;k<cp[(i+j+3)%5];k++){
				d[1][k]=INF;
			}
		}
		for(j=0;j<cp[(i+4)%5];j++){
			if(d[0][j]+g[j]<ans1){
				ans2=i+1;
				ans1=d[0][j]+g[j];
			}
		}
	}
	if(ans1==INF)printf("NA\n");
	else printf("%d %d\n",ans2,ans1);
	}
}

	

Measured memory_bytes: 1080
// atcoder/abc124/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> v(n);
    cin >> v;
    int mx = v[0];
    int cnt = 0;
    each (i, v) {
      cnt += (mx <= i);
      setmax(mx, i);
    }
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define mod 1000000007

bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[200005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}
int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
int ans[200005];
void fun(int a, int b, int c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        int p = -a;
        a += (a & p);
    }
}
int find1(int a)
{
    int sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        int p = -a;
        a -= (a & p);
    }
    return sum;
}
void process2(int A[], int N)
{
    int i, j;

    for (i = 0; i < N; i++)
        M[i][0] = i;
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}

int32_t main()
{
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << "\n";
    return 0;
}

Measured memory_bytes: 50456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int b[n-1];
  rep(i,n-1)cin >> b[i];
  ll ans=0;
  ans += b[0];
  ans += b[n-2];
  rep(i,n-2){
    ans += min(b[i],b[i+1]);
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S, T;
    cin >> S;
    cin >> T;
    sort(begin(S), end(S));
    sort(rbegin(T), rend(T));
    bool flag=S<T;
    cout << (flag? "Yes": "No") << endl;
}


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

const int64_t MOD = 998244353;
int64_t powMod(int64_t m, int64_t n) {
    if (n == 0) return 1;
    int64_t ret = powMod(m, n / 2);
    if (n % 2 == 0) {
        return (ret * ret) % MOD;
    } else {
        return (((ret * ret) % MOD) * m) % MOD;
    }
}

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

    int N;
    cin >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) cin >> D[i];
    int64_t ret = 1;
    map<int, int64_t> M;
    int maxv = 0;
    for (int i = 0; i < D.size(); i++) {
        M[D[i]]++;
        if (i != 0 && D[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
        maxv = max(maxv, D[i]);
    }
    for (int i = 0; i <= maxv; i++) {
        if (M[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (i == 0 && M[i] != 1) {
            cout << 0 << endl;
            return 0;
        }
        if (i == 0) continue;
        ret = (ret * powMod(M[i - 1], M[i])) % MOD;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 6912
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line;
			while(true){
				/* input */
				line = br.readLine();

				int n = Integer.parseInt(line);

				if(n==0) break;

				String[] str = br.readLine().split(" ");
				
				/* processing */
				int sum = 0;
				for(int i=0;i<str.length;i++){
					sum += Integer.parseInt(str[i]);
				}
				
				/* output */
				System.out.println(sum/(n-1));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            char[][] S = new char[H][];
            for (int i = 0; i < H; i++) {
                S[i] = sc.next().toCharArray();
            }

            int max = 0;

            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    if (S[h][w] == '#') {
                        continue;
                    }

                    int[][] D = new int[H][W];
                    for (int i = 0; i < H; i++) {
                        Arrays.fill(D[i], Integer.MAX_VALUE);
                    }
                    D[h][w] = 0;

                    while (true) {
                        boolean update = false;

                        for (int i = 0; i < H; i++) {
                            for (int j = 0; j < W; j++) {
                                if (D[i][j] == Integer.MAX_VALUE) {
                                    continue;
                                }

                                if (i > 0 && S[i - 1][j] == '.') {
                                    if (D[i - 1][j] > D[i][j] + 1) {
                                        D[i - 1][j] = D[i][j] + 1;
                                        update = true;
                                    }
                                }

                                if (i < H - 1 && S[i + 1][j] == '.') {
                                    if (D[i + 1][j] > D[i][j] + 1) {
                                        D[i + 1][j] = D[i][j] + 1;
                                        update = true;
                                    }
                                }

                                if (j > 0 && S[i][j - 1] == '.') {
                                    if (D[i][j - 1] > D[i][j] + 1) {
                                        D[i][j - 1] = D[i][j] + 1;
                                        update = true;
                                    }
                                }

                                if (j < W - 1 && S[i][j + 1] == '.') {
                                    if (D[i][j + 1] > D[i][j] + 1) {
                                        D[i][j + 1] = D[i][j] + 1;
                                        update = true;
                                    }
                                }
                            }
                        }

                        if (!update) {
                            break;
                        }
                    }

                    for (int i = 0; i < H; i++) {
                        for (int j = 0; j < W; j++) {
                            if (D[i][j] != Integer.MAX_VALUE) {
                                max = Math.max(max, D[i][j]);
                            }
                        }
                    }
                }
            }

            System.out.println(max);
        }
    }

}


Measured memory_bytes: 23856
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
s=sum(A)
l=len(A)
m=0
for i in range(l):
    if A[i]>=s/(4*M):
        m+=1
if M<=m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 2e5 + 5;

int nxt[N][26], dp[N];
char s[N];
vi ans;

int main()
{
	#ifdef M1saki
		setI;
	#endif
//	ios::sync_with_stdio(false);
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	rep(j, 0, 26)  nxt[len + 1][j] = len + 1;
	per(i, len, 0)
	{
		rep(j, 0, 26)  nxt[i][j] = nxt[i + 1][j];
		nxt[i][s[i] - 'a'] = i;
	}
	dp[len + 1] = 1;
	per(i, len, 0)
	{
		dp[i] = len + 1;
		rep(j, 0, 26)  dp[i] = min(dp[i], dp[nxt[i][j] + 1] + 1);
	}
//	de(dp[1]);
	int cur = 1;
	while (cur <= len)
	{
		rep(j, 0, 26)
			if (dp[cur] == dp[nxt[cur][j] + 1] + 1)
			{
				ans.pb(j);
				cur = nxt[cur][j] + 1;
				break;
			}
	}
	rep(i, 0, sz(ans))  printf("%c", ans[i] + 'a'); puts("");

	return 0;
}


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

using namespace std;
#define int long long
#define x first
#define y second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(136786931);
int randlr(int l, int r) {
    return rand1() % (r - l + 1) + l;
}

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

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

    if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes";
    }

    else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
def warshall_floyd(d):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
  
h,w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
ans = 0

cost = warshall_floyd(c)

for i in range(h):
  for j in range(w):
    if a[i][j] != -1:
      ans += cost[a[i][j]][1]

print(ans)


Measured memory_bytes: 3444
from itertools import combinations, count
 
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
r = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))
         if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))
print(r)


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

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

    ll k,n;
    cin>>n>>k;

    vector<ll> inp(n);

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

    ll sum = 0;
    ll ans = 0;
    for(int i = 0; i < k; i++) {
        sum += (inp[i]+1);
    }

    for(int i = k; i < n; i++) {
        ans = max(ans, sum);
        sum -= (inp[i-k]+1);
        sum += (inp[i]+1);
    }

    ans = max(ans, sum);

    double res = ans/2.0;
    cout<<setprecision(15)<<res<<endl;

    

}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
S,T = inputSL()
s = list(S)
t = list(T)

print("".join([s[i]+t[i] for i in range(N)]))

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

// UnionFind (Disjoint set)
struct unionfind {
	vector<int> d;	// 親：連結のサイズ×(-1)、子：親のID（非負）
	unionfind(int n = 0): d(n, -1) {}
	int find(int x) {
		if(d[x] < 0) return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d[find(x)]; }
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	unionfind uf(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.unite(x, y);
	}
	map<int, int> mp;
	rep(i, n) {
		mp[p[i]] = i;
	}
	int ans = 0;
	rep(i, n) {
		if(p[i] == i+1) {
			ans++;
		} else {
			if(uf.same(mp[i+1], i)) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
/**akshaykumar99**/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
   IOS();
   ll n,i,j;
   cin>>n;
   vector<string> s(n);
   ll a[n];
   f(i,0,n)
   {
      cin>>s[i]>>a[i];
   }
   ll t=0,w=0;
   string x;
   cin>>x;
   f(i,0,n)
   {
      if(x==s[i])
      {
         w=1;
         continue;
      }
      if(w)
      {
         t+=a[i];
      }
   }
   cout<<t<<'\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
 
 
int main(){
   
  int64_t h,n,sum=0;
  cin>>h>>n;
  
  vector<int64_t> a(n);
  rep(i,n){
      cin>>a.at(i);
      sum+=a.at(i);
  }
  if(h<=sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  
  
      
  
  
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int32_t main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n; read(n);
    list<int> nums;
    int reversed = 0;
    for0(i,n) {
        int x; read(x);
        if (reversed) {
            nums.push_front(x);
        }
        else {
            nums.push_back(x);
        }
        reversed = (reversed+1)%2;
    }
    if (!reversed) {
        for (list<int>::iterator it=nums.begin(); it!=nums.end(); it++) {
            printf("%d ",*it);
        }
        printf("\n");
    }
    else {
        for (list<int>::reverse_iterator it=nums.rbegin(); it!=nums.rend(); it++) {
            printf("%d ",*it);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 8448
N=int(input())
a=list(map(int,input().split()))

count = 0
tmpNumber = 1

for idx in range(N):
    if (a[idx] != tmpNumber):
      	count += 1
    else:
        tmpNumber += 1
if (tmpNumber == 1):
    print(-1)
else:
    print(count)

Measured memory_bytes: 24744
import sys
INF = 10 ** 9
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {j:[] for j in range(3 * n)}
for i in range(m):
    u, v = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    graph[u].append(n+v)
    graph[u+n].append(2*n+v)
    graph[u + 2 * n].append(v)
s, t = [int(i) for i in sys.stdin.readline().split()]
s -= 1
t -= 1

que = [s]
flg = False
already = set()
dist = [INF for i in range(3 * n)]
dist[s] = 0
while que:
    cur= que[0]
    que.pop(0)
    for i in graph[cur]:
        if i not in already:
            if i == t:
                res = dist[cur] + 1
                que.clear()
                flg = True
                break
            que.append(i)
            dist[i] = dist[cur] + 1
            already.add(i)
if not flg:
    res = -1
else:
    res //= 3

print(res)

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

using namespace std;

#define endl "\n"
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define f first
#define se second
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007

typedef long long ll;

ll A[51],B[51],C[51],D[51];

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>A[i]>>B[i];
    }
    for(int i=1;i<=m;++i){
        cin>>C[i]>>D[i];
    }
    int ans;
    for(int i=1;i<=n;++i){
        ll small=1e16;
        for(int j=1;j<=m;++j){
            if(abs(A[i]-C[j])+abs(B[i]-D[j])<small){
                small=abs(A[i]-C[j])+abs(B[i]-D[j]);
                ans=j;
            }
        }
        cout<<ans<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //int t;
    //cin>>t;
    //while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b;
    char op;

    while (1) {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?') {
            break;
        } else if (op == '+') {
            printf("%d\n", a+b);
        } else if (op == '-') {
            printf("%d\n", a-b);
        } else if (op == '*') {
            printf("%d\n", a*b);
        } else if (op == '/') {
            printf("%d\n", a/b);
        }
    }
    return 0;
}



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

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

Measured memory_bytes: 256
#create date: 2020-07-03 18:05

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    k, x = na()
    amin, amax = x-k+1, x+k-1
    print(*list(range(amin, amax+1)))

if __name__ == "__main__":
    main()

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

using namespace std;

int main(void) {
	long long n, ans;
	scanf("%lld", &n);
    ans = n - 1;
	for (long long i = 2; i * i <= n; i++) {
		if (n % i == 0) {
            ans = n / i + i - 2;
		}
	}
    cout << ans << "\n";
} 

Measured memory_bytes: 256
x = int(input()) # input:"7" intを忘れない
List = [int(i) for i in input().split()] # input:"1 2 3 4 5"
ans = 0
for i in range(x):
  if abs(i+1-List[i])>0:
    ans += 1
if ans==2 or ans==0:
  print("YES")
else:
  print("NO")

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

using namespace std;

void solve() {
    string gr, ls, eq;
    gr = "GREATER"; ls = "LESS"; eq = "EQUAL";
    string A, B;
    cin >> A; cin >> B;
    if (A.size() > B.size())
        cout << gr;
    else if (A.size() < B.size())
        cout << ls;
    else {
        if (A < B)
            cout << ls;
        else if (A > B)
            cout << gr;
        else
            cout << eq;
    }

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3072
import numpy as np

a, b = map(int,input().split())
ans = 0

if a <= b:
  a_ = np.full(b, a)
  for i in range(len(a_)):
    ans +=a_[i]*10**i
else:
  b_ = np.full(a, b)
  for i in range(len(b_)):
    ans +=b_[i]*10**i

print(int(ans))

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  
  string a, b, c;
  a = A.at(0);
  b = B.at(0);
  c = C.at(0);
  
  cout << a << b << c << endl;
}

Measured memory_bytes: 3632
while True:
    try:
        m,f,r = map(int,input().split(" "))
        if m == -1 and f == -1 and r == -1:
            break
        if m == -1 or f == -1:
            print("F")
            continue
        if m+f >= 80:
            print("A")
        if m+f >= 65 and m+f < 80:
            print("B")
        if m+f >= 50 and m+f < 65:
            print("C")
        if m+f >= 30 and m+f < 50:
            if r >= 50:
                print("C")
            else:
                print("D")
        if m+f < 30:
            print("F")
    except EOFError:
        break

Measured memory_bytes: 7608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n, count, con2;
    cin >> n;
    count = 0;
    con2 = 0;
    vector<int> var(n);
    for (int x = 0; x < n; x++){
        cin >> var[x];
    }
    
    
    while (true){
        for (int x = 0; x < n; x++){
            if (var[x] % 2 == 0)
                count++;
        }
        if (count == n){
            for (int i = 0; i < n; i++){
                var[i] /= 2;
            }
            con2++;
            count = 0;
            
        }
        else
            break;
        
    }
    cout << con2 << endl;
}
   

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
int main() {
	int N, count = 0, ans = 0, maxi = -1;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		count = 0;
		for (int j = i; j % 2 == 0; j /= 2)
		{
			count++;
		}
		if (maxi<count)
		{
			maxi = count;
			ans = i;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256