akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.io.*;

public class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        int N = Integer.parseInt(br.readLine());
        String s = br.readLine();
        String[] b = new String[N];
        // b[0] = s;
        if(s.length() != 1){
            b = s.split(" ",0);
        }
        // System.out.println(b[0]);
        int[] X = new int[N];
        for(int i = 0;i<N;i++){
            X[i] = Integer.valueOf(b[i]);
        }
        int[] Y = X.clone();
        Arrays.sort(Y);
        for(int i = 0;i<N;i++){
            if(X[i]<Y[Y.length/2]){
                System.out.println(Y[Y.length/2]);
            }else{
                System.out.println(Y[Y.length/2-1]);
            }
        }
    }
}

Measured memory_bytes: 109220
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
vector<ll> tree[100010];
ll a[100010], b[100010], w[100010];
ll N, T, S, E;
ll parent[100010] = {};
bool path[100010] = {};
bool ok = true;
map<lpair, ll> is_once;
map<lpair, ll> weight;

void dfs(ll cur, ll par){
    parent[cur] = par;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
    }
}

void dfs2(ll cur, ll par){
    // if(tree[cur].size() == 1 && cur != S){
    //     // print(cur);
    //     return;
    // }
    vector<ll> edge;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        if(is_once[make_pair(cur, e)]) continue;
        ll ww = weight[make_pair(cur, e)];
        ww -= T * (ll)(tree[e].size());
        edge.push_back(ww);
    }
    sort(edge.begin(), edge.end());
    ll sz = edge.size();
    rep(i,0,sz){
        ll val = edge[i] - T * (i+1);
        if(cur == S) val += T;
        if(val <= 0) ok = false;
    }
    for(auto &e: tree[cur]){
        if(e == par) continue;
        if(is_once[make_pair(cur, e)]){
            // print2(cur, e);
            ll val = weight[make_pair(cur, e)] - T * (sz + 1);
            if(cur == S) val += T;
            if(val <= 0){
                ok = false;
            }
        }
    }
    for(auto &e : tree[cur]){
        if(e == par) continue;
        dfs2(e, cur);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> T >> S >> E;
    S--; E--; 
    // if(S == E){
    //     print("Yes");
    //     return 0;
    // }
    rep(i,0,N-1){
        cin >> a[i] >> b[i] >> w[i];
        a[i]--; b[i]--;
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
        weight[make_pair(a[i], b[i])] = w[i];
        weight[make_pair(b[i], a[i])] = w[i];
    }
    dfs(S, -1);
    ll p = E;
    while(p != -1){
        if(parent[p] == -1) break;
        is_once[make_pair(p, parent[p])]++;
        is_once[make_pair(parent[p], p)]++;
        // print2(p, parent[p]);
        p = parent[p];
        
    }
    dfs2(S, -1);
    if(ok){
        print("Yes");
    }else{
        print("No");
    }







    
}


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

//配列出力処理
void output(int a[], int n) {
  rep(i, n) {
    if (i > 0) printf(" ");  //要素間に空白を入れる
    printf("%d", a[i]);  //フォーマット指定子 %c char %d int10進数
  }
  printf("\n");
}

// Insertion Sort
void bubbleSort(int a[], int n) {
  int cnt = 0;
  bool flag = true;
  while (flag) {
    flag = false;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] < a[i - 1]) {
        int buf = a[i];
        a[i] = a[i - 1];
        a[i - 1] = buf;
        cnt++;
        flag = true;
      }
    }
  }
  output(a, n);
  cout << cnt << endl;
}

// O(n^2)
int main() {
  int n;
  int a[1000];
  cin >> n;
  rep(i, n) cin >> a[i];
  bubbleSort(a, n);
  return 0;
}



Measured memory_bytes: 3148
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <typeinfo>
#include <stdio.h>


using namespace std;

