akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k; cin >> n >> k;
	string s; cin >> s;
	if( s[k-1] == 'A' ) s[k-1] = 'a';
	else if( s[k-1] == 'B' ) s[k-1] = 'b';
	else s[k-1] = 'c';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
require 'set'
a=gets.split(" ").map{|e| e.to_i}
l=a[0]
r=a[1]

ans=2019
(l..([l+2019,r-1].min)).each{|e1|
	((e1+1)..([e1+2019,r].min)).each{|e2|
		ans=[ans,(e1*e2)%2019].min
	}
}
p ans

Measured memory_bytes: 2172
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      double a = Math.log(sc.nextDouble());
      double b = Math.log(sc.nextDouble());
      if(a > b){
      	System.out.println("GREATER");
      }else if(a==b){
      	System.out.println("EQUAL");
      }else{
      	System.out.println("LESS");
      }
    }
}


Measured memory_bytes: 23252
N, K = map(int, input().split())
A = list(map(int, input().split()))
a=[0]*200001
cnt=0
for i in range(N):
    if a[A[i]]==0:
        cnt+=1
    a[A[i]]+=1
a.sort(reverse=True)
sum=0
for i in range(cnt-K):
    sum+=a[cnt-i-1]

print(sum)


Measured memory_bytes: 32208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <fstream>
#include<iomanip>
#define endl "\n"
#define ll long long
#define countBit1(x) __builtin_popcountll(x)
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a+n);
    int s = 0;
    for(int i = 0; i < k; i++)
        s+= a[i];
        cout << s;
    return 0;
}

Measured memory_bytes: 3660
a, b, c, d = map(int,input().split())

sw1 = 0
sw2 = 0
count  = 0
for i in range(100):
    if i == a:
        sw1 = 1
    elif i == b:
        sw1 = 0
    if i == c:
        sw2 = 1
    elif i == d:
        sw2 = 0

    if sw1 == 1 and sw2 == 1:
        count += 1

print(count)

Measured memory_bytes: 3060
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int max = 1130;
        boolean[] prime = new boolean[max];
        for(int i=2; i<max; i++) prime[i] = true;
        for(int i=2; i<prime.length; i++){
            for(int j=i*2; j<prime.length; j+=i){
                prime[j] = false;
            }
        }

        int[][] dp = new int[15][max];
        /*
        for(int i=0; i<max; i++){
            if(prime[i]) dp[1][i] = 1;
        }
        */
        dp[0][0] = 1;
        for(int i=0; i<max; i++){
            if(!prime[i]) continue;
            for(int j=14; j>=1; j--){
                for(int k=max-1; k>=i; k--){
                    dp[j][k] += dp[j-1][k-i];
                }
            }
        }

        int n = sc.nextInt();
        int k = sc.nextInt();
        while(n!=0 || k!=0){
            System.out.println(dp[k][n]);
            n = sc.nextInt();
            k = sc.nextInt();
        }
    }

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

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

