akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

class RollingHash:

    MOD = 2 ** 64
    b = 10 ** 8 + 7

    def __init__(self, S):
        # 各文字を数値に変換しておく
        S = [ord(s)-97 for s in S]

        self.len = len(S)
        self.pow = [1] * (self.len+1)
        for i in range(self.len):
            self.pow[i+1] = self.pow[i] * self.b
            self.pow[i+1] %= self.MOD
        # ハッシュの生成
        self.hash = [0] * (self.len+1)
        for i in range(self.len):
            self.hash[i+1] = self.hash[i] * self.b + S[i]
            self.hash[i+1] %= self.MOD
    
    # 区間[i,j)のハッシュ値を取得
    def get(self, l, r):
        return (self.hash[r] - self.hash[l] * self.pow[r-l]) % self.MOD

def calc(m):
    A = {}
    for i in range(N-m+1):
        a_hash = rh.get(i, i+m)
        if a_hash in A:
            # a_hashが2回目以降に出現したindex
            j = A[a_hash]
            # iとjがm以上離れているかどうか
            if i-j >= m:
                return True
        else:
            # a_hashが最初に出現したindex
            A[a_hash] = i
    return False

rh = RollingHash(S)
print(bisearch_max(0, N, calc))


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

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a <= b * 2) {
        cout << 0 << endl;
    }
    else {
        cout << a - b * 2 << endl;
    }
}



Measured memory_bytes: 256
S = input()

Odd= S[0::2]
Even= S[1::2]

oddset  = {'R', 'U', 'D'}
evenset = {'L', 'U', 'D'}

if oddset >= set(Odd) and evenset >= set(Even):
    ans = 'Yes'
else :
    ans = 'No'
print(ans)

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


int main() {

long N,K;
cin>>N>>K;
vector<long> a(N);

vector<long> ans(N);
  for(long i=0;i<N;i++) {
    cin>>a[i];
    ans[i]=a[i];
  }


for(int i=0;i<min(long(1000),K);i++){
  vector<long> b(N+1);
  for(long i=0;i<N;i++){
    b[max(long(0),i-a[i])]++;
    b[min(N,i+a[i]+1)]--;
  }
  for(long i=0;i<N;i++){
    if(0<i) b[i]+=b[i-1];
    a[i]=b[i];
  }
}
for(long i=0;i<N;i++) cout<<a[i]<<" ";
cout<<endl;
}