int main(){
    string a,b;
    cin >> a;
    cin >> b;
    a += b;
    int c = stoi(a);
    int d = sqrt(c);
    if(c == d*d){
        cout << "Yes" << endl;
        return 0; 
    }

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

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

#define member 2*100000

int main(void){

    //input
    int N;
    cin >> N;

    int A[member] = {0};
    A[0] = 0;
    for (int i = 1; i < N; i++){
        cin >> A[i];
    }

    int Boss[member] = {0};

    for(int i=1; i < N; i++){
        int boss = A[i]-1;
        Boss[boss] += 1;
    }

    //output
    rep(i, N){
        cout << Boss[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5188
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
def minus(n):
  return 128-n

s = input()
total = 0
new_s = s.replace("BC", "D")
new_s_list = list(new_s)
new_s_list.append("G")
tmp_start = 0
for i in range(len(new_s_list)):
  if new_s_list[i] in {'B', 'C', 'G'}:
    ppp = list(map(minus, map(ord, new_s_list[tmp_start:i])))
    bit = Bit(128)
    ans = 0
    for j, p in enumerate(ppp):
      bit.add(p, 1)
      ans += j + 1 - bit.sum(p)
    total += ans
    tmp_start = i+1

print(total)

Measured memory_bytes: 8292
use proconio::*;

fn run() {
    input! {
        s: String,
    }
    let c = s.bytes().next().unwrap();
    let ans = if c.is_ascii_lowercase() {
        'a'
    } else {
        'A'
    };
    println!("{}", ans);
}

fn main() {
    run();
}

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

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  bool can=false;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(4*i+7*j==n) can=true;
    }
  }

  if(can)std::cout << "Yes" << endl;
  else std::cout << "No" << endl;
  return 0;
}


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

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int[] difficultyArr = fs.nextIntArr(n);
		
		Arrays.sort(difficultyArr);
		
		int preMax = difficultyArr[n/2 - 1];
		int postMin = difficultyArr[n/2];
		
		System.out.println(postMin - preMax);
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 34736
N = int(input())
S = input()
ans = 0
for i in range(1,len(S)):
    l = []
    r = []
    for k in range(0,i):
        l.append(S[k])
    for k in range(i,len(S)):
        r.append(S[k])
    count = 0
    for item in set(l):
        if item in r:
            count += 1
    if ans < count:
        ans = count
    count = 0
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pro{
  char name[100];
  int z;
}P;

P Q[LEN+1];
int head, tail, num;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1)%LEN;
  return x;
}

int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &num, &q);

  for ( i = 1; i <= num; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].z);
  }
  head = 1;
  tail = num +1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.z);
    u.z -= c;
    elaps += c;
    if(u.z > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
  return 0;
}



Measured memory_bytes: 11876
from itertools import accumulate
# エラトステネスの篩
# is_prime := 1~nが素数か否か
# table := 2~nのうち素数
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


Q = int(input())
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

max_R = max(R)
is_prime, table = sieve(max_R)

check = [0]*(max_R + 1)
for i in range(0, max_R + 1):
    if (i % 2 == 1):
        if (is_prime[i-1] and is_prime[(i+1)//2-1]):
            check[i] = 1

# 累積和
check = [0] + check
check = list(accumulate(check))

for i in range(Q):
    print(check[R[i] + 1] - check[L[i]])

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

int s;
double w, h;

int main() {
  while (1) {
    if (scanf("%d,%lf,%lf", &s, &w, &h) != 3) return 0;
    if (w/h/h >= 25.0) printf("%d\n", s);
  }
}

Measured memory_bytes: 2660
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    let minv = min(a, min(c, b));
    let maxv = max(a, max(b, c));
    let mid = (a + b + c) - minv - maxv;

    println!("{}", (maxv - mid) + (mid - minv));
}


Measured memory_bytes: 4352
#

import sys
input=sys.stdin.readline

def main():
    A=int(input())
    B=int(input())
    C=int(input())
    X=int(input())
    cnt=0
    for i in range(A+1):
        for j in range(B+1):
            if 0<=X//50-10*i-2*j<=C:
                cnt+=1
    print(cnt)
    
if __name__=="__main__":
    main()


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

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

 int c = a * b;

 if(c % 2 == 0){
     cout << "Even" << endl;
 }
 else if(c % 2 == 1){
     cout << "Odd" << endl;
 }

}

