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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    double res = 0;
    REP(i, N){
    	double tmp;
    	cin >> tmp;
    	res += (1.0/tmp);
    }
    double ans = 1.0/res;
    printf("%.10f\n", ans);
    return 0;
}

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

const int maxn = 2e5+10;

int black, white, fuck, nn;
vector <int> g[maxn];
bool vis[maxn], flag;
int lujing[maxn];

void fuck_dfs(int u, int end, int step) {
	if (u == end) {
		flag = 1;
		return ;
	}

	for (auto v:g[u]) {
		if (vis[v]) continue;
		vis[v] = 1;
		lujing[++nn] = v;
		fuck_dfs(v,end,step+1);
		if (flag) return ;
		nn--;
	}
}

void shit_dfs(int u, int fuck) {
	//printf("%d\n", u);
	if (fuck == 0) black++;
	else white++;
	vis[u] = 1;
	for (auto v:g[u]) {
		if (vis[v]) continue;
		vis[v] = 1;
		shit_dfs(v, fuck);
	}
}

int main() {
	black = 0;
	white = 0;

	int n; 
	scanf("%d", &n);
	for (int i=1; i<n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	memset(vis, 0, sizeof vis);
	memset(lujing, 0, sizeof lujing);
	// vv.clear();
	nn = 0;
	vis[1] = 1;
	fuck_dfs(1, n, 0);

	int nb = (nn-1) / 2;
	if (nn % 2 == 0) nb++;
	//printf("%d\n", nb);
	// puts("1");
	
	memset(vis, 0, sizeof vis);
	lujing[0] = 1;
	for (int i=0; i<=nn; ++i) {
		vis[lujing[i]] = 1;
	}
	//puts("1");
	black = 0;
	for (int i=0; i<=nb; ++i) {
		//puts("1");
		shit_dfs(lujing[i], 0);
		//puts("");
	}

	white = 0;
	for (int i=nb+1; i<=nn; ++i) {
		shit_dfs(lujing[i], 1);
		//puts("");
	}

	//printf("%d %d\n", black, white);

	if (black > white) puts("Fennec");
	else puts("Snuke");

	return 0;
}

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


#define N (111)
int seg[N+1];

void add(int x,int v){
	for(int i = x ; i < N ; i+=i&-i){
		seg[i] += v;
	}
}

int get(int x){
	int ans = 0;
	for(int i = x ; i > 0 ; i -= i & -i){
		ans += seg[i];
	}
	return ans;
}

int a[101];

int main(){
	int n;
	while(cin >> n && n){
		vector<int> u;
		for(int i = 0 ; i < 101 ; i++) seg[i] = 0;
		
		for(int i = 0 ; i < n ; i++) cin >> a[i] , u.push_back(a[i]);
		sort(u.begin(),u.end());
		u.erase(unique(u.begin(),u.end()),u.end());
		for(int i = 0 ; i < n ; i++)
			a[i] = lower_bound(u.begin(),u.end(),a[i]) - u.begin() + 1;
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			add(a[i],1);
			ans += (i+1) - get(a[i]);  //a[i]より大きな値
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1220
n = int(input())
import collections
# hashmap = collections.OrderedDict()
hashmap = {
    'AC' : 0,
    'WA' : 0,
    'TLE': 0,
    'RE' : 0
}

while n > 0:
    t = input()
    hashmap[t] = hashmap.get(t, 0) + 1
    n -= 1

for key, val in hashmap.items():
    print(key + " x " + str(val))



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

int main() {
    
 char S;
 cin>>S;
  
    if(S == 'e'||S =='a'||S =='i'||S =='u'||S =='o')
    {
     
        cout<<"vowel"<<endl;
    }
    
    else
    {
        cout<<"consonant"<<endl;
    }
    
 

}

Measured memory_bytes: 256
#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()
static const int INF (1<<30);

int main() {
  int N, L;
  cin >> N >> L;

  int sum = 0;
  rep(i, N) sum += L + i;

  int ans = INF;
  int res = 0;

  rep(i, N) {
    int tmp = 0;
    rep(j, N) {
      if (j == i) continue;
      tmp += L + j;
    }
    if (abs(sum-tmp) < ans) {
      ans = abs(sum - tmp);
      res = tmp;
    }
  }

  cout << res << endl;


  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

int main() {
    vector<string> S(3);
    cin >> S[0] >> S[1] >> S[2];

    char now = 'a';
    vector<ll> cnt(3, 0);
    while (1) {
        ll idx = now - 'a';

        if (cnt[idx] == S[idx].size()) {
            cout << char(idx + 'A') << endl;
            return 0;
        }
        now = S[idx].at(cnt[idx]);
        cnt[idx]++;

        // repv(cnt) cout << *it << " ";
        // cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
r = [[0]*W for _ in range(H)]
S = 0
for i in range(2**H):
  for j in range(2**W):
    cnt = 0
    for k in range(H):
      for l in range(W):
        if (i >> k) & 1:
          if (j >> l) & 1:
            if c[k][l] == "#":
              cnt += 1
    if cnt == K:
      S += 1
print(S)

Measured memory_bytes: 9200
#include<stdio.h>
#include<string.h>
int main(void){
  char s[500];
  int i;
  int max=0;
  int count=0;
  int len;
scanf("%s",&s);
 len=strlen(s);
  for(i=0;i<=len;i++){
  if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){
  count++;
    if(max<count){
      max=count;
    }
  }
    else{
    count=0;
    }
  }
  printf("%d",max);
  return 0;
}
  

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	int kakeru = 1;
	for(int i=1;i<=m;i++){
		kakeru *= 2;
	}
	float ans = (m*1900+(n-m)*100)*kakeru;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  vector<int>a(100);
  rep(i,s.size()){
    a.at(s.at(i)-'0')++;
  }
  int k = 0;
//  cout << a.at(49) << endl;
//  cout << a.at(74) << endl;
  
  for(int i=49;i<75;i++){
    if(a.at(i) == 0){
      k = i;
      break;
    }
  }
  if(k==0) cout <<"None"<<endl;
  else  cout << char(k+48) << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<iomanip>
#include<queue>
#include<string>

typedef long long ll;
const int inf = 0x3f3f3f3f,maxn = 100 + 5;

using namespace std;

int main(){

	int n;
	int a[maxn];
	bool book[maxn];

	while(cin >> n)
	{
		memset(book,false,sizeof(book));

		int ans = 0;
		for(int i = 1;i <= n;i++)
		{
			cin >> a[i];

			if(!book[a[i]])
			{
				book[a[i]] = true;
				ans++;
			}

		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


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


n = ni()
tnow, xnow, ynow = 0, 0, 0
for _ in range(n):
    t, x, y = na()
    l = abs(xnow - x) + abs(ynow - y)
    if (t - tnow) < l or (t - tnow) % 2 != l % 2:
        print("No")
        quit()
print("Yes")


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

int main(){
	int x, y;
	
	while(1){
		cin >> x >> y;
		if(x==0&&y==0)
			break;
		if(x>=y)
			cout << y << ' ' << x << endl;
		else
			cout << x << ' ' << y << endl;
		
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
	int input_sec,hour,minute,second;
	scanf("%d",&input_sec);
	hour=input_sec/3600;//???????????????
	minute=input_sec%3600/60;//????????????
	second=input_sec%3600%60;//?§??????????
	printf("%d:%d:%d\n",hour,minute,second);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
vector<int> base;
int a[3] = {3,5,7};
int main(){
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 3; i <= 10; i++) {
    for (int b = 0; b < pow(3, i); b++) {
      ll bit3 = b;
      ll tmp = 0;
      int cnt[3] = {};
      for (int k = 0; k < i; k++) {
        tmp += a[bit3 % 3];
        cnt[bit3 % 3]++;
        bit3 /= 3;
        if (k != i - 1) tmp *= 10;
      }
      //cout << tmp << endl;
      if (cnt[0] != 0 && cnt[1] != 0 && cnt[2] != 0) {
          //cout << tmp << endl;
        if (tmp <= n) {
//          cout << tmp << endl;
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int cnt = 0;

  for(int i = 0; i < s.size(); i++){
      if(s.at(i) == '1'){
          cnt++;
      }
  }
    cout << cnt << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 101;
ll dp[MAX_N][3*MAX_N];

ll w[MAX_N];
ll v[MAX_N];

int main2() {
  CLR(dp, 0);
  int N = nextInt();
  ll W = nextInt();
  REP(i, N) {
    w[i] = nextInt();
    v[i] = nextInt();
  }

  ll w0 = w[0];
  REP(i, N) w[i] -= w0;

  dp[0][0] = 0;

  REP(i, N) {
    for (int k = N-1; k >= 0; k--) {
      for (int j = 3*N; j-w[i] >= 0; j--) {
        chmax(dp[k+1][j], dp[k][j - w[i]] + v[i]);
      }
    }
  }
  // REP(i, N+1) {
    // pv(dp[i], dp[i]+MAX_N*3);
  // }
  ll ans = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= min(W-i*w0, 3LL*N); j++)
      chmax(ans, dp[i][j]);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=25;
int a[maxn];
int n;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=2;i<=n;i++){
		if(a[i]>=a[1]){
			int f=0;
			for(int j=2;j<=i;j++){
				if(a[j]>a[i]){
					f=1;
					break;
				}
			}
			if(f==0)
				cnt++;
		}
	}
	cout<<cnt+1<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val prefectures = Array.fill(n) {
      ArrayBuffer.empty[Int]
    }
    val cities = Array.fill(m) {
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(p, y) =>
          prefectures(p - 1) += y
          (p, y)
      }
    }

    val ids = for (p <- 0 until n) yield {
      prefectures(p).zipWithIndex.sortBy(_._1).map(_._2).zipWithIndex.sortBy(_._1).map(_._2 + 1)
    }

    val idCursors = Array.ofDim[Int](n)

    @inline
    def print(v: Int): Unit = {
      var column = 100000
      while (true) {
        if (column > v) {
          out.print(0)
          column /= 10
        } else {
          out.print(v)
          return
        }
      }
    }

    @inline
    def println(p: Int, id: Int): Unit = {
      print(p)
      print(id)
      out.println()
    }

    for (city <- cities) {
      val p = city._1
      val id = ids(p - 1)(idCursors(p - 1))

      println(p, id)
      idCursors(p - 1) += 1
    }

    out.flush()
  }
}


Measured memory_bytes: 151544
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
using ld = long double;

ld exp[310][310][310];

int n;
ld cts[3];

ld getE(int a, int b, int c) {
	if (a < 0 || b < 0 || c < 0) return 0;
	else return exp[a][b][c];
}

int main() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int x; scanf("%d", &x);
		++cts[x-1];
	}
	// f(a, b, c) = (n/(a+b+c))*((c/n)*f(a, b+1, c-1) + (b/n)*f(a+1, b-1, c) + (a/n)*f(a-1, b, c))
	for (ld c = 0; c <= cts[2]; ++c) {
		for (ld b = 0; b <= cts[1] + cts[2]; ++b) {
			for (ld a = 0; a <= cts[0] + cts[1] + cts[2]; ++a) {
				// printf("%d %d %d\n",  (int)a, (int)b, (int)c);
				if (a+b+c == 0) continue;
				exp[(int)a][(int)b][(int)c] = (n/(a+b+c))*(c/n*getE(a, b+1, c-1) + b/n*getE(a+1, b-1, c)+(a/n)*getE(a-1, b, c) + 1);
				// printf("e %d %d %d %.5Lf\n", (int)a, (int)b, (int)c, exp[(int)a][(int)b][(int)c]);
			}
		}
	}
	printf("%.15Lf\n", exp[(int)cts[0]][(int)cts[1]][(int)cts[2]]);
	return 0;
}

Measured memory_bytes: 452736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
#define ALL(a)  (a).begin(),(a).end()


int main() {
	ll p,c,P[100010],C[100010];
	cin>>p>>c;
	vector<int>a[100010];
	for(int i=0;i<c;i++){
		int x,y;
		cin>>x>>y;
		x--;
		P[i]=x;C[i]=y;
		a[x].push_back(y);
	}
	for(int i=0;i<p;i++){
		sort(a[i].begin(),a[i].end());
	}
	for(int i=0;i<c;i++){
		printf("%06d",P[i]+1);
		auto itr=lower_bound(ALL(a[P[i]]),C[i]);
		printf("%06d\n",itr-a[P[i]].begin()+1);
	}
	return 0;
}

Measured memory_bytes: 8576
import java.lang.Math

fun main(args: Array<String>){
    val input: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    val n = input[0]
    val a = input[1]
    val b = input[2]
    val max = Math.min(a, b)
    val min = Math.max(0, a+b-n)
    println("$max $min")
}

Measured memory_bytes: 36064
N= int(input())
a =list(map(int,input().split()))
a.sort()
ans=0
Amax=max(a)
DP=[1]*(Amax+1)#これが0のとき、該当する数はカウント済み
#上から順に攻めていく
for i in range(N-1):
    p=a[i]
    if DP[p]==1:#まだ数えられていなかったら
        for j in range(Amax//p+1):#倍数をすべて0にする
            DP[p*j]=0
        if p!=a[i+1]:#隣の数と違うならば
            ans+=1
if DP[Amax]==1:#最後の数は隣の数と比べられんので個別判断
    ans+=1

print(ans)


Measured memory_bytes: 117008
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <typeinfo>
#include <queue>
#include <math.h>
using namespace std;


int main(){
	long n,x;
	cin>>n>>x;
	long a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	long long ans=0;
	if (a[0]>x){
		ans+=a[0]-x;
		a[0]=x;
		
	}
	for (int i = 0; i < n-1; ++i)
	{
		if (a[i]+a[i+1]>x){
		long long z=a[i]+a[i+1]-x;
		a[i+1]-=z;
		ans+=z;
		}
		
		
	}
	cout<<ans<<endl;

	

return 0;
}




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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  int N;
  cin >> N;

  vector<vector<int>> graph(N);
  vector<pi> edges;

  rep(i, N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
    edges.emplace_back(make_pair(a,b));
  }

  int max = 0;
  rep(i, N){
    int t = graph[i].size();
    chmax(max, t);
  }

  map<pi, int> ce;
  vector<int> cp(N, 0);
  vector<bool> used(N, false);
  used[0] = true;

  queue<int> que;
  que.emplace(0);
  while(!que.empty()){
    int v = que.front(); que.pop();
    int color = 1;
    for(auto u : graph[v]){
      if(used[u]) continue;
      if(cp[v] == color) color++;
      cp[u] = color;
      ce[make_pair(u, v)] = color;
      ce[make_pair(v, u)] = color;
      color++;
      used[u] = true;
      que.emplace(u);
    }
  }

  cout << max << endl;
  rep(i, N-1){
    cout << ce[edges[i]] << endl;
  }
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  auto gcd = [](long long int a, long long int b) {
    while (b) {
      a %= b;
      swap(a, b);
    }
    return a;
  };
  long long int L = 1ll * n * m / gcd(n, m);
  long long int vn = L / n, vm = L / m;
  long long int lcm = vn * vm / gcd(vn, vm);
  for (long long int on = 0; 1; on += lcm) {
    if (on / vn >= n || on / vm >= m) {
      break;
    }
    if (s[on / vn] != t[on / vm]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << L << endl;
  return 0;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////



ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 2000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}


int main(){fastio
    calc();
    ll n,k;cin>>n>>k;
    ll dp[k+1];
    rep(i,1,k){
        dp[i]=po(k/i,n);
    }
    //rep(i,1,k)cout<<dp[i]<<" ";cout<<endl;
    for(ll i=k-1;i>=1;i--){
        for(ll j=i*2;j<=k;j+=i){
            Add(dp[i],-dp[j]);
        }
    }
    ll ans=0;
    rep(i,1,k)Add(ans,i*dp[i]);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 35684
a,b,x,y,s,m = map(int,input().split())

#a,b,x,y,s,m = (1,2,1,2,100,1000)
a *= 100
b *= 100

#入れられる水の候補
waterlist=[]
amax = int(m/a)
for i in range(amax+1):
  bmax = int((m-a*i)/b)
  for j in range(bmax+1):
    water = a*i + b*j
    if water:
      waterlist.append(a*i + b*j)
waterlist = set(waterlist)

#砂糖の組み合わせから最大を
def makesatolist(maxsato,x,y):
  satolist = []
  xmax = int(maxsato/x)
  for i in range(xmax+1):
    ymax  = int((maxsato-x*i)/y)
    for j in range(ymax+1):
      satolist.append(x*i + y*j)
  return max(satolist)
  
nownodo = 0
ans = [0] * 2
for i in waterlist:
 
  # iグラムの水に何グラムの砂糖まで解ける？
  maxsato = i * s/100
  if i + maxsato > m:
    maxsato = m - i

  sato = makesatolist(maxsato,x,y)
  satowater = i + sato
  nodo = sato / satowater
  if nodo >= nownodo:
    nownodo = nodo
    ans = [satowater,sato]

print(ans[0]," ",ans[1])

Measured memory_bytes: 5324
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class data
{
public:
    int i, u, a, p;
    bool operator<(const data& d) const{
        return a > d.a || (a == d.a && p < d.p) || (a == d.a && p == d.p && i < d.i);
    }
};

void solve(vector<data>& d)
{
    int n = d.size();
    sort(d.begin(), d.end());

    int num = 0;
    map<int, int> cnt;
    for(int i=0; i<n; ++i){
        if(num < 26){
            if(cnt[d[i].u] < (39 - num) / 10){
                cout << d[i].i << endl;
                ++ num;
                ++ cnt[d[i].u];
            }
        }
    }
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<data> d(n);
        for(int i=0; i<n; ++i)
            cin >> d[i].i >> d[i].u >> d[i].a >> d[i].p;
        solve(d);
    }
}

Measured memory_bytes: 0
#![allow(clippy::many_single_char_names)]
// ngtio {{{
#[allow(dead_code)]
mod ngtio {
    use ::std::collections::VecDeque;

    pub struct Buffer {
        buf: VecDeque<String>,
    }

    impl Buffer {
        pub fn new() -> Self {
            Self {
                buf: VecDeque::new(),
            }
        }

        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = ::std::io::stdin().read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }

        pub fn string(&mut self) -> String {
            self.load();
            self.buf
                .pop_front()
                .unwrap_or_else(|| panic!("入力が終了したのですが。"))
        }

        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(
                chars.next().is_none(),
                "char で受け取りたいのも山々なのですが、さては 2 文字以上ありますね？"
            );
            res
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string()
                .parse::<T>()
                .expect("Failed to parse the input.")
        }

        pub fn read_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            (0..len).map(|_| self.read::<T>()).collect()
        }
    }

    macro_rules! define_primitive_reader {
        ($($ty:tt,)*) => {
            impl Buffer {
                $(
#[inline]
                    pub fn $ty(&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                )*
            }
        }
    }

    define_primitive_reader! {
        u8, u16, u32, u64, usize,
        i8, i16, i32, i64, isize,
    }

    impl Default for Buffer {
        fn default() -> Self {
            Self::new()
        }
    }
}
// }}}

fn main() {
    let mut buf = ngtio::Buffer::new();
    let s = buf.string().chars().collect::<Vec<_>>();
    let t = buf.string().chars().collect::<Vec<_>>();
    let ans = (0..=s.len() - t.len())
        .map(|l| {
            s[l..]
                .iter()
                .zip(t.iter())
                .filter(|&(&c, &d)| c != d)
                .count()
        })
        .min()
        .unwrap();
    println!("{}", ans);
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const int mod = 1000000007;

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

        n >>= 1;
    }
    return res;
}

vector<long> divisor(int n) {
    vector<long> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}


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

    int n, k; cin >> n >> k;

    vector<ll> X(100100, 0);

    int ans = 0;

    for (int i = k; i > 0; i--) {
        ll num = ((modpow(k/i, n, mod) - X.at(i)) % mod + mod) % mod;
        ans = (ans + num * i + mod) % mod;
        vector<long> d = divisor(i);
        for (auto &it:d) X.at(it) = (X.at(it) + num + mod) % mod;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3984
#include <bits//stdc++.h>
using namespace std;
#define int long long
signed main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(b>a){
		swap(a,b);
	}
	if(c>a){
		swap(a,c);
	}
	cout<<(1<<k)*a+b+c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll m=1e9+7; 
ll d,x,y;
ll power(ll b,ll a)
{
	if(a==0) return 1;
	if(a%2) return (b*power((b*b)%m,(a-1)/2))%m;
	else return power((b*b)%m,a/2);
}
int main()
{
	ll n,a,b,i;
	ll p,num=1,den=1;
	cin>>n>>a>>b;
	p=power(2,n)-1;
	for(i=0;i<a;i++) num=num*(n-i)%m;
	for(i=1;i<=a;i++) den=den*i%m;
	den=power(den,m-2);
	num=num*den%m;
	p=(p-num)%m;
	num=1;
	for(i=0;i<b;i++) num=num*(n-i)%m;
	den=1;
	for(i=1;i<=b;i++) den=den*i%m;
	den=power(den,m-2);
	num=num*den%m;
	p=(p-num)%m;
	p=(p+m)%m;
	cout<<p;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in freopen("input.txt", "r" , stdin)
#define out freopen("output.txt" , "w" , stdout)
#define pb push_back
#define p_b pop_back
#define pf push_front
#define pop_front
#define mp make_pair
#define ll long long
#define sc second
#define fr first
using namespace std;
int n;
int a[105];
bool used[100005];
vector<int> ans;
set<pair<int,int> > s;
set<pair<int,int> >::iterator it;
int main () {
//in;out;
cin >> n;
for (int i  = 1; i <= n; i++){
    cin >> a[i];
    s.insert({i,a[i]});
}

for (int i = 1; i <= n; i++){
    if (a[i] > i){
        cout << -1;
        return 0;
    }
}

for (int i = 1; i <= n; i++){

    it = s.end();
    it--;
        int cnt = 0;
        bool flag = false;
    for (it  = it; it!=s.begin(); it--){
        if (it->sc == s.size() - cnt){
            ans.pb(it->sc);
            s.erase(it);
            flag = 1;
            break;
        }
            cnt++;
    }

    if (it == s.begin()) {
         ans.pb(it->sc);
         s.erase(it);
    }
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++){
    cout << ans[i] << endl;
}
}


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

int main(){
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for(ll i= 0; i < n; i++){
        cin >> a[i];
    }   
    vector<bool> dp(k + 1, false);
    for(ll i =0; i <= k; i++){
        for(auto x: a){
            if(i >= x && !dp[i - x]){
                dp[i] = true;
            }
        }
    }
    if(dp[k]){
        cout << "First" << endl;
    } else cout << "Second" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c ;
  
  char a = 'a';
  char e = 'e';
  char i = 'i';
  char o = 'o';
  char u = 'u';
  
  cin >> c;

  if((c == a) || (c == e) || (c == i) || (c == o) || (c == u)){
  cout << "vowel" << endl;
  }

  else{
  cout << "consonant" << endl;
  }
}

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

	int h[100000];

int main(){
	int n,i,br=0,k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> h[i];
		if(h[i]>=k)
			br++;
	}
	cout << br;
}		

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(2e3) + 17;

int n;

bool read() {
    if (!(cin >> n))
        return false;

    return true;
}

int dig(int x) {
    int res = 0;

    for (; x > 0; x /= 10)
        res += x % 10;

    return res;
}

void solve() {
    int ans = INF;

    for (int a = 1; a < n; ++a)
        ans = min(ans, dig(a) + dig(n - a));

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 256
import static java.lang.System.*;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if(h == 0 && w == 0) {
				break;
			}
			for(int a = 1; a <= h; a++) {
				boolean flg = true;
				for(int b = 1; b <= w; b++) {
					if(a % 2 == 1) {
						if(flg) {
							out.print("#");
						}else {
							out.print(".");
						}
						flg = !flg;
					}else {
						if(flg) {
							out.print(".");
						}else {
							out.print("#");
						}
						flg = !flg;
					}
				}
				out.println();
			}
			out.println();
		}
	}
}


Measured memory_bytes: 33228
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();

    vi lake(n+1);
    rep(i, n) {
        if(s[i] == '/') {
            lake[i+1] = lake[i] + 1;
        } else if(s[i] == '_') {
            lake[i+1] = lake[i];
        } else {
            lake[i+1] = lake[i]-1;
        }
    }

    vi lm(n+1), rm(n+1);
    lm[0] = 0;
    rm[n] = lake[n];
    rep(i, n) {
        lm[i+1] = max(lm[i], lake[i+1]);
        rm[n-i-1] = max(rm[n-i], lake[n-i-1]);
    }

    vector<double> l;
    bool make = false;
    rep(i, n) {
        int hight = min(lm[i], rm[i+1]);
        if(hight > lake[i]) {
            if(s[i] == '/') {
                l[l.size()-1] += hight-lake[i]-0.5;
            } else if(s[i] == '_') {
                l[l.size()-1] += hight-lake[i];
            } else {
                l[l.size()-1] += hight-lake[i]+0.5;
            }
        } else if(hight == lake[i]) {
            if(s[i] == '/' or s[i] == '_') continue;
            else {
                l.push_back(0.5);
            }
        }
    }

    double a = 0;
    rep(i, l.size()) {
        a += l[i];
    }

    cout << (int)a << endl;
    cout << l.size();
    rep(i, l.size()) {
        cout << ' ' << (int)l[i];
    }
    cout << endl;
}


Measured memory_bytes: 3368
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100;
const int MAXVAL=1000;
const int MAXSUMVAL=MAXN*MAXVAL;


int n,cap;
int cost[MAXN],val[MAXN];

ll dp[MAXSUMVAL+1];

ll solve() {
	int sumval=0; REP(i,n) sumval+=val[i];
	REPE(i,sumval) dp[i]=LLONG_MAX; dp[0]=0;
	REP(i,n) for(int j=sumval;j>=val[i];--j) if(dp[j-val[i]]!=LLONG_MAX) dp[j]=min(dp[j],dp[j-val[i]]+cost[i]);
	int ret=0; REPE(i,sumval) if(dp[i]<=cap) ret=max(ret,i); return ret;
}

void run() {
	scanf("%d%d",&n,&cap);
	REP(i,n) scanf("%d%d",&cost[i],&val[i]);
	printf("%lld\n",solve());
}

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


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

int main(){
    int a, b;
    cin >> a >> b;
    int sum = 1;
    rep(i,22){
        if(sum >= b){
            cout << i << endl;
            return 0;
        }
        sum--;
        sum += a;
    }
}

Measured memory_bytes: 3648
//#include<iostream>
//using namespace std;
//int apple[1000];
//int main(void)
//{
//    int n,d,cnt=0,t;
//    bool a=false;
//    cin >> n >> d;
//    t=1;
//    while(a==false){
//        t=t+d+1;
//        for(int i=t;i<=d+t;i++)
//            apple[i]=1;
//        cnt++;
//
//        int num=0;
//        for(int i=1;i<=n;i++)
//            if(apple[i]==1)
//                num++;
//        if(num==n)
//            a=true;
//    }
//    cout << cnt;
//    return 0;
//}
#include<iostream>
using namespace std;
int h[25];
int main(void)
{
    int n,num=0;
    cin >>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=2;i<=n;i++)
    {
        int num2=0;
        for(int j=1;j<i;j++)
            if(h[i]>=h[j])
                num2++;
        if(num2==i-1)
            num++;
    }
    cout<<num+1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

int main(){
  ll n,W; cin>>n>>W;
  ll weight[n];
  ll value[n];
  for(int i=0;i<n;i++){
    cin>>weight[i]>>value[i];
  }

  ll N = 1000*n+100;
  ll dp[n+1][N];
  ll inf=pow(10,13);
  for(int i=0;i<=n;i++){
    for(int j=0;j<N;j++){
      dp[i][j]=inf;
    }
  }

  dp[0][0]=0;

  for(int i=0;i<n;i++){
    for(int v=0;v<N;v++){
      if(v>=value[i]) dp[i+1][v]=min(dp[i][v],dp[i][v-value[i]]+weight[i]);
      else dp[i+1][v]=min(dp[i+1][v],dp[i][v]);
    }
  }

  ll ans=0;

  for(int v=0;v<N;v++){
    if(dp[n][v]<=W){
      ans=v;
    }
  }
  
  cout<<ans<<endl;
  /*
  for(int i=0;i<n;i++){
    for(int w=0;w<=W;w++){
      if(w-weight[i]<0) dp[i+1][w]=dp[i][w];
      else dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+value[i]);
    }
  }

  cout<<dp[n][W]<<endl;*/
}

Measured memory_bytes: 79232
/*
 * Author       : YangDavid
 * Created Time : 2019年11月23日 星期六 20时30分15秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 222222;
ll n, d[maxn], c[maxn];
ll sum, dig;
int main() {
	scanf("%lld", &n);
	rep(i, n) {
		scanf("%lld%lld", &d[i], &c[i]);
		sum += d[i] * c[i];
		dig += c[i];
	}
	ll extra = 0;
	if(sum > 9) extra = (sum - 9) / 9 + ((sum - 9) % 9 != 0);
	printf("%lld\n", dig - 1 + extra);

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int N; cin>>N;
    long long int tmp=N;
    int f=0;
    while(tmp>0){
        f=f+tmp%10;
        tmp=tmp/10;
    }
    if(N%f==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
/*
 * 2583.cc: JAG-channel
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

string ss[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i < n; i++) cin >> ss[i];

    for (int i = 1; i < n; i++) {
      string &si = ss[i];
      int k = 0;
      si[0] = ' ';
      while (si[k + 1] == '.') si[k++] = ' ';
      si[k] = '+';
      for (int j = i - 1; j >= 0 && ss[j][k] == ' '; j--)
	ss[j][k] = '|';
    }

    for (int i = 0; i < n; i++) cout << ss[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1984
x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
# print("x = ", x)
# print("a = ", a)
# print("b = ", b)

if x < a:
  distance_xa = a-x
else:
  distance_xa = x-a
# print("distance_xa = ", distance_xa)

if x < b:
  distance_xb = b-x
else:
  distance_xb = x-b
# print("distance_xb = ", distance_xb)

if distance_xa < distance_xb:
  print("A")
else:
  print("B")

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

int main()
{
  
  int N;
  cin >>N;
  string s;
  cin >> s;
  
  
  if( N % 2)
  {
    cout <<"No";
    return 0;
  }
  
  int L = N/2;
  int f = 0;
  for(int i= 0 ; i  < L ; i++)
  {
    if(s[i] != s[i + L])
    {
      f =1;
      break;
    }
  }
  
  if(f)
    	cout<<"No";
  else
    	cout <<"Yes";
  
  return 0;
}
  
  
  
  
  
  
  
  
  
  
  
  


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

const MOD = 1000000007

func initComb(n, k int) [][]int {
	max := n-k+1
	if k-1 > max {
		max = k-1
	}

	c := make([][]int, max+1)
	for i := 0; i <= max; i++ {
		c[i] = make([]int, i+1)
		c[i][0], c[i][i] = 1, 1
		for j := 1; j < i; j++ {
			c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD
		}
	}

	return c
}

func comb(a, b int, c [][]int) int {
	if b > a {
		return 0
	}

	return c[a][b]
}

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

	n, k := nextInt(), nextInt()
	red := n-k

	c := initComb(n, k)
	for i := 1; i <= k; i++ {
		fmt.Println((comb(red+1, i, c) * comb(k-1, i-1, c)) % MOD)
	}
}

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> CT(N);
    for(int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        CT[i] = make_pair(b, a);
    }
    int ans = 100000000;
    int index = -1;
    for(int i = 0; i < N; i++) {
        if(CT[i].first <= T) {
            if(CT[i].second < ans) {
                index = i+1;
            }
            ans = min(ans, CT[i].second);
        }
    }
    if(index == -1) {
        cout << "TLE" << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = input()
tt, xx, yy = 0, 0, 0
for i in range(n):
	t, x, y = map(int, raw_input().split())
	d = abs(x - xx) + abs(y - yy)
	if d > t - tt or (d + t - tt) % 2 > 0:
		print 'No'
		exit()
	tt, xx, yy = t, x, y
print 'Yes'

Measured memory_bytes: 5764
import java.util.*;
public class Main {
	static int p = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int a = (2 * x - y) / 3;
		int b =  (2 * y - x) / 3;
		if((x+y) % 3 != 0 || a < 0 || b < 0)
			System.out.println(0);
		else{
			long[] mm = new long[1000005];
			long[] nn = new long[1000005];
			
			mm[0] = 1;
			for(int i=1;i<mm.length;i++){
				mm[i] = mm[i-1] * i % p;
			}

			nn[0] = 1;
			nn[1] = 1;
			for(int i=2;i<nn.length;i++){
				nn[i] = nn[i-1] * fp(i, p-2) % p;
			}
			
			System.out.println(mm[a+b] * nn[a] % p * nn[b] % p);
		}
	}
	static long fp(int a, int k){
		
		if(k == 0)
			return 1;
		
		long num = fp(a, k/2);
		if(k % 2 != 0)
			return a * num % p * num % p;
		else
			return num * num % p;
	}
}

Measured memory_bytes: 39636
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int N,M,C;
    scanf("%d %d %d",&N,&M,&C);
    int i,j;
    int **A, *B;

    B = (int*)malloc(sizeof(int)*M);
    A = (int**)malloc(sizeof(int*)*N);
    for(i=0;i<N;i++){
        A[i] = (int*)malloc(sizeof(int)*M);
    }

   for(i=0;i<M;i++){
        scanf("%d",&B[i]);
    }
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            scanf("%d",&A[i][j]);
        }
    }

    int tmp = 0,res=0;
    for(j=0;j<N;j++){
        for(i=0;i<M;i++){
            tmp += A[j][i]*B[i];
        }
        if(tmp+C>0)res++;
      	tmp=0;
    }
    printf("%d",res);
    return 0;


}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int yen = 0;
  for(int i = 0; i < N; i++){
  	if(i >= K){
    	yen += Y;
    }else{
    	yen += X;
    }
  }
  cout << yen << endl;
}

Measured memory_bytes: 256
n,a,b,c,d = gets.split.map(&:to_i)
s = gets.chomp.chars
s = ['no'] + s

visited = { 'a' => {}, 'b' => {}}

$n = n
$ans = "No"
def dfs(a, b, c, d, s, visited)
  if a == c && b == d
    $ans = "Yes"
    return
  end

  if a > $n
    return
  end

  if b > $n
    return
  end

  visited['a'][a] = true
  visited['b'][b] = true

  if a == c
  else
    if s[a + 1] != '#' && a + 1 != b
      if !visited['a'][a+1]
        dfs(a+1, b, c, d, s, visited)
      end
    end

    if s[a + 2] != '#' && a + 2 != b
      if !visited['a'][a+2]
        dfs(a+2, b, c, d, s, visited)
      end
    end
  end

  if b == d
  else
    if s[b + 1] != '#' && b + 1 != a
      if !visited['b'][b+1]
        dfs(a, b+1, c, d, s, visited)
      end
    end

    if s[b + 2] != '#' && b + 2 != a
      if !visited['b'][b+2]
        dfs(a, b+2, c, d, s, visited)
      end
    end
  end
end

dfs(a, b, c, d, s, visited)

puts $ans


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

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  int k;
  cin >> k;
  cout << a[k-1] << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
Data = [[0,0] for _ in range(N)]
for i in range(N):
    a,b = map(int,input().split())
    Data[i][0] = a
    Data[i][1] = b
Data.sort(key=lambda x:x[0])
Heap = []
heapq.heapify(Heap)

ans = 0
idx = 0
for i in range(1,M+1):
    max1 = 0
    maxindex = -1

    while idx < N:
        a = Data[idx][0]
        b = Data[idx][1]
        if a <= i:
            heapq.heappush(Heap,b*(-1))
            idx += 1
        else:
            break
    if len(Heap) > 0:
        max1 = heapq.heappop(Heap)*(-1)
        ans += max1

print(ans)

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

int main(){
    ld R;
    cin >> R;
    R *= (ld)2.0*(ld)3.1416;
    cout << setprecision(12) << R << "\n";
    return 0;
}


Measured memory_bytes: 3792
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = [[0 for i in range(l)]for j in range(n)]
for k in range(n):
    for i in range(l):
        for j in range(m):
            num[k][i] += a[k][j] * b[j][i]
for i in range(n):
    print(" ".join(map(str, num[i])))






Measured memory_bytes: 6888
from sys import stdin
input = stdin.readline

N = int(input())
A = list(map(int, input().split()))


def p(N):
    for i in range(len(N)):
        if i == len(N) - 1:
            print(N[i])
        else:
            print(N[i], end=" ")


ans = 0

for i in range(N):
    m = i
    for j in range(i + 1, N):
        if A[j] < A[m]:
            m = j
    if m != i:
        ans += 1
        A[m], A[i] = A[i], A[m]

p(A)
print(ans)



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

using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  int min = 1000;
  int m;
  for(int i=0;i<n;i++){
    cin >> m;
    x -= m;
    if(min>=m)min = m;
  }
  cout << n + (x / min) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void)
{
	double x1, x2, y1,y2,distance;

	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

	distance = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));

	printf("%f", distance);
	
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

//ok
ll comdiv(ll x, ll y){
  ll a=x,b=y,r=a%b;
  while(r>0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}
//ok
ll commul(ll x, ll y){
  ll a=x/comdiv(x ,y);
  return a*y;
}

int main(){
  ll n;
  cin >>n;
  ll t[n],ans=1;
  rep(i,n){
    cin >> t[i];
    ans*=t[i]/comdiv(ans,t[i]);
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

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

int main()
{
  string s; cin >> s;
  int n = s.size();
  int p = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'p') { ++p; }
  }
  int ans = n / 2 - p;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512