Measured memory_bytes: 8012
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 1005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
        
	int n,m,k;
	char a[10][10];
	vector<pair<int,int> > v;
	int ans=0;
        void solve(int i,vector<pair<int,int> > temp){
	if(i == v.size()){
		char tm[n][m];
		FOR(i,0,n){
			FOR(j,0,m){
				tm[i][j] =a[i][j];
			}
		}
		for(auto i : temp){
			if(i.second == 0){
				FOR(j,0,m){
					a[i.first][j] = 'R';
				}
			}
			else{
				FOR(j,0,n){
					a[j][i.first] = 'R';
				}
			}
		}
		int cnt = 0;
		FOR(i,0,n){
			FOR(j,0,m){
				if(a[i][j] == '#'){
					cnt++;
				}
			}
		}
		if(cnt == k)
			ans++;
		FOR(i,0,n){
			FOR(j,0,m){
				a[i][j] = tm[i][j];
			}
		}
		return;
	}
	
	solve(i+1,temp);
	temp.pb(v[i]);
	solve(i+1,temp);
	temp.pop_back();
}	
signed main(){

	cin >> n >> m >> k;
	FOR(i,0,n){
		FOR(j,0,m){
			cin >> a[i][j];
		}
	}
	FOR(i,0,n){
		v.pb({i,0});
	}
	FOR(i,0,m){
		v.pb({i,1});
	}
	vector<pair<int,int> > h;
	solve(0,h);
	cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3636
N = input()
pre = N[0:2]
pos = N[2:4]
if int(pre)!=0 and int(pre) <=12:
    if int(pos)!=0 and int(pos) <=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif int(pos)!=0 and int(pos) <=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
  double a,b,c;
  cin>>a>>b>>c;
  if(a/c<=b){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
}


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

using namespace std ;

#define N 5000010
#define inf 0x3f3f3f3f

int head[ N ] , cnt ;
int d[ N ] , vis[ N ] , q[ N ] ;
int n , m ;
struct node {
    int to , nxt , v ;
}e[ N ] ; 

void ins( int u , int v , int w ) {
    e[ ++ cnt ].to = v ;
    e[ cnt ].nxt = head[ u ] ;
    e[ cnt ].v = w ;
    head[ u ] = cnt ;
} 

map<pair<int,int>,int>mp;

int tot = 0 ;

int get_num( int x , int y ) {
    if( !mp.count( make_pair( x , y ) ) ) mp[ make_pair( x , y ) ] = ++tot ;
    return mp[ make_pair( x , y ) ] ;
}

void spfa() {
    for( int i = 1 ; i <= tot ; i ++ ) d[ i ] = inf ;
    vis[ 1 ] = q[ 1 ] = 1 ;
    d[ 1 ] = 0 ;
    int l = 1 , r = 2 ;
    while( l < r ) {
        int u = q[ l ++ ] ;
        vis[ u ] = 0 ;
        for( int i = head[ u ] ; i ; i = e[ i ].nxt ) {
            int v = e[ i ].to ;
            if( d[ v ] > d[ u ] + e[ i ].v ) {
                d[ v ] = d[ u ] + e[ i ].v ;
                if( !vis[ v ] ) vis[ v ] = 1 , q[ r ++ ] = v ;
            }
        }
    }
    if( d[ n ] == inf ) puts( "-1" ) ;
    else printf( "%d\n" , d[ n ] / 2 ) ;
}

int main() {
    scanf( "%d%d" , &n , &m ) ;
    tot = n ;
    for( int i = 1 ; i <= m ; i ++ ) {
        int x , y , c ;
        scanf( "%d%d%d" , &x , &y , &c ) ;
        int n1 = get_num( x , c ) , n2 = get_num( y , c ) ;
        ins( x , n1 , 1 ) ;
        ins( n1 , x , 1 ) ;
        ins( n1 , y , 1 ) ;
        ins( y , n1 , 1 ) ;
        ins( n1 , n2 , 0 ) ;
        ins( n2 , n1 , 0 ) ;
    }
    spfa() ;
}

Measured memory_bytes: 55936
#include<stdio.h>
#include<tuple>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<vector>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, int> pli;
typedef tuple<int,int,int> t3;
 
const int MX = 1<<19;
 
struct UF{
	int t[MX];
	int find(int x){ return t[x] ? t[x] = find(t[x]) : x; }
	int merge(int a, int b){
		a = find(a), b = find(b);
		return a == b ? 0 : (t[a] = b, 1);
	}
} uf;
 
vector<t3> E;
int C[MX];
int vst[MX];
 
int main()
{
	int N, M, K;
	scanf("%d%d%d", &N, &M, &K);
	int cnt = K;
	for(int i = 1; i <= N; i++){
		scanf("%d", C+i);
		if( C[i] == 0 ) C[i] = ++cnt;
	}
	for(int i = 1; i <= M; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		E.emplace_back(c, C[a], C[b]);
	}
	int add = 0;
	ll ans = 0;
	sort(E.begin(), E.end());
	for(t3 e : E){
		int a, b, c;
		tie(c, a, b) = e;
		if( uf.merge(a, b)){
			ans += c;
			add++;
		}
		if( add == K-1 ) break;
	}
	if( add != K-1 ) printf("-1\n");
	else printf("%lld\n", ans);
}

Measured memory_bytes: 6008
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] str = in.next().toCharArray();
		int len = str.length;
		int half = len / 2;
		int hugs = 0;
		for (int i = 0; i < half; i++)
			if (str[i] != str[len - 1 - i])
				hugs++;
		System.out.println(hugs);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int a, b, k;
    cin >> a >> b >> k;

    VEC(int) v;
    FOR(i, 1, b + 1)
        if (a % i == 0 && b % i == 0)
            v.push_back(i);

    cout << v[v.size() - k] << endl;

    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Maximize(m, x) m = max(m, x)
#define Minimize(m, x) m = min(m, x)

// constexpr int MOD = 1e9+7;

#include <queue>

