akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define LL long long
#define pa pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 100001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

bool v[N];
int l1, l2, l3, h1[N], h2[N], h3[N];

int main() {
	int n = read();
	int len = 1;
	for(; len <= n / 2; len <<= 1);
	if(len == n) {puts("No"); return 0;}
	puts("Yes");
	int ans = 0, s = 0;
	for(int i = 1; i <= n; i++) ans ^= i;
	if(ans == 0) {
		for(int i = 1; i < 2 * n; i++) put(i), putchar(' '), put(i + 1), puts("");
		return 0;
	} for(int i = 20; i >= 0; i--) if((1 << i) & ans){
		h1[++l1] = (1 << i), v[1 << i] = 1;
		if(ans ^ (1 << i)) h1[++l1] = (ans ^ (1 << i)), v[ans ^ (1 << i)] = 1;
		if(ans != 1) {
			if((1 << i) ^ 1) h2[++l2] = (1 << i) ^ 1, v[(1 << i) ^ 1] = 1;
			if(ans ^ (1 << i) ^ 1) h2[++l2] = ans ^ (1 << i) ^ 1, v[ans ^ (1 << i) ^ 1] = 1;
		} else {
			if((1 << i) ^ 2) h2[++l2] = (1 << i) ^ 2, v[(1 << i) ^ 2] = 1;
			if(ans ^ (1 << i) ^ 2) h2[++l2] = ans ^ (1 << i) ^ 2, v[ans ^ (1 << i) ^ 2] = 1;
		} break;
	} for(int i = 1; i <= n; i++) if(!v[i]) h3[++l3] = i;
	for(int i = 1; i < l2; i++) put(h2[i]), putchar(' '), put(h2[i + 1]), puts("");
	if(l2) put(h2[l2]), putchar(' '), put(h1[1]), puts("");
	for(int i = 1; i < l1; i++) put(h1[i]), putchar(' '), put(h1[i + 1]), puts("");
	if(l2) put(h1[l1]), putchar(' '), put(h2[1] + n), puts("");
	for(int i = 1; i < l2; i++) put(h2[i] + n), putchar(' '), put(h2[i + 1] + n), puts("");
	if(l2) put(h2[l2] + n), putchar(' '), put(h1[1] + n), puts("");
	for(int i = 1; i < l1; i++) put(h1[i] + n), putchar(' '), put(h1[i + 1] + n), puts("");
	for(int i = 1; i < l3; i++) put(h3[i]), putchar(' '), put(h3[i + 1]), puts("");
	if(l3) put(h3[l3]), putchar(' '), put(h1[1]), puts(""), put(h1[l1]), putchar(' '), put(h3[1] + n), puts("");
	for(int i = 1; i < l3; i++) put(h3[i] + n), putchar(' '), put(h3[i + 1] + n), puts("");
	return 0;
}



Measured memory_bytes: 3200
#include<stdio.h>

int main(void){
    int N;
    int chk[4] = {1,7,9,4};
    for(int i=0;i<4;i++){
    scanf("%d",&N);
        for(int j=0;j<4;j++){
            if(N==chk[j]){
                chk[j]=-1;
            }
        }
    }
    for(int i=0;i<4;i++){
        if(chk[i]!=-1){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 128
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string str;
    cin >> str;
    auto N = (int) str.size();
    stack<char> stk;
    for (int i = 0; i < N; i++) {
        stk.push(str[i]);
        if (stk.size() >= 2) {
            char first = stk.top(); stk.pop();
            char second = stk.top(); stk.pop();
            if (first == second) {
                stk.push(second);
                stk.push(first);
            }
        }
    }

    cout << N - stk.size() << endl;

    return 0;
}

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

int main()
{  
    int D, N;    
    cin >> D >> N;
    int X = 1;
    for(int i=0; i<D; i++)
    {
        X *= 100;
    }
    
    if(N!=100) cout << X*N << endl;
    else cout << X*101 << endl; 

    
	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]

def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e)

for i in range(n):
	G = map(int, raw_input().split())
	for j in range(G[1]):
		v[G[0]-1][G[j+2]-1] = 1
d[0] = 0

for i in range(n):
	BFS(i)
for i in range(n):
	if d[i] == 100:
		d[i] = -1
for i in range(n):
	print i+1, d[i]

Measured memory_bytes: 6492
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX_V 1000
int V,cmp[MAX_V];
vector<int> G[MAX_V],rG[MAX_V],vs,a,xx;
int used[MAX_V];
void addedge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
} 
void dfs(int v){
  used[v]=1;
  for(int i=0;i<G[v].size();i++)
    if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}