int main(){
	int a,b,c,ans=0;
	vector<int> ca,cb;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",&c);
		ca.push_back(c);
	}
	for(int i=0;i<b;i++){
		scanf("%d",&c);
		cb.push_back(c);
	}
	int k;
	for(int i=0;i<b;i++){
		k=i;
		for(int j=0;j<a;j++){
			if(ca[j]==cb[k])k++;
			if(k==b)break;
		}
		if(ans<k-i)ans=k-i;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
int main() {
    int S, W;
    cin >> S >> W;

    if(W>=S) cout << "unsafe" << endl;
    else cout <<  "safe" << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 1e6 + 233;
char str[N];
int n;

main(void) {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  int ans = n * (n + 1) / 2;
  vector<int> cnt(N);
  for (int i = 1; i <= n; i ++)
    cnt[str[i]] ++;
  for (int ch = 'a'; ch <= 'z'; ch ++)
    ans -= cnt[ch] * (cnt[ch] + 1) / 2;
  cout << ans + 1 << "\n";
}


Measured memory_bytes: 8192
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, d: "List[int]"):
    d.sort()
    print(d[N//2]-d[N//2-1])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14324
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int, int>
#define Point Vect
#define no {cout << "0\n"; return;}
#define mkp make_pair
#define cerr if (0) cerr

vector <int> cur;
vector <ti> ask;

int recurs (int pos, int m) {
    if (pos == cur.size()) {
        int ans = 0;
        for (ti t : ask)
            if (cur[get<1>(t) - 1] - cur[get<0>(t) - 1] == get<2>(t))
                ans += get<3>(t);
        return ans;
    }
    int lst = (pos == 0 ? 1 : cur[pos - 1]), ans = 0;
    for (int i = lst; i <= m; ++i) {
        cur[pos] = i; 
        ans = max(ans, recurs(pos + 1, m));
    }
    return ans;
}

void solve() {
    int n, m, q;
    cin >> n >> m >> q;
    ask.resize(q);
    cur.resize(n);
    loop(i, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        ask[i] = make_tuple(a, b, c, d);
    }
    cout << recurs(0, m);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3668
#include <cstdio>
using namespace std;
int main(){
  int i, n, max=-1000000, min=1000000;
  long long sum=0;
  scanf("%d", &n);
  int arr[n];
  for (i=0; i<n; i++) {
    scanf("%d", &arr[i]);
  }
  for (i=0; i<n; i++) {
    if(max<arr[i]) max=arr[i];
    if(min>arr[i]) min=arr[i];
    sum+=arr[i];
  }
  printf("%d %d %lld\n", min, max, sum);
}


Measured memory_bytes: 2760
/* Atcoder abc147c
 * See tasks at: https://atcoder.jp/contests/abc147/tasks/abc147_c
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <cmath>

using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    
    vector<int> a(n);
    vector<vector<int>> x(n);
    vector<vector<int>> y(n);
    for (int i=0; i < n; i++)
    {
        cin >> a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);

        for (int j=0; j < a[i]; j++)
        {
            int val;
            cin >> val >> y[i][j];
            x[i][j] = val - 1;
        }
    }

    int max_honest = 0;

    for (uint16_t bit=0; bit < pow(2, n); bit++)
    {
        vector<int> est(n);
        
        for (int i=0; i < n; i++)
        {
            est[i] = (bit & (1 << i)) == 0 ? 0 : 1;
        }
        
        for (int i=0; i < n; i++)
        {
            for (int j=0; j < a[i]; j++)
            {
                if (est[i] == 1 && y[i][j] != est[x[i][j]])
                {
                    goto COUNTINUE;
                }
            }
        }

        {
            int honest = count(est.begin(), est.end(), 1);
            max_honest = max(max_honest, honest);
        }

        COUNTINUE:;
    }

    cout << max_honest;
    
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    string X;
    cin >> X;
    ll t = count(X.begin(), X.end(), '1');
    if (t == 0) {
        for (int i = 0; i < N; i++) cout << 1 << endl;
        return 0;
    }
    vector<ll> powl(N+1, 1), pow(N+1, 1), powu(N+1, 1);
    for (int i = 1; i <= N; i++) {
        if (t > 1) powl[i] = powl[i-1]*2%(t-1);
        pow[i] = pow[i-1]*2%(t);
        powu[i] = powu[i-1]*2%(t+1);
    }
    ll allu = 0, all = 0, alll = 0;
    for (int i = 0; i <= N-1; i++) {
        if (X[N-1-i] == '1') {
            alll += powl[i];
            all += pow[i];
            allu += powu[i];
            if (t > 1) alll %= t-1;
            all %= t;
            allu %= t+1;
        }
    }
    
    for (int i = 0; i <= N-1; i++) {
        ll cnt = 1;
        ll now;
        if (X[i] == '0') {
            now = (allu + powu[N-1-i])%(t+1);
        }else {
            if (t == 1) {
                cout << 0 << endl;
                continue;
            }
            now = (alll + (t-1) - powl[N-1-i])%(t-1);
        }
        while (now > 0) {
            now %= __builtin_popcount(now);
            cnt++;
        }
        cout << cnt << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8320
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var a = int.Parse(Console.ReadLine());
        int[] one = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int[] two = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        Console.WriteLine(Math.Abs(num(one)-num(two)));
    }

    static int num(int[] arr)
    {
        int sum = 0;
        int[] b = new int[10];
        b = b.Select(v => v = 1).ToArray();
        int len = arr.Length;
        for(int i = 0; i < len; i++)
        {
            int val = arr[i];
            sum += kai(len-1-i) * b.Take(val - 1).Sum();
            b[val - 1] = 0;
        }
        return sum;
    }

    public static int kai(int n)
    {
        if (n == 0)
            return 1;
        return n * kai(n - 1);
    }


}

Measured memory_bytes: 27756
import java.util.Scanner;

/**
 *
 */

/**
 * @author bluen
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int a2=a*a;
		int a3=a*a*a;

		System.out.println(a+a2+a3);
	}

}


Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, answer = 0;
    cin >> N;
    vector<int> happiness(3);
    vector<vector<int>> dp(N + 1, vector<int>(3));
    for(int i = 0;i < N; i++){
        cin >> happiness[0] >> happiness[1] >> happiness[2];
        for(int j = 0;j < 3; j++){     // 前日の行動
            for(int k = 0;k < 3; k++){ // 今日の行動
                if(j == k) continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happiness[k]);
            }
        }
    }

    for(int i = 0;i < 3;i++){
        answer = max(answer,dp[N][i]);
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 5760
function main(input) {
  var inputs = input.split("\n");
  var N = Number(inputs[0]);
  var a = inputs[1].split(" ").map(v=>v-0);
  var sums = [];
  for(var i=0;i<a.length;i++){
    sums[i] = (sums[i-1]||0) + a[i];
  }
  sums.push(0);
  sums.sort((a,b)=>a-b);
  var map = {};
  for(var i=1;i<sums.length;i++){
    if(sums[i-1]==sums[i]) map[sums[i-1]] = (map[sums[i-1]]||0)+1;
  }
  var ans = 0;
  Object.keys(map).forEach(key=>{
    ans += map[key]*(map[key]+1)/2;
  });
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 62644
#C
import math
N = int(input())
n = math.ceil(math.sqrt(N))

yaku = []
for i in range(n):
    I = i+1
    if N%I == 0:
        yaku.append(I)
        
ans = 11
for y in yaku:
    a,b = y,N//y
    ast = str(a)
    bst = str(b)
    ans = min(ans,max(len(ast),len(bst)))

print(ans)



Measured memory_bytes: 3060
n,k = map(int,input().split(" "))
s = list(input())
if s[k-1] == "A":
    s[k-1] = "a"
elif s[k-1] == "B":
    s[k-1] = "b"
else:
    s[k-1] = "c"
for i in range(n):
    print(s[i],end= "")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0;
  int n;
  cin>>n;
  vector<int> num(n);
  for(int i=0; i<n; i++){
    cin>>num.at(i);
  }
  int a=n+1;
  for(int i=0; i<n; i++){
    if(num.at(i)<a){
      ans++;
      a=num.at(i);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string a, b; cin >> a >> b;
    a += b;
    int n = stoi(a);
    double x = 1.0;
    if (modf(sqrt(n), &x) == 0) printf("%s\n", "Yes");
    else printf("%s\n", "No");
}


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

int main(){
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string ss;
    cin >> ss;
    if(ss==s) a--;
    else b--;
    cout << a << " " << b << endl;

    return 0;
}








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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 2147483647

signed main() {
	int a, b;
	string op;
	cin >> a >> op >> b;
	int res;
	if (op == "+") {
		res = a + b;
	} else {
		res = a - b;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 - (y2 - y1) << " " << y2 + (x2 - x1) << " " << x1 - (y2 - y1) << " " << y1 + (x2 - x1) << endl;
    
    
}


Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

li = list(map(int, input().split()))
N, A, B, C = li[0], li[1], li[2], li[3]
l = sorted([ int(input()) for i in range(N) ])

INF = 1e9

def dfs(ind, a, b, c):
    if ind == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return INF
    ret0 = dfs(ind+1, a, b, c)
    ret1 = dfs(ind+1, a + l[ind], b, c) + 10
    ret2 = dfs(ind+1, a, b + l[ind], c) + 10
    ret3 = dfs(ind+1, a, b, c + l[ind]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 12440
# w を、英小文字のみからなる文字列とします。 
# w が以下の条件を満たすならば、
# w を美しい文字列と呼ぶことにします。
#   どの英小文字も、w 中に偶数回出現する。
# 文字列 w が与えられます。
# w が美しい文字列かどうか判定してください。

# 文字列を取得
w = gets.chomp

# 出現する文字を格納する配列を宣言
words = Array.new

# 出現する文字を配列に格納
w.length.times do |i|
  if words.include?(w[i])
    next
  else
    words << w[i]
  end
end

# 美しい文字列かどうかの結果を格納する変数を宣言
# 仮に、文字列は美しいとしておく
beautiful = true

# 美しい文字列か判定
words.length.times do |i|
  
  # その文字が何回、文字列中に出現するか格納する変数を宣言
  count = 0
  
  # その文字が何回、文字列中に出現するか数える
  w.length.times do |j|
    if words[i] == w[j]
      count += 1
    end
  end
  
  # その文字が奇数回、出現していた場合の処理
  # (文字列が美しくなかった場合)
  if count.odd?
    beautiful = false
    puts "No"
    break
  end
end

# 美しい文字列であれば、Yesと出力
if beautiful
  puts "Yes"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<vector<int>> ld(20, vector<int>(n));
    vector<vector<int>> rd(20, vector<int>(n));
    vector<vector<long long>> ls(20, vector<long long>(n));
    vector<vector<long long>> rs(20, vector<long long>(n));
    for (int i = 0; i < n; i++) {
        ld[0][i] = upper_bound(x.begin(), x.end(), x[i] - k) - x.begin() - 1;
        rd[0][i] = lower_bound(x.begin(), x.end(), x[i] + k) - x.begin();
        ls[0][i] = ld[0][i];
        rs[0][i] = rd[0][i];
    }
    for (int i = 1; i < 20; i++) {
        for (int j = 0; j < n; j++) {
            ld[i][j] = (ld[i - 1][j] == -1 ? -1 : ld[i - 1][ld[i - 1][j]]);
            rd[i][j] = (rd[i - 1][j] == n ? n : rd[i - 1][rd[i - 1][j]]);
            ls[i][j] = (ld[i - 1][j] == -1 ? 0 : ls[i - 1][j] + ls[i - 1][ld[i - 1][j]]);
            rs[i][j] = (rd[i - 1][j] == n ? 0 : rs[i - 1][j] + rs[i - 1][rd[i - 1][j]]);
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        if (l == r) {
            cout << 1 << '\n';
            continue;
        }
        l--, r--;
        long long ans = r - l + 1;
        int pl = l, pr = r;
        for (int i = 19; i >= 0; i--) {
            if (rd[i][pl] <= r) {
                ans -= rs[i][pl];
                pl = rd[i][pl];
                ans += 1 << i;
            }
            if (ld[i][pr] >= l) {
                ans += ls[i][pr];
                pr = ld[i][pr];
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 100236
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,tt,tcst, cst=10000;
  cin >> n >> t;
  for(int i=0;i<n;i++){
    cin >> tcst >> tt;
    if(tcst < cst && tt <= t) cst = tcst;
  }
  if(cst == 10000) cout << "TLE" << endl;
  else cout << cst << endl;
}

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

namespace ConsoleApp15
{
    class Class308
    {
        static void Main()
        {
            string s = Console.ReadLine();
            if (s == "ABC") Console.WriteLine("ARC");
            else Console.WriteLine("ABC");
        }
    }
}


Measured memory_bytes: 25884
#include<bits/stdc++.h> 
using namespace std; 
#define int long long
const int mod = 1e9 + 7, N = 3001;
vector < int > l(N, 0);

int memo[N][N];

int dp(int i, int j){
    if(memo[i][j] != -1) return memo[i][j];
    if(i == j) return memo[i][j] = l[i];
    return memo[i][j] = max(l[i] - dp(i + 1, j), l[j] - dp(i, j - 1));
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    for(int i = 0;i < n;++i) cin >> l[i];

    memset(memo, -1, sizeof(memo));

    cout << dp(0, n - 1) << endl;

}

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

int main(){
  int N;
  cin>>N;
  ll h,n,w;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      if(4*i*j-N*i-N*j>0&&(N*i*j)%(4*i*j-N*i-N*j)==0){
        h=i;
        n=j;
        w=N*h*n/(4*h*n-N*n-N*h);
        break;
      }
    }
  }
  cout<<h<<" "<<n<<" "<<w<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
double dp[3010][3010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    vector<double> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n + 1)rep(j, n + 1) dp[i][j] = 0;
    dp[0][0] = 1;

    _rep(i, 1, n + 1)rep(j, i + 1){
        if(j > 0) dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
        else dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
    }

    double ans = 0;
    _rep(i, n / 2 + 1, n + 1) ans += dp[n][i];
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 74360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X;
  cin >> X;
  long long Y = 100;
  long long i = 0;


while(X > Y){
    Y = 1.01 * Y;
    i = i + 1;
}

cout << i <<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <ctype.h>

int main()
{
 char str[1200];
 char c;
 int i=0;
 while(1)
 {
  scanf("%c",&c);
  if(c== '\n' )
   break;
  if(isupper(c))
    str[i]=tolower(c);
  else
  {
     str[i]=toupper(c);
  }
  i++;
 }
 str[i] = '\0';
 printf("%s\n", str);
 return 0;
}

Measured memory_bytes: 528
/* An ACEASH Source code  */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>

#define vvi vector< vector < int > >
#define vvl vector< vector < ll > >

#define pii pair< int , int >
#define pll pair< ll , ll >

#define vpl vector< pll >
#define vpi vector< pii >

#define MOD 1000000007

#define mp make_pair
#define pb push_back

#define sare(v) (v).begin(),(v).end()

#define F first
#define S second

#define tez  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ld pie = 3.1415926535897932384626 ;



int main()
{

       ll n,x,t;
       cin>>n>>x>>t;
       ll h=ceil((double)n/x);
       cout<<(h*t);







    return 0;
}




Measured memory_bytes: 3740
#https://atcoder.jp/contests/abc139/tasks/abc139_b

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

c = a-1
cnt=0
'''
cnt = b // c
if b%c>1:
    cnt+=1
print(cnt)
'''
'''
b-=a
cnt = 1
if b>0:
    while True:
        if b>0:
            b-=c
            cnt+=1
        else:
            break
'''
while True:
    if b>1:
        b-=c
        cnt+=1
    else:
        break
print(cnt)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  string S; cin >> S;

  int ans = 0;
  int cnt = 0;
  rep(i, S.length()) {
    if (S[i] == 'g') {
      if (cnt > 0) {
        ans++;
        cnt--;
      } else {
        cnt++;
      }
    } else {
      if (cnt > 0) {
        cnt--;
      } else {
        ans--;
        cnt++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

const int INF = 1001001001;

struct Sieve{
  ll n;
  vector<ll> f, primes;
  Sieve(ll n = 1): n(n), f(n+1, 0){
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; i++){
      if(f[i]) continue;
      primes.emplace_back(i);
      f[i] = i;
      for(ll j = i*i; j <= n; j += i) if(!f[j]) f[j] = i;
    }
  }
  bool isPrime(const ll x){ return f[x] == x; }
  vector<ll> factorList(ll x){
    vector<ll> res;
    while(x != 1){
      res.emplace_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<pair<ll, ll>> factor(const ll x){
    vector<ll> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<pair<ll, ll>> res(1, pair<ll, ll>(fl[0], 0));
    for(ll p : fl){
      if(res.back().first == p) res.back().second++;
      else res.emplace_back(pair<ll, ll>(p, 1));
    }
    return res;
  }
};

ll gcd(ll a, ll b){ return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b){ return a/gcd(a,b)*b; }

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  Sieve s(1000000);
  map<ll, ll> mp;
  REP(i, n){
    auto f = s.factor(a[i]);
    for(auto p : f){
      mp[p.first]++;
    }
  }
  bool pc = true;
  for(auto p : mp){
    if(p.second > 1) pc = false;
  }
  if(pc){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  ll g = gcd(a[0], a[1]);
  REP(i, n-2) g = gcd(g, a[i+2]);
  if(g == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  return 0;
}

Measured memory_bytes: 24436
/* atcoder.jp : abc177_a : practice */
#include <iostream>
#include <sstream>
#include <string>
#include <utility>


std::tuple<int,int,int> parse_3_ints(const std::string& s) 
{
    int space_pos = s.find_first_of(' ');
    int fst = std::stoi(s.substr(0, space_pos));

    while (++space_pos < s.length() && s[space_pos] == ' ') { }
    int space_pos2 = space_pos;
    while (++space_pos2 < s.length() && s[space_pos2] != ' ') { }
    int snd = std::stoi(s.substr(space_pos, space_pos2));

    while (++space_pos2 < s.length() && s[space_pos2] == ' ') { }
    int trd = std::stoi(s.substr(space_pos2));
    return {fst, snd, trd};
}

std::string ok_message(bool condition)
{
    return condition ? "Yes" : "No";
}

int main() 
{
    std::string line;
    std::getline(std::cin, line);
    auto [d, t, s] = parse_3_ints(line);
    
    bool ok = d <= t * s;
    std::cout << ok_message(ok) << "\n";

    return 0;
}


Measured memory_bytes: 3112
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.insert(N+1, 0)

sum_a = 0
for i in range(1, N+2):
    sum_a += abs(a[i-1]-(a[i]))
for i in range(1, N+1):
    print(sum_a-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

Measured memory_bytes: 14048
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
n, m = map(int, input().split())
L = []
R = []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
maxL = max(L)
minR = min(R)
print(max(0, minR - maxL + 1))


Measured memory_bytes: 11548
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
       Scanner sc = new Scanner(System.in);
     int A = sc.nextInt();
     int B = sc.nextInt();
     int H = sc.nextInt();
     int M = sc.nextInt();
     
     double rad = 2*Math.PI*(H+M/60.0)/12-2*Math.PI*M/60; 
     double C = Math.sqrt(A*A+B*B-2*A*B*Math.cos(rad));
     
     System.out.println(C);
     }
    
}


Measured memory_bytes: 27072
#include <iostream>
#include <stdio.h>

#define N 16'001
#define O 8'000

using namespace std;

bool X[2][N]{};
bool Y[2][N]{};

int main() {
  string s;
  int x, y;
  cin >> s;
  cin >> x >> y;

  int i = 0;
  int M = s.size();
  int d = 0;
  while (i < M && s[i++] == 'F') {
    ++d;
  }
  X[0][d + O] = true;
  d = 0;
  while (i < M && s[i++] == 'F') {
    ++d;
  }
  Y[0][d + O] = true;
  Y[0][-d + O] = true;

  int j = 1;
  while (i < M) {
    d = 0;
    while (i < M && s[i++] == 'F') {
      ++d;
    }
    for (int k = 0; k <= 2 * M; ++k) {
      if ((k - d) >= 0 && (k + d) <= 2 * M) {
        X[j % 2][k - M + O] = X[(j - 1) % 2][k - M + O - d] || X[(j - 1) % 2][k - M + O + d];
      } else if ((k - d) >= 0) {
        X[j % 2][k - M + O] = X[(j - 1) % 2][k - M + O - d];
      } else if ((k + d) < N) {
        X[j % 2][k - M + O] = X[(j - 1) % 2][k - M + O + d];
      }
    }

    d = 0;
    while (i < M && s[i++] == 'F') {
      ++d;
    }
    for (int k = 0; k <= 2 * M; ++k) {
      if ((k - d) >= 0 && (k + d) < N) {
        Y[j % 2][k - M + O] = Y[(j - 1) % 2][k - M + O - d] || Y[(j - 1) % 2][k - M + O + d];
      } else if ((k - d) >= 0) {
        Y[j % 2][k - M + O] = Y[(j - 1) % 2][k - M + O - d];
      } else if ((k + d) < N) {
        Y[j % 2][k - M + O] = Y[(j - 1) % 2][k - M + O + d];
      }
    }
    ++j;
  }
  bool res = X[(j - 1) % 2][x + O] && Y[(j - 1) % 2][y + O];
  if (res) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

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

int main() {
    int N; 
    cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    cout << vec.back()-vec.at(0) << endl;
}

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

int main() {
	int S;

	cin >> S;

	int h, m, s;

	h = S/3600;
	m = (S/60)%60;
	s = S - (h*3600+m*60);

	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int n,k,h[200005];
ll ans=0;
int main(void){
	cin>>n>>k;
	REP(i,n)cin>>h[i];
	sort(h,h+n);
	reverse(h,h+n);
	FORN(i,k,n)ans+=h[i];
	cout<<ans;
	return 0;
}

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

bool check(int S) {
    for(int x = 1; x * x <= S; ++x) {
        if((S - x) % (2 * x + 1) == 0) {
            return true;
        }
    }
    return false;
}

int main() {
    int N; cin >> N;
    int ans = 0;
    while(N--) {
        int S; cin >> S;
        ans += !check(S);
    }
    cout << ans << endl;
}



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

#define int long long

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

struct P {
  double x, y, z;
  P() {}
  P(double x, double y, double z) : x(x), y(y), z(z) {}
  P operator+(P p) { return P(x+p.x, y+p.y, z+p.z); }
  P operator-(P p) { return P(x-p.x, y-p.y, z-p.z); }
  P operator*(double k) { return P(x*k, y*k, z*k); }
  P operator/(double k) { return P(x/k, y/k, z/k); }
  P operator*(P p) {
    return P(y*p.z-z*p.y, z*p.x-x*p.z, x*p.y-y*p.x);    
  }
};

typedef P V;

struct Seg {
  P p1, p2;
  Seg(){}
  Seg(P p1, P p2) : p1(p1), p2(p2) {}
};

typedef Seg Line;

struct Sphere {
  P c;
  double r;
  Sphere() {}  
  Sphere(P c, double r) : c(c), r(r){}
};

double norm(V a) {
  return a.x*a.x+a.y*a.y+a.z*a.z;
}

double abs(V a) {
  return sqrt(norm(a));
}

double dot(V a, V b) {
  return a.x*b.x+a.y*b.y+a.z*b.z;
}

V cross(V a, V b) {
  return V(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);  
}

double gdLP(Line l, P p) {
  return abs(cross(l.p2-l.p1, p-l.p1)/abs(l.p2-l.p1));  
}

double gdSP(Seg s, P p) {
  if ( dot(s.p2-s.p1, p-s.p1) < 0.0 ) return abs(p-s.p1);
  if ( dot(s.p1-s.p2, p-s.p2) < 0.0 ) return abs(p-s.p2);
  return gdLP(s, p);  
}

bool iSC(Seg s, Sphere c) {
  double d = gdSP(s, c.c);
  if ( d > c.r ) return 0;
  return !((abs(s.p1-c.c)<=c.r) && (abs(s.p2-c.c)<=c.r));  
}

signed main(){
  int N, Q;
  cin >> N >> Q;
 
  vector<Sphere> s(N);
  vector<int> l(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> s[i].c.x >> s[i].c.y >> s[i].c.z >> s[i].r >> l[i];    
  }

  for ( int i = 0; i < Q; i++ ) {
    int sum = 0;
    Seg seg;
    P p1, p2;
    cin >> p1.x >> p1.y >> p1.z >> p2.x >> p2.y >> p2.z;
    seg = Seg(p1, p2);
    for ( int j = 0; j < N; j++ ) {
      if ( iSC(seg, s[j]) ) {
	sum += l[j];	
      }
    }

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


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define Mod 1000000007

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


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int k,a=0;int n;string s;cin>>s>>k;
  n=s.size();
  if(n==1)cout<<k/2<<endl;
  else{
    vector<int>r(1);
    r.at(0)=1;int x=0;
    for(int i=1;i<n;i++){
      if(s.at(i)==s.at(i-1))r.at(x)++;
      else{
        r.push_back(1);
        x++;
      }
    }
    if(x==0)cout<<n*k/2<<endl;
    else{
      for(int i=0;i<=x;i++)a+=r.at(i)/2;
      a*=k;
      if(s.at(0)==s.at(n-1)){
        if(r.at(0)%2!=0&&r.at(x)%2!=0)a+=k-1;
      }
      cout<<a<<endl;
    }
  }
}
      

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n>>a;
    vector<ll> v(n);
    rep(i,n)   cin >> v[i];
    sort(v.begin(),v.end());
    rep(i,a) sum+=v[i];
    cout<<sum<<endl;

    return 0;
}


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

using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;

	vector<int> a(n);
	for(long long i=0;i<n;i++){
		cin >> a[i];
		a[i]-=1;
	}

	// 探索準備
	int select=0;					// 探索場所
	vector<bool> check(n,false);	// 訪れているかチェック
	int loopcnt=0;					// ループ内のステップ数
	int start=-1;					// ループ開始場所
	for(long long i=1;i<=k;i++){
		// ステップ数カウント
		if(start != -1){
			loopcnt++;
			if(start==select){
				// ループ分だけ省略
				k=(k-i)%loopcnt+i;
			}
		}
		// loop開始場所登録
		if(start == -1 && check[select]) start=select;
		else check[select] = true;

		// 次の町へ移動
		select = a[select];
	}
	
	cout << select+1 << endl;
}

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

int main(void) {

	priority_queue<int> que;
	int size, tickets, temp;
	int64_t 	total = 0;
	cin >> size >> tickets;
	for (int i = 0; i < size; i++) {
		cin >> temp;
		que.push(temp);
	}
	for (int i = 0; i < tickets; i++) {
		temp = que.top() / 2;
		que.pop(); que.push(temp);
	}
	
	while (!que.empty()) {
		total += que.top();
		que.pop();
	}

	cout << total << endl;
	return 0;
}


Measured memory_bytes: 892
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[105];
int mini=0x5FFFFFFF,maxi=-0x5FFFFFFF;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mini=min(mini,a[i]);
		maxi=max(maxi,a[i]);
	}
	
	int ans=0x5FFFFFFF,S;
	for(int i=mini;i<=maxi;i++)
	{
		S=0;
		for(int j=1;j<=n;j++)
			S+=(int)pow(i-a[j],2);
		ans=min(S,ans);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll r;

	cin >> r;

	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(void) {
  int n;
  while(cin >> n, n) {
    vector<P> vc;
    for(int i = 0 ; i < n ; i++) {
      int c, m1, m2, m3, m4, s1, s2, s3, s4;
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
    
      P p(time, c);
      vc.push_back(p);
    }
    sort(vc.begin() , vc.end());
    
    cout << vc[0].second << endl;
    cout << vc[1].second << endl;
    cout << vc[vc.size()-2].second << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int D, N;
	
	scanf("%d %d", &D, &N);
	
	switch (D) {
	  case 0:
	    if (N != 100){
	        printf("%d\n", N);
	    }
	    else {
	    	   printf("101\n");
	    }
	    break;
	   
	  case 1:
	    if (N != 100){
	        printf("%d\n", N * 100);
	    }
		else {
			printf("10100\n");
		}
	    break;
	   
	  case 2:
	    if (N != 100){
	        printf("%d\n", N * 10000);
	    }
		else {
			printf("1010000\n");
		}
	    break;
	}
	
	return (0);
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
num = [0] * N
ng = False
for i in range(N):
    num[A[i]] += 1
for i in range(1, N):
    if N % 2:
        if i % 2 and num[i]:
            ng = True
        elif i % 2 == 0 and num[i] != 2:
            ng = True
    else:
        if i % 2 == 0 and num[i]:
            ng = True
        elif i % 2 and num[i] != 2:
            ng = True
if N % 2 and A.count(0) != 1:
    ng = True
if N % 2 == 0 and A.count(0) > 0:
    ng = True
ans = pow(2, N // 2, 1000000007)
if ng:
    ans = 0
print(ans)


Measured memory_bytes: 14008
A, B = map(int,input().split())

def yinshufenjie(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf


def calculate(a,b):
    s1 = yinshufenjie(a)
    s2 = yinshufenjie(b)

    set1 = set()
    set2 = set()
    for key in s1.keys():
        set1.add(key)

    for key in s2.keys():
        set2.add(key)

    a = set1 & set2
    print(len(a)+1)


calculate(A,B)

Measured memory_bytes: 3188
#include<cstdio>
int n, a;
int x[55];
long long dy[55][2505];
int main() {
	scanf("%d%d", &n, &a);
	int i,j,k;
	for (i = 1; i <= n; i++) scanf("%d", &x[i]);
	dy[0][0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = i; j >= 1; j--) {
			for (k = 50 * n; k >= x[i]; k--) {
				dy[j][k] += dy[j - 1][k - x[i]];
			}
		}
	}
	long long ans = 0;
	for (i = 1; i <= n; i++) {
		ans += dy[i][a*i];
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1152
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
ans = 0
for i in range(N):
    if AB[i][1] < M:
        ans += AB[i][0]*AB[i][1]
        M -= AB[i][1]
    else:
        ans += AB[i][0]*M
        break
print(ans)

Measured memory_bytes: 27756
using System;
using System.Collections.Generic;

namespace ABC103_B_String_Rotation
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string t = Console.ReadLine();
			List<string> rollS = new List<string>();
			
			bool matchStr = false;
			
			for (int i = 0; i < s.Length; i++) {
				rollS.Add(s.Substring(i, 1));
			}

			string endStr = "";
			for (int i = 0; i < s.Length; i++)
			{
				for (int j = s.Length - 1; j > 0; j--) {
					if (j == s.Length - 1)
					{
						endStr = rollS[j];
					}
					rollS[j] = rollS[j - 1];
					if (j == 1)
					{
						rollS[0] = endStr;
					}
				}
				
				string rollEndS = "";
				foreach (var str in rollS)
				{
					rollEndS += str;
				}
				if (rollEndS == t)
				{
					matchStr = true;
					break;
				}
			}

			if (matchStr)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {

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

		int k = sc.nextInt();
		
		if(k % 2 == 0) {
			System.out.println((k/2)*(k/2)); 
		} else {
			System.out.println((k/2)*(k+1)/2);
		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

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

    int n;
    cin >> n;

    vector<int> x(n), p(n), q(n);

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

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

    for (int i = 0; i < n; i++) {
        x[i] = i + 1;
    }

    int a = 0, b = 0, counter = 0;

    do {
        counter++;
        if (p == x) {
            a = counter;
        }

        if (q == x) {
            b = counter;
        }
    } while (next_permutation(x.begin(), x.end()));

    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for i in range(N)]
DP = [[0 for i in range(W+1)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(1,W+1):
    DP[i][j] = max(DP[i][j],DP[i-1][j])
    if j-wv[i-1][0] >= 0:
      DP[i][j] = max(DP[i][j],DP[i-1][j-wv[i-1][0]]+wv[i-1][1])
print(DP[-1][-1])

Measured memory_bytes: 173832
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1 and M != 1:
    ans = M - 2
elif N != 1 and M == 1:
    ans = N - 2
elif N == 2 or M == 2:
    ans = 0
else:
    ans = (N-2)*(M-2)

print(ans)


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

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int tempmin = 1<<30;
    for(int i =0; i < N; i++){
        int p;
        cin >> p;
        if(p < tempmin){
            ans ++;
            tempmin = p;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;

int n;
pair<int, int> p[100010];


bool cmp(pair<int, int> x, pair<int, int> y) {
	return x.X+x.Y<y.X+y.Y;
}

int main () {

	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> p[i].X >> p[i].Y;
	}
	sort(p, p + n, cmp);
	ll sol = 0;
	int t = 1;
	for (int i = n-1; i >= 0; i --) {
		if (t == 1) sol += p[i].X;
		else sol -= p[i].Y;
		
		
		t *= -1;
	}
	
	cout << sol;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MN = 555;
char t[MN][MN];
char b[MN][MN];
char r[MN][MN];
int main() {
    int h,w;
    cin>>h>>w;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin>>t[i][j];
            b[i][j] = '.';
            r[i][j] = '.';
        }
    }
    for(int i = 0; i < h; ++i) {
        b[i][0] = '#';
        r[i][w-1] = '#';
        for(int j = 1; j < w-1; ++j) {
            if(i%2 == 0) {
                b[i][j] = '#';
            }
            else {
                r[i] [j] = '#';
            }
        }
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(t[i][j] == '#') {
                r[i][j] = '#';
                b[i][j] = '#';
            }
        }
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cout<<b[i][j];
        }
        cout<<'\n';
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cout<<r[i][j];
        }
        cout<<'\n';
    }


}


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

int main(void){
  while(1){
    int stone[50];
    for(int k = 0 ; k < 50 ; k++){stone[k] = 0;}

    int bowl;
    int n, p;  // n：候補者人数，p：小石の総数
    cin >> n;
    cin >> p;

    if(n == 0 && p == 0){return 0;}

    bowl = p;

    bool flg = true;
    int ans;

    for(int i = 0 ; flg ; i = (i+1) % n){

      if(bowl == 0){
        bowl = bowl + stone[i];
        stone[i] = 0;
      }else{
        stone[i]++;
        bowl--;
        if(bowl == 0 && stone[i] == p){ans = i; flg = false;}
      }
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 3068
program main
Implicit None
	character(len = 10),allocatable::s(:)
	integer(8)::n,i,j,p=0,x=0,y=0,z=0
	integer(8),allocatable::a(:),b(:)
	
	read*,n
	allocate(s(n),a(n),b(n))
	a = 0 ;b = 0
	
	read*,s
	
	do i = 1,n
		if(s(i)(1:1) == "B") b(i) = 1
		do j = 1,9
			if(s(i)(j:j) == " ")then
				if(s(i)(j-1:j-1) == "A") a(i) = 1
				exit
			endif
			if(s(i)(j:j+1) == "AB")then
				p = p+1
			endif
		enddo
		if(s(i)(9:10) == "A ") a(i) = 1
		if(s(i)(10:10) == "A") a(i) = 1
	enddo
	
	do i = 1,n
		if(a(i) == 1 .and. b(i) == 1) z = z+1
		if(a(i) == 1) x = x+1
		if(b(i) == 1) y = y+1
	enddo
	x = x-z
	y = y-z
	
	if(x == 0 .and. y == 0)then
		p = p+max(0,z-1)
		else if(y == 0 .or. x == 0)then
			p = p + z
		else if(z == 0)then
			p = p + min(x,y)
		else
			p = p + z + min(x,y)
	endif
	
	print*,p
end program main

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;
void bubbleSort(int A[], int N)
{
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N-1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
			// 隣接要素を交換する
				swap(A[j], A[j-1]);
				flag = 1;
			}
		}
	}
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, d[110];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    bubbleSort(d, n);

    int max = d[0], cnt = 1;
    for (int i = 1; i < n; i++) {
        if (d[i] > max) {
            max = d[i];
            cnt++;
        }
    }
    cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256