int main(void){
    Cin(int, n, m);
    Vec2(int, n, n, a);
    Rep(m){
        Cin(int, x, y, c);
        x--, y--;
        a[x][y] = a[y][x] = c;
    }
    Vec2(int, n, n, d);
    constexpr int Inf = 1e9;
    For(i, n) For(j, n) d[i][j] = Inf;
    For(ic, n){
        using P = pair<int, int>;
        auto cmp = [](P p, P q){ return p.first > q.first; };
        priority_queue<P, vector<P>, decltype(cmp)> q(cmp);
        q.emplace(0, ic); d[ic][ic] = 0;
        while(!q.empty()){
            auto e = q.top();
            For(i, n){
                if(a[e.second][i] && d[ic][i] > d[ic][e.second] + a[e.second][i]){
                    d[ic][i] = d[ic][e.second] + a[e.second][i];
                    q.emplace(d[ic][i], i);
                }
            }
            q.pop();
        }
    }
    // For(i, n) Couts(d[i]);
    
    int ans = 0;
    For(i, n) for(int j = i+1; j < n; j ++){
        if(a[i][j] == 0) continue;
        // Cout(i, " ", j);
        For(s, n) For(t, n){
            if(d[s][i] + a[i][j] + d[j][t] == d[s][t]) goto next;
        }
        ans ++;
        next:;
    }
    Cout(ans);
}


Measured memory_bytes: 384
import math
import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import bisect
# import numpy as np
# from scipy.special import comb


def main():
    S = input()

    acgt = set(['A', 'C', 'G', 'T'])

    ans = 0
    for i in range(1, len(S) + 1):
        for j in range(len(S) - i + 1):
            if not set(S[j:j + i]) - acgt:
                ans = max(ans, len(S[j:j + i]))

    print(ans)


list(itertools.combinations([1, 2, 3, 4], 2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#!/usr/bin/perl
use Data::Dumper;
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
( my $x = scalar(<STDIN>) ) =~ s/[\x00-\x20]+$//ios;

my $bit_cnt = 0;
for(my $i=0;$i<$n;$i++){
  my $bit = substr($x,$n-1-$i,1) - 0;
  $bit_cnt++ if $bit == 1;
}

if( $n == 1 ){
  my $r = &f( oct('0b' . $x) ^ 1 );
  print "$r\n"; exit(0);
}
if( $n == 2 ){
  my $r1 = &f( oct('0b' . $x) ^ 2 );
  my $r2 = &f( oct('0b' . $x) ^ 1 );
  print "$r1\n$r2\n"; exit(0);
}
if( $n == 3 ){
  my $r1 = &f( oct('0b' . $x) ^ 4 );
  my $r2 = &f( oct('0b' . $x) ^ 2 );
  my $r3 = &f( oct('0b' . $x) ^ 1 );
  print "$r1\n$r2\n$r3\n"; exit(0);
}

if( $n == 4 and 1 == 0 ){
  my $r1 = &f( oct('0b' . $x) ^ 8 );
  my $r2 = &f( oct('0b' . $x) ^ 4 );
  my $r3 = &f( oct('0b' . $x) ^ 2 );
  my $r4 = &f( oct('0b' . $x) ^ 1 );
  print "$r1\n$r2\n$r3\n$r4\n"; exit(0);
}

my @d1 = ();
$#d1 = 200000;
my @d3 = ();
$#d3 = 200000;

my $m_1 = ( $bit_cnt > 1 ? ( 2 % ($bit_cnt-1) ) : 0 );
my $m_3 = ( 2 % ($bit_cnt+1) );

my $b_1 = 1;
my $b_3 = 1;

my $t_1 = 0;
my $t_3 = 0;

for(my $i=0;$i<$n;$i++){
  my $bit = substr($x,$n-1-$i,1) - 0;
  if( $bit_cnt > 1 ){
    my $v1 = $b_1 * $bit;
    $d1[$i] = $b_1;
    $t_1 = ($t_1 + $v1) % ($bit_cnt-1);
    $b_1 = ( $b_1 * $m_1 ) % ($bit_cnt-1);
  }
  my $v3 = $b_3 * $bit;
  $d3[$i] = $b_3;
  $t_3 = ($t_3 + $v3) % ($bit_cnt+1);
  $b_3 = ( $b_3 * $m_3 ) % ($bit_cnt+1);
}

#print &Dumper(@d1[0..22]);
#print &Dumper(@d3[0..22]);

#print "t1 =$t_1 , t3=$t_3\n";

my @out = ();
$#out = $n-1;

for(my $i=0;$i<$n;$i++){
  my $bit = substr($x,$n-1-$i,1) - 0;
  if( $bit == 1 ){
    if( $bit_cnt == 1 ){
      $out[$i] = 0;
    } else {
      my $tv1 = ( $t_1 - $d1[$i] + ($bit_cnt - 1) ) % ($bit_cnt - 1);
      my $v1 = 1 + &f($tv1);
      $out[$i] = $v1;
    }
  } else {
    my $tv3 = ( $t_3 + $d3[$i] + ($bit_cnt + 1) ) % ($bit_cnt + 1);
    #print "i=$i , tv3=$tv3\n";
    my $v3 = 1 + &f($tv3);
    $out[$i] = $v3;
  }
}

for(my $i=0;$i<$n;$i++){
  print "$out[$n-1-$i]\n";
}

exit(0);

sub f {
  my $n1 = shift;
  my $c = 0;
  return 0 if $n1 == 0;
  return 1 if $n1 == 1;
  while($n1>0){
    my $bit_c = 0;
    my $n2 = $n1;
    while($n2>0){
      $bit_c ++ if ( $n2 & 1 ) != 0;
      $n2 >>= 1;
    }
    $n1 = $n1 % $bit_c;
    $c++;
    if( $n1 == 1 ){
      $c++;
      last;
    }
  }
  return $c;
}






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

int main() {
    int n, rankInp;
    char suitInp;
    int a[4][13];  // 0 1 2 3 represent the 'S' 'H' 'C' 'D'
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 13; ++j) {
            a[i][j] = 0;
        }
    }

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> suitInp >> rankInp;
        switch (suitInp) {
        case 'S':
            a[0][rankInp - 1] = 1;
            break;
        case 'H':
            a[1][rankInp - 1] = 1;
            break;
        case 'C':
            a[2][rankInp - 1] = 1;
            break;
        case 'D':
            a[3][rankInp - 1] = 1;
            break;
        default:
            break;
        }
    }

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 13; ++j) {
            if (!a[i][j]) {
                switch (i) {
                case 0:
                    cout << "S " << j + 1 << endl;
                    break;
                case 1:
                    cout << "H " << j + 1 << endl;
                    break;
                case 2:
                    cout << "C " << j + 1 << endl;
                    break;
                case 3:
                    cout << "D " << j + 1 << endl;
                    break;
                default:
                    break;
                }
            }
        }
    }
}

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

