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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}
/****** define variable start ******/
ll n, m;
/******* define variable end *******/
int solve() {
	cin >> n >> m;
	vector<pair<ll, ll>> ans;
	if(m % 2 == 0){
		ll waruni = (m * 2 + 1) / 2 + 1;
		for(ll i = 1;;i++){
			if(waruni-i+1 - i <= 1){
				break;
			}
			ans.push_back(make_pair(i, waruni-i+1));
		}
		for(ll i = waruni+ 1;;i++){
			if(m * 2 + 1 - (i - waruni) + 1 - i <= 0){
				break;
			}
			ans.push_back(make_pair(i, m * 2 + 1 - (i - waruni) + 1));
		}
	}else{
		ll waruni = (m * 2 + 1) / 2;
		for(ll i = 1;;i++){
			if(waruni-i+1 - i <= 1){
				break;
			}
			ans.push_back(make_pair(i, waruni-i+1));
		}
		for(ll i = waruni+ 1;;i++){
			if(m * 2 + 1 - (i - waruni) + 1 - i <= 0){
				break;
			}
			ans.push_back(make_pair(i, m * 2 + 1 - (i - waruni) + 1));
		}
	}
	REP(i, m){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 5224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long x = Long.parseLong(scan.next());
        long k = Long.parseLong(scan.next());
        long d = Long.parseLong(scan.next());
        scan.close();

        long ans = 0;
        long absX = Math.abs(x);
        if (absX / d >= k) {
            ans = absX - k * d;
        } else {
            long sho = absX / d;
            long amari = absX % d;
            if ((k - sho) % 2 == 0) {
                ans = amari;
            } else {
                ans = d - amari;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35616
#include <iostream>

using namespace std;

int main() {
	int color[3][30] = {0};
	int D[30][30];
	int N, C;

	cin >> N >> C;
	for(int i = 0; i < C; i++) {
		for(int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			int c;
			cin >> c;
			color[(i+j)%3][c-1]++;
		}
	}

	int summin = 1100000000;
	for(int a = 0; a < C; a++) {
		for(int b = 0; b < C; b++) {
			if(b != a) {
				for(int c = 0; c < C; c++) {
					if(c != b && c != a) {
						int sum = 0;
						for(int i = 0; i < C; i++) sum += color[0][i]*D[i][a];
						for(int i = 0; i < C; i++) sum += color[1][i]*D[i][b];
						for(int i = 0; i < C; i++) sum += color[2][i]*D[i][c];
						summin = min(sum, summin);
					}
				}
			}
		}
	}
	cout << summin << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()

# 以下1と0の数を数える
num_1 = 0
num_0 = 0
for t in s:
    if t == '1':
        num_1 += 1
    else:
        num_0 += 1
# 文字列中に1と0が混在していたら必ず2つプロックを消すことが出来る
# よって1,0の最小の個数×2個消すことが出来る
ans = 2 * min(num_0, num_1)
print(ans)



Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;



int main(){
	int N,T,A;
	cin>>N>>T>>A;
	
	double mini = 1000000;
	int ans = -1;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		if(mini>(double)abs(T-a*0.006-A)){
			mini=(double)abs(T-a*0.006-A);
			ans = i+1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,i,r;
    cin>>n>>r;
    
    ll maxv=-2000000000,minv=r;
    for(i=1;i<n;i++){
        cin>>r;
        maxv=max(maxv,r-minv);
        minv=min(minv,r);
    }
    cout<<maxv<<endl;
}



Measured memory_bytes: 3108
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# 差が偶数だったら/2
# 奇数だったら端に行くまで対戦を続けないと行けない 折り返すのも考える
N, A, B = ints()
if (B - A) % 2 == 0:
    exit((B - A) // 2)
else:
    exit(min(A + (B - A) // 2, (N - B + 1) + (B - A) // 2))


Measured memory_bytes: 68824
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

enum FState { PLAIN, TREE, JUMP };
enum PState { LAND, AIR };

int field[17][16];
int dp[17][16][2];

int main() {
  int x, y;
  while (cin >> x >> y, x) {
    for (int yi = 1; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        cin >> field[xi][yi];
      }
      field[0][yi] = field[x + 1][yi] = TREE;
    }

    for (int xi = 1; xi <= x; xi++) {
      dp[xi][1][LAND] = field[xi][1] == TREE ? 0 : 1;
      dp[xi][1][AIR] = 0;
    }
    for (int yi = 2; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        // AIR
        dp[xi][yi][AIR] = field[xi][yi - 1] == JUMP ? dp[xi][yi - 1][LAND] : 0;
        // LAND
        auto& ldp = dp[xi][yi][LAND];
        switch (field[xi][yi]) {
        case PLAIN:
          ldp = dp[xi][yi - 1][AIR];
          for (int offset : {-1, 0, 1}) {
            if (field[xi + offset][yi - 1] == PLAIN) ldp += dp[xi + offset][yi - 1][LAND];
          }
          break;
        case TREE:
          ldp = 0;
          break;
        case JUMP:
          ldp = dp[xi][yi - 1][AIR];
          if (field[xi][yi - 1] == PLAIN) ldp += dp[xi][yi - 1][LAND];
          break;
        }
      }
    }
    
    int r = 0;
    for (int xi = 1; xi <= x; xi++) {
      r += dp[xi][y][LAND] + dp[xi][y][AIR];
    }
    cout << r << endl;
  }
  return 0;
}

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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;

	public static void main(String[] args) throws Exception {
		N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int cur = 0;
		while (cur < a.length && a[cur] == 0) {
			++cur;
		}
		int c0 = cur;
		while (cur < a.length && a[cur] == 1) {
			++cur;
		}
		int c1 = cur - c0;
		if (c0 % 2 == 0) {
			solve(cur, a);
			for (int i = 0; i < c0; ++i) {
				System.out.println(0);
			}
			for (int i = 0; i < c1; ++i) {
				System.out.println(1);
			}
		} else {
			if (c1 > 0) {
				solve(cur, a);
				for (int i = 0; i < c0 - 1; ++i) {
					System.out.println(0);
				}
				System.out.println(1);
				System.out.println(0);
				for (int i = 0; i < c1 - 1; ++i) {
					System.out.println(1);
				}
			} else {
				solve(cur + 1, a);
				for (int i = 0; i < c0 - 1; ++i) {
					System.out.println(0);
				}
				if (cur < a.length) {
					System.out.println(a[cur]);
				}
				System.out.println(0);
			}
		}
	}

	static void solve(int pos, int[] a) {
		if (pos <= a.length - 2 && a[a.length - 2] == 2 && a[a.length - 1] == 3) {
			for (int i = pos; i < a.length - 2; ++i) {
				System.out.println(2);
			}
			System.out.println(3);
			System.out.println(2);
			return;
		}
		for (int i = pos; i < a.length; ++i) {
			System.out.println(a[i]);
		}
	}

}

Measured memory_bytes: 12000
s = input()
x, y = map(int, input().split())
a = []
b = []

p = 0 #進む長さ
q = 1 #aとbのどちらに加えるか

for i in range(len(s)):
    if s[i] == 'T':
        if q == 1:
            a.append(p)
        else:
            b.append(p)
        q *= -1
        p = 0
    if s[i] == 'F':
        p += 1
        if i == len(s) - 1:
            if q == 1:
                a.append(p)
            else:
                b.append(p)

if a:
    x -= a.pop(0)


def knapsack(L, n):
    #リストLの要素のいくつかの足し合わせでnを作れるか？
    if n < 0 or n > sum(L):
        return False
    else:
        dp = [True] + [False] * (n)
        for l in L:
            for i in range(n, -1, -1):
                if i >= l:
                    dp[i] = dp[i - l] or dp[i]
        return dp[n]

def reachable(L, n):
    #リストLの要素の+-1倍の足し合わせでnを作れるか？
    S = sum(L)
    return (S - n) % 2 == 0 and knapsack(L, (S - n) // 2)


if reachable(a, x) and reachable(b, y):
    print('Yes')
else:
    print('No')



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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg

int main()
{
	int x, n;
	cin >> x >> n;
	vector<int> v;

	REP(i, n) {
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}

	if (n == 1) {
		if (x == v[0]) {
			cout << x-1 << endl;
			return 0;
		}
	}

	const int INIT = -10;

	sort(v.begin(), v.end());

	auto itr = std::find(v.begin(), v.end(), x);

	if (itr == v.end()){
		cout << x << endl;
	} else {
		int before = INIT;
		int next = INIT;

		auto be_itr = itr;
		auto ne_itr = itr;

		while (be_itr != v.begin()+1) {
			if (*(be_itr - 1) + 1 == *(be_itr)) {
				be_itr--;
			} else {
				before = *(be_itr)-1;
				break;
			}
		}

		if (before == INIT){
			before = v[0]-1;
		}

		while (ne_itr != v.end()-1) {
			if (*(ne_itr + 1) - 1 == *(ne_itr)) {
				ne_itr++;
			}
			else {
				next = *(ne_itr)+1;
				break;
			}
		}

		if (next == INIT) {
			next = v[n - 1]+1;
		}

		if (x - before > next - x) {
			cout << next << endl;
		} else {
			cout << before << endl;
		}

	}

	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return a;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

const int MAX = 510000;

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

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

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

int main() {
  COMinit();
  // 前処理
  ll n,k; cin >>n >>k;
  vector<ll> a(n);
  for (int i=0; i<n; i++) cin >>a.at(i);
  sort(all(a));

  ll maxes = 0;
  ll mines = 0;

  for (int i=k-1; i<n; i++){
    maxes = maxes + COM(i, k-1) * a.at(i) % MOD;
    maxes %= MOD; 
  }
  for (int i=0; i<n-k+1; i++){
    mines = mines + COM(n-1-i, k-1) * a.at(i) % MOD;
    mines %= MOD;
  }
  ll ans = (maxes - mines + MOD) % MOD;
  cout <<ans <<endl;
}

Measured memory_bytes: 12928
N,M = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
rem = M
min_price = 0
for i in range(N):
    if rem > AB[i][1]:
        min_price += AB[i][0] * AB[i][1]
        rem -= AB[i][1]
    else:
        min_price += AB[i][0] * rem
        break
print(min_price)

Measured memory_bytes: 27876
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, k;
int d;
int hasSnack[110];

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1 ; i <= n ; i++) {
		hasSnack[i] = false;
	}
	for (int i = 0 ; i < k ; i++) {
		scanf("%d", &d);
		int a;
		for (int j = 0 ; j < d ; j++) {
			scanf("%d", &a);
			hasSnack[a] = true;
		}
	}
	
	int count = 0;
	for (int i = 1 ; i <= n ; i++) {
		if (hasSnack[i] == false) {
			count++;
		}
	}
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 1720
package main

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

func main() {
    var fp *os.File = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)

    N, _ := strconv.Atoi(readLine(reader))
    line := readLine(reader)
    a_arr := strings.Split(line, " ")
    line = readLine(reader)
    b_arr := strings.Split(line, " ")

    var before_num = 0
    var cnt = 0

    for k, v := range a_arr {
        num_a, _ := strconv.Atoi(v)
        num_b := 0

        if k != N {
            num_b, _ = strconv.Atoi(b_arr[k])
        } else {
            num_b = 0
        }

        // 前の桁処理
        if before_num > 0 {
            if before_num >= num_a {
                cnt += num_a
                before_num = num_b
                continue
            } else {
                cnt += before_num
                num_a = num_a - before_num
            }
        }

        // 本桁処理
        if num_a <= num_b {
            cnt += num_a
            before_num = num_b - num_a
        } else {
            cnt += num_b
            before_num = 0
        }
    }

    fmt.Println(cnt)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, cnt, A[N];
map < int , int > M;
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]), M[A[i]] = i;
    sort(A, A + n);
    for (int i = 0; i < n; i += 2)
        if ((i & 1) != (M[A[i]] & 1))
            cnt ++;
    return !printf("%d\n", cnt);
}

Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

	vector<int> num(w + 1);

	for (int i = 1; i <= w; i++){
		num[i] = i;
	}

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

	for (int i = 1; i <= w; i++){
		printf("%d\n", num[i]);
	}

	return (0);
}

Measured memory_bytes: 1188
import sys
sys.setrecursionlimit(10**9)
f=lambda:map(int,sys.stdin.readline().split())
n,q=f()
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
c=[0]*n
for i in range(q):
  v,x=f()
  c[v-1]+=x
def dfs(v,p=-1):
  for i in g[v]:
    if i==p: continue
    c[i]+=c[v]
    dfs(i,v)
dfs(0)
print(*c)

Measured memory_bytes: 268464
K = int(input())

str_runrun = "1"

for i in range(K-1):
    str_next_runrun = str_runrun
    # 次のルンルン数を作る。ただし、未定の桁は"x"にしておく。
    for j in range(1, len(str_runrun)+1):
        if j < len(str_runrun):
            if abs(int(str_runrun[-(j+1)]) - (int(str_runrun[-j])+1)%10) <= 1:
                str_next_runrun = str_runrun[:-j] + str(int(str_runrun[-j])+1) + "x"*max((j-1),0)
                break
            else:
                pass
        elif str_runrun[0] != "9":
            str_next_runrun = str(int(str_runrun[0])+1) + "x"*(len(str_runrun)-1)
        else:
            str_next_runrun = "1" + "x"*len(str_runrun)
    # "x"にしておいた未定の桁を埋める。
    str_next_runrun_no_x_list = []
    for l in str_next_runrun:
        if l != "x":
            str_next_runrun_no_x_list.append(l)
        else:
            str_next_runrun_no_x_list.append(str(max(int(str_next_runrun_no_x_list[-1])-1, 0)))
    str_runrun = "".join(str_next_runrun_no_x_list)

print(str_runrun)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n;
    string s;
    cin>>n>>s;
    int m = COUNT(s,'.');
    int ans = m;
    REP(i,n) {
        if (s[i] == '#') {
            m++;
        } else {
            m--;
        }
        ans = min(ans, m);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>  
#include <cstdio>  
#include <algorithm>  
#include <set>  
#include <string>  
#include <cstring>  
#include <cmath>  
#include <map>  
#define N 505  
using namespace std;  
typedef long long ll;  
int c[505]; //到一个车站的花费时间  
int s[505]; //一个车站出发的等待时间  
int f[505];  //一个车站每f秒出发一个车  
int main()  
{  
    int n;  
    scanf("%d",&n);  
    for(int i=1;i<=n;i++)  
        scanf("%d%d%d",&c[i],&s[i],&f[i]);  
    for(int i=1;i<=n;i++){  
        int ans=0;  
        for(int j=i;j<n;j++){  
            if(ans<s[j])   //小于等待时间重新赋值  
                ans=s[j];  
            if(ans%f[j]!=0)    //是否处于间隔时间  
                ans=ans+f[j]-ans%f[j];  
            ans+=c[j];  
        }  
        printf("%d\n",ans);  
    }  
}  


Measured memory_bytes: 384
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[10];
		for(int i = 0; i < 10; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[9]);
		System.out.println(a[8]);
		System.out.println(a[7]);
		
	}
}

Measured memory_bytes: 0
import sys
from collections import deque
input = sys.stdin.readline

def bfs(sl, visited, sy, sx, gy, gx, h, w, k):
    q = deque([ (sy,sx) ])
    visited[sy][sx] = 0
    while q:
        # print(q)
        y, x = q.popleft()
        if [y, x] == [gy, gx]:
            return visited[gy][gx]
        for i in range(1,k+1):
            ny = y+i
            if ny >= h:
                break
            if sl[ny][x] == '@':
                break
            if 0 <= visited[ny][x] <= visited[y][x]:
                break
            if visited[ny][x] != visited[y][x]+1: 
                visited[ny][x] = visited[y][x]+1
                q.append((ny,x))

        for i in range(1,k+1):
            ny = y-i
            if ny < 0:
                break
            if sl[ny][x] == '@':
                break
            if 0 <= visited[ny][x] <= visited[y][x]:
                break
            if visited[ny][x] != visited[y][x]+1: 
                visited[ny][x] = visited[y][x]+1
                q.append((ny,x))

        for i in range(1,k+1):
            nx = x+i
            if nx >= w:
                break
            if sl[y][nx] == '@':
                break
            if 0 <= visited[y][nx] <= visited[y][x]:
                break
            if visited[y][nx] != visited[y][x]+1: 
                visited[y][nx] = visited[y][x]+1
                q.append((y,nx))

        for i in range(1,k+1):
            nx = x-i
            if nx < 0:
                break
            if sl[y][nx] == '@':
                break
            if 0 <= visited[y][nx] <= visited[y][x]:
                break
            if visited[y][nx] != visited[y][x]+1: 
                visited[y][nx] = visited[y][x]+1
                q.append((y,nx))

    return -1

def main():
    h,w,k = map(int, input().split())
    x1,y1,x2,y2 = map(int, input().split())
    cl = []
    for i in range(h):
        row = list(input())
        cl.append(row)

    visited = [ [-1]*w for i in range(h)]
    ans = bfs(cl, visited, x1-1,y1-1,x2-1,y2-1,h,w,k)
    print(ans)

if __name__ == "__main__":
    main()

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

int main(){
    string s,t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++){
        if (s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <time.h>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);		//最大公倍数
ll lcm(ll m, ll n);		//最小公倍数

int main(void) {

	int ans = 0;

	string a;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}




	cout << ans << endl;

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  

#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int A,B,C,D,E,F;
	scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);

	int m = 0;
	int w = 100*A;

	for(int i=1;i<31;i++){
		for(int j=0;j<31;j++){
			int x = 100*A*i + 100*B*j;
			if(F<x) continue;
			for(int k=0;C*k<=E*x/100;k++){
				for(int l=0;C*k+D*l<=E*x/100;l++){
					int y = C*k+D*l;
					if(y*(w+m) > m*(x+y) && (x+y)<=F){
						m = y;
						w = x;
					}
				}
			}
		}
	}

	printf("%d %d\n", (m+w), m);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) a[i] /= 400;
    vbool color(8, false);
    int over = 0;
    rep(i, n) {
        if (a[i] < 8) color[a[i]] = true;
        else over++;
    }

    int mn = accumulate(all(color), 0);
    int mx = mn + over;
    if (mn == 0) mn++;

    cout << mn << " " << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;

int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    for(int i=a;i<=b;i++){
        int s,t,u,v;
        s=i%10;t=i/10%10;
        u=i/1000%10;v=i/10000%10;
        if(s==v&&t==u) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[99];
  int N;
  cin >> N;
  for(int i=0;i<99;i++){
    int count=0;
    for(int j=1;j<=2*i+1;j++){
      if((2*i+1)%j==0) count++;
    }
    a[i]=count;
  }
  int num=0;
  for(int k=0;k<N/2+N%2;k++){
    if(a[k]==8) num++;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		int h2 = sc.nextInt(), w2 = sc.nextInt();
		sc.close();
		int ans = h2 * w + w2 * h;
		ans -= h2 * w2;
		ans = h * w - ans;
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int mul_max(int A, int B) {
  int C = 0;
  for(int i = 0; i < 10000; i++) {
    C += B;
    if(C > A) {
      break;
    }
  }
  return C - B;
}
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int X, Y;
  X = mul_max(A - 1, C) / C;
  Y = mul_max(B, C) / C;
  cout << Y - X << endl;
}


Measured memory_bytes: 3588
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(isize);
    let v_ab = get_tuple!(isize, isize; n);

    let mut v_a: Vec<_> = v_ab.iter().map(|&(a, b)| a).collect();
    let mut v_b: Vec<_> = v_ab.iter().map(|&(a, b)| b).collect();

    let ans = median(&mut v_b) - median(&mut v_a) + 1;

    println!("{}", ans)



}

fn median(numbers: &mut Vec<isize>) -> isize {

    numbers.sort();

    let mid = numbers.len() / 2;
    if numbers.len() % 2 == 0 {
        numbers[mid - 1] + numbers[mid]
    } else {
        numbers[mid]
    }

}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 2.1e5;
int N;
string S;
int op[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> S;
	S.insert(S.begin(), 'W');
	op[0] = 0;
	for (int i = 1; i <= 2*N; i++) {
		op[i] = (op[i-1] ^ (S[i-1] == S[i]));
	}
	if (op[1] == 1 || op[2*N] == 0 || accumulate(op + 1, op + 2*N + 1, 0) != N) {
		cout << 0 << '\n';
		exit(0);
	}

	int cnt = 0;
	num ans = 1;
	for (int i = 1; i <= 2*N; i++) {
		if (op[i] == 1) {
			ans *= cnt--;
		} else {
			cnt++;
		}
	}
	for (int i = 1; i <= N; i++) {
		ans *= i;
	}
	cout << ans << '\n';

	return 0;
}


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



int main() {
   int n, m;
   cin >> n >> m;
   vector<int> a(m);
   for (int i=0; i<m; i++) {
      cin >> a[i];
   }
   int suma = accumulate(a.begin(), a.end(), 0LL);
   if (suma > n) cout << -1 << endl;
   else cout << n - suma << endl;
   return 0;
}

Measured memory_bytes: 3668
import java.util.*;

public class Main{
public static void main(String... args){
Scanner sc = new Scanner(System.in);
char[] a=sc.next().toCharArray();
char[] b=sc.next().toCharArray();
Arrays.sort(a);
Arrays.sort(b);
char[] c=Arrays.copyOf(b,b.length);
for(int i=b.length-1;i>=0;i--){
b[b.length-1-i]=c[i];
}
String aa=String.valueOf(a);
String bb=String.valueOf(b);
if(aa.equals(bb)){
System.out.println("No");
return;
}
String[] x=new String[]{aa,bb};
Arrays.sort(x);
if(x[0].equals(aa)){
System.out.println("Yes");
}else{
System.out.println("No");
}


}
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rnr(i, a, b) for(int i = int(a); i >= int(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

bool isRectangle(int a, int b, int c) {
    return (a + b > c) && (b + c > a) && (c + a > b);
}

bool isDifferent(int a, int b, int c) {
    return a != b && a != c && b != c;
}

int main() {
    int n; cin >> n;
    ll l[n]; rep(i, n) cin >> l[i];
    sort(l, l + n);
    //sort不要かも
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            for(int k = j + 1; k < n; ++k) {
                if(isRectangle(l[i], l[j], l[k]) && isDifferent(l[i], l[j], l[k]))
                    ++ans;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 7;
int dp[N][2];
char s[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> s + 1; int n = strlen(s + 1);
	vector<int> v(1);
	for(int i = 1; i <= n; ++ i){
		v.push_back(s[i] - '0');
	}
	dp[0][0] = 0; dp[0][1] = 11;
	for(int i = 1; i <= n; ++ i){
		dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + v[i];
		dp[i][1] = min(dp[i - 1][0] + 1, dp[i - 1][1] - 1) + 10 - v[i];
	}
	cout << min(dp[n][0], dp[n][1]) << '\n';
	return 0;
}

Measured memory_bytes: 13036
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
	int h;
	std::vector<int> heights;
	for(int i=0; i<10; i++){
		std::cin >> h;
		heights.push_back(h);
	}
	std::sort(heights.begin(), heights.end(), std::greater<int>());
	int i=0;
	for(std::vector<int>::iterator it=heights.begin();
		i<3 && it!=heights.end(); i++, it++){
			std::cout << *it << '\n';
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long ll;
#define F(i,L,R) for (ll i = L; i < R; i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(x) scanf("%lld",&x)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll l,r,d;
  cin>>l>>r>>d;

  ll p = l/d;
  if(l%d!=0) p++;
  ll cnt = 0;
  while(p*d<=r) {
      cnt++;
      p++;
  }

  cout<<cnt<<endl;


  return 0;
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll x,a;
	cin >> x >> a;
	if(x < a) cout << 0 << endl;
	else cout << 10 << endl;
}
    // Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int a[10],x;
char c;
int main()
{
    while(cin>>c&&c!='\0')
    {
        if(c=='0') a[x++]=0;
        else if(c=='1') a[x++]=1;
        else
        {
            if(x) x--;
        }
    }
    if(x)
    {
        for(int i=0;i<x;i++) printf("%d",a[i]);
        printf("\n"); 
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main()
{
	int n, m;
	cin >> n >> m;
	if (n == m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int max = 0;
  vector<int> ary;
  vector<int> sorted;
  for(int i=0; i<N; i++) {
    int num;
    cin >> num;
    ary.push_back(num);
    sorted.push_back(num);
  }
  sort(sorted.begin(), sorted.end(), greater<int>());

  for (int i=0; i<N; i++) {
    if (sorted[0] == ary[i]) {
      max = sorted[1];
    } else {
      max = sorted[0];
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 3436
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

N = intinput()
a = []
for i in range(N):
    a.append(intinput())
state = 1
flag = 0
count = 0
for i in range(N):
    if a[state-1] == 2:
        flag = 1
        count += 1
        break
    else:
        state = a[state-1]
        count += 1

if flag == 1:
    print(count)
else:
    print(-1)


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

namespace A_Frog_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var hi = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var costs = new int[N];
            costs[0] = 0;
            costs[1] = Math.Abs(hi[0]-hi[1]);

            for(int i=2;i<=N-1;i++)
            {
                costs[i] = Math.Min(costs[i-2]+Math.Abs(hi[i-2]-hi[i]),costs[i-1]+Math.Abs(hi[i-1]-hi[i]));
            }
            Console.WriteLine(costs[N-1]);
        }
    }
}


Measured memory_bytes: 18016
// Greatest Common Divisor
// 最大公約数を求めるプログラム
// ヒント：X>=YにおいてGCD(Y,X%Y)とGCD(X,Y)は等しい。
// 入力　X,Y
// 出力　GCD(X,Y)
// 
// 1,入力値において大きい値をx,小さい値をyにならべかえる
// 2,x%y==0ならば終了。yを出力する。
// 3,x%yの値と、yの値を入力値として1に戻る。

#include<iostream>

int main(){
	
	long x, y, tmp;

	// Input
	std::cin >> x>>y;

	// Search

	for (;;) {
		if (x < y) {
			tmp = x;
			x = y;
			y = tmp;
		}
	
	// x>=yとなる。

		if (x % y == 0) break;

		x = x % y;
	}

	std::cout << y << std::endl;

	return 0;
}


Measured memory_bytes: 3116
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long k = sc.nextLong();
			long n = sc.nextLong();
			List<Long> an = new ArrayList<>();
			for (long i = 0; i < n; i++) {
				an.add(sc.nextLong());
			}
			long max = 0;
			for (int i = 0; i < an.size(); i++) {
				long cand;
				if (i == an.size() - 1) {
					cand = k - an.get(i) + an.get(0);
				} else {
					cand = an.get(i + 1) - an.get(i);
				}
				if (cand > max) {
					max = cand;
				}
			}

			// 出力(整数)
			System.out.println(k - max);
		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}

Measured memory_bytes: 85608
def is_int(s):
    try:
        i = int(s)
    except:
        return False
    return True

stdin = input().split()

if (len(stdin) > 3):
    print("Too many arguments.")
    exit()
elif (len(stdin) < 3):
    print("Too few arguments.")
    exit()
elif (not is_int(stdin[0])):
    print("N is not a number.")
    exit()
elif (not is_int(stdin[1])):
    print("M is not a number.")
    exit()
elif (not is_int(stdin[2])):
    print("C is not a number.")
    exit()

N = int(stdin[0])
M = int(stdin[1])
C = int(stdin[2])

if (N < 1 or N > 20):
    print("Out of range at N.")
    exit()
elif (M < 1 or M > 20):
    print("Out of range at M.")
    exit()
elif (C < -100 or C > 100):
    print("Out of range at C.")
    exit()

stdin = input().split()

if (len(stdin) > M):
    print("Too many arguments.")
    exit()
elif (len(stdin) < M):
    print("Too few arguments.")
    exit()

B = []

for index, value in enumerate(stdin):
    if (not is_int(value)):
        print("B[%d] is not a number." % (index + 1))
        exit()

    B.append(int(value))

for index, value in enumerate(B):
    if (value < -100 or value > 100):
        print("Out of range at B[%d]." % (index + 1))
        exit()

A = [[] for j in range(N)]

for i in range(0, N):
    stdin = input().split()

    if (len(stdin) > M):
        print("Too many arguments.")
        exit()
    elif (len(stdin) < M):
        print("Too few arguments.")
        exit()

    for index, value in enumerate(stdin):
        if (not is_int(value)):
            print("A[%d][%d] is not a number." % ((i + 1), (index + 1)))
            exit()

        A[i].append(int(value))

    for index, value in enumerate(A[i]):
        if (value < -100 or value > 100):
            print("Out of range at A[%d][%d]." % ((i + 1), (index + 1)))
            exit()

right_answer = 0

for i in A:
    sum = 0

    for index, value in enumerate(i):
        sum += value * B[index]

    sum += C

    if (sum > 0):
        right_answer += 1

print(right_answer)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
int bit[10]={1,2,4,8,16,32,64,128,256,512};
int main(){
	
	for(int n;cin>>n,n;){
		int K[26]={},f[26]={},u[26]={},ans=0;
		for(int i=1;i<=n;i++){
			string s;cin>>s;
			for(int j=s.size()-1,k=1;j>=0;j--,k*=10){
				if(j==0 && s.size()!=1)f[s[j]-'A']=1;
				K[s[j]-'A']+=(i==n?-k:k);
				u[s[j]-'A']=1;
			}
		}
		map<int,vector<int> >M;
		vector<P>V;
		for(int i=0;i<26;i++)if(u[i])V.push_back(P(K[i],f[i]));
		int base=1,num=V.size();num=min(5,num);
		for(int i=0;i<num;i++,base*=10);
		for(int i=0;i<base;i++){
			int tmp=0,flg=0,k=i,g=0;
			for(int j=0;j<num;j++,k/=10){
				if(g&bit[k%10])flg=1;
				g+=bit[k%10];
				if(V[j].second && k%10==0)flg=1;
				
				tmp+=V[j].first*(k%10);
				
			}
			if(flg)continue;
			M[tmp].push_back(g);
		}
		if(V.size()<=5){
			cout<<M[0].size()<<endl;
			continue;
		}
		
		base=1;num=V.size();
		for(int i=5;i<num;i++,base*=10);
		for(int i=0;i<base;i++){
			int tmp=0,flg=0,k=i,g=0;
			for(int j=5;j<num;j++,k/=10){
				if(g&bit[k%10])flg=1;
				g+=bit[k%10];
				if(V[j].second && k%10==0)flg=1;
				tmp-=V[j].first*(k%10);
			}
			if(flg)continue;
			for(int j=0;j<M[tmp].size();j++){
				int p=M[tmp][j];
				
				if((p & g) == 0)ans++;
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};




int row,col;
char grid[55][55];
bool visited[52][52];

void runDFS(int x,int y)
{
    if(x < 1  ||  y < 1  ||  x > row  ||  y > row  ||  grid[x][y] == '.'  ||  visited[x][y])return;
    visited[x][y]=true;
    for(int i=0;i<4;i++)runDFS(x+dx[i],y+dy[i]);
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,j;
    cin >> row >> col;
    for(i=1;i<=row;i++)cin >> grid[i]+1;
    for(i=1;i<=row;i++)
    {
        for(j=1;j<=col;j++)
        {
            if(grid[i][j] == '#'  &&  !visited[i][j])
            {
                if(grid[i-1][j] != '#'  &&  grid[i+1][j] != '#'  &&  grid[i][j-1] != '#'  &&  grid[i][j+1] != '#')
                {
                    cout << "No";
                    return 0;
                }
                runDFS(i,j);
            }
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  ll i,j;
  int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
  if(a==0){cout << 1 << endl;return 0;}
  if(b==0){cout << 2 << endl;return 0;}
  if(c==0){cout << 3 << endl;return 0;}
  if(d==0){cout << 4 << endl;return 0;}
  if(e==0){cout << 5 << endl;return 0;}
  ll ans = 0;

  return 0;
}


Measured memory_bytes: 3636