akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3)
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define temp template<typename T>
#define Re register
#define rt Re int
#define rch Re char
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
temp inline void read(T&res){
    #define num ch-'0'
    char ch;bool flag=0;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=(res<<1)+(res<<3)+num);
    (flag)&&(res=-res);
    #undef num
}
temp inline void write(T x){
    if(x<0)putchar('-'),x=-x;
    if(x==0){putchar('0');return;}
    rt num=0;rch ch[25];
    while(x)ch[++num]=x%10+48,x/=10;
    while(num)putchar(ch[num--]);
}
temp inline void writeln(T x){
    write(x);putchar('\n');
}
namespace HZ{
    #define ld long double
    #define ll long long
    #define rll register ll
    #define up(i,x,y) for(rt i=x;i<=y;i++)
    #define down(i,x,y) for(rt i=x;i>=y;i--)
    temp inline void Max(T&x,T y){if(x<y)x=y;}
    temp inline void Min(T&x,T y){if(x>y)x=y;}
    temp inline void SWAP(T&x,T&y){T t=x;x=y;y=t;}
    inline void Swap(rt&x,rt&y){x^=y^=x^=y;}
}using namespace HZ;
ll n,a,b;
#define r(x) read(x)
int main(){
    r(n);r(a);r(b);
    if(a>b){putchar('0');return 0;}
    if(n==1&&a!=b){putchar('0');return 0;}
    n--,n--;
    write(b*n-a*n+1);
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2500)
 
def erase(x, y):
    c[y][x] = '0'
    for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1':
            erase(nx, ny)
 
while True:
    w, h = map(int, sys.stdin.readline().split())
    if w == h == 0:
        break
    c = [sys.stdin.readline().split() for _ in range(h)]
    ans = 0
    for y in range(h):
        for x in range(w):
            if c[y][x] == '1':
                ans += 1
                erase(x, y)
    print(ans)

Measured memory_bytes: 9556
import numpy as np
N = int(input().strip('\n'))
lis = []
for i in range(N):
    lis.append(int(input().strip('\n')))
lis = np.sort(np.array(lis))
mx_n = lis[-1]
ms_n = lis[0]
lis = lis[1:-1]
point = mx_n-ms_n
while lis.shape[0]>=2:
    mx = lis[-1]
    ms = lis[0]
    point += (mx_n-ms+mx-ms_n)
    mx_n = mx
    ms_n = ms
    lis = lis[1:-1]
if lis.shape[0]==1:
    point += max(abs(mx_n-lis[0]),abs(ms_n-lis[0]))
print(point)

Measured memory_bytes: 26000
import bisect
N = int(input())
L = sorted([int(i) for i in input().split()])
ans = 0

for j in range(N-2):
    for k in range(j+1,N-1):
        S = L[j] + L[k]
        a = bisect.bisect_left(L, S)
        ans += a - 1 - k 

print(ans)


