akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n, a, b := bs.IntScan(), bs.IntScan(), bs.IntScan()

	sum := 0
	for i := 0; i <= n; i++ {
		s := sumDigits(i)
		if a <= s && s <= b {
			sum += i
		}
	}

	bw.Printf("%v\n", sum)
}

func sumDigits(n int) int {
	sum := 0
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
retu = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"

retu = retu.split(",")
retuint=[]
for i in retu :
	retuint.append(int(i))

index=input()

print(retuint[int(index)-1])

Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;

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

	int v[n];

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

	int gu[100001];
	int ki[100001];
	for(int i=0;i<100001;i++){
		gu[i]=0;
		ki[i]=0;
	}
	int firstmax=0;
	int firstsoeji=-1;
	int secondmax=0;
	int secondsoeji=-1;



	for(int i=0;i<n;i=i+2){
		gu[v[i]]++;
		if(gu[v[i]]>firstmax)
		{
			if(v[i]!=firstsoeji)
			{
			secondmax=firstmax;
			secondsoeji=firstsoeji;
			}
			firstmax=gu[v[i]];
			firstsoeji=v[i];
		}
		else{
			if(gu[v[i]]>secondmax)
			{
				secondmax=gu[v[i]];
				secondsoeji=v[i];
			}
		}
	}

	int afirstmax=0;
	int afirstsoeji=-1;
	int asecondmax=0;
	int asecondsoeji=-1;
	for(int i=1;i<n;i=i+2){
		ki[v[i]]++;
		if(ki[v[i]]>afirstmax)
		{
			if(v[i]!=afirstsoeji)
			{
			asecondmax=afirstmax;
			asecondsoeji=afirstsoeji;
			}
			afirstmax=ki[v[i]];
			afirstsoeji=v[i];
		}
		else{
			if(ki[v[i]]>asecondmax)
			{
				asecondmax=ki[v[i]];
				asecondsoeji=v[i];
			}
		}
	}

	if(firstsoeji!=afirstsoeji)
	{
		printf("%d", n-firstmax-afirstmax);
	}
	else
	{
		int kari;
		kari=max(firstmax+asecondmax, afirstmax+secondmax);
		printf("%d", n-kari);
	}




}


Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
 
int main(){
  int co=0,i;
  char a[100],b[100];
 
  scanf("%s",b);
  for(i=0;b[i]!='\0';i++) if('A'<=b[i] && b[i]<='Z') b[i]+=('a'-'A');
 
  while(1){
    scanf("%s",a);
    if(!strcmp(a,"END_OF_TEXT")) break;
    for(i=0;a[i]!='\0';i++) if('A'<=a[i] && a[i]<='Z') a[i]+=('a'-'A');
    if(!strcmp(a,b)) co++;
  }
  printf("%d\n",co);
  
  return 0;
}


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

using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

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


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, a[N], av;

ll dp[55][55][M];

ll solve(int i, int cnt, int sum){
    if(i == n)
        return (cnt != 0 && sum % cnt == 0 && sum / cnt == av);

    ll &ret = dp[i][cnt][sum];
    if(~ret)    return ret;

    return ret = solve(i + 1, cnt + 1, sum + a[i]) + solve(i + 1, cnt, sum);
}
int main(){
    init();

    cin >> n >> av;
    for(int i = 0;i < n;i++)    cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0);
}

Measured memory_bytes: 71168
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int N;
    long long sum=0;
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0){
            sum+=i;
        }
    }
    printf("%lld\n",sum);

    return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 1005;

char s[N];
bool x[2],y[2];

