akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>

using namespace std;

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

        map< int, int > mp;
        map< int, int > tmp;
        for (size_t i=0; i<s.size(); ++i) {
                if (mp.find(s[i]-'a')==mp.end()) {
                        mp[s[i]-'a'] = 1;
                } else {
                        mp[s[i]-'a']++;
                }
        }

        for (size_t j=0; j<n-1; ++j) {
                cin >> s;
                tmp.clear();
                for (size_t i=0; i<s.size(); ++i) {
                        if (tmp.find(s[i]-'a')==tmp.end()) {
                                tmp[s[i]-'a'] = 1;
                        } else {
                                tmp[s[i]-'a']++;
                        }
                }
                for (int i=0; i<26; ++i) {
                        map<int, int>::iterator it;
                        it = mp.find(i);
                        if (tmp.find(i)==tmp.end()) {
                                if (it != mp.end()) {
                                        mp.erase(it);
                                }
                        } else {
                                if (it != mp.end()) {
                                        mp[i] = min(mp[i], tmp[i]);
                                }
                        }
                }
        }

        if (mp.size()==0) cout << endl;
        else {
                for (int i=0; i<26; ++i) {
                        if (mp.find(i)!=mp.end()) {
                                for (int j=0; j<mp[i]; ++j) {
                                        cout << char(i+'a');
                                }
                        }
                }
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn=110;
int n,m,a[maxn],b[maxn];
int main(){
	int iodd=0;
	n=rd(),m=rd();
	Rep(i,1,m)a[i]=rd(),iodd+=a[i]&1;
	if(m==1){
		if(a[1]==1) puts("1 1\n1"); else{
			printf("%d 2\n%d %d\n",a[1],a[1]-1,1);
		}
		return 0;
	}
	if(iodd>2){
		puts("Impossible");
		return 0;
	} else{
		Rep(i,2,m){
			if(a[i]&1){
				if(a[1]&1) swap(a[m],a[i]); 
				else swap(a[1],a[i]);
			}
		}
		int t=0;
		if(a[1]>1) b[++t] = a[1] - 1;
		rep(i,2,m) b[++t] = a[i];
				   b[++t] = a[m] + 1;
		Rep(i,1,m){
			printf("%d ",a[i]);
		}puts("");
		writeln(t);
		Rep(i,1,t){
			printf("%d ",b[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PAIR;
const int N = 1e3+5;
const int INF = 0x3f3f3f3f;

int main(){
	ll n,k;
	cin >> n >> k;
	if(n > k) n = (n-1)%k+1;
	printf("%lld\n",min(n,k-n));
    return 0;
}


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

typedef long long ll;
const int maxn = 3e3 + 3;
const ll inf = 0x7ffffffff;
typedef long long ll;
int n, m;
ll L;
struct dt {
    ll f, r;
    bool operator<(const dt &u) const {
        return f < u.f || f == u.f && r > u.r;
    }
};

std::vector<std::pair<int, ll>> E[maxn];

dt dist[maxn];
bool inq[maxn];
void spfa(int S) {
    std::deque<int> q;
    for(int i = 1; i <= n; ++i) {
        inq[i] = false;
        dist[i] = {inf, 0};
    }
    dist[S] = {0, L};
    q.push_back(S);
    inq[S] = true;
    while(!q.empty()) {
        int u = q.front(); q.pop_front();
        inq[u] = false;
        const auto &du = dist[u];
        for(const auto &e : E[u]) {
            int v; ll w;
            std::tie(v, w) = e;
            dt dv = du.r >= w ? dt{du.f, du.r - w} : dt{du.f + 1, L - w};
            if(dv < dist[v]) {
                dist[v] = dv;
                if(inq[v])
                    continue;
                inq[v] = true;
                if(!q.empty() && dv < dist[q.front()])
                    q.push_front(v);
                else
                    q.push_back(v);
            }
        }
    }
}

dt d[maxn][maxn];

int main() {
    scanf("%d%d%lld", &n, &m, &L);
    for(int i = 0; i < m; ++i) {
        int u, v;
        ll w;
        scanf("%d%d%lld", &u, &v, &w);
        if(w > L)
            continue;
        E[u].push_back({v, w});
        E[v].push_back({u, w});
    }
    for(int i = 1; i <= n; ++i) {
        spfa(i);
        for(int j = 1; j <= n; ++j) {
            d[i][j] = dist[j];
            // printf("%lld%c", dist[j].f, " \n"[j == n]);
        }
    }
    int q;
    scanf("%d", &q);
    while(q--) {
        int u, v;
        scanf("%d%d", &u, &v);
        printf("%lld\n", d[u][v].f < inf ? d[u][v].f : -1ll);
    }
    return 0;
}

Measured memory_bytes: 15616
m,k = map(int, input().split())
if k >= 2 ** m:
  print(-1)
  exit()
if m == 1:
  if k == 0:
    print(0,0,1,1)
  if k == 1:
    print(-1)
  exit()
base = [i for i in range(2**m) if i != k]
ans = base + [k] + base[::-1] + [k]
print(*ans)

Measured memory_bytes: 16268
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {
	ll N;
	cin >> N;
	vector<pair<ll,ll>>a(N);
	ll ans=0;
	int t = 1;
	for (ll i = 0;i < N;i++) { 
		cin >> a[i].second >> a[i].first;
	}
	sort(a.begin(), a.end());
	for (ll k = 0;k < N;k++) {
		ans = ans + a[k].second;
		if (ans > a[k].first) { t = 0;cout << "No" << endl;break; }
	}
	if (t == 1) { cout << "Yes" << endl; }
	return 0;
}

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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++ i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-8, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
#define SZ(x) ((int)(x).size())

namespace Math {
int MOD;

IL int add(int a, int b) {
  a += b;
  return a >= MOD ? a - MOD : a;
}

template <class ...Args>
IL int add(int a, const Args &...args) {
  a += add(args...);
  return a >= MOD ? a - MOD : a;
}

IL int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + MOD : a;
}

IL int mul(int a, int b) {
  return (LL)a * b % MOD;
}

template <class ...Args>
IL int mul(int a, const Args &...args) {
  return (LL)a * mul(args...) % MOD;
}

IL int quickPow(int a, int p) {
  int ret = 1;
  for (; p; p >>= 1, a = mul(a, a)) {
    if (p & 1) {
      ret = mul(ret, a);
    }
  }
  return ret;
}
}

using namespace Math;

const int MAXN = 300 + 5;

int binom[MAXN][MAXN], f[MAXN][MAXN], pref[MAXN][MAXN];

int main() {
  int n, k;
  scanf("%d%d%d", &n, &k, &MOD);
  binom[0][0] = 1;
  For(i, 1, n) {
    binom[i][0] = 1;
    For(j, 1, i) {
      binom[i][j] = add(binom[i - 1][j], binom[i - 1][j - 1]);
    }
  }
  f[1][0] = 1;
  For(i, 1, k) {
    f[1][i] = 1;
    pref[1][i] = i % MOD;
  }
  For(i, 2, n + 1) {
    For(j, 0, k) {
      FOR(p, 1, i) {
        f[i][j] = add(f[i][j], mul(f[i - p][j], binom[i - 2][p - 1], sub(pref[p][k], pref[p][j])));
      }
      if (j) {
        pref[i][j] = add(pref[i][j - 1], f[i][j]);
      }
    }
  }
  printf("%d\n", f[n + 1][0]);
  return 0;
}



Measured memory_bytes: 1280
let K = Int(readLine()!) ?? 0
var result = 0
for i in 1...K{
    for j in 1...K{
        for k in 1...K{
           result += gcd(gcd(i,j),k)
        }
    }
}

print(result)

func gcd(_ a:Int,_ b:Int)->Int{
    let r = a % b == 0 ? b : gcd(b,a % b)
    return r
}



Measured memory_bytes: 7776
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	s <- getLine
	print $ length $ head $ filter check $ drop 1 $ reverse $ inits s

check s
	| l `mod` 2 == 1 = False
	| otherwise = take l2 s == drop l2 s
	where
		l = length s
		l2 = l `div` 2


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

int main() {
  int n, d[100], sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a;
    scanf("%d",&a);
    int t=0,i;
    long int b[20000000],k=0;
    for(i=0;i<a;i++){
        scanf("%ld",&b[i]);
        if(t<b[i]) t=b[i];
        else k+=t-b[i];
    }
    printf("%ld",k);
    return 0;
}


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

/////DFSの問題

int N;

void dfs(string s, char mx){
    if(s.length()==N){
        cout << s << endl;
        //printf("%s\n", s.c_str());
    }else{
        for(char c='a';c<=mx;c++){
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
            /*条件式 ? 真の時の式 : 偽の時の式*/
        }
    }
}

int main(){
    cin >> N;
    dfs("",'a');
    //return 0;
}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
// import lib.util.*;
// import lib.graph.*;
// import lib.io.*;
// import lib.math.*;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int res = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == 'R') {
                res++;
            }
        }
        if (s[1] != 'R' && res == 2) {
            System.out.println(1);
        } else {
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 35448
#include <stdio.h>

#define NUMBER 10000

int main(void){
  int i,j;
  int num[NUMBER];
  int max;

  j=0;
  while(1){
    scanf("%d", &num[j]);
    if(num[j]==0)
      break;
    j++;
    max=j;
  }

  for(i=0; i<max; i++){
    printf("Case %d: %d\n", i+1, num[i]);
  }

  return 0;
}

Measured memory_bytes: 1728
# coding:utf-8

machi = dict()
for i in range(4):
    machi[i+1] = []

for _ in range(3):
    a, b = map(int, input().split())
    machi[a].append(b)
    machi[b].append(a)

# 始点と終点を決める
count = 0
start, end = 0, 0
for i in range(4):
    if len(machi[i+1]) == 1:
        if count == 0:
            start = i+1
            count += 1
        else:
            end = i+1

# 探索開始
if (start != 0) & (end != 0):
    second = machi[start][0]
    third = machi[end][0]
    if third in machi[second]:
        print("YES")
    else:
        print("NO")
else:
    print("NO")


Measured memory_bytes: 3064
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	if n < 1000 {
		println!("ABC");
	}else{
		println!("ABD");
	}
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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


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

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i, a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

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

  ll x, y;
  cin >> x >> y;

  if ((x + y)%3) {
    cout << 0 << endl;
    return 0;
  }
  
  if (x > 2*y || y > 2*x) {
    cout << 0 << endl;
    return 0;
  }

  ll n = 2*y - x;
  ll m = 2*x - y;

  if (n < 0 || m < 0) {
    cout << 0 << endl;
    return 0;
  }

  n /= 3;
  m /= 3;

  cout << choose(n+m, min(n, m)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
parse :: [String] -> [[[Int]]]
parse [] = []
parse (x:xs) = if n == 0 then [] else map (map read) (map words (take n xs)) : parse (drop n xs)
    where
        n = read x

addsumr :: [Int] -> [Int]
addsumr xs = xs ++ [sum xs]

addsumc :: [[Int]] -> [[Int]]
addsumc xs = xs ++ [sumc xs]
    where
        sumc :: [[Int]] -> [Int]
        sumc ys
            | any null ys = []
            | otherwise = sum (map head ys) : sumc (map tail ys)

show5 :: Show a => a -> String
show5 x = if n < 5 then replicate (5 - n) ' ' ++ s else s
    where
        n = length s
        s = show x

showMatrix :: Show a => [a] -> String
showMatrix = concat . map show5

solve :: [[Int]] -> [String]
solve = map showMatrix . addsumc . map addsumr

main :: IO ()
main = getContents
    >>= return . parse . lines
    >>= return . map solve
    >>= mapM_ (mapM_ putStrLn)

Measured memory_bytes: 4376
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	int N, K;
	string S;
	cin >> N >> S >> K;
	rep(i, N) {
		if (S[i] != S[K - 1])cout << "*";
		else cout << S[i];
	}
}

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

template<typename T> void print(const T & v);


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    vector<int> dist(M, 0);
    rep(i, M) cin >> X[i];

    if(N >= M){
        cout << 0 << endl;
        return 0;
    }

    sort(X.begin(), X.end());
    for(int i = 0; i < M - 1; i++){
        dist[i] = X[i + 1] - X[i];
    }
    sort(dist.begin(), dist.end());
    ll ans = 0;
    for(int i = 0; i < M - N + 1; i++){
        ans += dist[i];
    }
    cout << ans << endl;
    return 0;
}






// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int  A,B;
    cin >> A >> B;
    bool OK = false;
    if (A < B) swap(A,B);
    if (A == B)  {
        OK = true;
    } else {
        int d = abs(A-B);
        int left = 16 - (A+B);
        if (left < d * 2 - (left % 2 == 1 ? 1 : 0)) OK = false;
        else OK = true;
    }
    if (OK) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

n=ip()
city=[]
score=[]
for i in range(n):
    s,p=inpstr()
    city.append([s,int(p),i+1])
city.sort(key=lambda e:e[0])
city.sort(key=lambda e:(e[0],-e[1]),reverse=False)
for i in range(n):print(city[i][2])


Measured memory_bytes: 3064
/*This is the solution from Ling2Feng1,
  no matter AC or not.
  OJ:AtCoder
  ProblemID:ARC087A
  Date:2017/12/16
*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>
using namespace std;
int n,ans;
int a[100005];
map<int,int> cnt;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];cnt[a[i]]++;
	}
	for(int i=0;i<n;i++){
		if(cnt[a[i]]!=a[i]){
			ans++;cnt[a[i]]--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#define N 1000000
main()
{
  int i,j,k,n,v,A[N],cnt,m;
  scanf("%d",&n);
  int G[12];
  for(i = 0; i < n; i++) scanf("%d",&A[i]);
 
  i = 0;
  G[i] = 1;
  m = 1;
 
  while (3 * G[m-1] + 1 < n) {
    G[m] = 3 * G[m-1] + 1;
    m++;
  }
 
  for (i = 0; i < m / 2; i++) {
    v = G[i];
    G[i] = G[m-1-i];
    G[m-1-i] = v;
  }
 
 
  printf("%d\n",m);
  cnt = 0;
 
  for(i = 0; i < m; i++){
    for(j = G[i]; j < n; j++){
      v = A[j];
      k = j - G[i];
      while(k >= 0 && A[k] > v){
    A[k+G[i]] = A[k];
    k = k - G[i];
    cnt++;
      }
      A[k+G[i]] = v;
    }
  }
 
  for (i = 0; i < m; i++) {
    if (i != m - 1) printf("%d ", G[i]);
    else printf("%d\n", G[i]);
  }
 
    printf("%d\n",cnt);
 
    for(i = 0; i < n; i++)printf("%d\n",A[i]);
    return 0;
}

Measured memory_bytes: 4504
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    int k,a,b;

    scanf("%d",&k);

    scanf("%d %d",&a,&b);

    int s = 0;

    while(1)
    {
        s = s+ k;
        

        if(a<=s && s<=b)
        {
            printf("OK\n");
            break;
        }

        if(b < s )
        {
            printf("NG\n");
            break;
        }

    }

    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 500010
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main(){
	fast;
	int x;
	cin>>x;
	if(x<600)	cout<<8;
	else if(x<800)	cout<<7;
	else if(x<1000)	cout<<6;
	else if(x<1200)	cout<<5;
	else if(x<1400)	cout<<4;
	else if(x<1600)	cout<<3;
	else if(x<1800)	cout<<2;
	else if(x<2000)	cout<<1;
	//cout<<"Case #"<<x<<": "<<y<<endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
	int n,i,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0)
			printf(" %d",i);
		else{
			while(x){
				if(x%10==3){
					printf(" %d",i);
					break;
				}
				x/=10;
			}
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d%d%d", &a, &b, &c);
  if (a == b && b != c){
    printf("Yes\n");
  }else if (b == c && c != a){
    printf("Yes\n");
  }else if (c == a && a != b){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

const int N = 200;

int n, m, r;
ll ans = INF;
vector<pair<ll, ll>> conn[N];
vector<ll> dist[N];

void dijkstra(int v) { 
    vector<ll> d(n, INF);
    vector<ll> u(n, false);
    d[v] = 0;
    
    for (int i = 0; i < n; ++i) {
        int c = -1;
        for (int j = 0; j < n; ++j) {
            if ((c == -1 || d[j] < d[c]) && !u[j])
                c = j;
        }
        
        // cout << v << ' ' << c << '\n';
        u[c] = true;
        for (auto edge : conn[c]) {
            ll to = edge.first, len = edge.second;
            if (d[c] + len < d[to])
                d[to] = d[c] + len;
        }
    }

    // for (int i = 0; i < n; ++i) {
        // cout << "DIST: " << v << ' ' << i << ' ' << d[i] << '\n';
    // }
    dist[v] = d;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> r;

    vector<int> req(r);
    for (auto& i : req) {
        cin >> i;
        --i;
    }
    sort(req.begin(), req.end());

    for (int i = 0; i < m; ++i) {
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        conn[a].push_back({b, c});
        conn[b].push_back({a, c});
    }

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

    do {
        ll tmp = 0;
        for (int i = 1; i < r; ++i) {
            // cout << req[i] << ' ' << req[i - 1] << ' ' << dist[req[i]][req[i - 1]] << '\n';
            tmp += dist[req[i]][req[i - 1]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(req.begin(), req.end()));
    
    cout << ans;
}


Measured memory_bytes: 4596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

        public static string sousa(string str) {
            int renzoku = 0;
            char ch = str[0];
            StringBuilder resultstr = new StringBuilder();
            for (int i = 1; i < str.Length; i++) {
                if (str[i] == ch) {
                    renzoku++;
                }
                else {
                    resultstr.Append(renzoku+1);
                    resultstr.Append(ch);
                    ch = str[i];
                    renzoku = 0;
                }
            }
            resultstr.Append(renzoku+1);
            resultstr.Append(ch);
            return resultstr.ToString();
        }


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = int.Parse(line);
                if(n==0){break;}

                string str = Console.ReadLine();
                for (int i = 1; i <= n; i++) {
                    str = sousa(str);
                }
                Console.WriteLine(str);
            }
        }

        
    }



    
}

Measured memory_bytes: 6164
#include <stdio.h>

main(){
    int N,a,b,c,i;


    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d %d %d",&a,&b,&c);
        if(a*a==b*b+c*c || b*b==c*c+a*a || c*c==a*a+b*b)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, T;
		N = sc.nextInt();
		T = sc.nextInt();
		int c[] = new int[N];
		int t[] = new int[N];
		int ans = 1001;
		for (int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
			if (t[i] <= T && ans > c[i]) {
				ans = c[i];
			}
		}
		sc.close();
		if (ans == 1001) {
			System.out.println("TLE");
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
  private static final long INF = 1_000_000_000_000_000_000L;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<List<Dst>> from = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      from.add(new ArrayList<>());
    }
    for (int i = 0; i < N-1; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      a--;
      b--;
      int c = sc.nextInt();
      from.get(a).add(new Dst(b,c));
      from.get(b).add(new Dst(a,c));
    }

    int Q = sc.nextInt();
    int K = sc.nextInt();
    K--;
    
    PriorityQueue<Dst> pq = new PriorityQueue<>((a,b)->{
      if (a.cost == b.cost) {
        return 0;
      }
      return a.cost > b.cost ? 1 : -1;
    });
    long[] cost = new long[N];
    Arrays.fill(cost, INF);
    
    pq.offer(new Dst(K,0));
    while (!pq.isEmpty()) {
      Dst now = null;
      while (!pq.isEmpty()) {
        now = pq.poll();
        if (cost[now.to] > 0) {
          cost[now.to] = -now.cost;
          break;
        }
      }
      if (now == null) break;
      
      for (Dst p : from.get(now.to)) {
        long newCost = now.cost+p.cost;
        if (cost[p.to] > 0 && newCost < cost[p.to]) {
          cost[p.to] = newCost;
          pq.offer(new Dst(p.to,newCost));
        }
      }
    }
      
    StringBuilder ans = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      x--;
      y--;
      ans.append(-(cost[x]+cost[y])).append('\n');
    }
    System.out.print(ans.toString());
  }
  private static class Dst {
    private final int to;
    private final long cost;
    Dst(int to, long cost) {
      this.to = to;
      this.cost = cost;
    }
  }
}

Measured memory_bytes: 173372
// Always have fun - aNONYMOUS //

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define mod 1e9+7
#define inf 1e18
#define pb push_back
#define mp make_pair
#define vll vector<ll>

int main(){
	IOS;
	ll t,n,i,j,k,ans;
	t=1;//cin >> t;
	while(t--){
		ans=0;
		cin >> n;
		ll x,y;
		cin>>x>>y;
		cout<<((n+x-1)/x)*y<<endl;
	}
	return 0;
}

Measured memory_bytes: 3612
n = int(input())
s = input()

ans = 0
for i in range(n):
  count = 0
  checked = []
  for item in s[:i]:
    if item not in checked:
      if item in s[i:]:
        count += 1
      checked.append(item)
  ans = max(ans, count)
  
print(ans)

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

int main(){
  int n,k;
  cin >> n >> k;
  //int a[n];
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a[i];
  //int b[n] ={0};
  //vector<int> b(n+1); //b[n+1]にしとくと便利。aと比較する時は末尾消す
  for(int x=0; x<k; x++){
    vector<int> b(n+1); //前のxの時の引きずらないように
    for(int i=0; i<n; i++){
      int l=max(0,i-a[i]);
      int r=min(i+a[i]+1,n);
      b[l]++;
      b[r]--;
    }
    for(int i=0; i<n; i++)
      b[i+1]+=b[i];
    b.pop_back();
    if(a==b)
      break;
    a=b; //vectorで配列宣言すると出来る
  }
  for(int i=0; i<n; i++) //a:1~nから0~n-1にしたのに添字変え忘れた
    cout << a[i] << '\t';
}

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

// S[pos] の右側に '+' を 入れる/入れない
string f(string S, int pos) {
    if (S.size() == pos+1)
        return S;

    return f(S.substr(0,pos+1)+"+"+S.substr(pos+1), pos+2) + "+" + f(S, pos+1);
}

// 数字と'+'を含む文字列を式とみて，計算結果を返す
long long eval(string S) {
    std::size_t pos;
    if( (pos = S.find("+")) != std::string::npos )
        return stoll(S.substr(0, pos)) + eval(S.substr(pos+1));
    else
        return stoll(S);
}

int main() {
    string S;
    cin >> S;
    cout << eval(f(S, 0));
}


Measured memory_bytes: 15360
a, b, c, d = map(int, input().split())

ans = 0
if b < c or d < a:
  ans = 0
elif a <= c and c <= b and b <= d:
  ans = b - c
elif a <= c and c <= d and d <= b:
  ans = d - c
elif c <= a and a <= b and b <= d:
  ans = b - a
else:
  ans = d - a
  
print(ans)

Measured memory_bytes: 3060
#include "iostream"
#include "vector"
#include "string"
#include <iomanip>
#include <algorithm>
#define rep(i,n) for (int i= 0; i < (n); ++i)
using ll = long long;
using namespace std;
const double PI = 3.14159265358979323846;


int A, W, T, R = 0;

void CheckStr(string S) {
	if (S.compare("AC")==0) {
		A++;
	}
	else if (S.compare("WA") == 0) {
		W++;
	}
	else if (S.compare("TLE") == 0) {
		T++;
	}
	else if (S.compare("RE") == 0) {
		R++;
	}
}

int main() {
	double N;
	string S;
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> S;

		CheckStr(S);
	}

	cout << "AC x " << A << endl;
	cout << "WA x " << W << endl;
	cout << "TLE x " << T << endl;
	cout << "RE x " << R << endl;

	return 0;

}

Measured memory_bytes: 3208
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
LL a[100000+20],miu[200000+20],k[200000+20];
LL sum,l; 

int main(){
	fastio;
	R(n);
	if(n==1){
		cout<<"YES"<<endl;
		return 0;
	}
	rb(i,1,n){
		R(a[i]);
		sum+=a[i];
	}
	if(sum%(1ll*n*(n+1)/2)){
		cout<<"NO"<<endl;
		return 0;
	}
	l=sum/(1ll*n*(n+1)/2);
	a[0]=a[n];
	rb(i,1,n){
		if(a[i-1]-a[i]+l<0||(a[i-1]-a[i]+l)%n!=0)
		{	
			cout<<"NO"<<endl;
		return 0;
		}
		k[i]=(a[i-1]-a[i]+l)/n;
	}
	rb(i,1,n)
		k[i+n]=k[i];
	int cnt=0;
	LL sumsum=0;
	rb(i,1,2*n){
		cnt+=k[i];
		sumsum+=cnt;
		miu[i]=sumsum;
//		cout<<miu[i]<<"_" ;
		if(i>n){
			cnt-=k[i-n];
			miu[i]-=k[i-n]*(n+1);
			sumsum-=k[i-n]*(n+1);
		}
//		cout<<miu[i]<<" "<<sumsum<<endl;;
	}
	rb(i,1,n){
		int is=n+i;
		if(i==n)
			is=n;
//		cout<<k[i]<<" "<<miu[is]<<endl;
		if(miu[is]!=a[i]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


Measured memory_bytes: 7552
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            int z = s-(i+j);
            if(z>=0 && z<=k) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 384
const Main = (input: string): void => {
	const [a, b] = input.split(' ') // スペース区切り
	const isOdd = (num: number): boolean => num % 2 == 0
	if (isOdd(a) || isOdd(b)) console.log("Even")
	else console.log("Odd")
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))



Measured memory_bytes: 9420
#include<bits/stdc++.h>
using namespace std;
#define INF = 2e9
#define LINF = 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

int main(){

    string s;
    getline(cin, s);

    rep(i, s.length()){
        if(s[i] >= 'a' && s[i] <= 'z')s[i] -= 'a'-'A';
        else if(s[i] >= 'A' && s[i] <= 'Z')s[i] += 'a'-'A';
    }

    cout << s << endl;

}


Measured memory_bytes: 3156
//https://atcoder.jp/contests/abc160/submissions/11279519

#include<iostream>
using namespace std;
int N,X,Y;
int cnt[2020];
main()
{
	cin>>N>>X>>Y;
	X--,Y--;
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			cnt[min(j-i,abs(X-i)+1+abs(Y-j))]++;
		}
	}
	for(int k=1;k<N;k++)cout<<cnt[k]<<endl;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
	int res = 1;

	while (b)
	{
		if (b & 1) res = (res * a);

		a = (a * a); 
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

#define N 200010
#define MOD 1000000007

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	int n;
	cin >> n;

	cout << ceil((n + 0.0)/ 2);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int m, n;
	int[][] a;
	int mx0, my0, cx0, cy0, gx, gy;

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			a=new int[n][m];
			for(int j=0; j<n; j++){
				for(int i=0; i<m; i++){
					a[j][i]=sc.nextInt();
					if(a[j][i]==2){
						// Éà
						cx0=i;
						cy0=j;
						a[j][i]=0;
					}else if(a[j][i]==3){
						// S[
						gx=i;
						gy=j;
						a[j][i]=0;
					}else if(a[j][i]==4){
						// l
						mx0=i;
						my0=j;
						a[j][i]=0;
					}
				}
			}
			solve();
		}
	}

	void solve(){
		PriorityQueue<P> que=new PriorityQueue<P>();
		boolean[][][][] visited=new boolean[m][n][m][n];
		int[][][][] d=new int[m][n][m][n];

		for(int k=0; k<m; k++){
			for(int j=0; j<n; j++){
				for(int i=0; i<m; i++){
					fill(d[k][j][i], INF);
				}
			}
		}

		que.add(new P(mx0, my0, cx0, cy0));
		visited[mx0][my0][cx0][cy0]=true;
		d[mx0][my0][cx0][cy0]=0;

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

		for(; !que.isEmpty();){
			P p=que.poll();
			if(d[p.mx][p.my][p.cx][p.cy]<p.d){
				continue;
			}
			for(int i=0; i<4; i++){
				P q=new P(p.mx+dx[i], p.my+dy[i], p.cx, p.cy);
				int push=0;
				// lªæÊOorÚ®sÂ
				if(q.mx<0||q.mx>=m||q.my<0||q.my>=n||a[q.my][q.mx]==1){
					continue;
				}
				// lÌÚ®æªubN
				if(q.mx==q.cx&&q.my==q.cy){
					q.cx+=dx[i];
					q.cy+=dy[i];
					push=1;
				}
				// ubNªæÊOorzusÂ
				if(q.cx<0||q.cx>=m||q.cy<0||q.cy>=n||a[q.cy][q.cx]==1){
					continue;
				}
				// KâµÄ¢È¢
				if(!visited[q.mx][q.my][q.cx][q.cy]){
					q.d=d[q.mx][q.my][q.cx][q.cy]=d[p.mx][p.my][p.cx][p.cy]
							+push;
					visited[q.mx][q.my][q.cx][q.cy]=true;
					que.offer(q);
				}
			}
		}

		int min=INF;
		for(int j=0; j<n; j++){
			for(int i=0; i<m; i++){
				min=min(min, d[i][j][gx][gy]);
			}
		}

		println(""+(min==INF?-1:min));

	}

	class P implements Comparable<P>{
		int mx, my, cx, cy;
		int d;

		P(int mx, int my, int cx, int cy){
			this.mx=mx;
			this.my=my;
			this.cx=cx;
			this.cy=cy;
		}

		@Override
		public int compareTo(P p){
			return d-p.d;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
using ll=long long;

int main(){
    long long  n;
    cin>>n;
    long long dec=1;
    for(long long i=2; i*i<=n; i++){
        if(n%i!=0)continue;
        dec=i;
    }
    
    long long  del=n/dec;
    string str=to_string(del);
    cout<<str.length()<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var c0, c1 string
	fmt.Scan(&c0, &c1)
	if c0[0] == c1[2] && c0[1] == c1[1] && c0[2] == c1[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d){
        cout << "Left" << endl;
    }else if(a+b < c + d){
        cout << "Right" << endl; 
    } else{
        cout << "Balanced" << endl;
    }


    return 0;
}

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

using namespace std;

#define DPRINTF(...) printf(__VA_ARGS__)
#define FOR0(i, n) for(int i=0;i<n;i++)
#define ALL(c) (begin(c)), (end(c))
#define fst(t) get<0>(t)
#define snd(t) get<1>(t)
#define thd(t) get<2>(t)

typedef tuple<int,int> P;
typedef long long ll;

int main(){
  //*
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  /*/
  /*/

  int C[3];
  FOR0(i, 3){
      cin >> C[i];
  }

  sort(C, C+3);

  if(C[0] == 5 && C[1] == 5 && C[2] == 7){
      cout << "YES" << endl;
  }else{
      cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			int n = Integer.parseInt(br.readLine());
			
			if(n == 0){
				break;
			}
			
			int[] score = new int[n];
			
			for(int i = 0; i < n; i++){
				score[i] = Integer.parseInt(br.readLine());
			}
			
			Arrays.sort(score);
			
			int sum = 0;
			for(int i = 1; i < n - 1; i++){
				sum += score[i];
			}
			
			System.out.println(sum/(n - 2));
		}
	}

}

Measured memory_bytes: 24372
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    D = i2nn()
    D.sort()
    a = D[(N//2)-1]
    b = D[N//2]
    print(b-a)

main()


Measured memory_bytes: 51948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int pnt[maxn],c[maxn];
int pd(int x){
  if(x!=pnt[x])pnt[x]=pd(pnt[x]);
  return pnt[x];
}
int x[maxn],y[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
  }
  ll ret = n*ll(n-1)/2;
  for(int i=1;i<=n;i++){
    pnt[i]=i;
    c[i]=1;
  }
  vector<ll>ans;
  for(int i=m-1;i>=0;i--){
    ans.push_back(ret);
    int fx=pd(x[i]);
    int fy=pd(y[i]);
    if(fx!=fy){
      pnt[fx]=fy;
      ret-=c[fx]*ll(c[fy]);
      c[fy]+=c[fx];
      c[fx]=0;
    }
  }
  for(int i=m-1;i>=0;i--){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3828
package main

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

func main() {
  //fmt.Print("Input :")
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  var h int
  var w int

  for {
    if sc.Scan() { h, _ = strconv.Atoi(sc.Text()) }
    if sc.Scan() { w, _ = strconv.Atoi(sc.Text()) }

    if h == 0 && w == 0 { break }
    for i := 0; i < h; i++ {
      for j := 0; j < w; j++ {
        if i == 0 || i == h-1 || j == 0 || j == w-1 {
          fmt.Printf("#")
        } else {
          fmt.Printf(".")
        }
      }
      fmt.Println()
    }
    fmt.Println()
  }
}



Measured memory_bytes: 1076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int A,B,M;
    cin>>A>>B>>M;
    ll a[A],b[B];
    ll mia=1LL<<60;
    ll mib=1LL<<60;
    rep(i,A){
        cin>>a[i];
        mia=min(mia,a[i]);
    }
    rep(i,B){
        cin>>b[i];
        mib=min(mib,b[i]);
    }
    int x[M],y[M],c[M];
    rep(i,M){
        cin>>x[i]>>y[i]>>c[i];
        x[i]--;
        y[i]--;
    }
    ll ans=1LL<<60;
    rep(i,M){
        ll tmp=a[x[i]]+b[y[i]]-c[i];
        ans=min(ans,tmp);
    }
    ans=min(ans,mia+mib);

    cout<<ans<<endl;

}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
using mii = map<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
// int ans;

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

    int idx = 0;
    rep(i, N) {
        int a; cin >> a;
        if (a == idx + 1) idx++;
    }

    if (idx == 0) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << N - idx << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
int n,x[N],y[N],fa[N],sz[N];
map<int,int>X,Y,cx[N],cy[N];
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
    scanf("%d",&n);
    int fx,fy;
    for(int i=1;i<=n;i++)
	{
        fa[i]=i;
        sz[i]=1;
        scanf("%d%d",&x[i],&y[i]);
        if(!X.count(x[i]))X[x[i]]=i;
        fx=find(X[x[i]]);
        if(!Y.count(y[i]))Y[y[i]]=i;
        fy=find(Y[y[i]]);
        if(fx!=fy)
		{
            if(sz[fx]<sz[fy])swap(fx,fy);
            fa[fy]=fx;
            sz[fx]+=sz[fy];
            X[x[i]]=fx;
            Y[y[i]]=fx;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
	{
        fx=find(X[x[i]]);
        cx[fx][x[i]]=1;
        cy[fx][y[i]]=1;
    }
    for(int i=1;i<=n;i++)
        if(fa[i]==i)
            ans=ans+1ll*cx[i].size()*cy[i].size()-sz[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20608
import numpy as np

N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = input().split()
    ls.append(int(l)-1)
    rs.append(int(r)-1)

arr = np.zeros(N, np.int)
# flag = False
# for i in range(N):
#     if S[i] == 'A':
#         flag = True
#     elif S[i] == 'C' and flag:
#         arr[i - 1] = 1
#     else:
#         flag = False
for i, (a, c) in enumerate(zip(S, S[1:])):
    if a == 'A' and c == 'C':
        arr[i] = 1

cum = np.cumsum(arr)

for l, r in zip(ls, rs):
    if l == 0:
        print(cum[r-1])
    else:
        print(cum[r-1] - cum[l-1])


Measured memory_bytes: 22568
#include<stdio.h>
void main(){
	int x,y,i;
	for(i=0;i<=3000;i++)
	{
		scanf("%d %d",&x,&y);
		
		if(x<y)
		printf("%d %d\n",x,y);
		
		else if(x==0&&y==0)break;
		else printf("%d %d\n",y,x);
	}

}

Measured memory_bytes: 600
h,w=map(int,input().split())
list1=[[0 for i in range(w)] for j in range(h)]
list2=[[0 for i in range(w)] for j in range(h)]
dx=[-1,-1,-1,0,0,1,1,1]
dy=[-1,0,1,-1,1,-1,0,1]

for j in range(h):
    s=input()
    for i in range(w):
        list1[j][i]=s[i]
        
for j in range(h):
    for i in range(w):
        if list1[j][i] == '#':
            for k in range(8):
                xk=i+dx[k]
                yk=j+dy[k]
                if xk >=0 and xk < w and yk >= 0 and yk < h:
                    list2[yk][xk] +=1
                    
for j in range(h):
    for i in range(w):
        if list1[j][i] == '#':
            list2[j][i] ='#'
        else:
            list2[j][i]=str(list2[j][i])

for j in range(h):
    print("".join(list2[j]))

Measured memory_bytes: 3188
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    a = [0] * n
    b = [0] * (n // 100 + 1)

    for _ in range(q):
        com, x, y = (int(s) for s in readline().split())
        if com:
            x -= 1
            bx = x - x % 100 + 100
            by = y - y % 100
            if bx < by:
                s = sum(a[x:bx]) + sum(b[bx//100:by//100]) + sum(a[by:y])
            else:
                s = sum(a[x:y])
            print(s)
        else:
            x -= 1
            a[x] += y
            bx = x - x % 100
            b[x//100] = sum(a[bx:bx+100])


main()

Measured memory_bytes: 8932