void rdfs(int v,int k){
  used[v]=1;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]])rdfs(rG[v][i],k);
  }
}
void dfs2(int v,int k){
  used[v]=k;
  for(int i=0;i<G[v].size();i++)
    if(!used[G[v][i]])dfs(G[v][i]);
  xx.push_back(v);
}
int scc(){
  int pp=0;
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v=0;v<V;v++)
    if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=1;
  for(int i=vs.size()-1;i>=0;i--)
    if(!used[vs[i]]){
      rdfs(vs[i],k++);
    }
  k=1;
  map<int,int>m;
  memset(used,0,sizeof(used));
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]]){
      dfs(vs[i]);
      r(j,xx.size())if(used[xx[j]]!=k){
        m[used[xx[j]]]=0;
      }
      xx.clear();
      m[vs[i]]=cmp[vs[i]];
      k++;
    }
  }
  r(i,V)if(m[i])
    a.push_back(m[i]);
  return k;
}
int main(){
  int x,y;
  while(cin>>V,V){
    double d[V],ans=0;
    a.clear();
    r(i,1000)G[i].clear(),rG[i].clear();
    r(i,V){
      cin>>d[i]>>x;
      r(j,x){
        cin>>y;
        addedge(i,y-1);
      }
    }
    scc();
    int cnt=0;
    r(i,a.size()){
      double p=0;
      int c=0;
      r(j,V)if(cmp[j]==a[i]){
        if(!c++)p+=d[j];
        else p*=d[j];
      }
      if(!cnt++)ans+=(1.0-p);
      else ans*=(1.0-p);
    }
    printf("%.9f\n",ans);
  }
}

Measured memory_bytes: 3524
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,q=map(int,input().split())
STX=[tuple(map(int,input().split())) for i in range(n)]
D=[int(input()) for i in range(q)]
event=[]
for si,ti,xi in STX:
  event.append((si-xi,0,xi))
  event.append((ti-xi,-1,xi))
for di in D:
  event.append((di,1,di))
event.sort()
hq=[]; S=set()
for time, query, number in event:
  if query == 0:
    heapq.heappush(hq,number)
    S.add(number)
  elif query == -1:
    S.remove(number)
  else:
    while hq and hq[0] not in S:
      heapq.heappop(hq)
    if not hq:
      print(-1)
    else:
      print(hq[0])




Measured memory_bytes: 120004
#include <bits/stdc++.h>
using namespace std;
int main () {
    string x[] = {"KIH", "B", "R", ""};
    string s;
    cin >> s;
    for (int i = 0; i < (1 << 4); i++) {
        string res = "";
        for (int j = 0; j < 4; j++) {
            if ((1 << j) & i) {
                res += "A";
            }
            res += x[j];
        }
        if (s == res) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,a,b;
	cin >> n >> a >> b;
	if(a+b > n)cout << min(a,b) << " " << a+b-n << endl;
	else cout << min(a,b) << " " << "0" << endl;
	return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
        private static int s_maxWater;
        private static int s_maxSugar;
        private static double s_maxDensity = double.MinValue;
        static void SolveA()
        {
            var o = ReadAndParseIntArr();
            int x = o[0];
            int t = o[1];

            int ans = Math.Max(0, x - t);
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<=h[b-1]:
    ans[a-1]=0
  if h[a-1]>=h[b-1]:
    ans[b-1]=0
print(ans.count(1))

Measured memory_bytes: 20144
#include<stdio.h>

int main(){
  int A, B, C;
  char op[2];
  
  scanf("%d %s %d", &A, op, &B);
  
  if(op[0] == '+'){
    C = A + B;
  } else if(op[0] == '-'){
  	C = A - B;
  }
  
  printf("%d\n", C);
  
  return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc089/tasks/abc089_d
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, d, t, q;
    cin >> h >> w >> d;
    vector<pii> v(h * w + 1);
    vector<vector<int>> disp(h, vector<int>(w));
    REP(i, h) REP(j, w) {
        cin >> t;
        v[t] = {i, j};
        disp[i][j] = t;
    }
    vector<int> memo(h * w + 1, 0);
    REP(i, d) {
        int start = i;
        int sum = 0;
        while (start + d <= h * w) {
            pii posNow = v[start];
            pii posNext = v[start + d];
            int diff = abs(posNow.first - posNext.first) +
                       abs(posNow.second - posNext.second);
            sum += diff;
            start += d;
            memo[start] = sum;
        }
    }
    cin >> q;
    vector<pii> s(q);
    REP(i, q) cin >> s[i].first >> s[i].second;
    REP(i, q) cout << memo[s[i].second] - memo[s[i].first] << "\n";

    return 0;
}


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

int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    vector<ll> vec;
    rep(i, n){
        ll num;
        cin >> num;
        vec.push_back(num);
        mp[num]++;
    }
    ll sum;
    for(ll i=1; i<=n; i++){
        sum += mp[i]*(mp[i]-1)/2;
    }
    rep(i, n){
      	ll before = (mp[vec[i]]*(mp[vec[i]]-1)/2);
      	ll after = ((mp[vec[i]]-1)*(mp[vec[i]]-2)/2);
        cout << sum - before + after << endl;
    }
    return 0;
}


Measured memory_bytes: 16624
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		sc.nextLine();
		int A[] = new int[N];
		int B[] = new int[N];
		int C[] = new int[N];
		String[] a1An = sc.nextLine().split(" ");
		String[] b1Bn = sc.nextLine().split(" ");
		String[] c1Cn = sc.nextLine().split(" ");

		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(a1An[i]);
			B[i] = Integer.parseInt(b1Bn[i]);
			C[i] = Integer.parseInt(c1Cn[i]);
		}
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);

		long[] cntB = new long[N];
		int aIx = 0;

		for (int i = 0; i < N; i++) {
			int b = B[i];
			while (aIx < A.length && A[aIx] < b) {
				aIx++;
			}
			cntB[i] = aIx;
		}

		long[] cntC = new long[N];
		int bIx = 0;
		long total = 0;
		for (int i = 0; i < N; i++) {
			int c = C[i];
			long subTotal = (i == 0) ? 0 : cntC[i - 1];
			while (bIx < B.length && B[bIx] < c) {
				subTotal += cntB[bIx];
				bIx++;
			}
			cntC[i] = subTotal;
			total += subTotal;
		}

		System.out.println(total);
		sc.close();
	}

}