int main(){
    scanf("%s",s);
    int n = strlen(s);
    for(int i=0;i<n;i++){
        if(s[i]=='N') {
            y[1] = true;
        }
        if(s[i]=='S'){
            y[0] = true;
        }
        if(s[i]=='E'){
            x[1] = true;
        }
        if(s[i]=='W'){
            x[0]= true;
        }
    }
    bool o1 = false, o2 = false; 
    if((x[0] && x[1])||(!x[0] && !x[1])){
        o1 = true;
    }
    if((y[0] && y[1])||(!y[0] && !y[1])){
        o2 = true;
    }
    if(o1 && o2){
        puts("Yes");
    }
    else{
        puts("No");
    }
    return 0;   
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int T[N];
  int R[N];
  for(int i = 0; i < N; ++i){
    cin >> T[i];
    R[i] = T[i];
  }
  int M;
  cin >> M;
  int P[M], X[M];
  for(int j = 0; j < M; ++j){
    cin >> P[j] >> X[j];
    R[P[j]-1] = X[j];
    int sum = 0;
    for(int k = 0; k < N; ++k){
      sum += R[k];
    }
    R[P[j]-1] = T[P[j]-1];
    cout << sum << endl;
  }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

vector<vector<int> > g;
vector<int> a, b;
vector<bool> visited;

void dfs(int s = 0) {
    visited[s] = true;
    rep (i, g[s].size()) {
        if (!g[s][i]) continue;
        if (visited[i]) continue;
        dfs(i);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    g.resize(n), visited.resize(n);
    rep (i, n) g[i].resize(n);
    a.resize(m), b.resize(m);
    rep (i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    int res = 0;
    rep (i, m) {
        rep (j, n) visited[j] = false;
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        dfs();
        bool ok = true;
        rep (i, n) if (!visited[i]) ok = false;
        if (!ok) res++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
li = []
c = 0
for aa, bb in zip(a, b):
    if bb>aa:
        total += bb-aa
        c += 1
    elif bb<aa:
        li.append(aa-bb)
if c==0:
    print(0)
    exit()
li.sort(reverse=True)
for ans, i in enumerate(li):
    total -= i
    if total<=0:
        print(ans+c+1)
        break
else:
    print(-1)

Measured memory_bytes: 18356
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;

int main() {
    ios_base::sync_with_stdio(false);

    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans=0;
    if (a>=k) ans=k;
    else if (a+b>=k) ans=a;
    else ans=a-(k-(a+b));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
import Control.Monad
import Data.Array.IO
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)

readPair :: IO (Int,Int)
readPair = do
    [a,b] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    return (a,b)

main = do
    (n,q) <- readPair :: IO (Int,Int)
    s <- getLine
    e <- newArray (1,n) 0
    a <- accumACIndices 0 1 e s
    r <- replicateM q $ solve a
    mapM_ print r

accumACIndices :: Int -> Int -> IOArray Int Int -> String -> IO (IOArray Int Int)
accumACIndices _ n arr []           = return arr
accumACIndices c n arr ('A':'C':ls) = do
    let c' = c+1
    ar <- accumACIndices c' (n+2) arr ls
    writeArray ar n c'
    writeArray ar (n+1) c'
    return arr
accumACIndices c n arr (_:ls)       = do
    ar <- accumACIndices c (n+1) arr ls
    writeArray ar n c
    return arr

solve :: IOArray Int Int -> IO Int
solve arr = do
    (l,r) <- readPair
    l' <- if l > 1 then readArray arr (l-1) else return 0
    r' <- readArray arr (r-1)
    return (r' - l')


Measured memory_bytes: 17788
#include <stdio.h>

int main()
{
  int x, y, z;
  char line[1024];
  fgets(line, 1024, stdin);
  int a[100];
  int sp = 0;
  for (char *p=line; *p!='\n';p++) {
    if (*p=='+') {
      x = a[--sp];
      y = a[--sp];
      a[sp++] = x + y;
    } else if (*p=='-') {
      x = a[--sp];
      y = a[--sp];
      a[sp++] = -x + y;
    } else if (*p=='*') {
      x = a[--sp];
      y = a[--sp];
      a[sp++] = x * y;
    } else if (*p>='0'){
      for (z = 0; *p>='0'; p++) z = z * 10 + *p - '0';
      a[sp++] = z;
    }
  }
  printf("%d\n", a[--sp]);

  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int ans=2019;
long L,R;
main()
{
	cin>>L>>R;
	for(int i=L;i<=R&&i<=L+2019;i++)
	{
		for(int j=i+1;j<=R&&j<=i+2019;j++)
		{
			long I=i,J=j;
			if(I*J%2019<ans)ans=I*J%2019;
		}
	}
	cout<<ans<<endl;
}


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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans = 1e9;
    int r = 0;
    int now = 0;
    for(int i=0;i<n;i++){
        while(r<n && now<k){
            now += a[r];
            r++;
        }
        if(now >= k) ans = min(ans,r-i);
        now -= a[i];
    }
    if(ans==1e9)ans=0;
    cout << ans << endl;
    
}


Measured memory_bytes: 3600
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;
ll const MAX = 105;
vector<ll> a[5];

int main(){
	ll n, w;
	cin >> n >> w;
	ll min_w, sss;
	cin >> min_w >> sss;
	REP(i, 1, 4) {
		a[i].push_back(0);
	}
	a[1].push_back(sss);

	REP(i, 2, n) {
		ll x, y;
		cin >> x >> y;
		a[x + 1 - min_w].push_back(y);
	}
	REP(i, 1, 4) {
		sort(a[i].begin(), a[i].end());
		reverse(a[i].begin() + 1, a[i].end());
	}
	ll len[5];
	REP(i, 1, 4) {
		len[i] = a[i].size()-1;
	}
	REP(i, 1, 4) {
		REP(j, 1, len[i]) {
			a[i][j] += a[i][j - 1];
		}
	}
	ll ans = 0;
	REP(i, 0, len[1]) {
		REP(j, 0, len[2]) {
			REP(k, 0, len[3]) {
				ll wei = (min_w*i) + ((min_w + 1)*j) + (min_w + 2)*k;
				if (wei > w) break;
				ll l = (w - wei) / (min_w + 3);
				if (0 <= l) {
					l = min(l, len[4]);
					ll val = a[1][i] + a[2][j] + a[3][k] + a[4][l];
					ans = max(ans, val);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from collections import * #deque, Counter,OrderedDict,defaultdict
#set([]) 
import math
import copy
import itertools
import string
import sys
myread = lambda : map(int,raw_input().split())
def solver():
    nums = myread()
    nums += nums
    ans = nums[0] * nums[1] * nums[2]
    for i in xrange(3):
        A,B,C = nums[i], nums[i+1], nums[i+2]
        c, c2 = C / 2, C - (C/2)
        ans = min(ans, abs(A * B * (c-c2)))
    print ans

if __name__ == "__main__":
    solver()
    


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

const int N = 40000 + 7;

int a[N], b[N];



int32_t main() {
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string str; cin >> str;
    deque <char> s;
    for(auto ch: str) s.push_back(ch);
    int q, f = 0; cin >> q;
    for(int i = 1; i <= q; i++) {
        int typ; cin >> typ;
        if(typ == 1) f ^= 1;
        else {
            int fx; string ss; cin >> fx >> ss; fx--;
            fx ^= f;
            if(!fx) s.push_front(ss[0]);
            else s.push_back(ss[0]);
        }
    }

    string ans;
    while(!s.empty()) {
        ans.push_back(s.front());
        s.pop_front();
    }
    if(f) reverse(ans.begin(), ans.end());

    cout << ans << endl;
}


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

int main() {
	string s,t;cin>>s>>t;
  	sort(s.begin(),s.end());
  	sort(t.begin(),t.end());
  	reverse(t.begin(),t.end());
  	cout<<(s<t?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 2e5;
int n;
struct NOOD {
	int x, pos;
}a[maxn + 5];
int b[maxn + 5];
bool cmp(NOOD x, NOOD y){return x.x < y.x;}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i].x);
		a[i].pos = i;
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++) {
		if(i <= n / 2)b[a[i].pos] = a[n / 2 + 1].x;
		else b[a[i].pos] = a[n / 2].x;
	}
	for(int i = 1; i <= n; i++)printf("%d\n", b[i]);
	return 0;
}

Measured memory_bytes: 4480
void main() {
	auto N = readAs!ulong;
	auto A = readAs!(ulong[]);
	auto bits = new ulong[](64);
	foreach(v; A) {
		foreach(k; 0..64) {
			ulong n = 1UL << k;
			if(v & n) bits[k]++;
		}
	}
	ulong res;
	ulong MOD = 1000000007;
	foreach(i; 0..64) {
		ulong tmp = (1UL << i);
		tmp %= MOD;
		tmp *= bits[i];
		tmp %= MOD;
		tmp *= (N - bits[i]);
		tmp %= MOD;
		res += tmp;
		res %= MOD;
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int n, a[200005];

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

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	long long res = 0;
	for (int i = n; i >= 1; --i) {
		if (a[i] >= i) {
			return cout << -1 << endl, 0;
		}
		if (i < n && a[i] < a[i + 1] - 1) {
			return cout << -1 << endl, 0;
		}
		if (a[i] == a[i + 1] - 1) {
			continue;
		}
		res += a[i];
	}

	cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;
typedef long long ll;

string S;
ll dp[300][300][2];

ll number(int l, int r) {
  ll ret = 0;
  REP(i, l, r) {
    if('0' <= S[i] && S[i] <= '9') ret = ret * 10 + (S[i] - '0');
    else return -1;
  }
  return ret;
}

ll dfs(int l, int r, int mode, int depth) {

  if(dp[l][r][mode] > -INF * 2) return dp[l][r][mode];

  ll n = number(l, r);
  if(n >= 0) return n;

  ll ret = mode == 0 ? -INF : INF;
  REP(i, l, r) if(S[i] == '+' || S[i] == '-') {
    int nl = l, nr = r;
    while(1) {
      ll n1 = dfs(nl, i, mode, depth + 1);
      ll n2 = dfs(i + 1, nr, S[i] == '-' ? 1 - mode : mode, depth + 1);
      if(abs(n1) != INF && abs(n2) != INF) {
        if(mode == 0) {
          if(S[i] == '+') ret = max(ret, n1 + n2);
          if(S[i] == '-') ret = max(ret, n1 - n2);
        } else {
          if(S[i] == '+') ret = min(ret, n1 + n2);
          if(S[i] == '-') ret = min(ret, n1 - n2);
        }
      }
      if(S[nl] != '(' && S[nr - 1] != ')') break;
      if(S[nl] == '(') nl++;
      if(S[nr - 1] == ')') nr--;
    }
  }
  return dp[l][r][mode] = ret;
}

int main(void) {
  cin >> S;

  REP(i, 0, 201) REP(j, 0, 201) REP(k, 0, 2) dp[i][j][k] = -INF * 2;
  cout << dfs(0, S.size(), 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 4108
N = int(input())
A = [int(input()) for i in range(N)]

if A[0] != 0:
    print(-1)
    exit()

for i in range(N - 1):
    if A[i] < A[i + 1] and A[i + 1] - A[i] != 1:
        print(-1)
        exit()
    if A[i] > i + 1:
        print(-1)
        exit()

ans = 0
i = 1
old = 0
while i != N:
    if A[i] <= old:
        ans += old
    old = A[i]
    i += 1

print(ans + A[-1])


Measured memory_bytes: 11052
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

int main(){
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;

    int K_cnt = K;
    vector<int> L;
    REP(i, 0, N){
        if (S[i] == 'x'){
            continue;
        }
        --K_cnt;
        L.push_back(i);
        i += C;
        if (K_cnt == 0) break;
    }

    K_cnt = K;
    vector<int> R;
    REP(i, 0, N){
        if (S[N - 1 - i] == 'x'){
            continue;
        }
        --K_cnt;
        R.push_back(N - 1 - i);
        i += C;
        if (K_cnt == 0) break;
    }
    reverse(ALL(R));

    REP(i, 0, K){
        if (R[i] == L[i]){
            cout << R[i] + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3448
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

vector<bool> checked(200000, false);
vector<vector<int>> G(200000);
int cnt = 1;
vector<int> group;

void dfs(int now) {
    for(int v : G[now]) {
        if(v == now || checked[v]) continue;
        checked[v] = true;
        cnt++;
        dfs(v);
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int a, b;
    rep(i,m) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, n) {
        checked[i] = true;
        dfs(i);
        group.push_back(cnt);
        cnt = 1;
    }
    cout << MAX(group) << endl;
}

Measured memory_bytes: 24484
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        List<Integer> list = new ArrayList<Integer>();
        for(int k = 0; k< s.length();k++) {
          list.add(0);
        }
        boolean inR = true;
        int hotR = -1;
        int hotL = -1;
        int leftRange = 0;
        for(int k = 0; k < s.length();k++) {
          char cha = s.charAt(k);
          if(inR){
            if(cha == 'L') {
              inR = false;
              hotL = k;
              hotR = k-1;
            }
          } else {
            if(cha == 'R') {
              resolve(list,hotR,hotL,leftRange,k-1);
               leftRange=k;
               inR=true;
            }
          }
        }
        resolve(list,hotL,hotR,leftRange,s.length()-1);
        String str = list.stream().map(i->i.toString()).collect(Collectors.joining(" "));
        System.out.println(str);
    }
    
    private static void resolve(List<Integer> list, int hotL,int hotR, int leftRange, int rightRange) {

      int value = (rightRange-leftRange+1)/2;
      if((rightRange-leftRange+1)%2==0) {
        
        list.set(hotL, value);
        list.set(hotR, value);
      } else {
        if((hotR-leftRange) %2 ==0) {
          
          list.set(hotL, value);
          list.set(hotR, value+1);

        } else {
          list.set(hotL, value+1);
          list.set(hotR, value);
        }
        
      }
    }
}

Measured memory_bytes: 35868
n, x, y = map(int, input().split())
x -= 1
y -= 1


def shortest_path(i, j):
    res = min(abs(i-x)+abs(j-y)+1, j-i)
    return res


ans = [0]*(n-1)
for i in range(n-1):
    for j in range(i+1, n):
        d = shortest_path(i, j)
        ans[d-1] += 1

print(*ans, sep='\n')


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

int N;
#define MAX_N 2000
int C[2 * MAX_N], A[2 * MAX_N];
int P[2][MAX_N];
int F[2][MAX_N + 1][2 * MAX_N];
int D[MAX_N + 1][MAX_N + 1];

int main() {
  cin >> N;
  for(int i = 0; i < 2 * N; ++i) {
    char c; int a; cin >> c >> a; --a;
    C[i] = c == 'W'; A[i] = a; P[C[i]][A[i]] = i;
  }
  for(int i = 2 * N - 2; i >= 0; --i) {
    for(int c = 0; c < 2; ++c) for(int a = 0; a <= N; ++a) {
      F[c][a][i] = F[c][a][i + 1] + (c == C[i + 1] && a > A[i + 1]);
    }
  }
  for(int i = 0; i <= N; ++i) for(int j = 0; j <= N; ++j) {
    if(i == 0 && j == 0) continue;
    D[i][j] = 1e9;
    if(i > 0) D[i][j] = min(D[i][j],
      D[i - 1][j] + F[0][i - 1][P[0][i - 1]] + F[1][j][P[0][i - 1]]);
    if(j > 0) D[i][j] = min(D[i][j],
      D[i][j - 1] + F[1][j - 1][P[1][j - 1]] + F[0][i][P[1][j - 1]]);
  }
  cout << D[N][N] << endl;
  return 0;
}


Measured memory_bytes: 78464
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <cassert>

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main() {
    long a,b,c;
    cin >> a >> b >> c;

    if (a*b*c%2==0) {
        cout << 0 << endl;
    } else {
        cout << (a<b ? a* (b<c? b : c) : b* (a<c? a : c)) << endl;
    }
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()


def isOk(k):
    return k >= 0


ok, ng = max(h)//B+1, -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    c = mid
    for i in range(N):
        t = h[i]-mid*B
        if t > 0:
            c -= (t+A-B-1)//(A-B)
            if c < 0:
                break
    if isOk(c):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 50904
n, a, b = map(int, input().split())
a = min(a, b)
b = max(a, b)

ret = 0
if (b - a) & 1:
    if n - a < b - 1:
        ret = n - b + 1
        a += ret
        b = n
    else:
        ret = a
        a = 1
        b -= ret
print(ret + (b - a) // 2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 1005;//change it when needed
int n, m;
char a[N][N];
int dp[N][N];
void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    // memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
        if (a[i][0] == '#')break;
        dp[i][0] = 1;
    }
    for (int i = 0; i < m; i++) {
        if (a[0][i] == '#')break;
        dp[0][i] = 1;
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            if (a[i][j] == '#')continue;
            else {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }

    cout << dp[n - 1][m - 1] << endl;
}

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

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		int[] num = new int[n];
		char[] mark = new char[n];

		for (int i = 0; i < n; i++) {
			String s = scan.next();
			mark[i] = s.charAt(0);
			num[i] = s.charAt(1) - '0';
		}

		int[] a = new int[num.length];
		char[] m = new char[num.length];
		for (int i = 0; i < num.length; i++) {
			a[i] = num[i];
			m[i] = mark[i];
		}
		runBub(m, a);

		int[] a1 = new int[num.length];
		char[] m1 = new char[num.length];
		for (int i = 0; i < num.length; i++) {
			a1[i] = num[i];
			m1[i] = mark[i];
		}

		runSel(m1, a1);
		int ic;
		for (ic = 0; ic < mark.length; ic++)
			if (m1[ic] != m[ic])
				break;
		if (ic < mark.length)
			System.out.println("Not stable");
		else
			System.out.println("Stable");

		scan.close();
		System.exit(0);
	}

	private static void runSel(char[] m, int[] a) {
		for (int i = 0; i < a.length; i++) {
			int min = i;
			for (int j = i; j < a.length; j++)
				if (a[j] < a[min])
					min = j;
			if (min != i) {
				int tmp = a[i];
				a[i] = a[min];
				a[min] = tmp;
				char tmpc = m[i];
				m[i] = m[min];
				m[min] = tmpc;
			}
		}

		outResult(m, a);
	}

	private static void runBub(char[] m, int[] a) {
		for (int i = 0; i < a.length; i++)
			for (int j = a.length - 1; j > i; j--)
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					char tmpc = m[j];
					m[j] = m[j - 1];
					m[j - 1] = tmpc;
				}

		outResult(m, a);
		System.out.println("Stable");
	}

	private static void outResult(char[] m, int[] a) {
		for (int i = 0; i < m.length; i++)
			if (i == 0)
				System.out.print("" + m[i] + a[i]);
			else
				System.out.print(" " + m[i] + a[i]);
		System.out.println();

	}

}

Measured memory_bytes: 26260
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n;
	cin >> n;
	V<int> p(n), q(n);
	REP(i, n) {
		cin >> p[i];
	}	
	REP(i, n) {
		cin >> q[i];
	}

	V<int> r(n);
	REP(i, n) {
		r[i] = i + 1;
	}

	int a = 0, b = 0, k = 0;
	do {
		if (p == r) {
			a = k;
		}	
		if (q == r) {
			b = k;
		}
		k++;
	} while (next_permutation(ALL(r)));

	int ans = (a > b) ? (a - b) : (b - a);
	col(ans);
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>

void main()
{
  int i,j,n,m,votes=0,c=0,k=0;
  scanf("%d%d", &n, &m);
  int a[n];
  for(i=0; i<n; i++)
  {
    scanf("%d", &a[i]);
    votes+=a[i];
  }
  k=ceil(1.0*votes/(4*m));
  for(j=0; j<n; j++)
  {
    if(a[j]>=k)
    {
      c=c+1;
      if(c==m)
      {
        printf("Yes");
        break;
      }
    }
  }
    if(c<m)
      printf("No");
}

Measured memory_bytes: 128
use std::collections::HashMap;
use std::io;
use std::vec::Vec;

const MOD: i64 = 1000000007;

fn modinv(a: i64, n: i64) -> i64 {
    let mut t = (0, 1);
    let mut r = (n, a);
    while r.1 != 0 {
        t = (t.1, t.0 - (r.0 / r.1) * t.1);
        r = (r.1, r.0 % r.1);
    }
    while t.0 < 0 {
        t.0 += n
    }
    t.0
}

fn main() {
    let mut l = String::new();
    io::stdin().read_line(&mut l).expect("");
    let l = l
        .trim()
        .split(" ")
        .map(|x| x.parse().expect(""))
        .collect::<Vec<i64>>();
    let (n, mut m) = (l[0], l[1]);
    let mut h = HashMap::new();
    let mut i = 2;
    while i * i <= m {
        if m % i == 0 {
            h.insert(i, 1);
            m /= i;
            while m % i == 0 {
                if let Some(x) = h.get_mut(&i) {
                    *x = *x + 1
                }
                m /= i;
            }
        }
        if i % 2 == 0 {
            i += 1
        } else {
            i += 2
        }
    }
    if m > 1 {
        h.insert(m, 1);
    }
    let mut r = 1;
    for (_, &v) in h.iter() {
        let mut k = 1;
        for i in 0..v {
            k = k * (n + i) % MOD
        }
        let mut l = 1;
        for i in 2..v + 1 {
            l = (l * i) % MOD
        }
        r = r * (k * modinv(l, MOD) % MOD) % MOD
    }
    if r < 0 {
        r += MOD
    }
    println!("{}", r)
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
typedef long long ll;
using namespace std;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if((c-a-b)*(c-a-b)>4*a*b&&c>(a+b)) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <ll, int> P;

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

    int n, m;
    cin >> n >> m;

    vector <ll> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];

    sort(A.begin(), A.end(), greater<ll>());

    vector <P> BC(m);
    for (int i = 0; i < m; i++) {
        int b;
        ll c;
        cin >> b >> c;
        BC[i] = P(c, b);
    }

    sort(BC.begin(), BC.end(), greater<P>());

    ll ans = 0LL;
    int Aidx = 0;
    int Bidx = 0;
    for (int i = 0; i < n; i++) {
        if (Bidx >= m) {
            ans += A[Aidx];
            Aidx++;
        } else {
            if (A[Aidx] >= BC[Bidx].first) {
                ans += A[Aidx];
                Aidx++;
            } else {
                ans += BC[Bidx].first;
                BC[Bidx].second--;
                if (BC[Bidx].second == 0) Bidx++;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = min (n*a, b);
    cout << ans <<endl;
    return 0;
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N;
  cin >> N;

  VP points(N);
  REP(i, N) cin >> points[i].fst >> points[i].snd;
  map<PII, int> pointCost;

  int ans=0;

  SORT(points);

  REP(i, N){
    FOR(j, i+1, N){
      int p, q; //2点の差
      p = points[i].fst - points[j].fst;
      q = points[i].snd - points[j].snd;
      pointCost[{p,q}]++;
      ans = max(ans, pointCost[{p,q}]);
    }
  }

  cout << N-ans << endl;

  return 0;
}


Measured memory_bytes: 384
import fractions
n = int(input())
*a, = map(int, input().split())

left = [0]*(n+1)
for i in range(n):
    left[i+1] = fractions.gcd(left[i], a[i])
right = [0]*(n+1)
for i in range(n-1, -1, -1):
    right[i] = fractions.gcd(right[i+1], a[i])

ans = 0
for i in range(n):
    ans = max(ans, fractions.gcd(left[i], right[i+1]))

print(ans)


Measured memory_bytes: 16128
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

vector<int> V, W;
constexpr int MAXW = 100000;
vector< vector<int> > dp((1 << 9), vector<int>(MAXW, 0));

int dfs(int v, int w){
    if(w < 0){
        return -IINF;
    }else if(v < (1 << 9)){
        return dp[v][w];
    }
    return max(dfs(v >> 1, w), dfs(v >> 1, w - W[v]) + V[v]);
}

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

    int N;
    cin >> N;

    V.resize(N + 1);
    W.resize(N + 1);
    reps(i, N){
        cin >> V[i] >> W[i];
    }

    REP(i, 1, min(N + 1, 1 << 9)){
        rep(j, MAXW + 1){
            chmax(dp[i][j], dp[i >> 1][j]);
            if(j - 1 >= 0){
                chmax(dp[i][j], dp[i][j - 1]);
            }
            if(j - W[i] >= 0){
                chmax(dp[i][j], dp[i >> 1][j - W[i]] + V[i]);
            }
        }
    }

    int Q;
    cin >> Q;

    while(Q--){
        int v, L;
        cin >> v >> L;
        cout << dfs(v, L) << '\n';
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 205872
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<ll, ll>
#define pb push_back
#define int long long

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 15 * 1e4;

vector<pii> adj[N], s[N], t1, t2;
int n;

void dfs(int v, int p, ll lim){
	int u1 = -1, u2 = -1 , w1 = -1, w2 = -1;
	for(auto U : adj[v]){
		int u = U.F, w = U.S;
		if(u == p)continue;
		dfs(u, v, lim);
		if(u1 == -1)u1 = u, w1 = w;
		else u2 = u, w2 = w;
	}

	if(u1 == -1){
		s[v].pb({0, 0});
		return ;
	}

	int sz1 = s[u1].size(), sz2 = s[u2].size();

	t1.clear(); t2.clear();

	for(int ptr = 0,i=0; i<sz1; i++){
		int b = -1;
		while(ptr < sz2 && s[u1][i].S + s[u2][ptr].F + w1 + w2 <= lim){
			b = ptr; ptr++;
		}
		if(b == -1)continue;
		t1.pb({s[u1][i].F + w1, s[u2][b].S + w2});
	}

	for(int ptr = 0, i=0; i<sz2; i++){
		int b = -1;
		while(ptr < sz1 && s[u2][i].S + s[u1][ptr].F + w1 + w2 <= lim){
			b = ptr; ptr++;
		}
		if(b == -1)continue;
		t2.pb({s[u2][i].F + w2, s[u1][b].S + w1});
	}

	s[v].resize((int)t1.size() + (int)t2.size());

	merge(t1.begin(), t1.end(), t2.begin(), t2.end(), s[v].begin());

//	sort(s[v].begin(), s[v].end());
//	s[v].resize(unique(s[v].begin(), s[v].end()) - s[v].begin());

	return ;
}

bool check(ll lim){
	for(int i=1; i<=n; i++)
		s[i].clear();

	dfs(1, -1, lim);

	if((int)s[1].size() > 0)return true;
	return false;
}

int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;

	for(int i=1; i<n; i++){
		int a, v; cin >> a >> v;
		adj[i + 1].pb({a, v}); adj[a].pb({i + 1, v});
	}

	ll lo = -1, hi = 1LL * n * N;

	while(hi - lo > 1){
		ll mid = (lo + hi)/2;
		if(check(mid))hi = mid;
		else lo = mid;
	}


	cout << hi << endl;
	return 0;
}

Measured memory_bytes: 39700
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k,m;
    while(cin>>n>>k>>m,n+k+m){
        vi v(n);rep(i,n)v[i]=i+1;
        v.erase(v.begin()+m-1);
        int index=m-1;
        while(1){
            if(v.size()==1)break;
            index+=k-1;
            index%=v.size();
            v.erase(v.begin()+index);
        }
        cout<<v.front()<<endl;
    }
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n; cin>>n;
    long long a[n];
    rep(i,n){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(a,a+n);
    long long center=(n%2?a[n/2]:(a[n/2-1]+a[n/2])/2);
    long long ans=0;
    rep(i,n){
        ans+=abs(a[i]-center);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
N=int(input())
blue=[]
for a in range(N):
    b=input()
    blue.append(b)
M=int(input())
red=[]
for c in range(M):
    d=input()
    red.append(d)
nblue=[]
for a in blue:
    if a in nblue:
        pass
    else:
        nblue.append(a)
numbers=[]
for b in nblue:
    c=blue.count(b)-red.count(b)
    numbers.append(c)
if max(numbers)<=0:
    print(0)
else:
    print(max(numbers))
    

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

long long arr[200005],B[200005];

int main(){
    long long n,i,j,ans=0,b;
    cin>>n;
    for(int i=0; i<n; i++){
            cin>>arr[i];
            B[i] = arr[i] - i-1;
    }
    sort(B, B+n);
    b = B[n/2];
    for(i=0; i<n; i++)ans+= abs(arr[i]-(b+i+1));

    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, K;

struct X {
    int s;
    int a, b, c;
};
vector<X> V;
multiset<int> C;

void solve() {
    FOR(N) {
        C.insert(K + N * 2 + i);
    }
    V.resize(N);
    int j = K + N + N / 2;
    FOR(N) {
        if (j >= K + N * 2) {
            j -= N;
        }
        V[i] = X{0, i + K, j, 0};
        j++;
    }
    FOR(N) {
        V[i].s = V[i].a + V[i].b;
    }

    for (auto& x : V) {
        auto it = C.lb(x.s);
        if (it == C.end()) {
            cout << -1 << endl;
            return;
        }
        x.c = *it;
        C.erase(it);
    }
    for (auto& x : V) {
        cout << x.a << " " << x.b << " " << x.c << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;


    solve();
    return 0;
}


Measured memory_bytes: 11392
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int n,k; cin >> n >> k;
    int A[200200];
    rep(i,n){
        cin >> A[i];
    }
    rep(i,n-k){
        if(A[i] < A[i+k]) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int a,b;
    cin >> a >> b;
    FOR(x,10*b, 10*b+10){
        if(floor(0.08*(float)x) == a){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
# coding=utf-8
import math

x = 0
y = 0
direction = math.pi/2
while True:
    d, a = map(int, input().split(','))
    if d == 0 and a == 0:
        break
    x += d * math.cos(direction)
    y += d * math.sin(direction)
    direction -= a*math.pi/180
print('{0:.0f}'.format(math.modf(x)[1]))
print('{0:.0f}'.format(math.modf(y)[1]))

Measured memory_bytes: 5732
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  
  int input = 0;
  scanf("%d", &input);
  int change = input % 1000; 
  if (change > 0) {
    change = 1000 - change; 
    printf("%d\n", change);
  } else {
      printf("%d\n", change);
  }
  
  
  return 0; 
}

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

const int INF =1001001001;
const ll BIG = 1000000007;

int main(){
    ll k;
    int n;
    cin >>k>>n;
    vector<ll> a_v(n);
    rep(i,n) cin >>a_v[i];
    ll diff, max_a = -1;
    rep(i,n){
        if(i==n-1){
            diff = (k-a_v[n-1])+a_v[0];
        }else{
            diff = a_v[i+1] - a_v[i];
        }
        max_a = max(diff,max_a);
    }
    cout << k-max_a << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
//ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,res,c1,x,y,c2;
    ci>>n;
    ll a[n];
    for(ll i=0;i<n;i++) ci>>a[i];
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            mx+=(a[i]*a[j]);
        }
    }
    co<<mx;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	
	if(A+B > C+D)		printf("Left\n");
	else if(A+B == C+D)	printf("Balanced\n");
	else			printf("Right\n");
	
	return 0;
}

Measured memory_bytes: 128