Measured memory_bytes: 9324
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		
		int row = 0;
		for (LinkedList<Integer> i : adjList) {
			if (i.size() > 0) {
				Iterator<Integer> it = i.iterator();
				for (int idx = 0; idx < i.size(); idx++) {
					adjMatrix[row][it.next()] = 1;
				}
				row++;
			} else {
				row++;
			}
		}
		
		for (int i = 0; i < totalVertex; i++) {
			for (int j = 0; j < totalVertex; j++) {
				String trail = " ";
				if (j == totalVertex-1) {trail = "";}
				if (adjMatrix[i][j] != null) {
					System.out.print(adjMatrix[i][j] + trail);
				} else {
					System.out.print("0" + trail);
				}
			}
			System.out.println();
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


Measured memory_bytes: 33748
using System;

class Program
{
    static void Main(string[] args)
    {
        string b;
        b = Console.ReadLine();
        switch (b)
        {
            case "A":
                Console.WriteLine("T");
                break;
            case "T":
                Console.WriteLine("A");
                break;
            case "C":
                Console.WriteLine("G");
                break;
            case "G":
                Console.WriteLine("C");
                break;
        }
    }
}

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

int main(){
    int a, b, c, d, e, f;
    double x, y;
    double t;

    while(cin >> a >> b >> c >> d >> e >> f){
        t = a*e - b*d;
        x = (e*c - b*f) / t + 0.0;
        y = (a*f - d*c) / t + 0.0;

        printf("%.3lf %.3lf\n", x, y);
    }

    return 0;
}

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

using namespace std;

#define pq priority_queue
#define MZ 1000000007

bool ok(long long x,long long a,long long b)
{
    long long lt,rt;
    if(x%2)
    {
        lt=x/2+1;
        rt=x/2+1;
    }
    else
    {
        lt=x/2;
        rt=x/2+1;
    }
    if(a<=lt)
        lt++;
    if(b<=rt)
        rt++;
    if((lt*rt)>=(a*b))
        return 0;
    if((a>lt) && (a<=x) && (b<(rt-a+lt)))
    {
        if(((a+1)*(rt-a+lt))>=(a*b))
            return 0;
    }
    if((b>rt) && (b<=x) && (a<(lt-b+rt)))
    {
        if(((b+1)*(lt-b+rt))>=(a*b))
            return 0;
    }
    lt++;
    rt--;
    if(lt==a)
        lt++;
    if(rt==b)
        rt--;
    if(lt*rt>=a*b)
        return 0;
    return 1;
}

int main()
{
    int q;
    long long a,b,l,r,mid;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%lld%lld",&a,&b);
        l=0;
        r=2LL*MZ;
        while(l!=r)
        {
            mid=(l+r+1)/2;
            if(ok(mid,a,b))
                l=mid;
            else
                r=mid-1;
        }
        printf("%lld\n",l);
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
t_base, x_base, y_base = 0, 0, 0
ans = True
for _ in range(n):
    t_new, x_new, y_new = map(int, input().split())
    dt, dx, dy = abs(t_new - t_base), abs(x_new - x_base), abs(y_new - y_base)

    if dx + dy > dt or (dx + dy - dt) % 2 == 1:
        ans = False
        break
    t_base, x_base, y_base = t_new, x_new, y_new

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
h, w = [int(n) for n in input().split()]

S = [['#'] * (w+2)] + [[0] * (w+2)] * h + [['#'] * (w+2)]

for i in range(1, h+1):
    S[i] = ['#'] + list(input()) + ['#']

for l in S:
    print(''.join(l))

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int small;
		int big;
		if (A <= B) {
			small = A;
			big = B;
		} else {
			small = B;
			big = A;
		}
		for (int i = small; i <= big; i++) {
			if (((small * i * big) % 2) != 0) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 21716
use proconio::input;

fn main() {
    input! {
        k: usize,
        s: String,
    }

    let ans = if s.len() <= k {
        s
    } else {
        let s: Vec<char> = s.chars().collect();
        let mut t = s[0..k].to_owned();
        t.append(&mut vec!['.', '.', '.']);
        t.iter().collect()
    };
    println!("{}", ans);
}


Measured memory_bytes: 2188
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum = 0
        for k in range(D):
            sum += (X[i][k] - X[j][k])**2
        if (sum**0.5).is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 3064
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto abcd = RDR.ARR;
	bool ans;
	if (abs(abcd[0] - abcd[2]) <= abcd[3])
	{
		ans = true;
	}
	else if (abs(abcd[0] - abcd[1]) <= abcd[3] && abs(abcd[1] - abcd[2]) <= abcd[3])
	{
		ans = true;
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		mp[a] = mp[a] + b
	}
	arr := make([]int, 0)
	for k := range mp {
		arr = append(arr, k)
	}
	sort.Sort(sort.IntSlice(arr))
	ans := 0
	for i, limit := 0, 0; i < len(arr) && limit < k; limit, i = limit + mp[arr[i]], i + 1 {
		ans = arr[i]
	}
	fmt.Println(ans)
}

Measured memory_bytes: 7808
import sys

def na(): return map(int,sys.stdin.readline().split())
def ns(): return sys.stdin.readline().strip()

n,m=na()

a=[]
for i in range(m):
    a.append(list(na()))

a.sort(key=lambda x:x[0])

inf = 10000000000
end = inf
ptr = 0
count = 0
for i in range(1,n+1):
    if end == i:
        count += 1
        end = inf
    while ptr < m and a[ptr][0] == i:
        end = min(end, a[ptr][1])
        ptr += 1

print(count)


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

int main() {
    char s[201],t[101],p[101];
    scanf("%s %s",s,p);
    strcpy(t,s);
    strcat(s,t);
    if(strstr(s,p)==NULL) printf("No\n");
    else printf("Yes\n");
}


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

bool G[10][10];

int main() {
  int N, M; cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; --a, --b;
    G[a][b] = G[b][a] = true;
  }
  vector<int> ord(N);
  for (int i = 0; i < N; i++) ord[i] = i;
  int res = 0;
  do {
    if (ord[0] != 0) break;
    bool ok = true;
    for (int i = 0; i + 1 < N; i++) {
      int from = ord[i];
      int to = ord[i + 1];
      if (!G[from][to]) ok = false;
    }
    if (ok) ++res;
  } while (next_permutation(ord.begin(), ord.end()));
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
using namespace std;

int n;
string c;
int main() {
	cin >> n >> c;
	int r = count(ALL(c), 'R');
	int frontW = 0, backR = 0;
	rep(i, 0, r) if(c[i] == 'W') frontW++;
	rep(i, r, n) if(c[i] == 'R') backR++;
	cout << max(frontW, backR) << endl;
    return 0;
}


Measured memory_bytes: 3464
#include <iostream>
#include <vector>

class A
{
public:
    A()
    {
        int n;
        std::cin >> n;

        std::vector<int> a(n);
        for(int i = 0; i < n; ++i)
        {
            std::cin >> a[i];
        }

        insertionSort(a);
    }

    void show(const std::vector<int>& a)
    {
        for(int i = 0; i < a.size(); ++i)
        {
            std::cout << a[i] << (i + 1 == a.size() ? "\n" : " ");
        }
    }

    void insertionSort(std::vector<int>& a)
    {
        for(int i = 1; i < a.size(); ++i)
        {
            int v = a[i];
            int j = i - 1;

            while(j >= 0 && a[j] > v)
            {
                a[j + 1] = a[j];
                j--;
            }

            a[j + 1] = v;

            show(a);
        }
    }
};

class D
{
public:
    D()
    {
        int n;
        std::cin >> n;

        std::vector<int> r(n);
        for(int i = 0; i < n; ++i)
        {
            std::cin >> r[i];
        }

        int min_r = r[0];
        int max_v = r[1] - r[0];

        for(int i = 1; i < n; ++i)
        {
            if(max_v < r[i] - min_r)
            {
                max_v = r[i] - min_r;
            }

            if(min_r > r[i])
            {
                min_r = r[i];
            }
        }

        std::cout << max_v << std::endl;
    }
};

int main(void)
{
    D d;
    return 0;
}

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

int main() {
    vector< char > S(6);
    rep(i, 6) cin >> S[i];
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        long a = 2;
        long b = 1;
        for (int i = 0; i < N; i++)
        {
            long c = a + b;
            a = b;
            b = c;
        }
        Console.WriteLine(a);
    }
}

Measured memory_bytes: 13140
n,k = map(int,input().split())
x = list(map(int,input().split()))
distance = []


for i in range(n-k+1):
    if x[i] * x[i+k-1] >= 0:
        dist = max(abs(x[i]),abs(x[i+k-1]))
    else:
        dist = min(abs(x[i]),abs(x[i+k-1]))+abs(x[i])+abs(x[i+k-1])

    distance.append(dist)

print(min(distance))


Measured memory_bytes: 14252
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

vector<int> edge[100005];
vector<ll> dp[100005];
ll M;

ll dfs(int cur, int pre)
{
	ll ret = 1;
	for (int i = 0; i < edge[cur].size(); i++) {
		int e = edge[cur][i];
		if (e != pre) {
			dp[cur][i] = dfs(e, cur);
			ret *= (1 + dp[cur][i]);
			ret %=M;
		}
	}
	return ret;
}

void dfs2(int cur, int pre, ll p)
{
	for (int i = 0; i < edge[cur].size(); i++) {
		int e = edge[cur][i];
		if(e == pre) {
			dp[cur][i] = p;
		}
	}
	vector<ll> l(edge[cur].size()), r(edge[cur].size());
	for (int i = 0; i < edge[cur].size(); i++) {
		l[i]= (i ? l[i - 1] : 1) * (1 + dp[cur][i]) % M;
	}
	for (int i = edge[cur].size() - 1; i >= 0; i--) {
		r[i] = ((i < edge[cur].size() - 1) ? (r[i + 1]) : 1) * (1 + dp[cur][i]) % M;
		if (edge[cur][i] != pre) {
			ll total = (i ? l[i - 1] : 1) * ((i < edge[cur].size() - 1) ? r[i + 1] : 1) % M;
			dfs2(edge[cur][i], cur, total);
		}
	}
}
int  main(int argc, char *argv[])
{
	int N;
	
	cin >> N >> M;
	for (int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y;
		edge[x - 1].push_back(y - 1);
		edge[y - 1].push_back(x - 1);
	}
	for (int i = 0; i < N; i++) {
		dp[i].resize(edge[i].size());
	}
	dfs(0, -1);
	dfs2(0, -1, 0);

	for (int i = 0; i < N; i++) {
		ll total = 1;
		for (ll d: dp[i]) {
			total *= (1 + d);
			total %=M;
		}
		cout << total << endl;
	}
	return 0;
}

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

const int MOD = 200003, G = 2;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

typedef complex<double> CMP;

void dft(vector<CMP>& f, int n, bool inverse){
    if(n==1) return;
    const double PI = acos(-1);
 
    vector<CMP> f0, f1;
    for(int i=0; i<n/2; i++){
        f0.push_back(f[2*i]);
        f1.push_back(f[2*i+1]);
    }
 
    dft(f0, n/2, inverse);
    dft(f1, n/2, inverse);
 
    CMP zeta, pow_zeta = 1.0;
    if(inverse){
        zeta = cos(2*PI/n) + sin(2*PI/n) * 1i;
    }else{
        zeta = cos(2*PI/n) - sin(2*PI/n) * 1i;
    }
    for(int i=0; i<n; i++){
        f[i] = f0[i%(n/2)] + pow_zeta * f1[i%(n/2)];
        pow_zeta *= zeta;
    }
}
 
vector<int64_t> convolution(const vector<int>& ff, const vector<int>& gg){
    int fsz = ff.size(), gsz = gg.size();
    vector<CMP> f, g;
    for(int i=0; i<fsz; i++) f.push_back(ff[i]);
    for(int i=0; i<gsz; i++) g.push_back(gg[i]);
    int n = 1;
    while(n <= fsz+gsz) n <<= 1;
	f.resize(n);
	g.resize(n);
    dft(f, n, false);
    dft(g, n, false);
 
    vector<CMP> h(n);
    for(int i=0; i<n; i++) h[i] = f[i] * g[i];
    dft(h, n, true);
 
    vector<int64_t> ret(fsz+gsz-1);
    for(int i=0; i<fsz+gsz-1; i++) ret[i] = round(h[i].real()/n);
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<int> n2p(MOD), p2n(MOD);
    int64_t now = 1;
    for(int i=0; i<MOD-1; i++){
        n2p[now] = i;
        p2n[i] = now;
        mul(now, G);
    }

    int64_t ans = 0;
    vector<int> num(MOD);
    for(int i=0; i<N; i++){
        int64_t a;
        cin >> a;
        ans -= a*a % MOD;
        if(a) num[n2p[a]]++;
    }

    auto conv = convolution(num, num);

    for(int i=0; i<int(conv.size()); i++){
        ans += conv[i] * p2n[i%(MOD-1)];
    }

    ans /= 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 46928
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k, x, y; cin >> n >> k >> x >> y;
  long long ans = 0;
  if (n < k) {
    REP(i, n) ans += x;
  } else {
    REP(i, k) ans += x;
    FOR(i, k, n) ans += y;
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

int h, w;
vector<string> v;
vector<vector<int>> vis;

const int MOD = (int)1e9 + 7;


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    cin >> h >> w;
    v.resize(h);
    vis.assign(h, vector<int>(w, 0));
    for(int i=0;i<h;i++) cin >> v[i];
    vis[h-1][w-1] = 1;
    for(int i=h-1;i>=0;i--)
    {
        for(int j=w-1;j>=0;j--)
        {
            if(v[i][j] == '#') continue;
            if(i+1 < h) vis[i][j] += vis[i+1][j];
            if(j+1 < w) vis[i][j] += vis[i][j+1];
            vis[i][j] %= MOD;
        }
    }
    cout << vis[0][0] << "\n";
    return 0;
}



Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define lb lower_bound
#define ld long double
using namespace std;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	int val = (c - a - b) * (c - a- b);
	int ab = (int)4*a*b;
	if(ab<val && c>(a+b)){
		cout<<"Yes";
	} 
	else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;

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

  if( (a >= b)&&(a >= c) )
    {
      printf("%d\n",b + c);
      return 0;
    }
  if( (b >= a)&&(b >= c) )
    {
      printf("%d\n",a + c);
      return 0;
    }
  if( (c>= a)&&(c >= b) )
      printf("%d\n",a + b);

  return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main(void)
{
	char s[101];
	int i = 0;


	scanf("%s", s);
	int j = strlen(s);
	int a;
	for(a=0;a<j;a++)

		if (s[a] != s[j - 1 - a]) i++;

printf("%d\n", i / 2);

}

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

int main() {
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;

    if (S == U) A--;
    if (T == U) B--;

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
import bisect
def main():
    s=input()
    t=input()
    s_abc=[]
    for i in range(26):
        s_abc.append([j for j,ss in enumerate(s) if ord(ss)==ord('a')+i])
    cur=-1
    loop=0
    for tt in t:
        tt_num=ord(tt)-ord('a')
        if s_abc[tt_num]==[]:
            print(-1)
            sys.exit()
        next_idx=bisect.bisect(s_abc[tt_num],cur)
        if next_idx==len(s_abc[tt_num]) or s_abc[tt_num][next_idx]<=cur:
            loop+=1
            cur=s_abc[tt_num][0]
        else:
            cur=s_abc[tt_num][next_idx]
    print(len(s)*loop+cur+1)


if __name__=='__main__':
    main()

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

const int N = 101;
const int K = 100001;
int a[N], g[K], n, k;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int pile = 1; pile <= k; pile++) {
        vector<bool> visited(n + 1, false);
        for (int i = 1; i <= n; i++) {
            if (pile - a[i] >= 0) {
                visited[g[pile - a[i]]] = true;
            }
        }
        int mex = 0;
        while (visited[mex]) {
            mex++;
        }
        g[pile] = mex;
    }
    if (g[k] != 0) {
        cout << "First";
    } else {
        cout << "Second";
    }
    return 0;
}


Measured memory_bytes: 640
while True:
    m, n_min, n_max = map(int, input().split())
    if m == 0:
        break
    p = [int(input()) for _ in range(m)]
    ans = tmp = 0
    for i in range(n_min, n_max+1):
        hoge = p[i-1] - p[i]
        if tmp <= hoge:
            tmp = hoge
            ans = i
    print(ans)

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

ll solve() {
    string S;
    int W;
    cin >> S >> W;
    string ans;
    for ( int i = 0; i < S.size(); i+=W ) {
        ans.push_back(S[i]);
    }
    cout << ans << "\n";
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())
flag = False

for i in range(k+1):
  tb = b
  tc = c
  for j in range(i):
    tb *= 2
  for j in range(k-i):
    tc *= 2
  if tb > a and tc > tb:
    flag = True
    break

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=4091001001001001001;
  //           3999999996000000001


  struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}//-1で初期化
    int root(int x) {
      if (d[x] < 0) return x;//rootを負にする（構成node数x(-1))
      //root以外は親の番号
      return d[x] = root(d[x]);
      //return(root(d[x]))とするとメモできないが上の書き方だとメモができる
    }
    bool unite(int x, int y) {
      x = root(x); y = root(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x,y);
      //swapすることで小さい方を大きい方につけられ計算量減らせる
      d[x] += d[y];
      d[y] = x;
      return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    //同じグループ化
    int size(int x) { return -d[root(x)];}
    //グループのnode数
      int group_num(int n){
          set<int> s;
          for(int i = 0; i < n; ++i){
              s.insert(root(i));
          }
          return int(s.size());}
  };

  int deg[100005];
  vector<int> to[100005];