Measured memory_bytes: 82316
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int ans[10001] = {};
	vector<vector<pair<int, int> > > graph(n + 1);
	for(int i = 0; i < n; i++){
		ans[i] = -1;
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v, c;
			cin >> v >> c;
			graph[u].push_back(make_pair(v, c));
		}
	}
	priority_queue<pair<int, int> > qu;
	qu.push(make_pair(0, 0));
	ans[0] = 0;
	while(!qu.empty()){
		int nowd = -(qu.top()).first;
		int nownode = (qu.top()).second;
		qu.pop();
		for(int i = 0; i < graph[nownode].size(); i++){
			int node = graph[nownode][i].first;
			int next = nowd + graph[nownode][i].second;
			if(ans[node] < 0 || ans[node] > next){
				ans[node] = next;
				qu.push(make_pair(-next, node));
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout << i << " " << ans[i] << endl;
	}
}

Measured memory_bytes: 7788
import java.io.PrintWriter;
import java.util.*;
//https://qiita.com/p_shiki37/items/3902f4e3adc3aeb382f1

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

        Map<String, String> map = new HashMap<>();
        map.put("Sunny", "Cloudy");
        map.put("Cloudy", "Rainy");
        map.put("Rainy", "Sunny");

        StringBuilder sb = new StringBuilder();
        sb.append(map.get(S));

        PrintWriter out = new PrintWriter(System.out);
        out.println(sb);
        out.flush();
    }
}

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

int main()
{
  ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
  string o, e;
  cin >> o >> e;
  
  int a = 0, b = 0;
  for(int i = 0; i < o.size()+e.size(); i++)
  {
    if(i&1)
      cout << e[a++];
    else
      cout << o[b++];
  }
  cout << endl;
  return 0;
}
  

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::cmp::Ordering;

enum ParRank {
    Parent(usize),
    Rank(usize),
}

struct UnionFind {
    v: Vec<ParRank>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut v = Vec::new();
        for _ in 0..n {
            v.push(ParRank::Rank(1));
        }
        UnionFind { v }
    }

    fn root(&self, i: usize) -> usize {
        match self.v[i] {
            ParRank::Rank(_) => i,
            ParRank::Parent(j) => {
                let r = self.root(j);
                // self.v[i] = ParRank::Parent(r);
                r
            }
        }
    }

    fn size(&self, i: usize) -> usize {
        if let ParRank::Rank(r) = self.v[self.root(i)] {
            r
        } else {
            panic!("UnionFind: root is not root");
        }
    }

    fn unite(&mut self, i1: usize, i2: usize) -> bool {
        let r1 = self.root(i1);
        let r2 = self.root(i2);
        if r1 == r2 {
            return false;
        }
        let rank1 = if let ParRank::Rank(r) = self.v[r1] { r } else {
            panic!("UnionFind: root is not root");
        };
        let rank2 = if let ParRank::Rank(r) = self.v[r2] { r } else {
            panic!("UnionFind: root is not root");
        };
        match self.size(r1).cmp(&self.size(r2)) {
            Ordering::Less => {
                self.v[r1] = ParRank::Parent(r2);
                self.v[r2] = ParRank::Rank(rank1 + rank2);
            },
            Ordering::Equal => {
                self.v[r1] = ParRank::Parent(r2);
                self.v[r2] = ParRank::Rank(rank1 + rank2);
            },
            Ordering::Greater => {
                self.v[r2] = ParRank::Parent(r1);
                self.v[r1] = ParRank::Rank(rank1 + rank2);
            },
        }
        return true;
    }
}

