akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    vector<vector<int>> a(3, vector<int> (3));
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    set<int> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        s.insert(x);
    }
    for (int i = 0; i < 3; i++){
        if (s.count(a[i][0]) && s.count(a[i][1]) && s.count(a[i][2])){
            cout << "Yes";
            return 0;
        }
    }
    for (int i = 0; i < 3; i++){
        if (s.count(a[0][i]) && s.count(a[1][i]) && s.count(a[2][i])){
            cout << "Yes";
            return 0;
        }
    }
    if (s.count(a[0][0]) && s.count(a[1][1]) && s.count(a[2][2])){
        cout << "Yes";
        return 0;
    }
    if (s.count(a[2][0]) && s.count(a[1][1]) && s.count(a[0][2])){
        cout << "Yes";
        return 0;
    }
    cout << "No";
}

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

int main(){
  int n;
  cin >> n;
  int arr[55];
  for (int i = 1; i <= n; ++i){
    cin >> arr[i];
  }
  int ct = 0;
  for (int i = 1; i <= n; ++i){
    if (arr[i] != i) ++ct;
  }
  if (ct == 2 or ct == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

cnt = 0
# for i in range(1,N):
#     for j in range(0,i):
#         if A[i] > A[j]:
#             break
#     else:
#         cnt += 1
min_value = A[0]
for i in range(N):
    if min_value >= A[i]:
        cnt += 1
        min_value = A[i]

print(cnt)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> x(N), L(N);
	vector<pair<Int, Int>> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> L[i];
		a[i] = { x[i] + L[i], x[i] - L[i] };
	}

	sort(a.begin(), a.end());
	int ans = 0;
	Int t = -1e18;
	for (int i = 0; i < N; ++i) {
		if (t <= a[i].second) {
			++ans;
			t = a[i].first;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  r(i,50000){
    int a=i*1.08;
    if(a==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define ll long long
const int maxn = 1e5+10;
using namespace std;

ll arr[maxn];
int main(){
  ll n,a,b,ans=0;
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    cin>>arr[i];
    //scanf("%lld",&a[i]);
  }
  for(int i=0;i<n-1;i++){
    if((arr[i+1]-arr[i])*a>=b)
      ans+=b;
    else ans+=((arr[i+1]-arr[i])*a);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
n,a,b = (int(x) for x in input().split())

ans = 0

def keta(N):
    sum = 0
    while N>0:
        sum += N%10
        N = N//10
    return sum

for i in range(1,n+1):
    if a<=keta(i)<=b:
        ans +=i
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;
using llong = long long;
using P = pair<llong,llong>;

P pos[50];
int N , K;
P num_and_area(llong xl,llong xr,llong yb,llong yt){
  if(xl > xr) swap(xl,xr);
  if(yb > yt) swap(yb,yt);

  int num = 0;
  for(int idx=0;idx<N;++idx){
    llong x = pos[idx].first , y = pos[idx].second;
    if( xl <= x && x <= xr && yb <= y && y <= yt ) num++;
  }
  // cout << num << " " << (xr-xl)*(yt-yb) << endl;
  return P(num,(xr-xl)*(yt-yb));
}

int main(){
  cin >> N >> K;
  for(int i=0;i<N;++i){
    llong x,y;
    cin >> x >> y;
    pos[i] = P(x,y);
  }

  llong min_area = 9000000000000000000;
  for(int ixl = 0 ; ixl < N ; ++ixl){
    for(int ixr = 0 ; ixr < N ; ++ixr){
      for(int iyb = 0 ; iyb < N ; ++iyb){
        for(int iyt = 0 ; iyt < N ; ++iyt){
          llong xl = pos[ixl].first , xr = pos[ixr].first , yb = pos[iyb].second , yt = pos[iyt].second;
          auto p = num_and_area(xl,xr,yb,yt);
          if(p.first == K&& min_area > p.second) min_area = p.second;
        }
      }
    }
  }
  cout << min_area << endl;
  return 0;
}

Measured memory_bytes: 384
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	char s;
	cin>>s;
	if(s>='a' && s<='z'){
		cout<<"a";
	}
	else cout<<"A";
		
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 505;

int n,c;
int cost[maxn][maxn];
int g[maxn][maxn];

vector<vector<int>> ways;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>c;
    for (int i=1; i<=c; i++) {
	for (int j=1; j<=c; j++) {
	    cin>>cost[i][j];
	}
    }
    vector<map<int,int>> mp(3);
    
    for (int i=1; i<=n; i++) {
	for (int j=1; j<=n; j++) {
	    cin>>g[i][j];
	    mp[(i+j)%3][g[i][j]]++;
	}
    }

    vector<int> v;
    for (int i=1; i<=c; i++) {
	v.push_back(i);
    }

    for (int i=0; i<c; i++) {
	for (int j=i+1; j<c; j++) {
	    for (int k=j+1; k<c; k++) {
		ways.push_back({v[i],v[j],v[k]});
	    }
	}
    }


    // watch(ways.size());
    
    int best = 1e9;

    for (auto x: ways) {
	
	do {

	    // for (int i: x) cout<<i<<" ";
	    // cout<<endl;
	    vector<int> cur(3);
	    cur[0]=x[0];
	    cur[1]=x[1];
	    cur[2]=x[2];
	    int tot=0;

	    for (int i=0; i<3; i++) {
		for (auto p: mp[i]) {
		    int color = p.first;
		    int freq = p.second;
		    tot += cost[color][cur[i]]*freq;
		}
	    }

	    best=min(best,tot);
	} while (next_permutation(x.begin(), x.end()));

    }



    cout<<best<<endl;
    

    return 0;
}


Measured memory_bytes: 1536
using System.Collections.Generic;
using System.Linq;
using System;

public class Result
{
    public int id { get; set; }
    public int v { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var results = new List<Result>();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var v = int.Parse(line[1]);
            results.Add(new Result { id = a, v = v });
        }
        var ret = results.OrderByDescending(x => x.v).ThenBy(x => x.id).First();
        Console.WriteLine("{0} {1}", ret.id,ret.v);
    }
}

Measured memory_bytes: 10160
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read()
{
    char c=getchar();LL f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
map<LL,LL>iv,cnt;
LL a;LL n,vis[100005],p[100005],tot,ans,gg;
void shai()
{
	for(int i=2;i<=100000;i++)
    {
        if(!vis[i]) p[++tot]=i;
        for(int j=1;j<=tot&&i*p[j]<=100000;j++){vis[i*p[j]]=1;if(i%p[j]==0) break;}
    }
}
int main()
{
    shai();
    n=read();
	for(int i=1;i<=n;i++)
    {
        a=read();LL t=a,val=1,inv=1;
        for(int j=1;j<=tot&&1ll*p[j]*p[j]*p[j]<=a;j++) if(t%p[j]==0)
        {
            int mi=0;while(t%p[j]==0) t/=p[j],mi++;mi%=3;
            for(int i=1;i<=mi;i++) val*=1ll*p[j];for(int i=1;i<=(3-mi)%3;i++) inv*=1ll*p[j];
        }
        if(t>1){val*=t;LL sq=sqrt(t);if(sq*sq==t) inv*=sq;else inv*=t*t;}
        if(val==1) gg=1;else cnt[val]++,iv[inv]=val,iv[val]=inv;
    }
    for(map<LL,LL>::iterator it=cnt.begin();it!=cnt.end();++it)
    {
        if(cnt.find(iv[it->first])==cnt.end()) ans+=it->second;
        else ans+=max(it->second,cnt[iv[it->first]]),it->second=0,cnt[iv[it->first]]=0;
    }
    printf("%lld\n",ans+gg);
}

Measured memory_bytes: 19840
from collections import*
from heapq import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while t[x]>=0:x=t[x]
 return x
def u(x,y):
 x,y=r(x),r(y)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for x,y in q:u(x,y)
i=c=0;b=[];k=(n+~m)*2;f=print
for v in a:d[r(i)]+=v,;i+=1
print(0if k<1else'Impossible'if k>n else exec("for r,p in d.items():p.sort();c+=p.pop(0);b+=p;k-=1")or c+sum(sorted(b)[:k]))

Measured memory_bytes: 35404
#include<stdio.h>

int quicksort_d(int list[], int lower, int upper);

int main()
{
	int m_height[10];
	int i;

	for (i=0;i<10;i++)
	{
		scanf("%d", &m_height[i]);
	}
	
	quicksort_d(m_height, 0, 9);
	
	for (i=0;i<3;i++)
	{
		printf("%d\n", m_height[i]);
	}
	
	return 0;
}

int quicksort_d(int list[], int lower, int upper)
{
	int p1 = lower, p2 = upper; 
	int flag_order = 1;
	int temp;

	if (p1 >= p2 || p2 >= 10) return 0;

	while (p1 != p2)
	{
		if (list[p1] < list[p2])
		{
			temp = list[p1];
			list[p1] = list[p2];
			list[p2] = temp;
			flag_order = !flag_order;
		}
		if (flag_order) p2--;
		else p1++;
	}

	quicksort_d(list, lower, p1 - 1);
	quicksort_d(list, p1 + 1, upper);

	return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
# ALDS1_4_B_BinarySearch

import sys

def input_lines():
    return sys.stdin.readlines()

def binary_search(l, v):    
    low = 0
    high = len(l) - 1
    while low <= high:
        mid = (low + high) // 2
        if l[mid] == v:
            return mid
        elif l[mid] < v:
            low = mid + 1
        else:
            high = mid - 1
    return -1

def main():
    lines = input_lines()
    s = sorted(set(map(int, lines[1].split())))
    t = sorted(map(int, lines[3].split()))
    
    count = 0
    for v in t:
        res = binary_search(s, v)
        if res != -1:
            count += 1
            s = s[res + 1:]
    print(count)
    
main()


Measured memory_bytes: 16124
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class B1 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int X;
        cin >> X;

        int cur = 100;
        int res = 0;
        while (cur < X) {
            cur = cur + cur / 100;
            res++;
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    B1 solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    string s; cin >> s;
    lol len = s.length();
    REP(i, len)
    {
        result += ((char)s[i]-(char)'0');
    }
    if(result%9 == 0) cout << "Yes" << endl;
    else
        cout << "No" << endl;

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

Measured memory_bytes: 3752
s = str(input())
n = len(s)
ans = 0

for i in range(2**(n-1)):
    s_tmp = s
    nbin = str(bin(i))[2:]
    nbin = nbin.zfill(n-1)
    for j in range(len(nbin)-1, -1, -1):
        if nbin[j] == '1':
            s_tmp = s_tmp[:j+1] + '+' + s_tmp[j+1:]

    ans += eval(s_tmp)
print(ans)

Measured memory_bytes: 9076
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&k)
	m := max(a, b)
	m = max(c, m)
	x := m*pow(2, k) - m
	fmt.Println(a + b + c + x)
}

func max(a, b int) int {
	if a <= b {
		return b
	}
	return a
}

func pow(a, p int) int {
	x := 1
	for i := 0; i < p; i++ {
		x = x * a
	}
	return x
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;


int main()
{
	int n;
	vector<int> as;
	int sum = 0;

	scanf("%d", &n);
	as.resize(n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &as[i]);
		sum += as[i];
	}

	int ans = 0;

	for(int fr = 1; fr < n; ++fr) {
		int a = as[fr];
		int a_diff = abs(a * n - sum);
		int ans_diff = abs(as[ans] * n - sum);
		if(a_diff < ans_diff) {
			ans = fr;
		}
	}

	printf("%d\n", ans);

	return 0;
}

/* waffle */


Measured memory_bytes: 256
import numpy as np
from scipy.sparse import csr_matrix, linalg
s = np.array(list(input()), dtype='U1')
n = len(s)
child = np.ones(n,dtype=np.int32)
rows = range(n)
cols = [i+1 if c == 'R' else i-1 for i,c in enumerate(s)]
x = csr_matrix((np.ones(n,dtype=np.int32),(rows,cols)),(n,n))

def power(x,n):
    if n == 1:
        return x
    y = power(x,n//2)
    y = y*y
    return x*y if n&1 else y

x = power(x,10**100)
print(*(child*x))

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


int main()
{
    string s, t;
    cin >> s >> t;

    int count = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == t[i]) {
            count++;
        }
    }
    cout << count << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> V(n);
  rep(i,n){cin>>V.at(i);}
  sort(V.begin(),V.end());
  double ans = V.at(0);
  rep1(i,n){
    ans = (ans+V.at(i))/2;
  }
  cout<<setprecision(20)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
ans = 0
a = []
last = [0]*26
for i in range(1,d+1):
    res = -float("inf")
    index = 0
    for k in range(26):
        x = k
        tnplast = last
        tnplast[x] = i
        tnp = 0
        tnp += s[i-1][x]
        for j in range(26):
            tnp -= c[j]*(i-last[j])
        if (tnp > res):
            res = tnp
            index = k+1
    ans += res
    a.append(index)

def rec(t,x,y,ans):
    ans -= s[x-1][t[x-1]-1]
    ans += s[x-1][y-1]
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==t[x-1]):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==t[x-1]):
            mi = j
            break
    ans -= c[t[x-1]-1]*(x-mi)*(ma-x)
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==y):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==y):
            mi = j
            break
    ans += c[y-1]*(x-mi)*(ma-x)
    return ans
    
for i in range(2000):
    x = random.randrange(1,d+1)
    y = random.randrange(1,27)
    t = a
    t[x-1] = y
    A = rec(t,x,y,ans)
    if (ans < A):
        a = t
        ans = A

print(*a ,sep="\n")
    
    

Measured memory_bytes: 9552
# n = int(raw_input())
# a = [int(raw_input()) for i in xrange(n)]
m, d = map(int, raw_input().split())

# print "".join(["a","b"])

# print "Yes" if 3 > 0 else "No"

if d >= m:
    print m
else:
    print m-1

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int H,n,val,sum;
int main(){
  cin>>H>>n;
  for(int i=1;i<=n;++i)
    cin>>val,sum+=val;
  puts(sum>=H?"Yes":"No");
  return 0;
}

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

int p[maxn], vis[maxn];
int ans[maxn], num;
int cnt = 0;

void init() {
    memset(p, 0, sizeof p);
    memset(vis, 0, sizeof vis);
    for(int i = 2; i < maxn; i++) {
        if(vis[i]) continue;
        for(int j = i + i; j < maxn; j += i) vis[j] = 1;
    }
    for(int i = 2; i< maxn; i++) if(!vis[i]) p[cnt++] = i;
}

int getNum(int n) {
    int ans = 0;
    while(n) { ans += n % 10; n /= 10; }
    return ans;
}

bool is_p(int n) {
    for(int i = 2; i < n; i++) if(n % i == 0) return 0;
    return 1;
}

int main() {
    int T;
    init();
////    for(int i = 0; i < 150; i++) cout << p[i] << " ";
////    cout << endl << endl;
//    for(int i = 0; i < cnt; i++) vis[i] = getNum(p[i]);
//    num = 0;
//    for(int i = 0; i < 4; i++) { ans[i] = p[i]; num += vis[i]; }
//    int gg = 4;
//    for(int i = 4; i < cnt; i++) {
//
//        if((num + vis[i]) % 11) continue;
//        ans[gg++] = p[i];
//        num -= getNum(ans[gg - 4]);
//    }
//    ans[11] = 11;
//    ans[24] = 19;
//    ans[25] = 541;
//    ans[28] = 13;
//    ans[29] = 149;
//    ans[33] = 61;
//    ans[35] = 71;
//    ans[36] = 349;
//    ans[39] = 29;
//    ans[40] = 79;
//    ans[45] = 797;
//    ans[53] = 37;
//    for(int i = 0; i < 55; i++) cout << ans[i] << " ";
//    cout << endl;
//    for(int i = 0; i < 55; i++) {
//        int sum = 0, j;
//        for(j = i; j < i + 5; j++) sum += ans[j];
//        cout << j << " " << sum << endl;
//    }
////    int n;
////    while(~scanf("%d", &n)) {
////        for(int i = 0; i < n; i++) printf("%d%c", ans[i], " \n"[i == n - 1]);
////    }
    int num = 0;
    for(int i = 0; i < cnt - 5; i++) {
        if(p[i] % 5 == 1) ans[num++] = p[i];
    }
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 0; i < n; i++) printf("%d%c", ans[i], " \n"[i == n - 1]);
    }
    return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 2017;