int main() {
  ll n;
  cin>>n;
  vector<P>x(n);
  vector<P>y(n);
  rep(i,n){
    cin>>x[i].first;
    cin>>y[i].first;
    x[i].second=i;
    y[i].second=i;
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  vector<P> g[n];//(to,edge)
  priority_queue <pair<ll,P>, vector<pair<ll,P>>, greater<pair<ll,P>>> q;

  rep(i,n-1){
    g[x[i].second].push_back(make_pair(x[i+1].second,x[i+1].first-x[i].first));
    g[y[i].second].push_back(make_pair(y[i+1].second,y[i+1].first-y[i].first));
    q.push(make_pair(x[i+1].first-x[i].first,make_pair(x[i].second,x[i+1].second)));
    q.push(make_pair(y[i+1].first-y[i].first,make_pair(y[i].second,y[i+1].second)));

  }
  UnionFind uf(n);
  ll ans=0;

while(!q.empty()){
    auto Q=q.top();
    q.pop();
    //cout<<Q.first;
    P now=Q.second;
    if (!uf.same(now.first,now.second)){
      uf.unite(now.first,now.second);
      ans+=Q.first;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 19756
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {

  int N, W;
  cin >> N >> W;
  vector<int> w;
  vector<int> v;
  long V = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    w.push_back(a);
    v.push_back(b);
    V += b;
  }

  long **dp = new long *[N + 1];
  for (int i = 0; i <= N; i++) {
    dp[i] = new long[V + 1];
  }

  for (int i = 0; i <= N; i++) {
    for (long j = 0; j <= V; j++) {
      dp[i][j] = LONG_MAX - 1e9;
    }
  }
  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (long j = 0; j <= V; j++) {
      long temp = dp[i][j];
      if (j - v[i] >= 0)
        temp =
            temp < (w[i] + dp[i][j - v[i]]) ? temp : (w[i] + dp[i][j - v[i]]);
      dp[i + 1][j] = temp < dp[i + 1][j] ? temp : dp[i + 1][j];
    }
  }

  long ans = 0;
  for (long i = 0; i <= V; i++) {
    if (W >= dp[N][i])
      ans = i;
  }
  cout << ans << endl;

  for (int i = 0; i <= N; i++) {
    delete[] dp[i];
  }
  delete[] dp;

  return 0;
}


Measured memory_bytes: 79488
bingo = [[int(c) for c in input().split()] for _ in range(3)]

n = int(input())

for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = 0
# よこ
for i in bingo:
    if sum(i) == 0:
        print('Yes')
        exit()
# たて
for i in range(3):
    tmp = 0
    for j in range(3):
        tmp += bingo[j][i]
    if tmp == 0:
        print('Yes')
        exit()

# ななめ
n1 = 0
n2 = 0
for i in range(3):
    n1 += bingo[i][i]
    n2 += bingo[i][2-i]
if n1 == 0 or n2 == 0:
    print('Yes')
    exit()

print('No')


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

using namespace std;
#define M 1100
#define a 6

int main(){
  int N, T, A, i, h[M], dis[M], index=0, min=100000000;
  cin >> N >> T >> A;
  for (i = 0; i < N; i++){
    cin >> h[i];
    dis[i] = abs(T*1000 - h[i]*6 - A*1000);
    if (dis[i] < min){
      min = dis[i];
      index = i;
    }
  }
  cout << index + 1 << endl;
  return 0;
}


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

int main(void){
    ll n;
    cin >> n;

    ll s[n];
    ll sum = 0;
    rep(i, n){
        cin >> s[i];
        sum += s[i];
    }

    sort(s, s + n);
    if(sum % 10 == 0){
        rep(i, n){
            sum -= s[i];
            if(sum % 10 != 0){
                break;
            }
            sum += s[i];
        }
    }

    if(sum % 10 == 0)
        sum = 0;

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readListInt()
    val ab = readMatrixInt(m)
    var boxA = mutableSetOf<Int>()
    var boxB = mutableSetOf<Int>()
    ab.forEach {
        if (it[0] == 1) boxA.add(it[1])
        if (it[1] == n) boxB.add(it[0])
    }

    if (boxA.find { boxB.contains(it) } != null) {
        println("POSSIBLE")
    } else {
        println("IMPOSSIBLE")
    }
}

private fun read() = readLine()!!

private fun readInt() = Integer.parseInt(read())

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { Integer.parseInt(it) }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 89144
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

main(){
    string s;
    cin >> s;
    reverse(ALL(s));
    
    bool rullonz = true;

    int ans = 0;

    REP(i,LEN(s)){
        if(i==LEN(s)-1){
            if(rullonz) ans += s[i]-48;
            else ans += (s[i]-48)-1;

            break;
        }
        if(rullonz) rullonz = (s[i]=='9');
        ans += 9;
    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

n = gets.chomp.to_i
a = []
n.times do
  a << gets.chomp.to_i
end

a.sort!
newa = []
newb = []
if (a.size % 2 != 0)
  c = a.size / 2
  t = a.size / 2
  b = a.clone
#  if (a[c] - a[c - 1]).abs > (a[c] - a[c + 1]).abs
    newa << a.delete_at(c)
    t.times do
      newa << a.shift
      newa << a.pop if a.size > 0
    end
#  else
    newb << b.delete_at(c)
    t.times do
      newb << b.pop
      newb << b.shift if b.size > 0
    end
#  end
else
  c = a.size / 2 - 1
  t = a.size / 2
  b = a.clone
#  if (a[c] - a[-1]).abs > (a[c + 1] - a[0]).abs
    newa << a.delete_at(c)
#
    t.times do
      newa << a.pop
      newa << a.shift if a.size > 0
    end
#  else
    newb << b.delete_at(c + 1)
#
    t.times do
      newb << b.shift
      newb << b.pop if b.size > 0
    end
#  end


end
#p newa
res = 0
s = newa.shift
newa.each do |e|
  res += (s - e).abs
  s = e
end

res2 = 0
s = newb.shift
newb.each do |e|
  res2 += (s - e).abs
  s = e
end

puts [res, res2].max


Measured memory_bytes: 5616
#define rep(i,n) for(i=0;i<(n);++i)
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<utility>
#include<string>
#include<algorithm>
#include<bitset>
#include<queue>
#include<cmath>
#include<iomanip>
using ll = unsigned long long int;
using namespace std;

std::vector<pair<ll,ll>> enum_div(ll n)//nの約数を列挙
{
	std::vector<pair<ll,ll>> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back({i,n/i});
			// if(i!=1 && i*i!=n)
			// {
			// 	ret.push_back({n/i,i});
			// }
		}
	}
	return ret;
}

ll src(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>> div = enum_div(n);
    ll min=n-1,cur;
    for(auto i:div){
        cur=i.first +i.second-2;
        if(min>cur) min=cur;
    }
    cout<<min;
    return 0;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

const int S = 1 << 18;
int bit[S * 2 + 10];
void inc(int i) {
	while (i <= S) {
		bit[i]++;
		i += i & -i;
	}
}
ll val(int i) {
	ll sum = 0;
	while (i > 0) {
		sum += bit[i];
		i -= i & -i;
	}
	return sum;
}

int main() {
	int N = in();
	ll K = in();
	vector<ll> a(N);
	rep(i,N) a[i] = in();
	vector<ll> vals;
	vals.pb(0);
	ll sum = 0;
	rep(i,N) {
		sum += a[i] - K;
		vals.pb(sum);
	}
	sort(vals.begin(), vals.end());
	map<ll,ll> v2i;
	ll prev = (ll)INF * 123456;
	rep(i,vals.size()) if (vals[i] != prev) {
		v2i[vals[i]] = i;
		prev = vals[i];
	}
	sum = 0;
	vector<ll> inds(N);
	rep(i,N) {
		sum += a[i] - K;
		inds[i] = v2i[sum] + 1;
	}
	inc(v2i[0] + 1);
	ll ans = 0;
	rep(i,N) {
		ans += val(inds[i]);
		inc(inds[i]);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = INF;
  rep(i, n - k + 1) ans = min(ans, h[i + k - 1] - h[i]);
  cout << ans << endl;
  return 0;
}


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

int main() {
  string str;  
  cin >> str;
  if(str.length()==4){
    if(('A'<=str[0]&&str[0]<='Z')&&('A'<=str[1]&&str[1]<='Z')&&('A'<=str[2]&&str[2]<='Z')&&('A'<=str[3]&&str[3]<='Z') ){
      if(str[0]==str[1] && str[2]==str[3] && str[0]!=str[2]){
        cout << "Yes";
      } else if(str[0]==str[2] && str[1]==str[3] && str[0]!=str[1]) {
        cout << "Yes";
      } else if(str[0]==str[3] && str[1]==str[2] && str[0]!=str[1]){
        cout << "Yes";
      } else {
        cout << "No";
      }
    } else {
      cout << "No";
    }
  } else {
    cout << "No";
  }
	return 0;
}

Measured memory_bytes: 256
#%%
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())


ans = 0
for i in make_divisors(n):
    if i >= n ** 0.5 + 1:
        ans += i-1

print(ans)

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[27],f[N],g[N],dp[N];
char s[N];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    f[n+1]=n+2;
    g[n+1]=1;
    dp[n+1]=1;
    for (int i=1; i<=26; i++)
    {
        a[i]=n+1;
    }
    for (int i=n; i>=1; i--)
    {
        a[s[i]-'a'+1]=i;
        int t=1;
        for (int j=2; j<=26; j++)
        if (dp[a[j]+1]<dp[a[t]+1])t=j;
        dp[i]=dp[a[t]+1]+1;
        f[i]=a[t];
        g[i]=t;
    }
    int now=1;
    while(now<=n+1)
    {
        putchar(g[now]+'a'-1);
        now=f[now]+1;
    }
    return 0;
}

Measured memory_bytes: 2816
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int INF=mod;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<int, int>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,k,n) for(int i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)


//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////



int main(){

  int N; int X;
  cin >> X >> N;
  set<int> s;
  rep(i, N){
    int p; cin >> p;
    s.insert(p);
  }

  for(int i = 0;true;i++){
    if(!s.count(X - i)){
      cout << X - i << endl;
      return 0;
    }
    if(!s.count(X + i)){
      cout << X + i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int n,m,h;
int data[21];
 
bool dfs( int v, int d ){
    if( v == h )    return true;
    if( v>h || d==n )        return false;
    bool ret = dfs(v+data[d], d+1);
    if(!ret)    ret = dfs(v, d+1);
    return ret;
}
 

int main(){

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>data[i];
	}

	cin>>m;
	for(int i=0;i<m;i++){
		
		cin>>h;
		cout<< (dfs(0,0)? "yes" : "no")<<endl;

	}

		return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int gcd(int, int);

int main(){

  int x,y;

  scanf("%d%d",&x,&y);

  printf("%d\n",gcd(x,y));
  
  return 0;
}

int gcd(int x, int y){
  if(x!=0 && y!=0) return gcd(y, x%y);
  else return x;



}



Measured memory_bytes: 2144
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < p.length; ++i) {
            p[i] = sc.nextInt();
        }

        System.out.println(solve(p) ? "YES" : "NO");

        sc.close();
    }

    static boolean solve(int[] p) {
        return IntStream.range(0, p.length).filter(i -> i + 1 != p[i]).count() <= 2;
    }
}

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	i64 n, w;

	std::cin >> n >> w;

	std::vector<i64> wt(n+1);
	std::vector<i64> val(n+1);

	for(i64 i=1; i<=n; ++i)
	{
		std::cin >> wt[i];
		std::cin >> val[i];
	}

	i64 dp[w+1][n+1];

	for(i64 i=0; i<=w; ++i)
	{
		for(i64 j=0; j<=n; ++j)
		{
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
			}
			else if(i-wt[j] >= 0)
			{
				dp[i][j] = std::max(dp[i][j-1], dp[i-wt[j]][j-1]+val[j]);
			}
			else
			{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
/*
	std::clog << "===DP===\n";

	for(i64 i=0; i<=w; ++i)
	{
		for(i64 j=0; j<=n; ++j)
		{
			std::clog << dp[i][j] << "\t";
		}
		std::clog << std::endl;
	}
	std::clog << "========" << std::endl;
*/
	std::cout << dp[w][n] << "\n";
	
	return 0;
}

Measured memory_bytes: 79232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int max = 0;
		for(int i = 1 ; i <= n ; i++) {
			int mod = i;
			int cnt = 0;
			while(mod % 2  == 0) {
				mod = mod / 2;
				cnt++;
			}
			if(cnt >= max) {
				max = cnt;
				ans = i;
			}
		}
		System.out.println(ans);
		sc.close();

	}

}


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