fn main() {
    input! {
        nm: (usize, usize),
        ab: [(Usize1, Usize1); nm.1],
    };
    let n = nm.0;
    let m = nm.1;
    let a: Vec<usize> = ab.iter().map(|(a,_)| *a).collect();
    let b: Vec<usize> = ab.iter().map(|(_,b)| *b).collect();
    let mut uf = UnionFind::new(n);
    for (a, b) in ab {
        uf.unite(a, b);
    }
    let size = (0..n).map(|i| uf.size(i)).max().unwrap();
    println!("{}", size);
}


Measured memory_bytes: 14028
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = InputNumList();
            var a = new List<int> { 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };

            WriteLine(a[x[0] - 1] == a[x[1] - 1] ? "Yes" : "No");
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



Measured memory_bytes: 11220
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
a = []
for i in range(N):
    x = input()
    a.append(x)
AC = 0
TLE = 0
WA = 0
RE = 0


y = []
for i in a:
    if i == "AC":
        AC += 1
    elif i == "WA":
        WA += 1
    elif i == "TLE":
        TLE += 1
    elif i == "RE":
        RE += 1

y.append(AC)
y.append(WA)
y.append(TLE)
y.append(RE)


z = ["AC","WA","TLE","RE"]

for i,j in zip(z,y):
    print("{} x {}".format(i,j))


Measured memory_bytes: 17248
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;