char c[N][N], used[N][N];
int add[N][N], addv[N][N], addh[N][N];

int n, m, q;

bool get(int i, int j) {
    if (i < 0 || i >= n || j < 0 || j >= m) return false;
    return (c[i][j] == '1' && !used[i][j]);
}


void dfs(int i, int j) {
    ++add[i][j];
    used[i][j] = 1;
    if (get(i + 1, j)) {
        ++addv[i][j];
        dfs(i + 1, j);
    }
    if (get(i - 1, j)) {
        ++addv[i - 1][j];
        dfs(i - 1, j);
    }
    if (get(i, j + 1)) {
        ++addh[i][j];
        dfs(i, j + 1);
    }
    if (get(i, j - 1)) {
        ++addh[i][j - 1];
        dfs(i, j - 1);
    }
}

int rez(int x, int y) {
    if (x == 0 || y == 0) return 0;
    --x, --y;
    int ans = add[x][y];
    //if (x) ans -= addv[x - 1][y];
    //if (y) ans -= addh[x][y - 1];
    return ans;
}

int rezv(int x, int y) {
    if (x == 0 || y == 0) return 0;
    --x, --y;
    if (x == 0) return 0;
    --x;
    return -addv[x][y];
}

int rezh(int x, int y) {
    if (x == 0 || y == 0) return 0;
    --x, --y;
    if (y == 0) return 0;
    --y;
    return -addh[x][y];
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    forn(i, 0, n) scanf("%s", c[i]);
    forn(i, 0, n) forn(j, 0, m) if (c[i][j] == '1' && !used[i][j]) {
        dfs(i, j);
    }
    forn(i, 1, n) forn(j, 0, m) {
        add[i][j] += add[i - 1][j];
        addh[i][j] += addh[i - 1][j];
        addv[i][j] += addv[i - 1][j];
    }
    forn(i, 0, n) forn(j, 1, m) {
        add[i][j] += add[i][j - 1];
        addh[i][j] += addh[i][j - 1];
        addv[i][j] += addv[i][j - 1];
    }
    //cerr << add[n - 1][m - 1] << '\n';
    while (q--) {
        int x1, x2, y1, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        --x1, --y1;
        int ans = rez(x2, y2) - rez(x1, y2) - rez(x2, y1) + rez(x1, y1);
        ans += rezh(x2, y2) - rezh(x1, y2) - rezh(x2, y1 + 1) + rezh(x1, y1 + 1);
        ans += rezv(x2, y2) - rezv(x1 + 1, y2) - rezv(x2, y1) + rezv(x1 + 1, y1);
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 58368
import bisect

A, B, Q = [int(e) for e in input().split()]
ss = [int(input()) for _ in range(A)]
tt = [int(input()) for _ in range(B)]
xx = [int(input()) for _ in range(Q)]
INF = 10 ** 18
for x in xx:
    idx_s_right = min(bisect.bisect_left(ss, x), A-1)
    idx_s_left = max(0, idx_s_right - 1)
    stmps = [ss[idx_s_right], ss[idx_s_left]]

    ttmps = [] 
    idx_t_right = min(bisect.bisect_left(tt, x), B-1)
    idx_t_left = max(0, idx_t_right - 1)
    ttmps = [tt[idx_t_right], tt[idx_t_left]]

    mem = INF
    for s in stmps:
        for t in ttmps:
            d_s = abs(s - x) + abs(t - s)
            d_t = abs(t - x) + abs(s - t)
            mem = min(mem, d_s, d_t)
    print(mem)


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

typedef long long ll;

using namespace std;

int main()
{ll N; cin >> N;
 ll c = (ll) sqrt((double) (N + 1)) - 1 ;
 
 ll total = 0;
 
 for(ll s = 1; s <= c; s++)
 {if( N % s == 0){total += N/s - 1;}}
 
  cout << total << endl;
 
 return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[[int(i) for i in input().split()] for i in range(N)]
ans=0
       
for i in range(N):
  tmp=0
  for j in range(M):
    tmp += A[i][j]*B[j]
  if tmp+C>0:
     ans +=1

print(ans)

Measured memory_bytes: 3064
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n , k , ans , sum , a , b ,arr[mx5], g[mx5];
string str;

int mex(set<int> s)
{
	int i=0;
	for(auto x : s)
	{
		if(i!=x)
		{
			return i;
		}
		i++;
	}
	return i;
}

int grundy(int i)
{
	if(g[i]!=-1)
	{
		return g[i];
	}
	set<int> s;
	fo(j,n)
	{
		if(i-arr[j]<0) break;
		s.insert(grundy(i-arr[j]));	
	}
	return g[i]=mex(s);
}

int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>k;
		fo(i,n)cin>>arr[i];
		memset(g,-1,sizeof(g));
		if(grundy(k)!=0)
		{
			cout<<"First";
		}
		else
		{
			cout<<"Second";
		}
		// fo(i,5)
		// {
		// 	cout<<g[i]<<" ";
		// }
		
		
	}
	return 0;
}

Measured memory_bytes: 19456
#include<stdio.h>
int main(void){
	int i,n;
	scanf("%d",&n);
	int array[100];
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	for(i=n-1;i>=0;i--){
		if(i==0){
			printf("%d\n",array[i]);
		}else {printf("%d ",array[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
function gcd(a, b) {
    if (b > a)
        return gcd(b, a);
    if (b == 0)
        return a;

    return gcd(b, a % b);
}
function lcm(a, b) {
    var d = gcd(a, b);
    return a * b / d;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var n = +lines.shift();

var nums = lines.shift().split(' ').map(function(num){return +num;});
var p = 1;
for (var i = 0; i < n; i++) {
    p = lcm(p, nums[i]);
}

console.log(p);

Measured memory_bytes: 7380
<?php
while (1) {
    list($h, $w) = explode(" ", trim(fgets(STDIN)));
    if ($h == 0 && $w == 0) exit;

    $str = str_repeat('.#', ($w/2)+1);
    for ($i = 0; $i < $h; $i++) {
        echo substr($str, ($i % 2) ? 0 : 1, $w) . PHP_EOL;
    }
    echo PHP_EOL;
}

Measured memory_bytes: 15420
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

bool comp(const pair<int, int> &u, const pair<int, int> &v) {
  return u.second < v.second;
}

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<pair<int, int>>> st(c);

  REP(i, n) {
    int s, t, ch;
    cin >> s >> t >> ch;
    ch--;
    s--;
    t--;
    st[ch].push_back(make_pair(s, t));
  }

  REP(i, c) { sort(st[i].begin(), st[i].end(), comp); }

  int ans = 0;
  REP(i, 100000) {
    int tmp = 0;
    REP(j, c) {
      if (st[j].empty())
        continue;

      auto itr = lower_bound(st[j].begin(), st[j].end(), make_pair(0, i), comp);
      if (itr != st[j].end() && (*itr).second >= i && (*itr).first <= i) {

        tmp++;
      }
    }

    ans = max(ans, tmp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;

int main(){
  ll n; cin>>n;
  ll res=1000000000000;
 FOR(a,1,1000001){
 if(n%a==0){
   if(res>=(a+(n/a)-2))res=a+(n/a)-2;
 }
 }
  cout<<res<<endl;
}

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

using namespace std;

int main() {
	int n,a;
	long long sum=0;
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>a;
		sum+=a-1;
	}
	cout<<sum<<endl;
//	system("pause");
	return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif


struct Node{
	int a,b;
	bool operator<(const Node&rhs)const{
		return a*rhs.b<rhs.a*b;
	}
};
using Heap=priority_queue<Node>;
Heap* Merge(Heap*x,Heap*y){
	if(x->size()<y->size())
		swap(x,y);
	while(!y->empty()){
		x->push(y->top());
		y->pop();
	}
	*y=Heap();
	return x;
}

const int Nmax=1000010;
Heap buf[Nmax];
Heap* NewHeap(){
	static int used=0;
	return buf+(used++);
}
int w[Nmax],ans;
vi tr[Nmax];
Node Merge(Node x,Node y){
	ans+=x.b*y.a;
	return Node{x.a+y.a,x.b+y.b};
}
Heap* dfs(int v){
	Heap* h=NewHeap();
	for(auto ch:tr[v])
		h=Merge(h,dfs(ch));
	Node tmp{1-w[v],w[v]};
	while(!h->empty()){
		if(h->top()<tmp)
			break;
		tmp=Merge(tmp,h->top());
		h->pop();
	}
	h->push(tmp);
	return h;
}

signed main(){
	int n=read();
	FOR(i,1,n){
		int p=read()-1;
		tr[p].PB(i);
	}
	REP(i,n)w[i]=read();
	Heap* h=dfs(0);
	Node tmp{0,0};
	while(!h->empty()){
		tmp=Merge(tmp,h->top());
		h->pop();
	}
	print(ans);
}


Measured memory_bytes: 78336
N = int(input())
As = list(map(int, input().split()))

approved = True
for i in range(N):
    if As[i] % 2 == 0:
        if As[i] % 3 != 0 and As[i] % 5 != 0:
            approved = False
            break
if approved:
    print("APPROVED")
else:
    print("DENIED")


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

int main()
{
  int f[1000001];
  int n,a,b,c;
  int i,j;
  while(cin>>n>>a>>b,n||a||b){
    memset(f,1,sizeof(int)*1000001);
    for(i=0;i<=n;i+=a)
      if(f[i])for(j=i;j<=n;j+=b)f[j]=0;
    c=0;
    for(i=1;i<=n;i++)if(f[i])c++;
    cout<<c<<endl;
  }
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, x;
	cin >> n >> x;
	VI a(n);
	FOR(i, 0, n) cin >> a[i];
	
	int ans = 0;
	int d = 0;
	FOR(i, 0, n)
	{
		ans += d <= x;
		d += a[i];
	}
	ans += d <= x;
	cout << ans;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
    string target[] = {"JOI", "IOI"};
    string a;

    while (cin >> a) {
        int cnt[2] = {0};
        for(int i = 0;i < 2;i++){
            for (int j = 0; j < a.size(); j++) {
                string::size_type b = a.find(target[i], j);
                if(b != string::npos){
                    cnt[i]++;
                    j = b + 1;
                }
            }
        }
        cout << cnt[0] << endl << cnt[1] << endl;
    }

    return 0;
}

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

constexpr int MOD = 1e9 + 7;

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using fint64 = int_fast64_t;
struct Combination {
	const int MAX = 5000010;
	const int MOD;
	vector<fint64> FAC;
	vector<fint64> INV;
	vector<fint64> FAC_INV;
	Combination(fint64 MOD) :
		MOD(MOD),
		FAC(vector<fint64>(MAX)),
		INV(vector<fint64>(MAX)),
		FAC_INV(vector<fint64>(MAX))
		{
			FAC[0] = INV[1] = FAC_INV[0] = 1;
			for(int i = 1; i < MAX; ++i) {
				FAC[i] = FAC[i - 1] * i % MOD;
				if(i > 1) INV[i] = MOD - INV[MOD % i] * (MOD / i) % MOD;
				FAC_INV[i] = FAC_INV[i - 1] * INV[i] % MOD;
			}
		}
	fint64 C(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[r] % MOD * FAC_INV[n - r] % MOD;
	}
	fint64 P(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[n - r] % MOD;
	}
	fint64 H(int n, int r) {
		if(r == 0) return 1;
		return C(n + r - 1, r);
	}
};

using mint = ModInt<MOD>;
Combination com(MOD);
int main() {
	int n, m; cin >> n >> m;
	mint ans = 0;
	for(int i = 0; i <= n; ++i) {
		mint tmp = com.C(n, i);
		tmp *= com.P(m, i);
		tmp *= com.P(m - i, n - i) * com.P(m - i, n - i);
		if(i % 2 == 0) ans += tmp;
		else ans -= tmp;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 120264
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,cnt,cnt2,l;
	char s[4];
	scanf("%s",s);
	cnt=0; cnt2=0; l=0;
	for(i=0;i<3;i++){
		if(s[i]=='R'){
			cnt++;
		}
		if(s[i]=='S'){
			cnt2++;
		}
		if(s[1]=='S'){
			l=1;
		
		}
	}
	if(cnt2>=1&&l>=1&&cnt>=1){
		printf("1\n");
	}
	else{
		printf("%d\n",cnt);
	}
	return 0;
}
		
	

Measured memory_bytes: 1720
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<string>
#include<cmath>

using namespace std;
#define rep(i,j) for(int i=0;i<(j);i++)
int ans[2][100][100];
int n,m;
int main(void){
    for(;;){
        scanf("%d%d",&n,&m);
        if(!n && !m)break;
        rep(i,2)rep(j,100)rep(k,100)if(j!=k)ans[i][j][k] = 99999999;else ans[i][j][k]=0;
        rep(i,n){
            int a,b,c,t;
            scanf("%d%d%d%d",&a,&b,&c,&t);
            a--;
            b--;
            ans[1][a][b] = t;
            ans[1][b][a] = t;
            ans[0][a][b] = c;
            ans[0][b][a] = c;
        }
        rep(k,m)rep(i,m)rep(j,m)rep(l,2)ans[l][i][j]=min(ans[l][i][j],ans[l][i][k]+ans[l][k][j]);
        int k,p,q,r;
        scanf("%d\n",&k);
        rep(i,k){
            scanf("%d%d%d",&p,&q,&r);
            q--;
            p--;
            printf("%d\n",ans[r][p][q]);
        }
    }

	return 0;
}

Measured memory_bytes: 1104
def show(array):
    for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i])


def selectionSort(array):
    count = 0 
    for i in range(len(array)):
        minj = i 
        flag = False
        for j in range(i, len(array)):
            if array[j] < array[minj]:
                minj = j 
                flag = True
        if flag and i != minj:
            array[i], array[minj] = [array[minj], array[i]]
            count += 1
    
    show(array)
    print(count)
    

input()
array = [int(x) for x in input().split()]
selectionSort(array)




Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll k,arr[202020],st,en;
main()
{
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",arr+i);
	sort(arr,arr+n); st=-2e18; en=2e18;
	while(st+1!=en)
	{
		ll mid=(st+en)/2;
		ll gesu=0;
		for(int i=0;i<n;i++)
		{
			if(arr[i]<0)
			{
				int l=i,r=n;
				while(l+1!=r)
				{
					int m=(l+r)/2;
					if(arr[i]*arr[m]<=mid) r=m;
					else l=m;
				} gesu+=n-r;
			} else
			{
				int l=i,r=n;
				while(l+1!=r)
				{
					int m=(l+r)/2;
					if(arr[i]*arr[m]<=mid) l=m;
					else r=m;
				} gesu+=l-i;
			} 
		} if(gesu<k) st=mid;
		else en=mid;
	} printf("%lld",en);
}




Measured memory_bytes: 1792
import java.util.*;

public class Main {
	
	static long MOD  = 1000000007;
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		HashSet<Integer> broken = new HashSet<>();
		
		for(int i =0;i<m;i++)broken.add(sc.nextInt());
		
		long[] dp = new long[n+1];
		
		
		dp[0]=1;
		if(broken.contains(1))dp[1]=0;
		else dp[1]=1;
		
		for(int i=2;i<n+1;i++) {
			if(broken.contains(i)) {
				dp[i]=0;
			}else{
				dp[i]=dp[i-2]%MOD +dp[i-1]%MOD;
			}
		}
		
		//for(int i=0;i<n+1;i++)System.out.println(dp[i]);
		long ans = dp[n]%MOD;
		System.out.println(ans);
		
		
	}

}


Measured memory_bytes: 64204
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        swap(a,b);
    }
    if(b>c){
        swap(b,c);
    }
    if(a>b){
        swap(a,b);
    }
    cout<<a<<' '<<b<<' '<<c<<endl;
}


Measured memory_bytes: 3088
#!/usr/bin/env python3
import sys
 
MOD = 1000000007  # type: int
 
 
def solve(S: str):
    """
    >>> solve("05")
    1
    >>> solve("18")
    1
    >>> solve("13")
    0
    """
    pre, cur = [0] * 13, None
    base = 10
    if S[-1] == "?":
        cur = [1] * 10 + [0] * 3
    else:
        cur = [0] * 13
        cur[int(S[-1])] = 1
    for n in reversed(S[:-1]):
        pre, cur = cur, pre
        for i in range(13): # 再生成を避ける
            cur[i] = 0
        g = range(10) if n == "?" else [int(n)]
        for i in g:
            t = base * i % 13
            for j in range(13):
                cur[(j+t)%13] = (cur[(j+t)%13] + pre[j]) % MOD
        base = (base * 10) % 13        
        # print(n, pre, cur, base)
    return cur[5]
 
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(solve(S))
 
def test():
    import doctest
    doctest.testmod()
 
if __name__ == '__main__':
    #test()
    main()

Measured memory_bytes: 43500
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
int main()
{
    long long N;
    cin >> N;
    if (N % 2 != 0)
    {
        cout << 0 << endl;
    }
    else
    {
        long long five = 0;
        long long nn = N / 2;
        while(nn>0)
        {
            five += nn / 5;
            nn = nn / 5;
        }
        cout << five << endl;
    }
}

Measured memory_bytes: 256
def nestfor(n,sti,sti1,poj,j,prof,bene)
  if j == n-2
    for sj in 0..poj/sti[j]
      poj1 = poj - sj*sti[j]
      b = sj*(sti1[j]-sti[j]) + (poj1/sti[j+1])*(sti1[j+1]-sti[j+1])
      prof = bene+b if prof < bene+b
    end
  else
    if sti1[j]<sti[j]
      prof = nestfor(n,sti,sti1,poj,j+1,prof,bene)
    else
      for sj in 0..poj/sti[j]
        poj1 = poj - sj*sti[j]
        prof = nestfor(n,sti,sti1,poj1,j+1,prof,bene+sj*(sti1[j]-sti[j]))
      end
    end
  end
  prof
end
  
n,d,x = gets.split(" ").map{|str| str.to_i}

stock = Array.new(d){gets.split(" ").map{|str| str.to_i}} #i??\??????????????????i??????????¨????

if n>=2
  for i in 0..d-2
    x += nestfor(n,stock[i],stock[i+1],x,0,0,0)
  end
else
  for i in 0..d-2
    si1,si = stock[i+1][0],stock[i][0]
    x += (si1-si)*(x/si) if si1 > si
  end
end

puts x

Measured memory_bytes: 8864
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
///#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 1000000007

/*void btod(ll x) {
	ll sum=0;
	ll mul=1;
	ll sub=x;
	int p=0;
	while (sub) {
		sub/=10;
		p++;
	}
	for (int i=0;i<=p;i++) {
		sum+=(x%10)*mul;
		x/=10;
		mul*=2;
	}
	return sum;
}*/

/*ll spe(ll x,ll pos) {
	ll dig=0;
	ll sub=x;
	while (sub) {
		sub/=10;
		dig++;
	}
	for (ll i=0;i<dig-1-pos;i++) {
		x/=10;
	}
	return(x%10);
}*/

string dtob(ll x,ll i) {
	ll rem;
	string sum="";
	while (x) {
		rem=x%2;
		if (rem) {
			sum.insert(0,"1");
		}
		else {
			sum.insert(0,"0");
		}
		x/=2;
	}
	while (i-sum.length()) {
		sum.insert(0,"0");
	}
	return sum;
}

int main() {
	ll h,w,k;
	cin>>h>>w>>k;
	char arr[h][w];
	char sub[h][w];
	for (ll i=0;i<h;i++) {
		for (ll j=0;j<w;j++) {
			cin>>arr[i][j];
			sub[i][j]=arr[i][j];
		}
	}
	ll ans=0;
	ll init=0;
	ll target=1;
	for (ll i=0;i<h+w;i++) {
		target*=2;
	}
	while (init!=target) {
		string bin=dtob(init,h+w);
		for (ll i=0;i<h;i++) {
			if (bin[i]=='1') {
				for (ll j=0;j<w;j++) {
					sub[i][j]='R';
				}
			}
		}
		for (ll i=h;i<(h+w);i++) {
			if (bin[i]=='1') {
				for (ll j=0;j<h;j++) {
					sub[j][i-h]='R';
				}
			}
		}
		

		
		ll sum=0;
		for (ll i=0;i<h;i++) {
			for (ll j=0;j<w;j++) {
				if (sub[i][j]=='#') sum+=1;
				sub[i][j]=arr[i][j];
			}
		}
		if (sum==k) ans++;
		init++;
	}
	cout<<ans;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
struct unionfind{
  vector<int> p;
  unionfind(int n){
    p = vector<int>(n, -1);
  }
  int root(int x){
    if (p[x] == -1){
      return x;
    } else {
      p[x] = root(p[x]);
      return p[x];
    }
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    p[x] = y;
  }
};
int main(){
  while (1){
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0){
      break;
    }
    vector<tuple<int, int, int>> E(m);
    for (int i = 0; i < m; i++){
      int s, t, c;
      cin >> s >> t >> c;
      s--;
      t--;
      E[i] = make_tuple(c, s, t);
    }
    sort(E.begin(), E.end());
    unionfind UF(n);
    int cnt = 0;
    for (int i = 0; i < m; i++){
      int c = get<0>(E[i]);
      int s = get<1>(E[i]);
      int t = get<2>(E[i]);
      if (!UF.same(s, t)){
        UF.unite(s, t);
        cnt++;
        if (cnt == n / 2){
          cout << c << endl;
          break;
        }
      }
    }
  }
}


Measured memory_bytes: 3232
"""
author : halo2halo
date : 8, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A = map(int,readline().split())
S = sum(A)
ans = 'bust' if S >= 22 else 'win'
print(ans)


Measured memory_bytes: 3064
#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>;

int main () {
  string s;
  int i;
  
  cin >> s;
  
  for(i=0; i<s.size(); i+=2){
    cout << s[i];
  }
  
}
    

Measured memory_bytes: 3692
package main

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

func max(a int, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Node struct {
	Index     int
	Value     int
	Neighbors []*Node
	Len       int
	IsSearched  bool
}

var nodes []*Node
var already map[int]bool

// dp[i]: 長さiの増加部分列において最後の値の最小値
func search(n *Node, dp []int) {
	if n.IsSearched {
		return
	}
	n.IsSearched = true

	idx := sort.SearchInts(dp, n.Value)
	befVal := dp[idx]
	dp[idx] = n.Value
	n.Len = sort.SearchInts(dp, MAX_INT)
	for _, to := range n.Neighbors {
		search(to, dp)
	}
	dp[idx] = befVal
}

var N, M int
var v [][]int
var h []int
var val []int

func main() {
	sc.Split(bufio.ScanWords)

	nextInt(&N, &M)
	h = make([]int, N)
	nextInts(&h)
	v = make([][]int, N)

	val = make([]int, N)

	for i := 0; i < M; i++ {
		var a, b int
		nextInt(&a, &b)
		v[a-1] = append(v[a-1], b-1)
		v[b-1] = append(v[b-1], a-1)
	}
	res := solve()
	//fmt.Printf("N: %d, M: %d, h: %v, v: %v\n", N, M, h, v)
	fmt.Printf("%d", res)
}


func solve() int {
	//fmt.Printf("%v, %v, %v\n", a, u, v)

	for i:=0; i < N; i++ {
		if val[i] != 0 {
			continue
		}
		//if val[i] != 0 {
		//	continue
		//}
		mayBeTop := true
		for _, j := range v[i] {
			if h[i] >= h[j] {
				val[j] = -1
			}
			if h[i] <= h[j] {
				val[i] = -1
				mayBeTop = false
			}
		}
		if mayBeTop {
			val[i] = 1
		}
	}

	var res int
	for i:=0; i < N; i++ {
		if val[i] == 1 {
			res++
		}
	}
	return res

}




const MAX_INT int = 1_000_000_000
var sc = bufio.NewScanner(os.Stdin)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)

func nextLine() string {
	buffer := make([]byte, 0)
	for true {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func nextInt(A ...*int) {
	L := strings.Split(nextLine(), " ")
	for i, a := range A {
		*a, _ = strconv.Atoi(L[i])
	}
}
func nextInts(A *[]int) {
	L := strings.Split(nextLine(), " ")
	(*A) = make([]int, len(L))
	for i, l := range L {
		(*A)[i], _ = strconv.Atoi(l)
	}
}

func nextInt64() int64 {
	sc.Scan()
	hoge := sc.Text()
	i, e := strconv.ParseInt(hoge, 0, 64)
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 21440