int main()
{
    int n,k; cin>>k>>n; int a[101];
    for(int i=0;i<k;i++) cin>>a[i];
    int dp[1000001]={0};
    
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            if(i-a[j]>=0)
            {
                if(dp[i-a[j]]==0) {dp[i]=1; break;}
            }
        }
    }
    if(dp[n]) cout<<"First";
    else cout<<"Second";
}





Measured memory_bytes: 4096
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if(b+c>a)
    printf("%d\n",b+c-a);
   else
    printf("0\n");

    return 0;
}


Measured memory_bytes: 256
/**
 * Partition
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=ja
 */

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

/*
partition(A, p, r)
  x = A[r]
  i = p-1
  for j = p to r-1
    if A[j] <= x
      i = i+1
      A[i] と A[j] を交換
  A[i+1] と A[r] を交換
  return i+1
*/

int partition(vector<int> &A, int p, int r) {
  int x = A.at(r);
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A.at(j) <= x) {
      i = i+1;
      // cout << "swap" << i << ' ' << j;
      swap(A.at(i), A.at(j));
    }
  }

  swap(A.at(i + 1), A.at(r));
  return i + 1;
}

int main(){
  // 1行目にn、2行目にSを表すn個の整数が与えられます。 
  int n;
  cin >> n;

  // 配列を受け取る
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  // パーティションの実行
  int place = partition(S, 0, n - 1);

  // 結果の出力
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << ' ';
    }
    if (i == place) {
      cout << '[' << S.at(i) << ']';
    } else {
      cout << S.at(i);
    }
	}

  cout << endl;
}



Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int m,t,p,r;
  while(cin>>m>>t>>p>>r,m+t+p+r){
    pair<int,int>pii[t+10][p+10];
    for(int i=0;i<t+10;i++)
      for(int j=0;j<p+10;j++)
	pii[i][j]=mp(-1,0);
    for(int i=0;i<r;i++){
      int a,b,c,d;cin>>a>>b>>c>>d;
      b--;c--;
      if(d==0)
	pii[b][c].F=a;
      else
	pii[b][c].S+=20;
    }
    vector<pair<int,pair<int,int> > >team(t+10);
    for(int i=0;i<t;i++)
      team[i]=mp(0,mp(INF,i+1));
    for(int i=0;i<t;i++){
      for(int j=0;j<p+10;j++){
	if(pii[i][j].F>=0){
	  team[i].S.F-=pii[i][j].F+pii[i][j].S;
	  team[i].F++;
	}
      }
    }
    sort(team.begin(),team.end(),greater<pair<int,pair<int,int> > >());
    for(int i=0;i<t;i++){
      if(i==0)
	cout<<team[i].S.S;
      else{
	if(team[i].F==team[i-1].F&&team[i-1].S.F==team[i].S.F){
	  cout<<"=";
	}else{
	  cout<<",";
	}
	cout<<team[i].S.S;
      }
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 2968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

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

  int G[n][n];
  int visited[n];
  int d[n];
  int p[n];
  REP(y, n) {
    REP(x, n) {
      int cost;
      cin >> cost;

      if (cost == -1) {
        G[y][x] = 1 << 15;
      } else {
        G[y][x] = cost;
      }
    }
    visited[y] = 0;
    d[y] = 1 << 15;
    p[y] = -1;
  }

  d[0] = 0;

  REP(_, n) {
    int mincost = 1 << 15;
    int minv = -1;
    REP(v, n) {
      if (!visited[v] && d[v] < mincost) {
        minv = v;
        mincost = d[v];
      }
    }
    visited[minv] = 1;
    REP(to, n) {
      if (!visited[to] && G[minv][to] < (1 << 15) && G[minv][to] < d[to]) {
        d[to] = G[minv][to];
        p[to] = minv;
      }
    }
  }

  ll sum = 0;
  REP(i, n) {
    if (p[i] != -1) {
      sum += G[i][p[i]];
    }
  }

  cout << sum << endl;
  return 0;
}

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

using mod_t = uint32_t;
using wmod_t = uint64_t;

constexpr mod_t MOD = 1e9 + 7;

struct BitSieve {
  static constexpr size_t N = 1ull << 26;
  static constexpr size_t LEN = (N + 31) / 32;
  static constexpr int SQRTN = 1 << 13;
  static constexpr int PC = 3957809;
  int pbit[LEN];

  BitSieve() {
    memset(pbit, 0xAA, sizeof(pbit));
    pbit[0] ^= 2;
    int pp[10] = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    for (int i = 0; i < 10; i++) {
      const int p = pp[i];
      for (size_t j = p * p; j <= N; j += p) {
        pbit[j >> 5] &= ~(1u << (j & 31));
      }
    }
    for (int i = 1, b = 32; b <= SQRTN; i++, b += 32) {
      int st = pbit[i];
      while (st) {
        size_t x = b + __builtin_ctz(st);
        st ^= st & -st;
        for (size_t y = x * x; y <= N; y += x) {
          pbit[y >> 5] &= ~(1u << (y & 31));
        }
      }
    }
    pbit[0] |= 4;
  }
  void build_prime(vector<int>& p) {
    p.reserve(PC);
    p.push_back(2);
    for (int i = 3; i <= N; i += 2) {
      if (pbit[i >> 5] & (1u << (i & 31))) p.push_back(i);
    }
  }
} sieve;

void factfact(int x, const vector<int>& ps, vector<pair<int, long long>>& factor) {
  for (auto&& p : ps) {
    if (p > x) break;
    int64_t y = p;
    int c = 0;
    while (y <= x) {
      c += x / y;
      y *= p;
    }
    factor.emplace_back(p, c);
  }
}

inline mod_t pow_mod(mod_t a, long long k) {
  mod_t r = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) r = (wmod_t)r * a % MOD;
    a = (wmod_t)a * a % MOD;
  }
  return r;
}