int main()
{
	ll N;
	cin >> N;
	vector<ll> l(N);
	rep(i, N)
	{
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	ll res = 0;
	for (ll i = 0; i < N; i++)
	{
		ll k = i;
		for (ll j = i + 1; j < N; j++)
		{
			while (k < N&& l[k] < l[i] + l[j]) ++k;
			res += k - (j + 1);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
fn main(){
    let mut sc = Scanner::new();
    while let Ok(n) = sc.wrapped::<usize>() {
        let s:String = sc.next();
        let t:String = sc.next();
        for i in 0..n+1 {
            let cand = s.to_owned() + &t[n-i..n];
            if cand[cand.len()-n..cand.len()] == t {
                println!("{}", cand.len());
                break;
            }
        }
    }
}

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner{
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(& mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(& mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s,t;
    cin>>n>>s>>t;
    string ans="";
    for(int i=0; i<n; i++) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
L, R = map(int, input().split())

if R - L >= 2018:
      ans = 0
else:
    tempL = L%2019
    tempR = R%2019
    if tempR - tempL < R-L-1:
        temp = tempL
        tempL = 0
        X = list(range(tempL,temp))
        Y = list(range(tempR,2018+1))
        Z = X + Y
    else:
        Z = list(range(tempL,tempR+1))

    ans = 2019
    for i in range(len(Z)):
        for j in range(i+1, len(Z)):
            if (Z[i]*Z[j])%2019 < ans:
                ans = (Z[i]*Z[j])%2019
print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    string s;
    cin >> s;
    ll ans = 0;
    string tmp = "";
    int n = pow(2,s.size()-1);
    for(int i = 0; i < n; i++){
        int bit = i;
        tmp = s[0];
        for(int j = 1; j < s.size(); j++){
            if(bit&1){
                ans += stoll(tmp);
                tmp = s[j];
            }else{
                tmp += s[j];
            }
            bit = bit >> 1;
        }
        ans += stoll(tmp);
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}

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

int size;
string str;
void change()
{
  for (int i = 0; i < size; i++){
    if ('a' <= str[i] && str[i] <= 'y'){
      str[i]++;
    }
    else if (str[i] == 'z'){
      str[i] = 'a';
    }
  }
}

int main()
{
 // string str;

  while (getline(cin, str), str != ""){
    size = str.size();

    for (;;){
      if (str.find("the") != -1 || str.find("this") != -1 || str.find("that") != -1){
        cout << str << endl;
        break;
      }
      change();
    }
    str = "";
  }
  return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int i,j,n,x,y,L=1000000;
  vector<pair<int,int> >a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    a.push_back(make_pair(x,y));}
  sort(a.begin(),a.end());
  for(i=1;i<n;i++)
    for(j=i-1;j>=0;j--){
      x=a[i].first-a[j].first;
      y=a[i].second-a[j].second;
      if (x*x>=L)break;
      L=min(L,x*x+y*y);}
  printf("%d\n",L);
}

Measured memory_bytes: 6556
#include <iostream>
#include <algorithm>
#include <cctype>

using namespace std;
int r, c;
char a[21][21];
bool vis[22][22][17][5];

int xdir[4] = {1, 0, -1, 0}, ydir[4] = {0, 1, 0, -1};
bool dfs(int x, int y, int m, int d)
{
  if(!vis[y][x][m][d]) return false;
  vis[y][x][m][d] = false;

  char ch = a[y][x];
  int nm = m, nd = d, dx, dy; 

  if(ch == '@') return true;
  else if(ch == '<') nd = 2;
  else if(ch == '>') nd = 0;
  else if(ch == '^') nd = 3;
  else if(ch == 'v') nd = 1;
  else if(ch == '|') nd = (m == 0)? 1 : 3;
  else if(ch == '_') nd = (m == 0)? 0 : 2;
  else if(ch == '+') nm = (m == 15)? 0 : m+1;
  else if(ch == '-') nm = (m == 0)? 15 : (m-1);
  else if(isdigit(ch)) nm = (int)(ch-'0');
  
  if(ch == '?'){
    for(int i = 0; i < 4; i++){
      dx = x+xdir[i], dy = y+ydir[i];
      if(dx < 0) dx = c-1;
      if(dx >= c) dx = 0;
      if(dy < 0) dy = r-1;
      if(dy >= r) dy = 0;

      if(dfs(dx, dy, nm, i)) return true;
    }

    return false;
  }
  
  dx = x+xdir[nd], dy = y+ydir[nd];
  if(dx < 0) dx = c-1;
  if(dx >= c) dx = 0;
  if(dy < 0) dy = r-1;
  if(dy >= r) dy = 0;
  
  return dfs(dx, dy, nm, nd);
}

int main()
{
  while(cin>>r>>c && (r+c)){
    for(int i = 0; i < r; i++)
      for(int j = 0; j < c; j++) cin >> a[i][j];

    fill(&vis[0][0][0][0], &vis[21][21][16][4], true);
    cout << ((dfs(0, 0, 0, 0))? "YES" : "NO") << endl;
  }

  return 0;
}

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

using namespace std;

int32_t main() {
    int n, C; cin >> n >> C;

    vector<int> x(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> c[i];
    }

    int ans = 0;

    vector<int> pref(n), suff(n);
    for (int i = 0; i < n; ++i) {
        pref[i] = c[i];
        if (i > 0) pref[i] += pref[i - 1];
        ans = max(ans, pref[i] - x[i]);
    }
    for (int i = n - 1; i >= 0; --i) {
        suff[i] = c[i];
        if (i < n - 1) suff[i] += suff[i + 1];
        ans = max(ans, suff[i] - (C - x[i]));
    }
    
    vector<int> maxes(n);
    for (int i = 0; i < n; ++i) {
        maxes[i] = pref[i] - 2 * x[i];
        if (i > 0) maxes[i] = max(maxes[i], maxes[i - 1]);
        if (i > 0) {
            ans = max(ans, suff[i] - (C - x[i]) + maxes[i - 1]);
        }
    }

    for (int i = n - 1; i >= 0; --i) {
        maxes[i] = suff[i] - 2 * (C - x[i]);
        if (i + 1 < n) maxes[i] = max(maxes[i], maxes[i + 1]);
        if (i + 1 < n) {
            ans = max(ans, pref[i] - x[i] + maxes[i + 1]);
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll kai[100002];
ll gyaku[100002];
ll modpow(ll n,ll a)
{
	ll ret=1;
	ll nn=n;
	while(a>0)
	{
		if(a&1)
		{
			ret*=nn;
			ret%=MOD;
		}
		nn=nn*nn;
		nn%=MOD;
		a>>=1;
	}
	return ret;
}

ll combi(int a,int b)
{
	ll ret=kai[a]*gyaku[b];
	ret%=MOD;
	ret*=gyaku[a-b];
	ret%=MOD;
	return ret;
}

int main()
{
	int n;
	int l,r,kabu;
	int cnt[100001];
	fill(cnt,cnt+100001,0);
	int a[100000];
	cin>>n;
	for(int i=0;i<n+1;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
		if(cnt[a[i]]==2)
		{
			kabu=a[i];
			r=n-i;
		}
	}
	for(int i=0;i<n+1;i++)
	{
		if(a[i]==kabu)
		{
			l=i;
			break;
		}
	}
	kai[0]=1;
	gyaku[0]=modpow(kai[0],MOD-2);
	for(ll i=1;i<100002;i++)
	{
		kai[i]=(kai[i-1]*i+MOD)%MOD;
		gyaku[i]=modpow(kai[i],MOD-2);
	}
	cout<<n<<endl;
	ll tmp=0;
	for(int k=2;k<=n+1;k++)
	{
		tmp=combi(n+1,k);
		if(l+r>=k-1)
			tmp-=combi(l+r,k-1);
		tmp%=MOD;
		if(tmp<0)
			tmp+=MOD;
		cout<<tmp<<endl;
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
typedef long long ll;
using namespace std;

int main()
{
	char y[3];
	char t[3];
	int c = 0;

	for( int i = 0; i < 3; i++ )
	{
		cin >> y[i];
	}
	for( int i = 0; i < 3; i++ )
	{
		cin >> t[i];
	}
	for( int i = 0; i < 3; i++ )
	{
		if( y[i] == t[i] )
		{
			c++;
		}
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
/*
My heart’s beating faster
I know what I’m after
 
I’ve been standing here my whole life
Everything I’ve seen twice
Now it’s time I realized
It’s spinning back around now
On this road I’m crawlin’
Save me 'cause I’m fallin’
Now I can’t seem to breathe right
'Cause I keep runnin' runnin' runnin' runnin'
Runnin' runnin' runnin' runnin'
Runnin' from my heart
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define slow_as_snail ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 
 
const ll mod = 1000000007;
#define mx 10000005
const ll mxi = 100005;

long long nsolver(long long n,long long x, long long y){
        return n - (n/x + n/y - n/(lcm(x,y)));
}
 
 
int main(){
	long long a,b,c,d;
    cin >> a >> b >> c >> d;
 
    cout << nsolver(b,c,d) - nsolver(a-1,c,d) << endl;
 
 
}


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

bool is_subseq(const string& S, const string& T) {
    int n = S.size();
    int m = T.size();
    int j = 0;
    // cout << "S: " << S << ", T: " << T << endl;
    for (int i = 0; i < n; i++) {
        if (S[i] == T[j]) {
            j++;
            if (j == m)
                return true;
        }
    }
    return false;
}

int solve(string& str) {
    stringstream ss;
    int ans = 0;
    for (int i = 0; i <= 999; i++) {
        ss.clear();
        ss.str("");
        ss << setfill('0') << setw(3) << i;
        if (is_subseq(str, ss.str()))
            ans++;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    string str;
    cin >> n >> str;
    int ans = solve(str);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,k; cin>>n>>k;
  long long res=0;
  for(int i=k+1; i<=n; ++i){
    int p=n/i,q=n-p*i;
    res+=(i-k)*p+(q-k<0? 0:(q-k+1))-!k;
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> P;
const double EPS = 1e-4;
int main(){
	int N;
	cin >> N;
	while(N--){
		P a,b,c,d;
		cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> c.real() >> c.imag() >> d.real() >> d.imag();
		P one = b-a;
		P two = d-c;
		bool f = false;
		if( abs(one.real()) < EPS || abs(two.real()) < EPS ){
			f = abs(one.real()) < EPS && abs(two.real()) < EPS;
		}else{
			f = one.imag()/one.real() - two.imag()/two.real() == 0;
		}
		cout << (f?"YES":"NO") << endl;
	}
}

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

const int MAXN = 100010;
int N, M;
int cnt[MAXN];

int main() {
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i++) {
		int x, y; scanf("%d %d", &x, &y);
		cnt[x]++; cnt[y]++;
	}

	for (int i = 1; i <= N; i++) {
		if (cnt[i] % 2 == 1) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");

	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int n = Integer.parseInt(sc.next());
    int ans=0;
    int temp=0;
    for (int i = 1; i <= n; i++) {
        if(temp<=Integer.numberOfTrailingZeros(i)){
        ans=i;
        temp=Integer.numberOfTrailingZeros(i);
        }
    }
    out.println(ans);
}
}

Measured memory_bytes: 21844
n=int(input())
s=[]
ans=0
for i in range(n):
  a=int(input())
  s.append(a)
k=s[0]
for j in range(n+1):
  if k==2:
    ans+=1
    print(ans)
    exit()
  else:
    ans+=1
    k=s[k-1]
print(-1)  

Measured memory_bytes: 7084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*** Loops ***/
#define ip(n) ll n; cin>>n;
#define ip2(n,k) ll n; cin>>n; ll k; cin>>k;
#define ff1(i,a,b) for(ll i = a; i < b; i++)
#define ff2(i,a,b) for(ll i = b-1; i >= a; i--)

/***input loops***/
#define ipve(vc,n) vll vc(n); ff1(i,0,n){cin>>vc[i];}
#define ipvc(vc,n) vll vc; ff1(i,0,n){ip(x);vc.pb(x);}

/*** STLs ***/
#define vvll vector<vll>
#define pb push_back
#define mem(name, value) memset(name, value, sizeof(name))
#define MN3(n1,n2,n3) min(n1,min(n2,n3))
#define MN4(n1,n2,n3,n4) min(n1,min(n2,min(n3,n4)))
#define MX3(n1,n2,n3) max(n1,max(n2,n3))
#define MX4(n1,n2,n3,n4) max(n1,max(n2,max(n3,n4)))

/*** Typedef ***/
typedef long long ll;
//typedef long long lli;
typedef long long int lli;
typedef unsigned long long ull;
typedef    long double   ld;

// DEBUG
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

using namespace std;
int main(){

	ios::sync_with_stdio(false);
    cin.tie(0);//this reduced the time by 2ms
    
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif

    char a;
    cin>>a;
    if(isupper(a)){
    	cout<<"A";
    }
    else{
    	cout<<"a";
    }
}


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

namespace AOJ_YOSEN {
	class Program {
		static void Main(string[] args) 
		{
			Console.WriteLine(Sum().Sum() >= 1000 ? 1 : 0);
		}

		static IEnumerable<int> Sum() 
		{
			var coins = new[] { 1, 5, 10, 50, 100, 500 };
			var list = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();

			for (int i = 0; i < list.Count; i++) {
				yield return coins[i] * list[i];
			}
		}
	}
}

Measured memory_bytes: 5916
#include <iostream>
using namespace std;
int main(void){
    while(1){
        int H, W;
        cin >>H >>W;
        if(H == 0 && W == 0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(i % 2 != 0){
                    if(j % 2 != 0){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }
                }
                else{
                    if(j % 2 == 0){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }
                }
            }
            cout<<endl;
        }cout<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3096
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    odds = V[0::2]
    evens = V[1::2]
    return min(
        len(odds) - oc + len(evens) - ec
        for o, oc in Counter(odds).most_common(2)
        for e, ec in Counter(evens).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))


Measured memory_bytes: 16228
#include <iostream>
#include <string>

using namespace std;


bool is_month(int num) {
  if (num >= 1 && num <= 12) {
    return true;
  } else {
    return false;
  }
}

bool is_year(int num) {
  return true;
}
int main() {
  string s;
  cin >> s;
  
  string head = s.substr(0, 2);
  string tail = s.substr(2, 2);
  bool head_is_year = is_year(stoi(head));
  bool head_is_month = is_month(stoi(head));
  bool tail_is_year = is_year(stoi(tail));
  bool tail_is_month = is_month(stoi(tail));

  if ((head_is_year && tail_is_month) && (head_is_month && tail_is_year)) {
    cout << "AMBIGUOUS" << endl;
  } else if (head_is_year && tail_is_month) {
    cout << "YYMM" << endl;
  } else if (head_is_month && tail_is_year) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,k,m,n;
string s1,s2;
int main()
{
	cin>>s1;
	s2=s1;
	reverse(s1.begin(),s1.end());
	for(i=0;i<s1.size();++i)
	{
		if(s1[i]=='b')
		{
			s1[i]='d';
		}
		else
		{
			if(s1[i]=='d')
		  {
			  s1[i]='b';
		  }
		  else
		  {
		  	if(s1[i]=='q')
		    {
			    s1[i]='p';
		    }
		    else
		    {
		    	if(s1[i]=='p')
		      {
			      s1[i]='q';
		      }
		    }
		      
		  }
		    
		}
	}
	if(s1==s2) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll w,h;
ll sy,sx;
vector<string> v;
ll memo[810][810];


int main() {
  ll h,w,k;
  cin>>h>>w>>k;
  rep(i,0,h){
    string s;
    cin>>s;
    v.pb(s);
  }
  rep(y,0,h){
    rep(x,0,w){
      if(v[y][x]=='S'){
        sy=y;
        sx=x;
        v[y][x]='.';
      }
    }
  }
  clr(memo,-1);
  queue<int> q1,q2,q3;
  q1.push(sy);
  q2.push(sx);
  q3.push(0);
  while(!q1.empty()){
    int y = q1.front();
    int x = q2.front();
    int c = q3.front();
    q1.pop();
    q2.pop();
    q3.pop();
    if(memo[y][x] != -1)continue;
    memo[y][x] = c;
    for(int t = 0; t < 4; t++){
      int dy[4] = {-1,0,0,1};
      int dx[4] = {0,-1,1,0};
      int y1 = y + dy[t];
      int x1 = x + dx[t];
      if(y1 < 0 || y1 >= h)continue;
      if(x1 < 0 || x1 >= w)continue;
      if(v[y1][x1] == '#')continue;
      q1.push(y1);
      q2.push(x1);
      q3.push(c+1);
    }
  }
  ll mn = 10000000;
  rep(y,0,h){
    rep(x,0,w){
      if(memo[y][x]!=-1&&memo[y][x]<=k){
        ll w1 = min(x,w-1-x);
        ll h1 = min(y,h-1-y);
        ll mn1 = min(w1,h1);
        mn = min(mn,(mn1+k-1)/k);
      }
    }
  }
  cout << mn+1 << endl;
  return 0;
}

Measured memory_bytes: 6272
N, X = map(int, input().split())
a = [int(input()) for _ in range(N)] 
sum_material = sum(a)
b = min(a)
count = 0
X = X - sum_material
if X < b:
    print(len(a))
else:
    while X >= b:
        X -= b
        count += 1
    print(len(a) + count)



Measured memory_bytes: 9092
from bisect import bisect_left, bisect_right


def main():
    N = int(input())
    parts = [sorted(list(map(int, input().split()))) for _ in range(3)]
    answer = 0
    for b in parts[1]:
        a = bisect_left(parts[0], b)
        c = bisect_right(parts[2], b)
        answer += a * (N - c)
    print(answer)


if __name__ == '__main__':
    main()



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

using namespace std;


int main(){
  int n,d,f[1000]={};
  string s;
  cin>>n;
  cin>>s;
  cin>>d;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'&&d>0)s[i]='1',f[i]=1,d--;
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='1'&&d>0&&!f[i])s[i]='0',d--;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  int a[2][n+1];
  for(i=0;i<2;i++)
    for(j=0;j<n;j++)
      scanf("%d",&a[i][j]);
  for(i=0;i<n-1;i++)
    a[0][i+1]+=a[0][i];
  for(i=n-1;i>0;i--)
    a[1][i-1]+=a[1][i];
  int max=0;
  for(i=0;i<n;i++)
    if(max<a[0][i]+a[1][i])
      max=a[0][i]+a[1][i];
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())

    ac=[0]*n
    wa=[0]*n

    for i in range(m):
        p,s=readline().rstrip().split()
        p=int(p)-1
        if s=="AC":
            ac[p]=1
            continue
        if ac[p]==0:
            wa[p]+=1
    for i in range(n):
        wa[i]*=ac[i]
    
    print(sum(ac),sum(wa))

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 17748
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin>>s;
  int numA,numZ;
  for(numA=0;;numA++){
    if(s[numA]=='A') break;
  }

  for(numZ=(int)s.size()-1;;numZ--){
    if(s[numZ]=='Z') break;
  }

  cout<<numZ-numA+1<<endl;
}


Measured memory_bytes: 640
;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 1))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))


;; Hauptteil

(declaim (inline dict<))
(defun dict< (str1 str2)
  (declare #.OPT
           (base-string str1 str2))
  (let* ((len1 (length str1))
         (len2 (length str2))
         (len (min len1 len2)))
    (loop for i below len
          for c1 = (aref str1 i)
          for c2 = (aref str2 i)
          do (cond ((char< c1 c2) (return t))
                   ((char> c1 c2) (return nil)))
          finally (return (if (< len1 len2) t nil)))))

(declaim (inline enum-words))
(defun enum-words (source)
  (declare #.OPT
           (base-string source))
  (let ((len (length source))
        res)
    (dotimes (idx1 len res)
      (loop for width from 1 to 5
            while (<= (+ idx1 width) len)
            do (push (make-array width
                                 :element-type 'base-char
                                 :displaced-to source
                                 :displaced-index-offset idx1)
                     res)))))

(defun get-min (tmp-min lst)
  (declare #.OPT)
  (cond ((null lst) tmp-min)
        ((dict< (car lst) tmp-min) (get-min (car lst) (cdr lst)))
        (t (get-min tmp-min (cdr lst)))))

(defun get-nth-min (n lst)
  (declare #.OPT
           (uint n))
  (let ((min (get-min (car lst) lst)))
    (if (= n 1)
        min
        (get-nth-min (- n 1)
                     (delete min lst :test #'string=)))))

(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (declare #.OPT)
  (let ((str (coerce (read-line) 'base-string))
        (n (read)))
    (write-line (get-nth-min n (enum-words str)))))

#-swank(main)


Measured memory_bytes: 20068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int  b, c;
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            c = int.Parse(str[1]);
            string aaaa = "";
            if (b < c)
            {
                
                for(int i=0; i<c; i++)
                {
                    aaaa += b.ToString();
                }
            }
            else
            {
                for (int i = 0; i < b; i++)
                {
                    aaaa += c.ToString();
                }
            }
            Console.WriteLine(aaaa);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long x = Math.min(n, b - 1);
        System.out.println((long) (Math.floor(a * x / b) - a * Math.floor(x / b)));
    }

}

Measured memory_bytes: 35792