akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var X = cin.scanint;
        var A = X.OrderBy(i => i).ToArray();
        int a = A[N / 2 - 1];
        int b = A[N / 2];
        for (int i = 0; i < N; i++)
        {
            if (X[i] <= a)
            {
                WriteLine(b);
            }
            else
            {
                WriteLine(a);
            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 38904
k, a, b = list(map(int, input().split()))

ans = 1
if b >= a+3:
    if k >= a+1:
        ans += b-1

        ans += (b-a)*((k-(a+1))//2)
        ans += (k-(a+1)) % 2
    else:
        ans += k
else:
    ans += k

print(ans)

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

#include<random> 

#define int long long 

#define pp pair<int,int> 

#define ss second 

#define ff first 

#define pb push_back 

#define mod 1000000007 

using namespace std; 

void fastio() 

{ 

    #ifndef ONLINE_JUDGE 

        freopen("INPUT.txt","r",stdin); 

            freopen("OUTPUT.txt","w",stdout); 

                #endif 

                    ios_base :: sync_with_stdio(false); 

                        cin.tie(NULL) ; 

                            cout.tie(NULL); 

                            }

signed main() 

{ 

    fastio(); 

        int t=1;

            //cin>>t;

                while(t--)

                    {

                       int n,s=0;

                       cin>>n;

                       n--;

                       int a[n],b[n],c[n-1];

                       for(int i=0;i<n;i++)

                       cin>>a[i];

                      

                      for(int i=0;i<n-1;i++){

                       if(a[i]>a[i+1])

                       s+=a[i+1];

                       else

                       s+=a[i];

                      }

                      s+=a[0]+a[n-1];

                      

                       cout<<s;

                       

    }

    }

    

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n;
     cin>>n;
     vector<int> v(3);
     for(int i=0;i<n;i++){
         vector<int> d(3);
     vector<int> vec(3,0);
            for(int w=0;w<3;w++){
                cin>>d[w];
            }
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    if(i!=j)
                        vec[j]=max(vec[j],v[i]+d[j]);
                }
            }
            v=vec;
     }
     cout<<max({v[0],v[1],v[2]});
 
    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 FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
*/

/* ===== コーナーケースに気をつけろ ===== */

int main()
{
    ll x;
    cin >> x;
    ll sum = (x / 500) * 1000;
    sum += ((x % 500) / 5) * 5;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll ss=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        ss+=a[i];
    }
    ll x=(ss/(4*m));
    if(ss%(4*m)){
        ++x;
    }
    sort(a,a+n,greater<ll>());
    for(ll i=0;i<m;i++){
        if(a[i]<x){
            cout<<"No\n";
            return;
        }
    }
    cout<<"Yes\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t N,M; cin>>N>>M;

    int64_t ans;
    if(N==1 && M==1) ans=1;
    else if(min(N,M)==1) ans=N*M-2;
    else ans=N*M-2*(N+M-2);

    cout<<ans<<endl;
}

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

using namespace std;

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

    int a,b;
    string s;
    cin>>a>>s>>b;

    if(s=="+")
        cout<<a+b;
    else
        cout<<a-b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n,m,maxn,minm,x;
	cin>>n>>m>>maxn>>minm;
	for (int i=1;i<=n;++i) cin>>x,maxn=max(maxn,x);
	for (int i=1;i<=m;++i) cin>>x,minm=min(minm,x);
	if (maxn<minm) cout<<"No War";
	else cout<<"War";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using ll = long long int;
using namespace std;

int main() {
  ll a, b;
  cin >> a >> b;
  if (a == 0 || b == 0 || (a < 0 && b > 0)) {
    cout << "Zero" << endl;
  } else if ((max(-a, (ll)0) % 2 + max(-(b + 1), (ll)0) % 2) % 2) {
    cout << "Negative" << endl;
  } else {
    cout << "Positive" << endl;
  }
  return 0;
}


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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, L, T;
int X[100000], W[100000];
int ans[100000];