inline mod_t inv_mod(mod_t x) {
  return pow_mod(x, MOD - 2);
}

inline mod_t sub_mod(mod_t x, mod_t y) {
  return (x + MOD - y) % MOD;
}

inline mod_t mul_mod(mod_t x, mod_t y) {
  return (wmod_t)x * y % MOD;
}

inline mod_t div_mod(mod_t x, mod_t y) {
  return mul_mod(x, inv_mod(y));
}

inline mod_t geomsum_mod(mod_t r, long long n) {
  return div_mod(sub_mod(pow_mod(r, n), 1), sub_mod(r, 1));
}

int main() {
  vector<int> ps;
  sieve.build_prime(ps);

  int N;
  cin >> N;
  vector<pair<int, long long>> factor;
  factfact(N, ps, factor);

  wmod_t ans = 1;
  for (auto&& fact : factor) {
    ans *= fact.second + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    int n=k;
    int r=0;
    int count=0;
    if(n%2==0||n%5==0)
        cout<<"-1";
    else
    {
        for(int i=0;i<(1e7);i++)
        {
            r=(r*10+7)%k;
            count++;
            if(r==0)
            {
                cout<<count;
                return 0;
            }
        }
        cout<<"-1";
    }
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n;
    cin >> n;
    map<string, Int> mp;

    string s;
    for (Int i = 0 ; i < n; ++i) {
        cin >> s;
        ++mp[s];
    }
    vector<pair<Int, string> > v;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        v.push_back(make_pair(itr->second, itr->first));
    }

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

    Int vec_size = (Int)v.size();

    Int max_times = v[vec_size - 1].first;
    for (Int i = 0; i < v.size(); ++i) {
        if (v[i].first == max_times) {
            cout << v[i].second << endl;
        }
    }
    return 0;
}



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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    return mint(*this) += a;
  }
  mint operator-(const mint a) const {
    return mint(*this) -= a;
  }
  mint operator*(const mint a) const {
    return mint(*this) *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a) {
    return *this *= a.inv();
  }
  mint operator/(const mint a) const {
    return mint(*this) /= a;
  }
};
istream &operator>>(istream &is, const mint &a) {
  return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
  return os << a.x;
}