int n;
char ope[15];
ll val[15];

void solve(){
    string str;
    rep(i,15) ope[i] = '_';
    rep(i,15) val[i] = 0;
    ope[0] = '+';
    val[0] = 0;
    if(n == 1){
        cin >> str;
        cout << str << endl;
        return;
    }
    rep(i,n){
        cin >> str;
        for(int j = 14; j >= str.size(); j--){
            if(j <= 1) break;
            if(ope[j-1] == '_') continue;
            if(ope[j-2] == '+'){
                val[j-2] += val[j-1];
            } else{
                val[j-2] *= val[j-1];
            }
            ope[j-1] = '_';
        }
        int j;
        for(j = 0; j < str.size(); j++){
            if(str[j] != '.') break;
        }
        if('0' <= str[j] && str[j] <= '9'){
            if(ope[j-1] == '+'){
                val[j-1] += str[j]-'0';
            } else{
                val[j-1] *= (str[j]-'0');
            }
        } else{
            ope[j] = str[j];
            if(ope[j] == '+') val[j] = 0;
            else val[j] = 1;
        }
    }
    for(int j = 14;; j--){
        if(j <= 1) break;
        if(ope[j-1] == '_') continue;
        if(ope[j-2] == '+'){
            val[j-2] += val[j-1];
        } else{
            val[j-2] *= val[j-1];
        }
        ope[j-1] = '_';
    }
    cout << val[0] << endl;
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}

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