signed main() {
    cin >> N >> L >> T;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> W[i];
        W[i] = W[i] % 2 * 2 - 1;
        ans[i] = (X[i] + W[i] * T + L * (int)1e9) % L;
    }
    int org = 0;
    for (int i = 0; i < N; i++) {
        if (ans[0] > ans[i]) {
            org++;
        }
    }
    stable_sort(ans, ans + N);
    if (W[0] == 1 && org + 1 < N && ans[org] == ans[org + 1]) {
        org++;
    }
    int a1 = 0;   //1周で何回なり替わるか
    for (int i = 1; i < N; i++) {
        if (W[0] != W[i]) {
            a1 += 2;
        }
    }
    int a2 = 0;   //T%L秒で何回なり替わるか
    for (int i = 1; i < N; i++) {
        if (W[0] != W[i]) {
            if ((L - X[i] * W[i] - X[0] * W[0]) % L <= T % L * 2) {
                a2++;
            }
            if ((L - X[i] * W[i] - X[0] * W[0]) % L + L <= T % L * 2) {
                a2++;
            }
        }
    }
    int a = (T / L * a1 + a2) % N;
    int start = (N - W[0] * a) % N;
    for (int i = 0; i < N; i++) {
        cout << ans[(i + start + org) % N] << endl;
    }
    return 0;
}


Measured memory_bytes: 3576
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

	slice := make([][]int, 3)
	for i := 0; i < 3; i++ {
		slice[i] = make([]int, 3)
	}

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			slice[i][j] = nextInt()
		}
	}

	// slice := [3][3]int{
	// 	{1, 0, 1},
	// 	{2, 1, 2},
	// 	{1, 0, 1},
	// }

	// fmt.Println(slice)

	a := make([]int, 3)
	b := make([]int, 3)
	a[0] = 0
	for i := 0; i < 2; i++ {
		for j := 0; j < 3; j++ {
			b[j] = slice[i][j] - a[i]
			a[i+1] = slice[i+1][j] - b[j]
		}
	}

	// fmt.Println(a)
	// fmt.Println(b)

	right := true

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			if slice[i][j] != (a[i] + b[j]) {
				right = false
			}
		}
	}

	if right {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
import sys

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


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


def solve(N):
    M = 3501

    for h in range(1, M):
        for n in range(h, M):
            denominator = 4 * n * h - N * h - N * n
            if denominator <= 0:
                continue
            numerator = N * h * n

            if numerator % denominator == 0:
                return h, n, numerator // denominator


def main():
    N = int(input())
    h, n, w = solve(N)
    print(h, n, w)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C

#D
h,w,n = LI()
dp = [0 for i in range(10)]
dp[0] = (h-2)*(w-2)
q = defaultdict(int)
for i in range(n):
    a,b = LI()
    a -= 1
    b -= 1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 0 < a+i < h-1 and 0 < b+j < w-1:
                q[(a+i)*w+b+j] += 1
                dp[q[(a+i)*w+b+j]] += 1
                dp[q[(a+i)*w+b+j]-1] -= 1
for i in dp:
    print(i)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 130684
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int r;
    cin >> r;
    cout << 3.14159 * 2 * r << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3788
k=int(input())
a,b=map(int,input().split())
flag=0
if a==b:
    if a%k==0:
        flag=1

for i in range(a,b+1):
    if i%k==0:
        flag=1

if flag==1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N1 1000
#define N2 100
int get,A[N1];

void push(int x){
  A[++get]=x;
}
 
int pop(){
  get--;
 
  return A[get+1];
}
 
int main(){
  char a[N2];
  int x=0,y=0;
  get=0;
 
 
  while(scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      x=pop();
      y=pop();
      push(y+x);
    }else if(a[0]=='-'){
      x=pop();
      y=pop();
      push(y-x);
    }else if(a[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }else {
      push(atoi(a)); 
    }
  }
 
  printf("%d\n",pop());
 
  return 0;
}



Measured memory_bytes: 2076
#import
#import math
#import numpy as np
K = int(input())

if K == 7:
    print(1)
    exit()

t = 7 % K
    
for i in range(1, K * 2):
    if t == 0:
        print(i)
        exit()

    t = (t * 10 + 7) % K

print(-1)

Measured memory_bytes: 8952
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int a; cin >> a;
	cout << 3 * a*a << endl;
	return 0;
}

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