Measured memory_bytes: 3560
import java.util.*;

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

        int a = s.nextInt();
        int b = s.nextInt();

        int amount = (a-1) * 2 + 1;
        int ans = b - (a-1);

        for (int i = 0; i < amount; i++) {
            System.out.print(ans + " ");
            ans++;
        }
    }
}


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

int p[200000];
int m[200000];
int hist[2019];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  p[0] = 1;
  for (int i=1; i<n; i++) p[i] = (p[i-1]*10) % 2019;
  m[0] = s[n-1]-'0';
  for (int i=1; i<n; i++) {
    m[i] = ((s[n-1-i]-'0')*p[i] + m[i-1])%2019;
  }
  rep(i, 2019) hist[i] = 0;
  rep(i, n) {hist[m[i]]++;}// cout << m[i] << endl;}
  int ans = hist[0];
  rep(i, 2019) if (hist[i] > 1) ans += hist[i]*(hist[i]-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5240
k = int(input())
d = int(input())

li = list(map(int,(list(str(k)))))
leng = len(li)
mod = 10**9+7

dp1 = [0 for _ in range(d)]
dp2 = [0 for _ in range(d)]

mm1 = li[0]
for i in range(mm1):
    dp2[i%d] += 1

for i in range(1,leng):
    for j in range(0,10):
        for l in range(d):
            #既にk以下であることが確定
            dp1[(l+j)%d] += dp2[l]
            dp1[(l+j)%d] %= mod

        #上からi桁目でk以下が確定
        if j<li[i]:
            dp1[(mm1+j)%d] += 1
            dp1[(mm1+j)%d] %= mod
    #print(dp1,dp2)
    mm1 = (mm1+li[i])%d
    dp2 = [dp1[i] for i in range(d)]
    dp1 = [0 for _ in range(d)]
dp2[sum(li)%d]+=1
print((dp2[0]-1)%mod)   








Measured memory_bytes: 42860
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

bool comp(pair < pair <string ,ll> , ll > a, pair < pair <string ,ll> , ll > b)
{
	if(((a.F.F)==(b.F.F)))
	return ((a.F.S)>(b.F.S));
	else
	return ((a.F.F)<(b.F.F));
	// and ((a.F.F)<(b.F.F)));
}

int main()
{
	IOS


	ll n;
	cin>>n;
	std::vector< pair < pair <string ,ll> , ll > > v;
	rep(i,n)
	{
		string s;
		cin>>s;
		ll x;
		cin>>x;
		v.pb(mp(mp(s,x),i+1));
	}
	sort(v.begin(), v.end(),comp);
	rep(i,n)
	{
		cout<<v[i].S<<endl;
	}

	

    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := map[int]int{}
	ok := true
	for i := 0; i < n; i++ {
		a := nextInt()
		if m[a] > 0 {
			ok = false
		}
		m[a]++
	}
	if ok {
		puts("YES")
	} else {
		puts("NO")
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 11776
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod) 繰り返し二乗法*/
ll modpow(ll a, ll n, ll mod){
    ll s[digits(n,2)],ans=1;
    rep(i,0,digits(n,2)){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;
    }
    return n?ans:1;
}
ll inv[200005],finv[200005];
void makeinv(ll n){
    inv[1]=1;finv[0]=finv[1]=1;
    rep(i,2,n+1){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        finv[i] = finv[i - 1] * inv[i] % MOD1;
    }
}
ll modfac(ll n, ll mod){
    ll x=1;
    rep(i,2,n+1){x*=i%mod;x%=mod;}
    return x;
}

int main(void){
    // char ;
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    ll pat[k];
    rrep(i,k,1){
        ll plus=modpow(k/i,n,MOD1);
        rep(j,2,k+1){
            if(i*j>k) break;
            plus-=pat[i*j-1];
        }
        if(plus<0){
            plus+=ABS(plus)/MOD1*MOD1;
        }
        while(plus<0) plus+=MOD1;
        pat[i-1]=plus;
        ans+=i*plus;
        ans%=MOD1;
        // printf("%lld ",ans);
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2484
x1, y1, x2, y2 = gets.split.map(&:to_i)
x = x2 - x1
y = y2 - y1
x3 = x2 - y
y3 = y2 + x
x4 = x3 - x
y4 = y3 - y
p x3, y3, x4, y4 


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int a[200005];//1为左括号，2为右括号
char s[200005];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    int t=0;
    if(s[1]=='W'||s[2*n]=='W')
    {
        printf("0\n");
        return 0;
    }
    for(int i=1;i<=2*n;i++)
    {
        if(s[i]=='B')
        {
            if(t%2==0)
            {
                a[i]=1;
                t++;
            }
            else
            {
                a[i]=0;
                t--;
            }
        }
        else if(s[i]=='W')
        {
            if(t%2==0)
            {
                a[i]=0;
                t--;
            }
            else a[i]=1,t++;
        }
    }
    if(t!=0)
    {
        printf("0\n");
        return 0;
    }
    t=0;
    ll ans=1;
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==1)
        {
            t++;
        }
        else
        {
            ans=(ans*t)%mod;
            t--;
        }
    }
    if(t!=0)
    {
        printf("0\n");
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        ans=ans*i%mod;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  int h[n];
  int dp[n+k];
  REP(i,n){
    scanf("%d",&h[i]);
    dp[i] = INF;
  }
  dp[0] = 0;
  REP(i,n){
    for(int j=1; j<=k; j++){
      dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout << dp[n-1] << endl;
  
}

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

using namespace std;

#define P(x,y) make_pair(x,y)
#define N 300000
#define lst(x) ((x)==1?n:(x)-1)
#define nxt(x) ((x)==n?1:(x)+1)

int n,a[N],b[N];
long long ans;
priority_queue<pair<int,int> > pq;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	for (int i=1;i<=n;++i){
		scanf("%d",b+i);
		pq.push(P(b[i],i));
	}
	while (!pq.empty()){
		int x=pq.top().second; pq.pop();
		int t=b[lst(x)]+b[nxt(x)];
		if (b[x]%t==a[x]%t){ans+=(b[x]-a[x])/t; b[x]=a[x];}
		else{
			ans+=b[x]/t; b[x]%=t;
			if (b[x]<a[x]){puts("-1"); return 0;}
			if (b[x]>=b[lst(x)]&&b[x]>=b[nxt(x)]){puts("-1"); return 0;}
			pq.push(P(b[x],x));
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 3700
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const a=input[1].split(' ').map(e=>{
    return e-0;
  });
  var next=1;
  a.forEach(e=>{
    if(next===e){
      next++;
    }
  });
  console.log(next===1?-1:N+1-next);


}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 43160
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    int c = 0;
    for(int i = 0; i < n; i++){
        if((double)a[i] >= (double)s / (4*m)){
            c++;
        }
    }
    if(c >= m ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
s,w = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

if s > w:
    print("safe")
else:
    print("unsafe")


Measured memory_bytes: 9088
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]        

def main():
    n, m = map(int, input().split())
    language = [[] for _ in range(m)]
    for i in range(n):
        kl = list(map(int, input().split()))
        for j in range(kl[0]):
            language[kl[j+1]-1].append(i)
    
    union = UnionFind(n)
    for lang in language:
        for i in range(1, len(lang)):
            union.union(lang[0], lang[i])
    
    ans = False
    for v in union.par:
        if v == -n:
            ans = True
    
    if ans:
        print("YES")
    else:
        print("NO")
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20724
using System;
using static System.Console;
using System.Linq;
using static System.Math;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] tmp = ReadLine().Split(' ').Select(decimal.Parse).ToArray();
            WriteLine((Abs(tmp[1] - tmp[0]) <= tmp[3] && Abs(tmp[2] - tmp[1]) <= tmp[3]) || Abs(tmp[2] - tmp[0]) <= tmp[3] ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11348
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,cnt=0;
string s,b;

int main()
{
	cin>>n>>s;
	rep(i,n)
	{
		if(s[i]=='(') cnt++;
		else cnt--;
		if(cnt<0)
		{
			b.pb('(');
			cnt++;
		}
	}
	cout<<b<<s;
	rep(i,cnt) cout<<')';
	cout<<endl;
	rt0;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);

    rep(i, N) cin >> a[i];

    //昇順にソート
    sort(a.begin(), a.end());

    vector<ll> sum(N+1, 0);
    for(int i = 1; i < N+1; i++){
        sum[i] = sum[i-1] + a[i-1];
    }

    int val = N-1;
    for(int i = N-1; i >= 1; i--){
        if(sum[i]*2 >= a[i]) val = i;
        else break;
    }

    int ans = N-val+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4812
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input().strip()
    count = 1
    for i, v in enumerate(S):
        if i == N - 1:
            break
        if S[i] != S[i + 1]:
            count += 1

    print(count)




if __name__ == '__main__':
    main()



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

const int N = 1e5+7;

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

    int n;
    cin>>n;

    vector<int> a(3*n);
    for (int i=0; i<a.size(); i++)  cin>>a[i];
    sort(a.begin(), a.end());

    long long ans = 0;
    for (int i=n; i<3*n; i+=2)  ans += a[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
from itertools import product

n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

cnt = 0
for pat in product([0, 1], repeat=n):
    for i in range(m):
        tmp = sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0]))
        if  tmp % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 9204
#include<bits/stdc++.h>
#include <math.h> 
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define modulo 998244353
#define endl "\n"
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define ff first //pair(p.first)
#define ss second

//v.back()->last element;
//myvector.clear();
/*
it = myvector.begin(); 
    myvector.erase(it);
    v.insert(v.begin()+i,num);     ////important for inserting a number at a particular position
    set<int>::iterator it;
    set<int>::reverse_iterator rit;*/
//memset(cache,-1,sizeof(cache));
//vector<int>::iterator ptr; 
//ll n,a,b,c;ṇ
//ternary operator max = (n1 > n2) ? n1 : n2; 
/* OUTPUT
cout<<"Case #"<<t<<": "<<a<<" "<<b;
cout<<endl;
reverse(a.begin(), a.end());
*/
vector<int>::iterator ptr;
int count =0;
int cache[10004];
//int dp[100005]={0};
int b[200005]={0};
int a[200005]={0};
int c[200005]={0};
int v[200005]={0};

bool pr(int n)  
{ 
    if(n==1)
        return false; 
    if(n==2)
        return true;
     
    if (n%2==0)
    {
        return false;
    }
      
  
    
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
          
       if(n%i==0)
        return false;
    }  
 
        return true;  
} 
int power(int x, unsigned int y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}
int dp[100005][3]={0};
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
   for (int i = 1; i <= n; ++i)
   {
       for (int j = 0; j < 3; ++j)
       {
           cin>>a[j];
       }
       dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[0];
       dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[1];
       dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[2];
   }
   int ans=0;
   for (int i = 0; i < 3; ++i)
   {
      ans=max(ans,dp[n][i]);
   }
   cout<<ans<<endl;

  
    return 0;
    
}


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

using namespace std;

int n, R(0), W(0);
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    for (auto i : s)
        if (i == 'R')
            R++;
        else
            W++;
    int r(0), w(0);
    for (int i = 0; i < R; i++)
        if (s[i] == 'W')
            w++;
    for (int i = R; i < n; i++)
        if (s[i] == 'R')
            r++;
    cout << max(w, r) << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define SIZE 200005

using namespace std;
typedef pair <int,int> P;

vector <int> vec[SIZE];
int par[SIZE],dep[SIZE];
int pr[SIZE],ng[SIZE];
bool use[SIZE];
int n;

int rev(int v)
{
	if(v>=n) return v-n;
	return v+n;
}
int dfs(int v,int d)
{
	dep[v]=d;
	int a=-1;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		int tg=dfs(to,d+1);
		if(tg!=-1)
		{
			if(a==-1) a=tg;
			else
			{
				//printf("%d %d\n",a,tg);
				pr[a]=tg;
				pr[tg]=a;
				a=-1;
			}
		}
	}
	if(a==-1) a=v;
	return a;
}
int LCA(int a,int b)
{
	while(a!=b)
	{
		if(dep[a]>dep[b]) swap(a,b);
		b=par[b];
	}
	return a;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<2*n;i++)
	{
		int p;
		scanf("%d",&p);p--;
		if(p<0) p=2*n;
		else if(i>=n) p+=n;
		par[i]=p;
		vec[p].push_back(i);
	}
	for(int i=0;i<n;i++)
	{
		if(vec[i].size()%2!=vec[i+n].size()%2)
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	memset(pr,-1,sizeof(pr));
	dfs(2*n,0);
	for(int i=0;i<2*n;i++)
	{
		if(!use[i]&&pr[i]!=-1)
		{
			use[i]=true;
			int now=i;
			do
			{
				use[now]=true;
				int to=pr[now];
				int p=LCA(now,to);
				//if(now==i) printf("%d %d : %d %d\n",now,to,p,i);
				for(int j=now;j!=p;j=par[j]) ng[j]=1;
				for(int j=to;j!=p;j=par[j]) ng[j]=-1;
				now=rev(to);
			}while(now!=i);
		}
	}
	puts("POSSIBLE");
	for(int i=0;i<n;i++)
	{
		int ret=ng[i];
		for(int j=0;j<vec[i].size();j++)
		{
			int to=vec[i][j];
			ret-=ng[to];
		}
		if(i!=0) printf(" ");
		printf("%d",ret);
	}puts("");
	return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string ans = s.substr(0,3);
    
    cout << ans << endl;
    
    
    



    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    int g[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            g[i][j] = 1e9;
        }
    }
    int a[m], b[m], c[m];
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }


    int ans = 0;
    for (int i = 0; i < m; i++) {
        if (g[a[i]][b[i]] != c[i]) {
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}


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

import static java.util.Comparator.*;


public class Main {
    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        FastReader s = new FastReader();
//        int t=s.nextInt();
////        StringBuilder ans=new StringBuilder();
//        while(t-->0) {
            int n=s.nextInt();
            StringBuilder ans=new StringBuilder();
            int count=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    for(int k=1;k<=n;k++)
                    {
                        count+=gcd(gcd(i,j),k);
                    }
                }
            }
            System.out.println(count);