#define ALL(a) sort((a).begin(), (a).end())
#define PB push_back

int main(){
    int N;
    cin >> N;
    vector<ll> a(3*N);
    int A = 3 * N;
    rep(i,A){
        cin >> a.at(i);
    }
    ALL(a);
    reverse(a.begin(), a.end());
    ll sum = 0;
    int count = N;
    int i = 1;
    while(count > 0){
        sum += a.at(i);
        count--;
        i += 2;
    }
    cout << sum << endl;
}


Measured memory_bytes: 2560
//Name: Puzzle
//Level: 2
//Category: 実装
//Note: 

/**
 * 問題文の通りに実装する。
 *
 * オーダーは O(1)。
 */
#include <iostream>
#include <vector>

using namespace std;

struct Cell {
    int val;
    bool wrong;

    Cell() : val(0), wrong(false) {}
};

void check_row(vector<vector<Cell>> &f) {
    for(int r = 0; r < 9; ++r) {
        int cnt[10] = {0};
        for(int c = 0; c < 9; ++c) {
            cnt[f[r][c].val]++;
        }
        for(int c = 0; c < 9; ++c) {
            if(cnt[f[r][c].val] > 1) f[r][c].wrong = true;
        }
    }
}

void check_col(vector<vector<Cell>> &f) {
    for(int c = 0; c < 9; ++c) {
        int cnt[10] = {0};
        for(int r = 0; r < 9; ++r) {
            cnt[f[r][c].val]++;
        }
        for(int r = 0; r < 9; ++r) {
            if(cnt[f[r][c].val] > 1) f[r][c].wrong = true;
        }
    }
}

