akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int N;
    cin >> N;
    int sum = 0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        while(a % 2 == 0){
            sum += 1;
            a = a/2;
        }
    }
    cout << sum <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

int main(void){
  string S;
  string T;
  int len1,len2;

  cin >> S >> T;

  len1 = S.length();
  if(len1 <= 10 && len1 >= 1){
    len2 = T.length();
    if(len2 == len1+1 && S == T.substr(0, len1)){
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";

  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#define N 36

typedef struct{
  char suit;
  int num;
}Cardinfo;

int isStable(Cardinfo [],Cardinfo [],int);
int output_status(int);

int main(){
  int i,j,n,minj,status;
  Cardinfo card[N],sorted[N],alt;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf(" %c%d",&card[i].suit,&card[i].num);

  // copy
  for(i=0;i<n;i++)sorted[i]=card[i];

  // Bubble Sort
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(sorted[j].num<sorted[j-1].num){
	alt=sorted[j];
	sorted[j]=sorted[j-1];
	sorted[j-1]=alt;
      }
    }
  }

  // output&copy
  status=isStable(card,sorted,n);
  for(i=0;i<n;i++){
    if(i==n-1)printf("%c%d\n",sorted[i].suit,sorted[i].num);
    else printf("%c%d ",sorted[i].suit,sorted[i].num);
    sorted[i]=card[i];
  }
  output_status(status);
  
  // Selection Sort
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(sorted[minj].num>sorted[j].num)minj=j;
    }
    if(i!=minj){
      alt=sorted[minj];
      sorted[minj]=sorted[i];
      sorted[i]=alt;
    }
  }

  status=isStable(card,sorted,n);
  for(i=0;i<n-1;i++){
    printf("%c%d ",sorted[i].suit,sorted[i].num);
  }
  printf("%c%d\n",sorted[i].suit,sorted[i].num);
  output_status(status);

  return 0;
}

int isStable(Cardinfo card[],Cardinfo sorted[],int n){
  int i,j,k,l;
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      for(k=0;k<n;k++)
	for(l=k+1;l<n;l++)
	  if(card[i].num==card[j].num && (card[i].num==sorted[l].num && card[i].suit==sorted[l].suit) && (card[j].num==sorted[k].num && card[j].suit==sorted[k].suit))
	    return 0;
  return 1;
}

int output_status(int status){
  if(status==0)printf("Not stable\n");
  else printf("Stable\n");
}
    

  
  

Measured memory_bytes: 608
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

string Change(int N){
  if (N == 0) return "0";
  else{
    string ans = "";
    while (N > 0){
      char now = N % 10 + '0';
      ans = now + ans;
      N /= 10;
    }
    return ans;
  }
}