bool done[2001];
mint memo[2001];

mint dfs(ll n) {
  if (!done[n]) {
    mint ans = 1;
    FOR(i, 3, n - 2) {
      ans += dfs(n - i);
    }
    done[n] = true;
    memo[n] = ans;
  }
  return memo[n];
}

void solve(long long S) {
  if (S < 3) {
    cout << 0 << endl;
    return;
  }
  cout << dfs(S) << endl;
}

int main() {
  long long S;
  scanf("%lld", &S);
  solve(S);
  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int x,y,z; cin>>x>>y>>z;
	x-=z;
	cout << x/(y+z) <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

int main() {
    int n; cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b; cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main()
{
    int n;
    cin >> n;
    map<int, bool> mp;
    int ans = 1;

    while (mp[n] == false)
    {
        mp[n] = true;
        if (n % 2 == 0)
            n /= 2;
        else
            n = 3 * n + 1;
        ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	ll n = s.size();

	for (ll i = 0; i < n; i++) {
		if (s[i] == '?') {
			if (i > 0 && s[i - 1] == 'P') s[i] = 'D';
			else if (i < n - 1 && s[i + 1] == 'D') s[i] = 'P';
			else if (i < n - 1 && s[i + 1] == '?') {
				s[i] = 'P';
				s[i + 1] = 'D';
				i++;
			}
			else s[i] = 'D';
		}
	}
	cout << s << endl;
}


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

#define f(i,a,b) for(  ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

#define PI acos(-1)

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

const ll MAX = 1e3+12;
const ll inf = 5e18;


int main(){
	fastio;
	ll tc,n,m;
//	cin>>tc;
	tc=1;
	string s;
	vi r,g,b;
	f(tt,1,tc+1){
		cin>>n>>s;
		f(i,0,n){
			if(s[i]=='R') r.push_back(i);
			else if(s[i]=='G') g.push_back(i);
			else b.push_back(i);
		}
		ll ans=0;
		f(i,0,r.size()){
			f(j,0,g.size()){
				ll aum=b.size(),k;
				if(binary_search(all(b),2*r[i]-g[j])) aum--;
				if(binary_search(all(b),2*g[j]-r[i])) aum--;
				if((r[i]+g[j])%2==0 && binary_search(all(b), (r[i]+g[j])/2  )) aum--;
				ans+=aum;
			}
		}
		cout<<ans<<endl;
	}

}


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

int main(){
unsigned long int N, T;
cin >> N;
int f;
if (N <= 9) {
f =1;
} else if(N <= 99) {
f = 2;
} else if(N <= 999) {
f = 3;
} else if(N <= 9999) {
f = 4;
} else if(N <= 99999) {
f = 5;
} else if(N <= 999999) {
f = 6;
} else if(N <= 9999999) {
f = 7;
} else if(N <= 99999999) {
f = 8;
} else if(N <= 999999999) {
f = 9;
} else if(N <= 9999999999) {
f = 10;
} else {
f = 11;
}
T = ceil(sqrt(N));
for(unsigned long int i = 1; i < T+1; ++i) {
unsigned long int a, b;
int c,d,e;
b = N%i;
if (b == 0) {
a = N/i;
if (a <= 9) {
c =1;
} else if(a <= 99) {
c = 2;
} else if(a <= 999) {
c = 3;
} else if(a <= 9999) {
c = 4;
} else if(a <= 99999) {
c = 5;
} else if(a <= 999999) {
c = 6;
} else if(a <= 9999999) {
c = 7;
} else if(a <= 99999999) {
c = 8;
} else if(a <= 999999999) {
c = 9;
} else if(a <= 9999999999) {
c =10;
} else {
c = 11;
}
if (i <= 9) {
d =1;
} else if(i <= 99) {
d = 2;
} else if(i <= 999) {
d = 3;
} else if(i <= 9999) {
d = 4;
} else if(i <= 99999) {
d = 5;
} else if(i <= 999999) {
d = 6;
} else if(i <= 9999999) {
d = 7;
} else if(i <= 99999999) {
d = 8;
} else if(i <= 999999999) {
d = 9;
} else if(i <= 9999999999) {
d =10;
} else {
d =11;
}
if(c >= d) {
e = c;
} else {
e = d;
}
if(e < f) {
f = e;
}
}
}
cout << f << endl;
}

Measured memory_bytes: 256
import collections

def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  CA = collections.Counter(A)
  minA = min(A)
  maxA = max(A)
  X = [CA[i] for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    return 0
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Measured memory_bytes: 21020
N,Y=map(int,input().split())
x,y,z=-1,-1,-1
for i in range(N+1):
    for j in range(N+1):
        a=N-i-j#10000 num
        if a>=0 and ((10000*i+5000*j+1000*a)==Y):
            x,y,z=i,j,a
            break
print(x,y,z)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define anal         '\n'
#define mod 1000000007
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  
const int N = 1e6;
int arr[N];
 
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
      freopen("input.in", "r", stdin);
      freopen("output.in", "w", stdout);
#endif 

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
       
      int n;
      cin >> n;
      int  X = 0;
      vector<int> ans;
      for(int i = 1; i <= n; i++){
            cin >> arr[i];
            X ^= arr[i];
      }
      for(int i = 1; i <= n; i++){
           ans.eb(X^arr[i]);
      }
      for(auto w : ans) cout << w << ' ';

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



   

Measured memory_bytes: 5020
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
#include<fstream>
using namespace std;
#define ll long long
#define endl '\n'
const int max_n = 2*1e5 + 3;
const int INF = 1e9+1;


int a, b;
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> a >> b;
	if (a >= 10 || b >= 10)
		cout << -1;
	else
		cout << a * b;
}

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

using namespace std;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; ++i) cin >> x[i];
  sort(x.begin(), x.end());
  int ans = abs(x[0] - X);
  for (int i = 0; i < N - 1; ++i) ans = gcd(ans, x[i + 1] - x[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int n, m;
vvi p;
vvi s;

void init()
{
	cin >> n >> m;
	p.resize(m, vi(2));
	s.resize(n, vi(2));

	REP(i, n)
		cin >> s[i][0] >> s[i][1];
	REP(i, m)
		cin >> p[i][0] >> p[i][1];
}

int main()
{
	init();

	REP(i, n)
	{
		int tmp = INTMAX;
		int ans;

		REP(j, m)
		{
			if (chmin(tmp, abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])))
				ans = j + 1;
		}

		cout << ans << endl;
	}

}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<ll> a(n);
	for (auto &i : a) cin >> i;

	const ll inf = numeric_limits<ll>::min();
	vector<vector<ll>> dp(n, vector<ll>(2, inf));

	dp[1][0] = a[0];
	dp[1][1] = -a[0];

	for (int i = 1; i < n-1; ++i)
		for (int j = 0; j < 2; ++j)
			for (int k = 0; k < 2; ++k)
			{
				int r = (j ? -1 : 1) * (k ? -1 : 1);
				if (dp[i][j] != inf)
					dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i]*r);
			}

	cout << max(dp[n-1][0] + a[n-1], dp[n-1][1] - a[n-1]) << "\n";

	return 0;
}