int main() {
	set<int>st;
    int t = 3;
   while (t-- ) {
   	int x;
     cin >> x;
     st.insert(x);
   }
  if (st.size() ==2){
  cout << "Yes\n";
  }
  else{
    cout<<"No\n";
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int x=0;
       try{
           x=System.in.read();
       }
       catch(IOException e){
           System.err.println( "入力エラーです。" );
       }
        System.out.println((char)x=='A'?"T":(char)x=='T'?"A":(char)x=='C'?"G":"C");
 
    }  
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll x;
    cin >> x;
    ll now = 100;
    int years = 0;
    while (now < x)
    {
        now *= 1.01;
        years++;
    }

    cout << years << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

int main(){
  long n,m;
  cin>>n>>m;

  if(abs(n-m)>=2){ cout << 0 << endl; return 0; }

  vector<long> fac(100005, 0);
  fac[0]=1;
  rep(i,100000) fac[i+1] = (fac[i]*(i+1))%MOD;

  if(n==m){
    long ans = 2*fac[n]*fac[m] % MOD;
    cout << ans << endl;
  } else {
    long ans = fac[n]*fac[m] % MOD;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
class String
  def to_ia
    self.split(/\s+/).map {|s| s.to_i}
  end
end
 
class Array
  def swap(i, j)
    t = self[i]
    self[i] = self[j]
    self[j] = t
  end
end

def insertion_sort(ary)
  swaps = 0
  n = ary.size
  (0...n).each do |i|
    min = i
    (i...n).each do |j|
      if ary[j] < ary[min]
        min = j
      end
    end
    unless i == min
      ary.swap i, min
      swaps += 1
    end
  end
  puts ary.join(" ")
  puts swaps
end
 
STDIN.readline
ary = STDIN.readline.to_ia
insertion_sort(ary)

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CSkillUp {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m, x; cin >> n >> m >> x;
      int s = 1<<n;
      int ret = INT_MAX;
      vector<int> c(n);
      vector<vector<int>> a(n, vector<int>(m));
      rep(i, n) {
        cin >> c[i];
        rep(j, m) {
          cin >> a[i][j];
        }
      }


      rep(i, s) {
        vector<int> und(m);
        int cost = 0;
        rep(k, n) {
          if (i&(1<<k)) {
            cost += c[k];
            rep(j, m) {
              und[j] += a[k][j];
            }
          }
        }
        bool flag = true;
        rep(j, m) {
          if (und[j] < x) {
            flag = false;
            break;
          }
        }
        if (flag) {
          chmin(ret, cost);
        }
      }
      if (ret == INT_MAX) {
        cout << -1 << endl;
      } else {
        cout << ret << endl;
      }
    }
};

signed main() {
  CSkillUp solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3652
# 整数の入力
K = int(input())
# スペース区切りの整数の入力
A, B = map(int, input().split())


#出力　#自力
if A%K != 0:
  if A-(A%K)+K <= B:
    print("OK")
  else:
    print("NG")
else:
    print("OK")

Measured memory_bytes: 9140
#include <iostream>
using namespace std;
typedef long long ll;
ll dist[1000];
bool negative[1000];
ll n,m;
int main(void){
    cin>>n>>m;
    ll a[m],b[m],c[m];
    for(int i=0;i<m;i++){
        ll aa,bb,cc;
        cin>>aa>>bb>>cc;
        a[i]=aa-1;
        b[i]=bb-1;
        c[i]=-1*cc;
    }
    for(int i=0;i<n;i++){
        dist[i]=1LL<<60;
    }
    dist[0]=0;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            if(dist[a[j]]==1LL<<60)continue;
            dist[b[j]]=min(dist[b[j]],dist[a[j]]+c[j]);
        }
    }
    ll ans=dist[n-1];
    for(int i=0;i<n;i++){
        negative[i]=false;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(dist[a[j]]==1LL<<60)continue;
            if(dist[b[j]]>dist[a[j]]+c[j]){
                dist[b[j]]=dist[a[j]]+c[j];
                negative[b[j]]=true;
            }
            if(negative[a[j]]==true)negative[b[j]]=true;
        }
    }
    if(negative[n-1])cout<<"inf"<<endl;
    else cout<<ans*-1<<endl;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t H,W;
int32_t N;
int32_t a[10000];
int32_t OUT[100][100];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H >> W;
	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> a[i];
	}
	int index = 0;
	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{
			OUT[h][w]= index + 1;
			if (--a[index] == 0) {
				++index;
			}
		}
		++h;
		if (h >= H) { break; }
		for (int w = W-1; w >= 0; w--)
		{
			OUT[h][w] = index + 1;
			if (--a[index] == 0) {
				++index;
			}
		}
	}
	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W-1; w++)
		{
			out<<OUT[h][w]<<' ';
		}
		out<< OUT[h][W-1] << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	int test = 0;

	string s;
	ll x, y;
	ll a[8000] = {}, b[8000] = {};
	bool flugx[16001] = {}, flugy[16001] = {};
	bool tflugx[16001] = {}, tflugy[16001] = {};
	ll na=0, nb=0;
	cin >> s;
	cin >> x >> y;
	ll len = s.length();

	ll flug = 0;
	ll posa =0,posb=0;
	na = 1; nb = 1;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'T') {
			if (flug == 0) {
				flug = 1;
				posa++;
				na++;
			}
			else {
				flug = 0;
				posb++;
				nb++;
			}
		}
		else {
			if (flug == 0) {
				a[posa]++;
			}
			else {
				b[posb]++;
			}
		}
	}


	if (test) {
		cout << "a" << endl;
		for (int i = 0; i < na; i++) {
			cout << a[i] << endl;
		}
		cout << "b" << endl;
		for (int i = 0; i < nb; i++) {
			cout << b[i] << endl;
		}
	}
	flugx[8000+a[0]] = true;
	flugy[8000] = true;
	

	for (int i = 1; i < na; i++) {
		for (int j = 0; j < 16001; j++) {
			if (flugx[j] == true) {
				if (0 <= j - a[i] && j - a[i] < 16001) {
					tflugx[j - a[i]] = true;
				}
				if (0 <= j + a[i] && j + a[i] < 16001) {
					tflugx[j + a[i]] = true;
				}
			}
			
		}
		for (int t = 0; t < 16001; t++) {
			flugx[t] = tflugx[t];
			tflugx[t] = false;
		}
	}
	for (int i = 0; i < nb; i++) {
		for (int j = 0; j < 16001; j++) {
			if (flugy[j] == true) {
				if (0 <= j - b[i] && j - b[i] < 16001) {
					tflugy[j - b[i]] = true;
				}
				if (0 <= j + b[i] && j + b[i] < 16001) {
					tflugy[j + b[i]] = true;
				}
			}
		}
		for (int t = 0; t < 16001; t++) {
			flugy[t] = tflugy[t];
			tflugy[t] = false;
		}
	}

	if (flugx[8000 + x] && flugy[8000 + y]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>

using namespace std;


int main() {

  int n;
  vector<int> s;

  vector<int> prev,n_s;
  map<int,int> runlength;
  int count;


  while(cin >> n) {

    if(n==0) break;

    s.clear();

    for(int i=0;i<n;i++) {

      int tmp;

      cin >> tmp;

      s.push_back(tmp);

    }

    n_s=s;

    //for(int i=0;i<temp.size();i++) cout << s[i] << " ";

    count=0;

    do {

      prev=n_s;

      runlength.clear();

      for(int i=0;i<n;i++) runlength[n_s[i]]++;

      for(int i=0;i<n;i++) n_s[i]=runlength[n_s[i]];

      if(prev==n_s) break;
      /*
      for(int i=0;i<n;i++) {

	if(i==0) cout << n_s[0];

	else cout << "  " << n_s[i];

      }
      */
      count++;

    } while(1);

    cout << count << endl;

    for(int i=0;i<n;i++) {

      if(i==0) cout << n_s[0];

      else cout << " " << n_s[i];

    }

    cout << endl;

  }

  return 0;

}

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

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define MREP(i,x) for(int i=beg[x],v;v=to[i],i;i=las[i])
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
typedef long long ll;

using namespace std;

void File(){
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
}

template<typename T>void read(T &_){
	T __=0,mul=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')mul=-1;
		ch=getchar();
	}
	while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
	_=__*mul;
}