//        }
    }

}


class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

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

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

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}
//3
//2 1 3
//3 3 6
//99995 9998900021 999890031

Measured memory_bytes: 32816
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;

		for (int i = 1; i <= n; i += 2) {
			int cnt = 0;
			for (int j = 1; j <= i; j++) {
				if (i % j == 0)
					cnt++;
			}
			if (cnt == 8) {
				ans++;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = b/a;
  if(ans > c) ans = c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define int long long
int fac[3010],inv[3010],S[3010][3010],mod,n,f[3010],ans;
int quickpow(int x,int y,int mod){
	int res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
int C(int x,int y){
	if(x<y||y<0)return 0;
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int sgn(int x){
	if(x%2==0)return 1;
	else return mod-1;
}
signed main(){
	scanf("%lld%lld",&n,&mod);
	S[0][0]=1;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=i;j++)
			S[i][j]=(j*S[i-1][j]%mod+S[i-1][j-1])%mod;
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2,mod);
	for(int i=n-1;i>=0;i--)
		inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++)
			(f[i]+=S[i+1][j+1]*quickpow(2,(n-i)*j,mod)%mod)%=mod;
		(f[i]*=quickpow(2,quickpow(2,n-i,mod-1),mod))%=mod;
	}
	for(int i=0;i<=n;i++)
		(ans+=sgn(i)*C(n,i)%mod*f[i]%mod)%=mod;
	printf("%lld\n",ans);
}

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