void check_sq(vector<vector<Cell>> &f) {
    for(int r = 0; r < 9; r += 3) {
        for(int c = 0; c < 9; c += 3) {
            int cnt[10] = {0};
            for(int dr = 0; dr < 3; ++dr) {
                for(int dc = 0; dc < 3; ++dc) {
                    cnt[f[r+dr][c+dc].val]++;
                }
            }
            for(int dr = 0; dr < 3; ++dr) {
                for(int dc = 0; dc < 3; ++dc) {
                    if(cnt[f[r+dr][c+dc].val] > 1) f[r+dr][c+dc].wrong = true;
                }
            }
        }
    }
}

bool solve(bool first) {
    vector<vector<Cell>> f(9, vector<Cell>(9));
    for(int r = 0; r < 9; ++r) {
        for(int c = 0; c < 9; ++c) {
            cin >> f[r][c].val;
        }
    }
    if(!first) cout << endl;

    check_row(f);
    check_col(f);
    check_sq(f);
    for(int r = 0; r < 9; ++r) {
        for(int c = 0; c < 9; ++c) {
            cout << (f[r][c].wrong ? '*' : ' ') << f[r][c].val;
        }
        cout << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    int N;
    cin >> N;
    while(N--) {
        solve(first);
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
signed main(){
	int a=read(),b=read(),c=read();
	return cout<<min(a+b+1,c)+b,signed();
}

Measured memory_bytes: 3540