const int maxn=1e6+10;
ll n,p,cnt[maxn],num[maxn],tot,ans=1;

int main(){
	//File();
	read(n),read(p);

	REP(i,2,sqrt(p))if(p%i==0){
		num[++tot]=i;
		while(p%i==0)p/=i,++cnt[tot];
	}
	if(p!=1){
		num[++tot]=p;
		++cnt[tot];
	}

	REP(i,1,tot)REP(j,1,cnt[i]/n)ans=ans*num[i];

	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  vpll vec(n);
  REP(i,n) cin >> vec[i].first >> vec[i].second;
  sort(ALL(vec));
  REP(i,n) cout << vec[i].first << " " << vec[i].second <<endl;


  return 0;
}




Measured memory_bytes: 4464
#include <iostream>
#include <algorithm>
#include <deque>

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

	std::deque<int> deq;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;

		if (i % 2 == 0)
			deq.push_back(a);
		else
			deq.push_front(a);
	}

	if (n % 2 == 0) {
		std::cout << deq[0];
		for (auto it = deq.begin() + 1; it != deq.end(); ++it)
			std::cout << " " << *it;
	}
	else {
		std::cout << deq.back();
		for (auto it = deq.rbegin() + 1; it != deq.rend(); ++it)
			std::cout << " " << *it;
	}

	std::cout << std::endl;
}