using namespace std;

string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.size() - 1; ++i) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
import bisect
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
for i in range(q):
    x = int(input())
    idx_s = bisect.bisect_left(s, x)
    idx_t = bisect.bisect_left(t, x)

    indices_s = []
    indices_t = []

    if idx_s == 0:
        indices_s.append(0)
    elif idx_s == a:
        indices_s.append(a-1)
    else:
        indices_s.append(idx_s)
        indices_s.append(idx_s-1)

    if idx_t == 0:
        indices_t.append(0)
    elif idx_t == b:
        indices_t.append(b-1)
    else:
        indices_t.append(idx_t)
        indices_t.append(idx_t-1)

    ans = []
    for i in indices_s:
        for j in indices_t:
            l, r = min(s[i], t[j]), max(s[i], t[j])
            if x < l:
                ans.append(r-x)
            elif l <= x and x < r:
                ans.append(min(r-l+(x-l), r-l+(r-x)))
            else:
                ans.append(x-l)
    print(min(ans))



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

int main() {
	ll x,k,d;
	cin >> x >> k >> d;
	ll ans = 0;
	x = abs(x);
	if (x/d>=k) ans = x - k*d;
	else {
		ll y = x/d;
		ll nokori = k - y;
		if (nokori%2) ans = abs(x - (y+1LL)*d);
		else ans = abs(x - y*d);
	}

	/*
	else {
		if (k%2==1) {
			x -= d;
			if (x<0) {
				cout << min(x+d,x) << endl;
				return 0;
			}
		}
		ll y = x / (2*d);
		ans = min(abs(x - 2LL*d*y), abs(x - 2LL*d*(y+1LL)));
	}*/

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
string a,b,c;
cin >> a >> b >> c;
cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  set<string> s;
  int n = S.length();
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  if (n == 2) {
    if (S[0] == S[1]) {
      cout << "1\n";
    } else {
      cout << "2\n";
    }
    return 0;
  }

  int dp[n + 1][2]{};
  dp[0][0] = 1;
  dp[0][1] = 0;
  if (S[0] == S[1]) {
    dp[1][0] = 1;
    dp[1][1] = 1;
  } else {
    dp[1][0] = 2;
    dp[1][1] = 1;
  }

  for (int i = 2; i < n; i++) {
    if(S[i] != S[i - 1]) {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; 
      dp[i][1] = max(dp[i - 2][0] + 1, dp[i - 1][1]);
    } else {
      dp[i][0] = max(dp[i - 2][0] + 1, dp[i - 1][1] + 1);
      dp[i][1] = max(dp[i - 2][0] + 1, dp[i - 1][1]);
    }
  }
  // for (int i = 0; i < n; i++) {
  //   cout << dp[i][0] << " " << dp[i][1] << "\n";
  // }
  cout << max(dp[n -1][0], dp[n - 1][1]) << "\n";
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    int ans=-INT_MAX;
    vector<int>f(n,0);
    vector<vector<int>>p(n,vector<int>(11));
    rep(i,n){
        rep(j,10){
            int x; cin>>x;
            f[i]+=x*pow(2,j);
        }
    }
    rep(i,n)rep(j,11){
        cin>>p[i][j];
    }
    for(int bit=1; bit<(1<<10); ++bit){
        int sum=0;
        rep(i,n){
            sum+=p[i][__builtin_popcount(f[i]&bit)];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, X: int, Y: int):
    D = [0 for _ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            if j <= X-1:
                d = j - i
            elif i >= Y-1:
                d = j - i
            else:
                d = min(j-i, abs(i-X+1)+abs(j-Y+1)+1)
            D[d] += 1
    for i in range(N-1):
        print(D[i+1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<stdio.h>

int search(int A[],int s,int key){
  int i=0;
  A[s] = key;
  while(A[i]!=key)i++;
  return i!=s;
}
int main(){
  int i,n,m[10000+1],q,key,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&m[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      if(search(m,n,key))sum++;
    }
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int n;
void dfs(string s){
	if(s.size()>=n){
		cout<<s<<endl;
		return;
	}
	char mx='a';
	for(int i=0;s[i];i++)
		mx=max(mx,s[i]);
	for(char c='a';c<=mx+1;c++)
		dfs(s+c);
}
int main(){
	cin>>n;
	dfs("a");
	return 0;
}

Measured memory_bytes: 1536
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<pair<int, int>> a(m);
	vector<int> col(w);
	vector<vector<pair<int, int>>> row(h);
	for (int i = 0; i < m; i++) {
		cin >> a[i].first >> a[i].second;
		a[i].first--;
		a[i].second--;
		col[a[i].second]++;
		row[a[i].first].push_back(a[i]);
	}
	multiset<int> all = { 0 };
	for (int i = 0; i < w; i++)
		if (col[i] != 0)
			all.insert(col[i]);
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (auto p : row[i]) {
			int x = p.second;
			all.erase(all.find(col[x]));
			all.insert(col[x] - 1);
		}
		ans = max(ans, (int)(*all.rbegin() + row[i].size()));
		for (auto p : row[i]) {
			int x = p.second;
			all.erase(all.find(col[x] - 1));
			all.insert(col[x]);
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

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


int main()
{
    int N;
    cin >> N;
    if(N==1) cout << "Hello World" << endl;
    else if(N==2) 
    {
    	int A, B;
    	cin >> A >> B;
    	cout << A + B << endl;
    }
    



	return 0;
}

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

int main(){
    int m, f, r;
    char grade;
    while(1){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        
        if(m == -1 || f == -1){
            grade = 'F';
        }else if(m + f >= 80){
            grade = 'A';
        }else if(m + f >= 65){
            grade = 'B';
        }else if(m + f >= 50){
            grade = 'C';
        }else if(m + f >= 30){
            if(r >= 50){
                grade = 'C';
            }else{
                grade = 'D';
            }
        }else{
            grade = 'F';
        }
        
        cout << grade << endl;        
    }
}



Measured memory_bytes: 3100
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;cin>>s;
  int n =s.size();
  vector<int>V(n,0);
  queue<int>R,L;
  rep(i,n-1){
    if(s[i]=='R'&&s[i+1]=='L')R.push(i);
    if(s[i+1]=='R'&&s[i]=='L')L.push(i);
  }
  L.push(n-1);
  int m1=-1;
  while(R.size()!=0){
    
    int m= L.front()-m1;
    int x= R.front();
    if(m%2==0){
      V[x]=m/2;
      V[x+1]=m/2;
    }else{
      if(L.front()%2==0){
        if(x%2==1){
          V[x]=m/2;V[x+1]=m/2+1;
        }else{
          V[x]=m/2+1;V[x+1]=m/2;
        }
      }else{
        if(x%2==1){
          V[x]=m/2+1;V[x+1]=m/2;
        }else{
          V[x]=m/2;V[x+1]=m/2+1;
        }
      }
    }
    m1=L.front();
    L.pop();
    R.pop();
  }
  
  rep(i,n)cout<<V.at(i)<<endl;
}

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

int main(){
    
    string S, T;
    int ans = 0;
    cin >> S >> T;
    
    for(int i = 0; i < S.size(); i++){
        if(S[i] == T[i]) ans++;
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n, a, b, ans = 0;
    cin >> n >> a >> b;
    for (int i = 0; i <= n; i++) {
        string s;
        s = to_string(i);
        int sum = 0;
        for (int j = 0; j < s.size(); j++) {
            sum += s[j] - '0';
        }
        if (sum >= a && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256