Measured memory_bytes: 6528
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BOneClue {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int k = sc.nextInt();
            int x = sc.nextInt();
            for (int i = x - k + 1; i < x + k; i++) {
                out.print(i + " ");
            }
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

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

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

    }
}



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

const int INF = 1 << 28;

int m, n;
int t[100];
int out[100];

void solve()
{
	vector<int> res;
	stack<int> st[10];
	queue<int> que;
	
	fill(out, out + 100, INF);
	
	int time = 0;
	while (res.size() < n){
//		printf("%d\n", time);
//		for (int i = 0; i < 10000; i++) printf("");
		
//		for (int i = 0; i < n; i++) printf("%d ", out[i]);
//		puts("");
		
		for (int i = 0; i < m; i++){
			while (st[i].size() && out[st[i].top()] <= time){
				int a = st[i].top(); st[i].pop();
				out[a] = INF;
				res.push_back(a);
//					printf("out %d\n", a);
			}
		}
		
		if (time % 10 == 0 && time / 10 < n){
			que.push(time / 10);
//				printf("wait %d\n", time / 10);
		}
		
		while (que.size()){
			int a = que.front();
			bool f = false;
			int ot = time + t[a];
			
			for (int i = 0; i < m; i++){
				if (st[i].size()) continue;
				st[i].push(a);
				out[a] = ot;
				que.pop();
				f = true;
//					printf("in %d\n", a);
				break;
			}
			if (f) continue;
			
			int mini = -1;
			for (int i = 0; i < m; i++){
				if (st[i].size() == 2) continue;
				if (out[st[i].top()] < ot) continue;
				if (mini == -1){
					mini = i;
				}
				else if (out[st[mini].top()] > out[st[i].top()]){
					mini = i;
				}
			}
			if (~mini){
				st[mini].push(a);
				out[a] = ot;
				que.pop();
//					printf("in %d\n", a);
				continue;
			}
			
			mini = -1;
			for (int i = 0; i < m; i++){
				if (st[i].size() == 2) continue;
				if (mini == -1){
					mini = i;
				}
				else if (out[st[mini].top()] < out[st[i].top()]){
					mini = i;
				}
			}
			if (~mini){
				st[mini].push(a);
				out[a] = ot;
				que.pop();
//					printf("in %d\n", a);
				continue;
			}
			
			break;
		}
		
		time++;
	}
	
	for (int i = 0; i < res.size(); i++){
		if (i) printf(" ");
		printf("%d", ++res[i]);
	}
	puts("");
}