Measured memory_bytes: 2944
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for a in A:
    d[a] += 1

if N % 2 == 0:
    for i in range(1, N // 2 + 1):
        if d[2 * i - 1] == 2:
            d[2 * i - 1] = 0
else:
    for i in range(1, N // 2 + 1):
        if d[2 * i] == 2:
            d[2 * i] = 0
    if d[0] == 1:
        d[0] = 0
if sum(d.values()) != 0:
        print(0)
else:
    print(2 ** (N // 2) % (10**9 + 7))


Measured memory_bytes: 14820
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> v(N), c(N);
    REP(i, N)
    {
        cin >> v[i];
    }
    REP(i, N)
    {
        cin >> c[i];
    }
    int ans = 0;
    REP(i, N)
    {
        ans += max(0, v[i] - c[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int x,y;
  cin >> x>> y;
  if(x==2&&y==2) {
    cout << "Yes"<<endl;
    return 0;
  }
  else if(x==4||x==6||x==9||x==11){
    if(y==4||y==6||y==9||y==11){
      cout << "Yes"<<endl;
      return 0;
    }
    }
    else if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
      if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
        cout <<"Yes"<<endl;
        return 0;
      }
    }
      cout <<"No"<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n, k  = in_ints()
n = abs(n-k)
print(min(n%k, k- (n%k)))

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xx first
#define yy second
#define sci(n) scanf("%d",&n)
#define scii(n,m) scanf("%d%d",&n,&m)
#define sciii(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define sclll(n,m,w) scanf("%lld%lld%lld",&n,&m,&w)
#define pf(a)   printf("%d\n",a)
#define CASE(a) printf("Case %d:\n",a)
#define dbg(i) printf("yo %lld\n", i)
#define endl '\n'
#define READ  freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout);
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define SQR(a) (a)*(a)
#define all(v) v.begin(),v.end()
#define pb push_back
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define inf INT_MAX
#define eps 1e-9

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

using namespace __gnu_pbds;
using namespace std;

#define mxn 100005


//bool vis[1LL << 19];
const ll nax=100005;
ll ar[nax][4];
void solve()
{
    ll a,b,n,k=0,c,i,q=0,j,l,m,mx;
    cin>>n;
    FOR(i,1,n+1) FOR(j,0,3) cin>>ar[i][j];
    for(i=n-1;i>=1;i--){
        for(j=0;j<3;j++){
            ar[i][j]+=max(ar[i+1][(j+1)%3],ar[i+1][(j+2)%3]);
        }
    }cout<<max(max(ar[1][0],ar[1][1]),ar[1][2])<<'\n';
}
int main()
{
    //IOS;
    double start_time = clock();
    ll t=1,mex=1;
   //cin>>t;
    while(t--){
        solve();
    }
    double end_time = clock();
    //fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, x: int, a: "List[int]"):
    a.sort()
    res = 0
    xx = x
    for i in range(N):
        if x >= a[i]:
            res += 1
            x -= a[i]
        else:
            x = 0
    if x > 0:
        res -= 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5044
INFTY = 9999999999999999999

N = int(input())
X = [int(i) for i in input().split()]

X.sort()
left = X[0]
right = X[-1]

score = INFTY
for P in range(left, right+1):
    tmp_score = 0
    for i in range(N):
        tmp_score += ((X[i] - P) * (X[i] - P))
    if (tmp_score < score):
        score = tmp_score

print(score)

Measured memory_bytes: 3188
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
int N, M, ans;
vector<vector<int>> v(100001);
priority_queue<int> q;
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0, A, B; i < N; ++i) {
    scanf("%d %d", &A, &B);
    v[A].push_back(B);
  }
  for(int i = 1; i <= M; ++i) {
    for(int j = 0; j < (int)v[i].size(); ++j) {
      q.push(v[i][j]);
    }
    if(q.empty()) continue;
    ans += q.top(); q.pop();
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 5632
#include<stdio.h>
#define MAXNUM 101
#define INF 100000000

int pass[MAXNUM][MAXNUM];

void PrintGraph(int num){
    int i;
    for(i=0; i<num; i++){
        printf("%d %d\n",i,pass[0][i]);
    }
    return;
}

void ShortestPass(int num){
    int i,j,k,cost;
    for(k=0; k<num; k++){
        for(i=0; i<num; i++){
            for(j=0; j<num; j++){
                cost=pass[i][k]+pass[k][j];
                if(cost<pass[i][j])pass[i][j]=cost;
            }
        }
    }
}

int main(){
    int i,j,num,from,to,passnum,weight;

    for(i=0; i<MAXNUM; i++){
        for(j=0; j<MAXNUM; j++){
            if(i==j)pass[i][j]=0;
            else pass[i][j]=INF;
        }
    }

    scanf("%d",&num);
    for(i=0; i<num; i++){
        scanf("%d%d",&from,&passnum);
        for(j=1; j<=passnum; j++){
            scanf("%d%d",&to,&weight);
            pass[from][to] = weight;
        }
    }

    ShortestPass(num);
    PrintGraph(num);
    return 0;
}


Measured memory_bytes: 2112
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve

N = int(input())
b = np.array(input().split())

rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

A = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))

x = (spsolve(A, b) * 2).astype(int)

print(*x)

Measured memory_bytes: 66088
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n;

int main(void)
{
    cin >> n;

    int tt = 0;
    int xx = 0;
    int yy = 0;

    rep(i, n)
    {
        int t, x, y;
        cin >> t >> x >> y;

        int dis = abs(xx - x) + abs(yy - y);
        int dt = t - tt;

        if (dis <= dt && (dt - dis) % 2 == 0)
        {
            tt = t;
            xx = x;
            yy = y;
            continue;
        }

        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}


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

typedef long long ll;

using namespace std;

int main() {
	ll x;
	cin >> x;

	ll joy = 0;

	while (x >= 500) {
		x -= 500;
		joy += 1000;
	}
	while (x >= 5) {
		x -= 5;
		joy += 5;
	}

	cout << joy;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	int mx = *max_element(a.begin(), a.end());
	vector<int> b = a;
	sort(b.begin(), b.end());
	int mxx = b[n - 2];
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == mx)
			cout << mxx << endl;
		else
			cout << mx << endl;
	}
}

Measured memory_bytes: 4660
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = n - 1; i > 0; i--)
		cout << a[i] << " ";
	cout << a[0] << endl;
}

Measured memory_bytes: 3096
a=int(input())
b=int(input())
c=int(input())
x=int(input())
if x%100>0 and c==0:
    print(0)
    exit()
else:
    a=min(a,x//500)
    b=min(b,x//100)
    c=min(c, x // 50)
    ans=0
    for i in range(a+1):
        for j in range(b+1):
            for c in range(c+1):
                if i*500+j*100+c*50==x:ans+=1
print(ans)


Measured memory_bytes: 9228
#include <stdio.h>

int partition(int a [], int l, int r) {
    int i = l - 1;
    int j = r;
    int temp;
 
    int pivot = a[r];
 
    while (1) {
        while (a[++i] < pivot) ;
        while (i < --j && pivot < a[j]) ;

        if (i >= j) break;
 
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    temp = a[i];
    a[i] = a[r];
    a[r] = temp;
    return i;
}

void quickSort(int a[], int l, int r) {
    int v;
    if (l >= r) {
        return;
    }
    v = partition(a, l, r);
    quickSort(a, l, v - 1);
    quickSort(a, v + 1, r);
}

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    int l[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &l[i]);
    }
    quickSort(l, 0, N - 1);
    int num = 0;
    for (int i = N - 1; i >= N - K; i--) {
        num = num + l[i];
    }
    printf("%d\n", num);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll g[2][3];
ll a[3],b[3];
int main(){
	cin >> N;
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin >> g[i][j];
		}
	}
	int cnt = 0;
	for(int i=0;i<3;i++){
		a[i] = min(g[0][i],g[1][i]);
		b[i] = max(g[0][i],g[1][i]);
		if(g[0][i]<g[1][i])cnt++;
		//cout << a[i] << ' ' << b[i] << endl;
	}
	if(cnt==0||cnt==3){
		ll ans = N;
		for(int i=0;i<=N;i++){
			for(int j=0;i+j<=N;j++){
				int p = i;
				int q = j;
				int r = N-q-p;
				//cout << p << q << r << endl;
				ll res = 0;
				ll rem = 0;
				res += (p/a[0])*b[0];
				res += (q/a[1])*b[1];
				res += (r/a[2])*b[2];
				rem += p%a[0];
				rem += q%a[1];
				rem += r%a[2];
				ans = max(ans,res+rem);
			}
		}
		cout << ans << endl;
	}else if(cnt==1){
		ll M=N;
		for(int i=0;i<3;i++){
			if(g[0][i]>=g[1][i])continue;
			M = max(M,(N/a[i])*b[i]+(N%a[i]));
		}
		//cout << M << endl;
		ll ans = M;
		for(int i=0;i<=M;i++){
			ll p[2];
			p[0] = i;
			p[1] = M-i;
			ll res = 0;
			int cnt = 0;
			for(int j=0;j<3;j++){
				if(g[0][j]<g[1][j])continue;
				//cout << j << endl;
				res += ((p[cnt]/a[j])*b[j])+(p[cnt]%a[j]);
				cnt++;
			}
			assert(cnt==2);
			ans = max(ans,res);
		}
		cout << ans << endl;
	}else{
		ll M = N;
		for(int i=0;i<=N;i++){
			ll p[2];
			p[0] = i;
			p[1] = N-i;
			ll res = 0;
			int cnt = 0;
			for(int j=0;j<3;j++){
				if(g[0][j]>=g[1][j])continue;
				res += ((p[cnt]/a[j])*b[j])+(p[cnt]%a[j]);
				cnt++;
			}
			assert(cnt==2);
			M = max(M,res);
		}
		ll ans = M;
		for(int i=0;i<3;i++){
			if(g[0][i]<g[1][i])continue;
			ans = max(ans,(M/a[i])*b[i]+(M%a[i]));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
char buf[101010];
int q,nw=0;
vector<char>v[2];
int main()
{
	scanf("%s",buf);
	s=buf;
	scanf("%d",&q);
	while(q--)
	{
		int tp;
		scanf("%d",&tp);
		if(tp==1)
		{
			nw^=1;
		}
		else
		{
			int nt;
			char c;
			scanf("%d",&nt);
			nt--;
			nt^=nw;
			cin>>c;
			v[nt].push_back(c);
		}
	}
	if(nw)
	{
		reverse(s.begin(),s.end());
		for(int i=v[1].size()-1;i>=0;i--)
		{
			printf("%c",v[1][i]);
		}
		printf("%s",s.c_str());
		for(int i=0;i<v[0].size();i++)
		{
			printf("%c",v[0][i]);
		}
	}
	else
	{
		for(int i=v[0].size()-1;i>=0;i--)
		{
			printf("%c",v[0][i]);
		}
		printf("%s",s.c_str());
		for(int i=0;i<v[1].size();i++)
		{
			printf("%c",v[1][i]);
		}
	}
	return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 10;

int a[N];
bool ex[N];
int aa[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> aa[i];
    a[i] = aa[i];
  }
  bool pc = true;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      int cnt = 0;
      while (a[i] % j == 0) {
        a[i] /= j;
        ++cnt;
      }
      if (cnt > 0) {
        if (ex[j] == true) {
          pc = false;
        }
        ex[j] = true;
      }
    }
    if (a[i] > 1) {
      int j = a[i];
      int cnt = 0;
      while (a[i] % j == 0) {
        a[i] /= j;
        ++cnt;
      }
      if (cnt > 0) {
        if (ex[j] == true) {
          pc = false;
        }
        ex[j] = true;
      }
    }
  }
  if (pc) {
    cout << "pairwise coprime" << '\n';
    return 0;
  }
  int g = __gcd(aa[0], aa[1]);
  for (int i = 2; i < n; i++) {
    g = __gcd(g, aa[i]);
  }
  cout << (g == 1 ? "setwise coprime" : "not coprime") << '\n';
  return 0;
}


Measured memory_bytes: 12268
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let _: i32 = read_as_vec()[0];

    let ell = read_as_vec::<i32>();
    let sum = ell.iter().sum::<i32>();

    for elem in &ell{
        //println!("elem = {}", *elem);
        if sum - *elem <= *elem{
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main () {
  long long n,d;
  cin >> n >> d;
  int ans=0;
  for(int i=0;i<n;i++){
    long long x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int n, m;
vector <int> x;

int main() {
    cin >> n >> m;
    x.resize(m);
    rep(i, m) cin >> x[i];
    sort(x.begin(), x.end());

    vector <int> dist;
    rep(i, m - 1) dist.push_back(x[i + 1] - x[i]);
    sort(dist.begin(), dist.end());
    int sum = 0;
    rep(i, m - n) sum += dist[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	long long x, y;
	cin >> x >> y;

	int ans = 0;
	while (x <= y) {
		++ans;
		x <<= 1;
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] x=new int[n];
    int[] y=new int[n];
    for(int i=0;i<n;i++){
      y[i]=x[i]=sc.nextInt();
    }
    Arrays.sort(y);
    int l=y[n/2-1];
    int r=y[n/2];
    for(int i=0;i<n;i++){
      if(x[i]<=l){
        System.out.println(r);
      }else{
        System.out.println(l);
      }
    }
  }
}

Measured memory_bytes: 91760