int main(){
  int N, M; cin >> N >> M;
  int S[M]; char C[M];
  for (int i = 0; i < M; i++){
    cin >> S[i] >> C[i];
    S[i]--;
  }
  

  int Start = pow(10, N - 1), End = pow(10, N);
  if (N == 1) Start = 0;

  for (int i = Start; i < End; i++){
    string now = Change(i);
    bool flag = true;
    for (int j = 0; j < M; j++){
      if (now[S[j]] != C[j]) flag = false;
    }
    if (flag == true){
      cout << now << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;
fn main() {
    let mut string = String::new();
    io::stdin().read_line(&mut string).unwrap();
    let iter = string.split_whitespace();
    let mut vec: Vec<i32> = Vec::new();
    for item in iter {
        vec.push(item.to_string().parse::<i32>().unwrap());
    }

    vec.sort();

    let mut count: usize = 0;
    for item in &vec {
        count += 1;
        if count == vec.len() {
            print!("{}\n", item);
        } else {
            print!("{} ", item);
        }
    }
}


Measured memory_bytes: 1060
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
int main(){
	int n=0, a=0, b=0, c=0;
	int k=0;
	int ans=10000;
	scanf("%d %d %d %d\n",&n,&a,&b,&c);
	int take[8];
	int group[8];
	for(int i=0;i<n;i++){
		take[i]=10000;
		group[i]=0;
	}
	for(int i=0;i<n;i++){
		scanf("%d\n",&take[i]);
	}
	for(int i=0;i<100000;i++){
		k=i;
		int as=0, bs=0, cs=0;
		int ak=0, bk=0, ck=0;
		for(int j=0;j<8;j++){
			group[j]=k%4;
			if(group[j]==0){
				as++;
				ak=ak+take[j];
			}
			if(group[j]==1){
				bs++;
				bk=bk+take[j];
			}
			if(group[j]==2){
				cs++;
				ck=ck+take[j];
			}
			k=k/4;
		}
		if(as*bs*cs==0){
		}else{
			k=(as+bs+cs-3)*10+ze(a, ak)+ze(b, bk)+ze(c,ck);
			if(k<ans){
				ans=k;
			}
		}
	}
	printf("%d\n",ans); 
}

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

using namespace std;

int main() {
	int w;
	int a, b;
	cin >> w >> a >> b;
	int ans;
	if ((a <= b && b <= a + w) || (a <= b + w && b + w <= a + w)) {
		ans = 0;
	} else {
		if (a + w < b) {
			ans = b - (a + w); 
		} else {
			ans = a - (b + w);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

def read
  gets.split.map(&:to_i) + [gets.split.map(&:to_i)]
end

def solve(n, k, xs)
  min_ix = Rational(xs.index(1))
  l = min_ix/(k-1)
  r = (n-min_ix-1)/(k-1)
  (l+r).ceil
end

puts solve(*read)
# puts [
#   solve(4, 3, [2, 3, 1, 4] ) == 2,
#   solve(3, 3, [1, 2, 3] ) == 1,
#   solve(8, 3, [7, 3, 1, 8, 4, 6, 2, 5] )== 4
# ].all?


Measured memory_bytes: 8068
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << "No" << endl;
        return 0;
    }
    int s = 1;
    int m = 0;
    rep(i,30){
        if(s-1<=n){
            m = s-1;
        }
        s*=2;
    }
    
    //cerr << n << " " << m << endl;
    vector<pair<int,int> > v;
    
    for(int i=1;i<m;i++){
        v.PB(MP(i,i+1));
    }
    v.PB(MP(m,n+1));
    for(int i=1;i<m;i++){
        v.PB(MP(n+i,n+i+1));
    }
    if((n-m)%2==0){
        for(int i=m+1;i<=n;i+=2){
            int k = i^(i+1);
            v.PB(MP(k,i));
            v.PB(MP(k,i+1));
            v.PB(MP(i,i+n+1));
            v.PB(MP(i+1,i+n));
        }
    }else{
        if(n-m==1){
            cout << "No" << endl;
            return 0;
        }else{
            v.PB(MP(m+3,m+2));
            v.PB(MP(m+2,1));
            v.PB(MP(m+2,m+1));
            v.PB(MP(2,n+m+3));
            v.PB(MP(n+m+3,n+m+2));
            v.PB(MP(1,n+m+1));
            for(int i=m+4;i<=n;i+=2){
                int k = i^(i+1);
                v.PB(MP(k,i));
                v.PB(MP(k,i+1));
                v.PB(MP(i,i+n+1));
                v.PB(MP(i+1,i+n));
            }
        }
    }
    cout <<"Yes" << endl;
    for(auto x:v){
        cout << x.first << " " << x.second << endl;
    }
    return 0;
}

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

int main(){
	int a;
	int b;
	cin >> a;
	cin >> b;
	if (((a<=9)&&(a>=1))&&((b<=9)&&(b>=1))){
		cout << a*b;
	}
	else {
		cout << -1;
	}
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	a := nextFloat64()
	b := nextFloat64()
	n := nextFloat64()
	var calc func(float64) float64
	calc = func(x float64) float64 {
		tmp := math.Floor(a*x/b) - a*math.Floor(x/b)
		return tmp
	}
	log.Println(a)
	fmt.Println(calc(math.Min(b-1, n)))
}

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

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1860
a = int(input())
b = [a]
c = 1
while True:
  c += 1
  if a % 2 == 0:
    a /= 2
    if a in b:
      print(c)
      exit()
    else:
      b.append(a)
  else:
    a = a * 3 + 1
    if a in b:
      print(c)
      exit()
    else:
      b.append(a)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

int n,m;
void init(vector<int>& par,vector<int>& height,int n){
    REP(i,n){
        par[i]  = i;
        height[i] = 0;
    }
}
int root(vector<int>& par,vector<int>& height,int x){
    if(par[x]==x){
        return x;
    }else{
        par[x] = root(par,height,par[x]);
        return par[x];
    }
}
bool same(vector<int>& par,vector<int>& height,int x,int y){
    return root(par,height,x)==root(par,height,y);
}
void unite(vector<int>& par,vector<int>& height,int x,int y){
    x = root(par,height,x);
    y = root(par,height,y);
    if(x==y)return;
    if(height[x]<height[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(height[x]==height[y])height[x]++;
    }
}
int main(){
    cin >> n >> m;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> x(m);
    vector<int> y(m);
    
    vector<int> par(n);
    vector<int> height(n);
    REP(i,n){
        cin >> p[i];
        p[i]--;
        q[p[i]]=i;
    }
    REP(i,m){
        cin >> x[i] >> y[i];
        x[i]--;y[i]--;
    }
    init(par,height,n);
    
    REP(i,m){
        unite(par,height,x[i],y[i]);
    }
    int res = 0;
    Rep(i,n){
        if(same(par,height,par[q[i]],i))res++;
    }
    put(res);
    return 0;
}


Measured memory_bytes: 2560
S=input()
N=len(S)
mod=13
mod2=10**9+7

#上からi桁目までみて，あまりがjになるものの個数
dp=[[0]*mod for _ in range(N+1)]

dp[0][0]=1

for i in range(N):
    if S[i]!="?":
        for j in range(mod):
            dp[i+1][(10*j+int(S[i]))%mod]=dp[i][j]
    else:
        for j in range(mod):
            for k in range(10):
                dp[i+1][(10*j+k)%mod]+=dp[i][j]%mod2

print(dp[-1][5]%mod2)

Measured memory_bytes: 61788
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int[] list = new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }
        Arrays.sort(list);
        int count = 0;
        int start = 0;
        for (int i = 1; i < n; i++) {
            if (list[i] - list[start] > k) {
                count++;
                if (i == n - 1) {
                    count++;
                }
                start = i;
            } else if (i - start == c) {
                count++;
                start = i;
            }
        }
        if (start != n - 1) {
            count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 51404
result = []
while True:
    m, f, r = map(int, input().split())
    if (m, f, r) == (-1, -1, -1):
        break
    if m == -1 or f == -1:
        result.append('F')
        continue
    if m + f >= 80:
        result.append('A')
    if 80 > m + f >= 65:
        result.append('B')
    if 65 > m + f >= 50:
        result.append('C')
    if 50 > m + f >= 30:
        result.append(['D', 'C'][r >= 50])
    if 30 > m + f:
        result.append('F')
for r in result:
    print(r)

Measured memory_bytes: 7732
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    w = [0] * n
    e = [0] * n
    wc = 0
    ec = 0
    for i in range(n):
        if s[i] == "W":
            wc += 1
        if s[-i-1] == "E":
            ec += 1
        w[i] = wc
        e[-i-1] = ec
    m_c = 10 ** 10
    for i in range(n):
        m_c = min(m_c, w[i] + e[i] - 1)
    print(m_c)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 46684
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

int main() {
	ll n, h, w; cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


K = I()

ans = []
def fn(n):
    ns = str(n)
    tail = int(ns[-1])
    if tail > 0:
        yield int(ns + str(tail - 1))
    yield int(ns + ns[-1])
    if tail < 9:
        yield int(ns + str(tail + 1))


for i1 in range(1, 10):
    ans.append(i1)
    for i2 in fn(i1):
        ans.append(i2)
        for i3 in fn(i2):
            ans.append(i3)
            for i4 in fn(i3):
                ans.append(i4)
                for i5 in fn(i4):
                    ans.append(i5)
                    for i6 in fn(i5):
                        ans.append(i6)
                        for i7 in fn(i6):
                            ans.append(i7)
                            for i8 in fn(i7):
                                ans.append(i8)
                                for i9 in fn(i8):
                                    ans.append(i9)
                                    for i10 in fn(i9):
                                        ans.append(i10)


ans.sort()
print(ans[K - 1])


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

int main(){
  map<string, int>m = {
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1},
    {"SUN", 7}
  };
  string s;
  cin >> s;
  cout << m[s];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  
  sort(all(a),greater<ll>());
  ll ans=0;
  
  ans+=a[0];
  int now=1;
  int cnt=2;
  while(cnt<n){
    ans+=a[now];
    cnt++;
    if(cnt>=n) break;
    ans+=a[now];
    cnt++;
    now++;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4840
def Bottommost( string )
	src  = string.split(//).map{|i| i.to_i}
	while src.size > 1
		dest = Array.new
		0.upto( src.size - 2 ){ |n|
			dest << (src[ n ] + src [n + 1]) % 10
		}
		src = dest.dup
	end
	src[ 0 ]	
end

answers = Array.new
while line = $stdin.gets
	answers << Bottommost( line.chomp )
end
answers.each{ |a| puts a }


Measured memory_bytes: 6096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);

ll mpow(ll a, ll n, ll mod){
    ll res = 1;
    while (n > 0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll fac(int n, ll mod){
    if (n == 1 || n == 0) return 1;
    return n * fac(n - 1,mod) % mod;
}

ll solve(int n, int i, int k){
    ll x1, x2, x3, tmp,mod = 1e9+7;
    if (k == 0) x1 = 1ll;
    else{
        tmp = fac(k - 1 - i, mod) * fac(i,mod) % mod;
        x1 = fac(k -1,mod) * mpow(tmp, mod - 2, mod) % mod;
    }
    x3 = fac(n - k + 1,mod);
    tmp = fac(i + 1,mod) * fac(n - k - i,mod) % mod;
    x2 = x3 * mpow(tmp, mod - 2,mod) % mod;
    
    return x1 * x2 % mod;
}
int main(){
    int n, k; 
    sc(n) sc(k)
    for (int i = 0; i < k; i++){
        if (n - k - i < 0) cout << 0 << endl;
        else cout << solve(n, i, k) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e2 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
typedef pair<int, int> pii;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])

int n, a[N], b[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n - 1) cin >> b[i];
  a[1] = b[1], a[n] = b[n - 1];
  rep(i, 2, n - 1) a[i] = min(b[i - 1], b[i]);
  int sum = 0;
  rep(i, 1, n) sum += a[i];
  cout << sum << '\n';
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, k;

    cin >> n >> k;

    ll a = n%k;
    ll b = abs(a-k);

  	cout << min(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        x: Chars,
    }
    // let x = [1].iter().cloned().cycle().take(100000).map(|v| std::char::from_digit(v, 10).unwrap()).collect_vec();
    // let n = x.len();

    let ones = x.iter().filter(|c| **c == '1').count() as i64;

    let p = [ones + 1, ones.saturating_sub(1)];

    let mut rems = vec![vec![0i64; n]; 2];
    for i in 0..2 {
        if p[i] == 0 || p[i] == 1 {
            continue;
        }
        rems[i][n-1] = 1;
        for pos in (1..n).rev() {
            rems[i][pos-1] = 2i64 * rems[i][pos] % p[i];
        }
    }

    let mut sums = vec![0i64; 2];
    for i in 0..2 {
        for pos in 0..n {
            if x[pos] == '1' {
                sums[i] += rems[i][pos];
            }
        }
    }

    for i in 0..n {
        let (sel, sign) = if x[i] == '0' {
            (0, 1i64)
        } else {
            (1, -1i64)
        };
        if p[sel] == 0 {
            println!("0");
            continue;
        }
        let mut rem = (sums[sel] + sign * rems[sel][i]) % p[sel];
        let mut ans = 1;
        let mut div = rem.count_ones() as i64;
        while rem != 0 {
            rem %= div;
            div = rem.count_ones() as i64;
            ans += 1i64;
        }

        println!("{}", ans);
    }

}

Measured memory_bytes: 6236
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var p = new int[M];
            var S = new string[M];
            for (int i = 0; i < M; i++)
            {
                var input2 = Console.ReadLine().Split(' ').ToArray();
                p[i] = int.Parse(input2[0]);
                S[i] = input2[1];
            }

            var ac = 0;
            var wa = 0;
            var waa = new int[N];
            var flags = new bool[N];

            for (int i = 0; i < M; i++)
            {
                if (!flags[p[i] - 1])
                {
                    if (S[i] == "WA")
                    {
                        waa[p[i] - 1]++;
                    }
                    else if (S[i] == "AC")
                    {
                        wa += waa[p[i] - 1];
                        ac++;
                        flags[p[i] - 1] = true;
                    }
                }
            }
            Console.WriteLine($"{ac} {wa}");
        }
    }
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  string a = "SS";
  string b = "SW";
  string c = "WS";
  string d = "WW";
  for (int i = 1; i < n - 1; i++) {
    /**same**/
    if ((s[i] == 'o' && a[i] == 'S')
        || (s[i] == 'x' && a[i] == 'W')) {
      a += a[i - 1];
    }
    /**different**/
    else {
      a += (a[i - 1] == 'S'? 'W' : 'S');
    }
  }
  bool f = 1;
  if ((a.back() == 'S' && s.back() == 'o')
      || (a.back() == 'W' && s.back() == 'x')) {
    f &= (a[n - 2] == a[0]);
  } else {
    f &= (a[n - 2] != a[0]);
  }
  if ((a[0] == 'S' && s[0] == 'o')
      || (a[0] == 'W' && s[0] == 'x')) {
    f &= (a[n - 1] == a[1]);
  } else {
    f &= (a[n - 1] != a[1]);
  }
  if (f) {
    cout << a << endl;
    return 0;
  }
  f = 1;
  /**b**/
  for (int i = 1; i < n - 1; i++) {
    if ((s[i] == 'o' && b[i] == 'S')
        || (s[i] == 'x' && b[i] == 'W')) {
      b += b[i - 1];
    }
    else {
      b += (b[i - 1] == 'S'? 'W' : 'S');
    }
  }
  if ((b.back() == 'S' && s.back() == 'o')
      || (b.back() == 'W' && s.back() == 'x')) {
    f &= (b[n - 2] == b[0]);
  } else {
    f &= (b[n - 2] != b[0]);
  }
  if ((b[0] == 'S' && s[0] == 'o')
      || (b[0] == 'W' && s[0] == 'x')) {
    f &= (b[n - 1] == b[1]);
  } else {
    f &= (b[n - 1] != b[1]);
  }
  if (f) {
    cout << b << endl;
    return 0;
  }
  f = 1;
  /**c**/
  for (int i = 1; i < n - 1; i++) {
    if ((s[i] == 'o' && c[i] == 'S')
        || (s[i] == 'x' && c[i] == 'W')) {
      c += c[i - 1];
    }
    else {
      c += (c[i - 1] == 'S'? 'W' : 'S');
    }
  }
  if ((c.back() == 'S' && s.back() == 'o')
      || (c.back() == 'W' && s.back() == 'x')) {
    f &= (c[n - 2] == c[0]);
  } else {
    f &= (c[n - 2] != c[0]);
  }
  if ((c[0] == 'S' && s[0] == 'o')
      || (c[0] == 'W' && s[0] == 'x')) {
    f &= (c[n - 1] == c[1]);
  } else {
    f &= (c[n - 1] != c[1]);
  }
  if (f) {
    cout << c << endl;
    return 0;
  }
  f = 1;
  /**d**/
  for (int i = 1; i < n - 1; i++) {
    if ((s[i] == 'o' && d[i] == 'S')
        || (s[i] == 'x' && d[i] == 'W')) {
      d += d[i - 1];
    }
    else {
      d += (d[i - 1] == 'S'? 'W' : 'S');
    }
  }
  if ((d.back() == 'S' && s.back() == 'o')
      || (d.back() == 'W' && s.back() == 'x')) {
    f &= (d[n - 2] == d[0]);
  } else {
    f &= (d[n - 2] != d[0]);
  }
  if ((d[0] == 'S' && s[0] == 'o')
      || (d[0] == 'W' && s[0] == 'x')) {
    f &= (d[n - 1] == d[1]);
  } else {
    f &= (d[n - 1] != d[1]);
  }
  if (f) {
    cout << d << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 976
import java.util.*;
public class Main {
    static Set<Long> lunluns = new HashSet<>();
    static long ketas[] = {
            0L, 1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L,
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        for(int i=0; i<10; i++) {
            addLunlun(i, 1, i);
        }
        List<Long> ll = new ArrayList<>();
        for(Long l : lunluns) {
            ll.add(l);
        }
        Collections.sort(ll);
        System.out.println(ll.get(K-1));
    }

    public static void addLunlun(long target, int keta, int lead) {
        if(target>3234566667L) return;
        if(keta > 10) return;
        if(lead>0) {
            addLunlun(target + ketas[keta+1] * (lead-1), keta+1, lead-1);
        }
        addLunlun(target+ketas[keta+1]*lead, keta+1, lead);
        if(lead<9) {
            addLunlun(target+ketas[keta+1]*(lead+1), keta+1, lead+1);
        }
        if(0L!=target) lunluns.add(target);
    }
}


Measured memory_bytes: 36916
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int h,w,magic[10][10],ans=0;
  cin>>h>>w;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>magic[i][j];
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        magic[j][k]=min(magic[j][k],magic[j][i]+magic[i][k]);
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int a;
      cin>>a;
      if(a!=-1){
        ans+=magic[a][1];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  string s1,s2,s3; cin >> s1 >> s2 >> s3;
  char dif='A'-'a';
  printf ("%c%c%c\n" , s1 [0] + dif , s2 [0] + dif , s3 [0] + dif );

  return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

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

	N := getInt()
	a := make([]int, N)
	s := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		sum += a[i]
		s[i] = sum
	}

	ans := math.MaxInt64
	for i := 0; i < N-1; i++ {
		A := s[i]
		B := s[N-1] - s[i]
		diff := asub(A, B)
		if diff < ans {
			ans = diff
		}
		//		out(A, B, diff)
	}
	out(ans)

}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n, i,j ,k ,l;
    cin >> n;
    ll a[100005], dp[100005];
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(i=2;i<n;i++){
        dp[i] = min(dp[i-2] + abs(a[i] - a[i-2]), dp[i-1] + abs(a[i] - a[i-1]));
    }

    cout << dp[n-1] << '\n';
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    n++;
    vvi data(n, vi(n, 0));
    Rep(i, n) {
        Rep(j, n) {
            cin >> data[i][j];
        }
    }
    Rep(i, n) {
        Rep(j, n) {
            data[i][j] += data[i][j-1];
        }
    }

    Rep(j, n) {
        Rep(i, n) {
            data[i][j] += data[i-1][j];
        }
    }

    int ans = -INF;
    Rep(i, n) {
        Rep(j, n) {
            rep(k, i+1) {
                rep(l, j+1) {
                    int tmp = -INF;
                    if (i == k && j == l) {
                        continue;
                    } else if (i == k || j == l) {
                        tmp = data[i][j] - data[k][l];
                    } else {
                        tmp = data[i][j] - data[k][j]
                            - data[i][l] + data[k][l];
                    }
                    ans = max(ans, tmp);
                }
            }
        }
    }



    cout << ans << endl;

    return 0;
}

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

using namespace std;

string s;
long long k;

int main() {
	cin >> s;
	cin >> k;
	int pos = 0;
	while(pos < s.length() && s[pos] == '1') pos++;
	if(pos >= k) printf("1");
	else {
		if(pos == s.length()) printf("1");
		else printf("%c", s[pos]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  bool stz=false;
  bool goz=false;
  vector<int> p={};
  rep(i,n){
    if(i==0 && s[i]=='0') stz=true;
    if(i==0 && s[i]=='1') p.pb(i);
    if(i-1>=0 && s[i-1]=='0' && s[i]=='1') p.pb(i);
    if(i+1<n && s[i]=='1' && s[i+1]=='0') p.pb(i);
    if(i==n-1 && s[i]=='1') p.pb(i);
    if(i==n-1 && s[i]=='0') goz=true;
  }

  int m=p.size();
  if(m==0) {
    cout << n << endl;
    return 0;
  }
  int zr=m/2-1;
  if(stz) zr++;
  if(goz) zr++;

  if(zr<=k) {
    cout << n << endl;
    return 0;
  }

  int ans=0;
  if(stz) ans=max(ans,p[2*k-1]+1);
  if(goz) ans=max(ans,n-1-p[m-2*k]+1);
  rep(i,m){
    if(2*i+2*k+1>=m) break;
    ans=max(ans,p[2*i+2*k+1]-p[2*i]+1);
  }

  cout << ans << endl;
}


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

using namespace std;

main(){
	int a;
	cin >> a;
	int b=0;
	long long c=a;
	int d=a;
	long long s=1;
	while(a > b+1){
		b=b+1;
		s=c*s;
		c=c-1;
	}
	printf("%lld\n",s);
}




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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, ans = 0;
    long long k, x = 0;
    cin >> n >> m >> k;
    vector <int> a(n), b(m);
    vector <long long> pf(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        x += a[i];
        pf[i] = x;
        if (x <= k) ans = i + 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
        k -= b[i];
        int l = 0, r = n - 1;
        while (l <= r)
        {
            int md = (l + r) >> 1;
            if (pf[md] <= k)
                l = md + 1;
            else
                r = md - 1;
        }
        if (k >= 0) ans = max(ans, i + 1 + l);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
ll a[N];
void solve(){
    ll ans = 0;
    ll n, t;
    cin >> n >> t;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    a[n + 1] = 2ll * INF + 2313211;
    for(int i = 2; i <= n + 1; ++i) {
        ans += min(a[i] - a[i - 1], t);
    }
    cout << ans;
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;



int main() {
  string a, b, c; cin >> a >> b >> c;
  if ((a[a.size() - 1] == b[0]) && (b[b.size() - 1] == c[0])) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,n,max=0,summin=100000000,min=101,sum;
    scanf("%d",&n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(max<a[i])
            max=a[i];
        if(min>a[i])
            min=a[i];
    }
    for(i=min; i<=max; i++)
    {
        sum=0;
        for(j=0; j<n; j++)
        {
            sum=sum+(i-a[j])*(i-a[j]);
        }
        if(summin>sum)
            summin=sum;
    }
    printf("%d",summin);
    return 0;
}


Measured memory_bytes: 128
#%%
def count(a, k, n):
    l = []
    i, j, count = 0, n-1, 0
    while True:
        tmp = a[i] + a[j]
        if tmp >= k: 
            if j > 0:
                j -= 1
        elif tmp < k:
            l.append(n-j-1)
            count += n - j - 1
            i += 1
        if i >= n:
            break
        tmp = a[i] + a[j]
        if j == 0 and tmp >= k:
            l.append(n-j)
            count += n - j
            i += 1
        if i >= n:
            break
    return [count, l]

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 10**6, 1


while l - r > 1:
    mid = (l+r)//2
    if count(a, mid, n)[0] < m:
        l = mid
    elif count(a, mid, n)[0] > m:
        r = mid
    else :
        l = mid
        r = mid

ans = 0
if l == r:
    tmp = count(a, l, n)
    for i in range(n):
        ans += a[i] * tmp[1][i] * 2
else:
    p = count(a, l, n)
    q = count(a, r, n)
    check = -1
    for i in range(n):
        if p[1][i] != q[1][i]:
            check = i
            break
    ans += (a[i] + a[n - p[1][check] - 1]) * (m - p[0])
    tmp = count(a, l, n)
    for i in range(n):
        ans += a[i] * tmp[1][i] * 2
print(ans)



    


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

long long mod = 1000000007;
long long nr[509][509];
long long N, X, L[509], cnt[509];
long long dp[509][509];

void init() {
	for (int i = 0; i <= 500; i++) {
		for (int j = 0; j <= 500; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
}

long long ncr(int n, int r) {
	if (r < 0 || n < r) return 0;
	return nr[n - r][r];
}

int main() {
	cin >> N >> X;
	for (int i = 1; i <= N; i++) {
		cin >> L[i];
		cnt[L[i]]++;
	}

	init();

	// dp[個数][合計長さ]
	dp[0][0] = 1;
	for (int i = X; i >= 1; i--) {
		for (int j = X; j >= 0; j--) {
			for (int k = (X + 1) - j; k >= j; k--) {
				if (dp[j][k] == 0) continue;
				
				int cx = j, cy = k, ct = 0;
				while (true) {
					cx++; cy += i; ct++;
					if (cx + cy - 1 > X) break;
					dp[cx][cy] += dp[j][k] * ncr(cx, ct);
					dp[cx][cy] %= mod;
				}
			}
		}
		for (int j = X; j >= 0; j--) {
			for (int k = (X + 1) - j; k >= j; k--) {
				long long rev = k - (i - 1) * j;
				for (int l = 0; l < cnt[i]; l++) {
					dp[j][k] *= rev;
					dp[j][k] %= mod;
				}
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i <= X; i++) {
		for (int j = 0; j <= X; j++) {
			if (dp[i][j] == 0) continue;
			int rem = X - j - (i - 1);
			if ((X - j) % 2 == 0) ans += dp[i][j] * ncr(rem + i, rem);
			else ans -= dp[i][j] * ncr(rem + i, rem);
			ans += mod * mod;
			ans %= mod;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
int main(void){
    int m,f,r;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1)break;
        if(m==-1||f==-1){
            printf("F\n");
        }else if(m+f>=80){
            printf("A\n");
        }else if(m+f>=65){
            printf("B\n");
        }else if(m+f>=50){
            printf("C\n");
        }else if(m+f>=30&&r<50){
            printf("D\n");
        }else if(m+f>=30&&r>=50){
            printf("C\n");
        }else if(m+f<30){
            printf("F\n");
        }
    }
    return 0;
}


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

int main(){
	int n,m;
	cin>>n>>m;
	int a,b,map[51]={};
	for(int i=0;i<m;++i){
		cin>>a>>b;
		map[a]++;
		map[b]++;
	}
	for(int i=1;i<=n;++i)cout << map[i] << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n, m, X, Y, x[1100], y[1100];

int main() {
	cin >> n >> m >> X >> Y;
	for (int i = 0;i < n;i++)cin >> x[i];
	for (int i = 0;i < m;i++)cin >> y[i];
	sort(x, x + n);
	sort(y, y + m);
	for (int i = X+1;i <= Y;i++) {
		if (x[n - 1] < i && i <= y[0]) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	return 0;
}


Measured memory_bytes: 256
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                elif targ==0:
                    break
                elif s>e*w/100:
                    break
                elif  mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Measured memory_bytes: 74052
l, r = map(int,input().split())

lmod=l%2019
rmod=r%2019

if r-l>=2019:
    mini = 0
elif l <= 2019*(r//2019):
    mini = 0
else:
    mini = 10**9
    for i in range(lmod,rmod+1):
        for j in range(i+1,rmod+1):
            mini = min(mini,(i*j)%2019)
print(mini)

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

template <class T>
inline void read(T &x)
{
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x)
{
	static char buf[15], *tail = buf; 
	if (!x)
		putchar('0'); 
	else
	{
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

template <class T>
inline void tense(T &x, const T &y)
{
	if (x > y) x = y; 
}

const int B = 200000; 
const int MaxN = 4e5 + 5; 
const int INF = 0x3f3f3f3f; 

namespace SegmentTree
{
	const int MaxS = MaxN << 2; 

	#define lcc x << 1, l, mid
	#define rcc x << 1 | 1, mid + 1, r

	int val[MaxN], seg[MaxS]; 

	inline void upt(int x)
	{
		seg[x] = seg[x << 1] + seg[x << 1 | 1]; 
	}
	inline void build(int x, int l, int r, int *v)
	{
		if (l == r)
			return (void)(val[l] = v[l], seg[x] = !v[l]); 
		int mid = (l + r) >> 1; 
		build(lcc, v), build(rcc, v); 
		upt(x); 
	}

	inline void modify(int x, int l, int r, int p, int d)
	{
		if (l == r)
		{
			val[l] += d, seg[x] = !val[l]; 
			return; 
		}
		int mid = (l + r) >> 1; 
		if (p <= mid)
			modify(lcc, p, d); 
		else
			modify(rcc, p, d); 
		upt(x); 
	}
	inline int query(int x, int l, int r, int u, int v)
	{
		if (u <= l && r <= v)
			return seg[x]; 
		int mid = (l + r) >> 1, res = 0;
		if (u <= mid)
			res += query(lcc, u, v); 
		if (v > mid)
			res += query(rcc, u, v); 
		return res; 
	}
}

int L, R; 
int n, m; 
int a[MaxN], s[MaxN];  

inline void init()
{
	static int val[MaxN]; 
	for (int i = 1 + B; i <= n + B; ++i)
	{
		++val[i - s[i] + 1]; 
		--val[i + 1]; 
	}
	for (int i = L; i <= R; ++i)
		val[i] += val[i - 1]; 
	SegmentTree::build(1, L, R, val); 
}

inline void change(int x, int y)
{
	SegmentTree::modify(1, L, R, a[x] - s[a[x]] + 1, -1); 
	--s[a[x]], ++s[a[x] = y]; 
	SegmentTree::modify(1, L, R, a[x] - s[a[x]] + 1, +1); 
}

int main()
{
	read(n), read(m); 
	L = B - n, R = B + n; 
	for (int i = 1; i <= n; ++i)
	{
		read(a[i]), a[i] += B; 
		++s[a[i]]; 
	}
	init(); 

	while (m--)
	{
		int x, y;  
		read(x), read(y); 

		change(x, y + B); 
		putint(SegmentTree::query(1, L, R, 1 + B, n + B)); 
		putchar('\n'); 
	}

	return 0; 
}

Measured memory_bytes: 13184
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        mut a_vec: [usize; 3*n],
    }

    a_vec.sort();
    let mut vq = VecDeque::from(a_vec);

    let mut ans = 0;
    for i in 0..n {
        vq.pop_front();
        vq.pop_back();
        ans += vq.pop_back().unwrap();
    }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int temp;
  for(int i=0; i<N; i++){
    for(int j=N-1; j>i; j--){
      if(a.at(j) > a.at(j-1)){
        temp = a.at(j);
        a.at(j) = a.at(j-1);
        a.at(j-1) = temp;
      }else if(a.at(j) == a.at(j-1)){
        a.at(j) = 0;
      }
    }
  }
  int count=0;
  for(int i=0; i<N; i++){
    if(a.at(i) != 0){
      count++;
    }
  }
  cout << count;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
n = int(input())

sum = 0
for i in range(1,n+1):
  for j in range(i,n+1):
    for k in range(j,n+1):
#      print(i, j, k)
      if i ==j and i == k:
        sum += gcd(i, j, k)
      elif i == j or j == k or i == k:
        sum += gcd(i, j, k)*3
      else: 
        sum += gcd(i, j, k)*6
#      print(sum)
print(sum)


Measured memory_bytes: 9632
# -*- coding: utf-8 -*-

n = int(input())
a = []

a = list((map(int, input().split())))

cnt = 0
for i in range(1000000000000):
    flag = 0
    for j in a:
        if j%2 != 0:
            flag = 1
            break

    if flag == 1:
        cnt = i
        break

    for k in range(n):
        a[k] = a[k]/2

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  
 int a,b;
 cin >> a >> b;
 
 if(a < b)
    cout << "a < b" << endl;
 else if(a > b)
    cout << "a > b" << endl;
 else if(a == b)
    cout << "a == b" << endl;
    
  return 0;
}


Measured memory_bytes: 3076
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] h = new int[n];
        int[] dp = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        for (int i = 0; i < n; i++) {
            if (i + 1 < n) {
                dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(h[i] - h[i+1]));
            } 
            if (i + 2 < n) {
                dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(h[i] - h[i+2]));
            }
        }

        System.out.println(dp[n-1]);        
    }
}

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

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

    string N;
    cin >> N;

    int n = N.size();
    vvi dp(n + 1, vi(2, 0));

    rrep(i, 0, n) {
        int ni = int(N[i] - '0');

        bool carry;
        if (i != 0 && dp[i + 1][1] + ni == 5 && int(N[i - 1] - '0') >= 5) {
            carry = true;
        } else if (dp[i + 1][1] + ni <= 5) {
            carry = false;
        } else {
            carry = true;
        }

        if (carry) {
            dp[i][0] = dp[i + 1][0] + 10 - (dp[i + 1][1] + ni);
            dp[i][1] = 1;
        } else {
            dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + ni;
        }
    }

    cout << dp[0][0] + dp[0][1] << endl;
    return 0;
}

Measured memory_bytes: 55964