int main()
{
	while (scanf("%d %d", &m, &n), m){
		for (int i = 0; i < n; i++){
			scanf("%d", &t[i]);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 2 * 1e5 + 10, MOD = 1e9 + 7, INF = 1e9;

ll dp[SIZE], lst[SIZE][26];

int main() {
    fastInp;

    string s;
    cin >> s;

    ll n = s.size();
    for (int i = 0; i < 26; i++) {
        lst[n][i] = INF;
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            lst[i][j] = lst[i + 1][j];
        }
        lst[i][s[i] - 'a'] = i;
    }

    for (int i = n - 1; i >= 0; i--) {
        ll mx = -1;
        for (int j = 0; j < 26; j++) {
            mx = max(mx, lst[i + 1][j]);
        }
        if (mx == INF) {
            dp[i] = 1;
        }
        else {
            dp[i] = dp[mx] + 1;
        }
    }

    string ans;
    ll ind = -1;
    while (ind != INF) {
        ll mn = INF;
        for (int j = 0; j < 26; j++) {
            if (lst[ind + 1][j] == INF) {
                mn = 0;
            }
            else {
                mn = min(mn, dp[lst[ind + 1][j]]);
            }
        }
        for (int j = 0; j < 26; j++) {
            if (lst[ind + 1][j] == INF) {
                ans.push_back('a' + j);
                ind = INF;
                break;
            }
            if (dp[lst[ind + 1][j]] == mn) {
                ind = lst[ind + 1][j];
                ans.push_back('a' + j);
                break;
            }
        }
    }

    cout << ans;
    return 0;
}


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

int main(){
  int64_t A;
  int64_t Bi;
  int64_t Bf;
  char t;

  cin >> A >> Bi >> t >> Bf;

  //cout << A << " " << Bi << " " << Bf << endl;

  cout << A*Bi + A*Bf/100 << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cmath>
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0; i<n; i++)
    cin>>h[i];
  int c[n];
  c[0] = 0;
  for(int i=1; i<n; i++){
    int x=1000000000;
      for(int j=1; j<=k; j++){
        if((i-j) >= 0){
          int z = abs(h[i] - h[i-j]) + c[i-j];
          if(x > z)
            x = z;
        }
      }
    c[i] = x;
  }
  cout<<c[n-1];
}


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

int main(){
  int64_t N,K,Q;
  cin >> N >> K >> Q;
  map<int,int> m;
  int A;
  for(int i=1;i<=N;i++){
    m[i]=0;
  }
  for(int i=0;i<Q;i++){
    cin >> A;
    m.at(A)++;
  }
  for(int i=1;i<=N;i++){
    if(m.at(i)>Q-K){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5376
a = list(map(int,input().split()))
n = len(a)-1
i = 0
for _ in range(len(a)-1):
    temp = a[i]
    a[i] = a[n-1]
    a[n-1] = temp
    n+=1
for  i in a:
         print(i,end=" ")

    

Measured memory_bytes: 2940
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

int main() {
	string s;
	cin >> s;
	cout << 2018 << s.substr(4, 6) << endl;
}

Measured memory_bytes: 256