akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
    long long int n;
    scanf("%lld",&n);
    
    printf("%lld\n",n*n);
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
n = len(s)

ans = [0]*n

#左からRを見る
nextl = [-1]*n
curl = n-1
for i, si in enumerate(s[::-1]):
    if si == "R":
        nextl[n-i-1] = curl
    else:
        curl = n-i-1

for i, nli in enumerate(nextl):
    if nli == -1:
        continue

    if(nli - i) % 2:
        ans[nli-1] += 1
    else:
        ans[nli] += 1

# 右からLを見る
nextr = [-1]*n
curr = 0
for i, si in enumerate(s):
    if si == "L":
        nextr[i] = curr
    else:
        curr = i

for i, nri in enumerate(nextr):
    if nri == -1:
        continue

    if (i - nri) % 2:
        ans[nri+1] += 1
    else:
        ans[nri] += 1

print(*ans)



Measured memory_bytes: 51012
import copy
H, W, K = map(int, input().split())
lst = []
num = 0
for i in range(H):
    arrange = input()
    num += arrange.count('#')
    lst.append(arrange)
# print(num)
count = 0

for i in range(2**H):
    # print("初期化")
    rlst = copy.copy(lst)
    counted = 0
    rstr = str(format(i, '0' + str(H) + 'b'))
    # print("rstr:" + rstr)
    while '1' in rstr:
        index = rstr.find('1')
        counted += rlst[index].count('#')
        rlst[index] = "." * W
        rstr = rstr.replace('1','0',1)
    # print(counted)
    for j in range(2**W):
        ccounted = counted
        clst = copy.copy(rlst)
        cstr = str(format(j, '0' + str(W) + 'b'))
        # print("cstr:" + cstr)
        while '1' in cstr:
            index = cstr.find('1')
            dlst = ""
            for k in range(H):
                dlst += clst[k][index]
                clst[k] = clst[k][:index] + '.' + clst[k][index+1:]
            ccounted += dlst.count("#")
            cstr = cstr.replace('1','0',1)
        # print(clst)
        # print(str(num-ccounted))
        if num - ccounted == K:
            count += 1

print(count)

Measured memory_bytes: 74804
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;


int main(){
    int N;
    int A[20], B[20], C[20];
    cin >> N;
    for(int a=0; a<N; a++){
        cin >> A[a];
    }
    for(int b=0; b<N; b++){
        cin >> B[b];
    }
    for(int c=0; c<N-1; c++){
        cin >> C[c];
    }

    int answer = 0;

    for(int i=0; i<N; i++){
        answer += B[A[i]-1];
        if(A[i]-A[i-1] == 1){
            answer += C[A[i-1]-1];
        } 
    }

    cout << answer;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  map<int,int> mp;
  while(N--){
    int a;
    cin>>a;
    mp[a]++;
  }
  int ans=0;
  for(auto p:mp)
    if(p.second%2)ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 9736
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m,s,t,u,v,a,b;
ll Cy[100010],Cs[100010];
ll have = 1e15,inf = 1e18;
vector<vector<P>> Y(100010),S(100010);

int main(){
	cin >> n >> m >> s >> t;
	for(int i=0;i<m;i++){
		cin >> u >> v >> a >> b;
		Y[u].push_back(P(a,v));
		Y[v].push_back(P(a,u));
		S[u].push_back(P(b,v));
		S[v].push_back(P(b,u));
	}
	priority_queue<P> Q;
	Q.push(P(0,s));
	for(int i=0;i<=n;i++){
		Cy[i] = inf;
	}
	Cy[s] = 0;
	while(!Q.empty()){
		P t = Q.top();
		ll w = t.second;
		Q.pop();
		if(Cy[w] < t.first) continue;
		for(int i=0;i<Y[w].size();i++){
			P e = Y[w][i];
			if(Cy[e.second] > Cy[w] + e.first){
				Cy[e.second] = Cy[w] + e.first;
				Q.push(P(-Cy[e.second],e.second));
			}
		}
	}
	Q.push(P(0,t));
	for(int i=0;i<=n;i++){
		Cs[i] = inf;
	}
	Cs[t] = 0;
	while(!Q.empty()){
		P t = Q.top();
		ll w = t.second;
		Q.pop();
		if(Cs[w] < t.first) continue;
		for(int i=0;i<S[w].size();i++){
			P e = S[w][i];
			if(Cs[e.second] > Cs[w] + e.first){
				Cs[e.second] = Cs[w] + e.first;
				Q.push(P(-Cs[e.second],e.second));
			}
		}
	}
	ll A[100010] = {0};
	for(int i=1;i<=n;i++){
		A[i] = Cy[i] + Cs[i];
	}
	for(int i=n-1;i>=1;i--){
		A[i] = min(A[i],A[i+1]);
	}
	//sort(T.begin(),T.end());
	//int id = 1;
	for(int i=1;i<=n;i++) cout << have-A[i] << endl;
}

Measured memory_bytes: 19704
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 10
for i in range(N - K + 1):
    j = i + K - 1
    if x[i] <= 0 <= x[j]:
        t = x[j] - x[i] + min(x[j], -x[i])
    else:
        t = max(abs(x[i]), abs(x[j]))
    ans = min(ans, t)
print(ans)


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

const int MOD = 1000000007;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> cnts(N, 0);
  cnts[0] = 3;
  int res = 1;
  for (int a : A) {
    res = 1LL * res * cnts[a] % MOD;
    cnts[a]--;
    cnts[a + 1]++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

int main()
{
    int a, b;
    cin >> a >> b;

    if (b < a) {
        swap(a, b);
    }

    if ((b - a) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << b - (b - a) / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 764
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,M;
int main() {
	cin>>N>>M;
	int B=0;
	B=(1900*M)+((N-M)*100);
	for(int i=0;i<M;i++){
		B=B*2;
	}
	cout<<B<<endl;
	return 0;
}


Measured memory_bytes: 256
#作っているものが違う
#作らなきゃいけないのは、「完全に被覆されている区間の数」を出すやつ
#作ったのは「部分的あるいは完全に被覆されている区間の数」を出すやつ

#いもす法で各地点における路線の通っている数をO(N + M)で配列化
#それをセグ木にしてO(logN)でクエリ1つずつ回答
#dc配列はダブルカウントを判定する
#例えば、1->2の路線があったとして、区間[1, 2]の路線数を取ると2になってしまう
#これは、自身しか通過しない路線を無視した路線数累積和でO(1)になる気がする（証明してない）

#ミスって自信満々に作ったクソ長レシートより
#数分で書いた正答コードの方が圧倒的に簡潔なの、あほですか？という感じ
#問題文と入出力例はよく読みましょう

"""
N, M, Q = map(int, input().split())
A = [0] * (N + 2)
X = [0] * (N + 2)
dc = [0] * (N + 2)
for i in range(M):
  l, r = map(int, input().split())
  A[l] += 1
  A[r + 1] -= 1
  if l == r:
    dc[l] -= 1
plus = 0
for i in range(1, N + 1):
  plus += A[i]
  X[i] += plus
  dc[i] += plus + dc[i - 1]
print(X)
ide_ele = 0
num = 2 ** (N + 2 - 1).bit_length()
seg = [ide_ele] * 2 * num

def segfunc(x, y):
  return x + y

def init(init_val):
  for i in range(N + 2):
    seg[i + num - 1] = init_val[i]    
  for i in range(num - 2, -1, -1) :
    seg[i]=segfunc(seg[2 * i + 1], seg[2 * i + 2]) 
    
def update(k, x):
  k += num - 1
  seg[k] = x
  while k + 1:
    k = (k - 1) // 2
    seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])
    
def query(p, q):
  if q <= p:
    return ide_ele
  p += num - 1
  q += num - 2
  res = ide_ele
  while q - p > 1:
    if p & 1 == 0:
      res = segfunc(res, seg[p])
    if q & 1 == 1:
      res = segfunc(res, seg[q])
      q -= 1
    p = p // 2
    q = (q - 1) // 2
  if p == q:
    res = segfunc(res, seg[p])
  else:
    res = segfunc(segfunc(res, seg[p]), seg[q])
  return res

init(X)
print(seg)
print(dc)
for i in range(Q):
  p, q = map(int, input().split())
  k = query(p, q + 1)
  print(k - dc[q] + dc[p])
"""

#二次元累積和しろ
#N = 500なので累積和をN回でも間に合う
N, M, Q = map(int, input().split())
LR = [[0] * (N + 2) for _ in range(N + 2)]
cs = [[0] * (N + 2) for _ in range(N + 2)]
for _ in range(M):
  l, r = map(int, input().split())
  LR[l][r] += 1
for i in range(N + 1):
  for j in range(N + 1):
    cs[i][j + 1] += cs[i][j] + LR[i][j + 1]
#print(cs)
#print(LR)
for _ in range(Q):
  l, r = map(int, input().split())
  temp = 0
  for i in range(l, r + 1):
    temp += cs[i][r] - cs[i][l - 1]
  print(temp)

Measured memory_bytes: 55384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void pot(int x){
	int r=7;
	int c=1;
	while(true){
		if(r%x!=0){
			c+=1;
			r=(10*r+7)%x;
		}
		else {
		   cout<<c; break;
		}
	}
}
int main() {
	ll x;
	cin>>x;
	int v=1000000;
	if(x%2==0 || x%5==0){
		cout<<"-1";
	}
	else{
		pot(x);
	} 
	return 0;
}

Measured memory_bytes: 3604
N = int(input())
zoro_count = 0
zoro = False
for n in range(N):
  dn1,dn2 = map(int, input().split())
  if dn1 == dn2:
    zoro_count += 1
  else:
    zoro_count = 0
  if zoro_count >= 3:
    zoro = True
if zoro:
  print('Yes')
else:
  print('No')

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

using namespace std;

typedef long long ll;

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

    deque <char> q;
    bool isFlipped = false;

    for(int i = 0; i < s.size(); i++)   q.push_back(s[i]);

    int Q;  cin >> Q;

    while(Q--)
    {
        int T;  scanf("%d", &T);

        if(T == 1)
        {
            isFlipped ^= 1;
        }

        else
        {
            int F;  scanf("%d", &F);
            char c; scanf(" %c", &c);

            if(F == 1)
            {
                if(!isFlipped)  q.push_front(c);
                else            q.push_back(c);
            }

            else
            {
                if(!isFlipped)  q.push_back(c);
                else            q.push_front(c);
            }
        }
    }

    if(isFlipped)   reverse(q.begin(), q.end());

    for(char c : q) printf("%c", c);    puts("");
}


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int sa, sb, sc;
  int count = 0;
  for (int i = 0; i <= a; i++) {
    sa = 500 * i;
    if (sa == x) {
      count++;
      break;
    }
    for (int j = 0; j <= b; j++) {
      sb = sa + 100 * j; 
      if (sb == x) {
        count++;
        j = 0;
        break;
      }
      else if (j == b && sb + 50*c < x) {
        j = 0;
        break;
      }
      for (int k = 0; k <= c; k++) {
        sc = sb + 50 * k;
        if (sc == x) {
          count++;
          k = 0;
          break;
        }
        else if (k == c) {
          k = 0;
          break;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

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

  int n;
  cin >> n;
  for(int i = 0; i * 4 <= n;i++){
    if((n-(4*i)) % 7 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
//typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n,m;
vector<int> v;
int a[50],b[50];
int main(){
  /**入力**/
  cin >> n;
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) {
    v.pb(a[i] - b[i]);
  }
  sort(v.begin(),v.end());
  int ans = 0;
  for(auto p:v) {
    ans = max(ans, ans + p);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
n = input()
inl = 3
while int(n) > int(inl) or int(n) == int(inl):
    if int(inl) % 3 == 0:
        print(' ' + str(inl),end='')
        inl += 1
    elif int(int(inl) / 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int(inl) % 10 == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 10) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 100) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 1000) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    else:
        inl += 1
print('')





Measured memory_bytes: 5888
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main()
{
  int R[MAX],n;

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

  int maxv = R[1]-R[0];
  int minv = R[0];

  for(int i=1;i<n;i++){
    maxv = max(maxv, R[i]-minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 3872
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').ToArray();
            var a = long.Parse(ab[0]);
            var b = long.Parse(ab[1].Replace(".", ""));
            Console.WriteLine(a * b / 100);
        }
    }
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int temp = 0;
  for (int i = 0; i < K; i++) {
    if (i % 2 == 0 || i == 0) {
      if (A % 2 != 0)
        A--;
      temp = A;
      A -= (temp / 2);
      B += (temp / 2);
    }
    if (i % 2 != 0) {
      if (B % 2 != 0)
        B--;
      temp = B;
      A += (temp / 2);
      B -= (temp / 2);
    }
  }
  cout << A << " " << B << endl;
}

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

inline int gcd(int a, int b){ return b?gcd(b,a%b):a; }
inline int lcm(int a, int b){ return a/gcd(a,b)*b; }
inline int hex(char a){ return isdigit(a)?(a-'0'):(a-'A'); }
inline char inv_hex(int a){ return (a<10)?(a+'0'):(a-10+'A'); }

inline vi reduce(vi a){
  int n = a.size();
  for(int i=n;i>=2;i--){
    if(n%i)continue;
    bool f = true;
    rep(j,n){
      if(j%i && a[j]){	f = false; break; }
    }
    if(f){
      int k = n/i;
      vi res(k);
      for(int j=0;j<k;j++)res[j] = a[j*i];
      return res;
    }
  }
  return a;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int casenum;
  cin >> casenum;
  while(casenum--){
    int n;
    cin >> n;
    int len = 1;
    vector< vi > rhythm(n);
    rep(i,n){
      string s;
      cin >> s;
      if(len<=1024){
	vi tmp(s.size()/2);
	rep(j,s.size()/2){
	  tmp[j] = hex(s[2*j])*16 + hex(s[2*j+1]);
	}
	rhythm[i] = reduce(tmp);
	len = lcm(len,rhythm[i].size());
      }
    }

    if(len>1024)cout << "Too complex." << endl;
    else{
      vi res(len,0);
      rep(i,n){
	int k = len/rhythm[i].size();
	rep(j,rhythm[i].size())res[j*k] |= rhythm[i][j];
      }
      rep(i,len){
	cout << inv_hex(res[i]/16) << inv_hex(res[i]%16);
      }
      cout << endl;
    }
  }
}

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

struct Card{
  int value;
  char suit;
};

int main(){
  Card c1[37],c2[37];
  int N,cnt=0,mini=99999999;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
    cin >> c1[i].suit >> c1[i].value;
    c2[i].suit = c1[i].suit;
    c2[i].value = c1[i].value;
  }
  
  for(int i = 0; i < N; i++){
    for(int j = N-1; j > i; j--){
      if(c1[j].value < c1[j-1].value) 
	swap(c1[j],c1[j-1]);
    }
  }

  for(int i = 0; i < N; i++){
    cout << c1[i].suit << c1[i].value;
    if(i != N-1) cout << " ";
    else cout << endl;
  }
  cout << "Stable" << endl;
  
  
 /* for(int i = 0; i < N; i++){
    cout << c2[i].suit << c2[i].value;
    }
    cout << endl;*/
  
  
  
  
 for(int i = 0; i < N; i++){
   mini = i;
   for(int j = i; j < N; j++){
     if(c2[j].value < c2[mini].value) 	mini = j;
   }
   swap(c2[i],c2[mini]);
 }

 for(int i = 0; i < N; i++){
   cout << c2[i].suit << c2[i].value;
   if(i != N-1) cout << " ";
   else cout << endl;
 }
 
 for(int i = 0; i < N; i++){
   if(c2[i].suit != c1[i].suit || c2[i].value != c1[i].value) cnt++;
 }

 if(cnt == 0) cout << "Stable" << endl;
 else cout << "Not stable" << endl;
 
 
 
 return 0;
}

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

vector<int> G[1000006];

 int main()
 {
	int n,m,i;
	scanf("%d%d",&n,&m);

	int a,b;
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

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


Measured memory_bytes: 23680
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
p = py[0][0]
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 2
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }

template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b;return 1; }return 0; }

int main() {
    int k;
    cin >> k;
    int even = k/2;
    int odd = (k+1)/2;
    cout << even*odd << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int A, B, C, D;
lint dp[3003][3003];
const lint MOD = 998244353;

void modAdd(lint & a, lint b) { a = (a + b) % MOD; }

int main() {
    cin >> A >> B >> C >> D;

    INIT(dp, 0);
    dp[A][B] = 1;

    for_(i,A+1,C+1) modAdd(dp[i][B], dp[i - 1][B] * B);
    for_(j,B+1,D+1) modAdd(dp[A][j], dp[A][j - 1] * A);

    for_(i,A+1,C+1) for_(j,B+1,D+1) {
        lint x = (dp[i][j - 1] * i) % MOD;
        lint y = (dp[i - 1][j] * j) % MOD;
        lint z = (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD;
        lint add = (x + y - z + MOD) % MOD;
        modAdd(dp[i][j], add);
    }

    cout << dp[C][D] << endl;
}

Measured memory_bytes: 74008
//
// Created by yamunaku on 2019/10/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    int n=s.size();
    if(n==1){
        cout << k/2 << endl;
        return 0;
    }else if(n==2){
        if(s[0]==s[1]){
            cout << k << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }
    ll ans=0;
    if(s[0]==s[n-1]&&k>1){
        ll x=0;
        string t=s;
        rep(i,n-1){
            if(t[i]==t[i+1]){
                x++;
                t[i+1]='*';
            }
        }
        if(t[n-1]=='*'){
            ans=x*k;
        }else{
            t=s;
            ll y=1;
            t[0]='*';
            rep(i,n-1){
                if(t[i]==t[i+1]){
                    y++;
                    t[i+1]='*';
                }
            }
            if(t[n-1]=='*'){
                ans=x*((k+1)/2)+y*(k/2);
            }else{
                ans=x+y*(k-1);
            }
        }
    }else{
        rep(i,n-1){
            if(s[i]==s[i+1]){
                ans++;
                s[i+1]='*';
            }
        }
        ans*=k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef struct {
	int x;
	int y;
}location;

int h, w, n;
location cheese[10] = {};
vector<vector<char> > map(1000, vector<char>(1000));
int dirx[] = { -1,0,0,1 }, diry[] = { 0,-1,1,0 };
int mint = 0;

void bfs(location now, location goal) {
	queue<location> que;
	que.push(now);
	vector<vector<int> > dist(h, vector<int>(w, -1));
	dist[now.x][now.y] = 0;
	while (!que.empty()) {
		now = que.front(); que.pop();
		if (now.x == goal.x && now.y == goal.y) {
			mint += dist[now.x][now.y];
			break;
		}
		for (int i = 0; i < 4; ++i) {
			location cnext; cnext.x = now.x + dirx[i], cnext.y = now.y + diry[i];
			if (cnext.x >= 0 && cnext.y >= 0 && cnext.x < h && cnext.y < w && map[cnext.x][cnext.y] != 'X' && dist[cnext.x][cnext.y] == -1) {
						dist[cnext.x][cnext.y] = dist[now.x][now.y] + 1;
						que.push(cnext);
			}
		}
	}
}

int main() {
	cin >> h >> w >> n;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> map[i][j];
			if (map[i][j] == 'S') {
				cheese[0].x = i, cheese[0].y = j;
			}
			if ('1' <= map[i][j] && map[i][j] <= '9') {
				cheese[map[i][j]-'0'].x = i;
				cheese[map[i][j]-'0'].y = j;
			}
		}
	}

	for (int cp = 0; cp < n; ++cp)
		bfs(cheese[cp], cheese[cp + 1]);

	cout << mint << endl;

	return 0;
}


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

int main() {
  double w,h,x,y;
  cin >> w >> h >> x >> y ;
  
  if(x == w/2 && y == h/2)
    cout << w*h/2 <<" "<< 1 << endl;
  else
    cout << w*h/2 <<" "<< 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a <= b && b <= c) { printf("%d %d %d\n",a,b,c); return 0; }
    if (a <= c && c <= b) { printf("%d %d %d\n",a,c,b); return 0; }
    if (b <= a && a <= c) { printf("%d %d %d\n",b,a,c); return 0; }
    if (b <= c && c <= a) { printf("%d %d %d\n",b,c,a); return 0; }
    if (c <= a && a <= b) { printf("%d %d %d\n",c,a,b); return 0; }
    if (c <= b && b <= a) { printf("%d %d %d\n",c,b,a); return 0; }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll X;
  cin  >> X;
  ll Y=gcd(360,X);
  cout << 360/Y << endl;
}

Measured memory_bytes: 3632
def rpn(p)
  st = []
  while p.size > 0
    x = p.shift
    case x
    when "+" then st.push(st.pop+st.pop)
    when "-" then st.push(-st.pop+st.pop)
    when "*" then st.push(st.pop*st.pop)
    when "/" then st.push(1.0/st.pop*st.pop)
    else st << x.to_f end
  end
  return st
end

while gets
  ln = $_.split.map(&:to_s)
  puts rpn(ln)
end

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

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

    int n, maxi = 0;
    cin >> n;
    vector<int> A(n);
    unordered_map<int, bool> mp;

    unordered_set<int> st;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        if(st.count(A[i])) mp[A[i]] = true;

        maxi = max(maxi, A[i]);
        st.insert(A[i]);
    }

    for(int i = 0; i < n; i++){
        int ml = 2;
        while(true){
            int t = A[i] * ml;
            if(t > maxi) break;
            mp[t] = true;
            ml++;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += !mp[A[i]];
    }

    cout << ans << endl;
    
    return 0;
}

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

int main() {
	double d;
	while(cin>>d,d>=0){
		double k=128;
		bool b[15];
		for(int i=0;i<12;i++){
			if(d>=k){
				d-=k;
				b[i]=1;
			}
			else b[i]=0;
			k/=2;
		}
		if(d!=0)cout<<"NA\n";
		else{
			for(int i=0;i<8;i++)cout<<b[i];
			cout<<'.';
			for(int i=0;i<4;i++)cout<<b[i+8];cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3156
from statistics import median
n=int(input())
a=list(map(int,input().split()))
mid=0
l=[]
for i in range(n):
    l+=[a[i]-i-1]

mid=median(l) if n%2!=0 else sorted(l)[n//2]
ans=0
for i in range(n):
    ans+=abs(a[i]-(mid+i+1))

print(int(ans))


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

int main(){
    int N,K;
    string S;
    char lowercase;

    cin >> N;
    cin >> S;
    cin >> K;

    lowercase = S[K-1];

    for(int i=0;i<N;i++){
        if(S[i]!=lowercase){
            S[i] = '*';
        }
    }
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
	int a, b=0, c, d, e[10000]={0}, g[10000]={0}, i, j, f,k;
	cin >> a;
	b=a*(a-1)/2;
	for(i=1;i<=b;i++){
		cin >> c >> d >> f >> k;
		if(f > k){
			g[c] = g[c] + 3;
		}
		else if(k > f){
			g[d] = g[d] + 3;
		}
		else{
			g[c]++;
			g[d]++;
		}
	}
	for(i=1;i<=a;i++){
		for(j=1;j<=a;j++){
			if(g[i]<g[j]){
				 e[i]++;
			}
		}
	}
	for(i=1;i<=a;i++){
	e[i]++;
	cout << e[i] << endl;
	}
}

Measured memory_bytes: 3164
<?php

while (true) {
    fscanf(STDIN, "%d %d", $H, $W);

    if (0 == $H && 0 == $W) break;

    for ($i = 0; $i < $H; $i++) {
        for ($j = 0; $j < $W; $j++) {
            echo '#';
        }
        echo "\n";
    }

    echo "\n";
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const ll INF = 1e15;

int main() {
  ll m1, m2, d1, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (d2 - d1 < 0) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int x;
    cin >>x;
    int v=100;
    int ans=0;
    
    while(v<x){
    	int add= v/100;
    	v+=add;
    	ans++;
    }
    // cout<<v<<" "<<x<<endl;
    cout<<ans<<endl;
    return 0;
}

/* Pooja Yadav */

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int index(int n) {
	int a = n % 10;
	while (n >= 10) n /= 10;
	return n*10 + a;
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n; cin >> n;
	vi cnt(100);
	for (int i = 1; i <= n; i++)
		cnt[index(i)]++;
	ll ans = 0;
	for (int i = 0; i < 100; i++) {
		int j = i/10 + (i%10) * 10;
		ans += (ll)cnt[i] * cnt[j];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int r;

void partition(int A[]){
  int i=0,j,k;
  int x;

  for(j=0;j<=r;j++){
    if(A[j]<=A[r]){
      if(r==j) r = i;
      x = A[i];
      A[i] = A[j];
      A[j] = x;
      i++;
    }
    
  }
}

int main(){

  int n,i;
  scanf("%d",&n);

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

  r=n-1;

  partition(A);

  for(i=0;i<n;i++){
    if(i==r) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n); rep(i, n) { cin >> a[i]; a[i] -= i + 1; }
	sort(a.begin(), a.end());
	int b = (n % 2 == 0 ? round((a[n / 2] + a[n / 2 - 1]) / 2.0) : a[(n - 1) / 2]);
	int sum = 0;
	rep(i, n)sum += abs(a[i] - b);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
N,K = map(int,input().split())
A=list(map(int,input().split()))

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print(P[y+c])

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  ll n ,t ; 
  cin>>n>>t;
  
  vector<ll>a(n);
  rep(i,n) cin>>a[i];
  ll sum=t;
  rep(i,n-1){
    sum+=min(a[i+1]-a[i],t);
  }
  cout<<sum<<endl;  
}
  



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout<<#a<<"="<<a<<nl
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<int,int>
#define vi vector<int>
#define md 998244353

using namespace std;

int solve()
{
    ll n;
    cin>>n;
    vl v(n);
    for(auto &it:v) cin>>it;
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll x=v[0];
    ll k=n-2;
    for(int i=1;i<n and k>0;i++)
    {
        x+=v[i];
        k--;
        if(k>0)
        {
            x+=v[i];
            k--;
        }
    }
    cout<<x<<endl;

    return 0;
}

int main()
{
    fast;
    solve();

    return 0;
}














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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    double w, h; 
    int x, y;
    cin >> w >> h >> x >> y;
    double ans = w * h / 2.0;

    cout << ans << ' ' << endl;
    if(w == 2 * x && h == 2 * y) cout << 1 << endl;
    else cout << 0 << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 300010;
ll cal(ll a, ll b, ll c) {
	if (a % 2 == 0) return 0;
	return b * c;
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	cout << min({cal(a, b, c), cal(b, a, c), cal(c, a, b)}) << '\n';
}



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

table = [[0] * 4 for i in range(N)]
for i, (Ai, Bi) in enumerate(AB):
    table[i][0] = Ai
    table[i][1] = Bi 
    table[i][2] = Ai + Bi
    table[i][3] = i

    
table_A = list(table)
table_A.sort(key=lambda x: -x[0])
table_A.sort(key=lambda x: -x[2])

table_B = list(table)
table_B.sort(key=lambda x: -x[1])
table_B.sort(key=lambda x: -x[2])

ans = 0
idx_a = 0
idx_b = 0
state = [0] * N
for i in range(N):
    # print("#", ans, idx_a, idx_b)
    # print("#", state)
    if i % 2:
        while True:
            A_tmp, B_tmp, score_tmp, i_tmp = table_B[idx_b]
            if state[i_tmp] < 1:
                # print("## b", B_tmp)
                ans -= B_tmp # inverted
                state[i_tmp] = 1
                idx_b += 1
                break
            idx_b += 1
    else:
        while True:
            A_tmp, B_tmp, score_tmp, i_tmp = table_A[idx_a]
            if state[i_tmp] < 1:
                # print("## a", A_tmp)
                ans += A_tmp
                state[i_tmp] = 1
                idx_a += 1
                break
            idx_a += 1

print(ans)

Measured memory_bytes: 47304
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int n;
ll a[maxn];
ll k;
inline ll CEIL22(ll x, ll y)
{
    return (x + y - 1) / y;
}
bool check(ll x)
{
    ll cnt = 0ll;
    repd(i, 1, n)
    {
        if (a[i] <= x)
        {
            continue;
        }
        cnt += CEIL22(a[i], x)-1;
    }
    return cnt <= k;
}
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","w",stdout);
    n = readint();
    k = readint();
    repd(i, 1, n)
    {
        a[i] = readint();
    }
    ll l = 1ll;
    ll r = 1e9;
    ll mid;
    ll ans = 0ll;
    while (l <= r)
    {
        mid = (l + r) >> 1;
        if (check(mid))
        {
            ans = mid;
            r = mid - 1;
        } else
        {
            l = mid + 1;
        }
    }
    printf("%lld\n", ans );
    return 0;
}




Measured memory_bytes: 5332
#include<stdio.h>

int main(void)
{
	char a[5];
	scanf("%s",a);
	int b=0,i;
	for(i=0;i<3;i++){
		if(a[i]=='o'){
			b++;
		}
	}
	printf("%d",700+b*100);
	return 0;
}

Measured memory_bytes: 128
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003, M = 2003, mod = 1000000007, inv2 = (mod + 1) >> 1;
int n, a[N], b[N], maxa, maxb, dp[M << 1][M << 1], fac[N], inv[N], ans;
bool vis[M << 1][M << 1];
inline int DP(int x, int y){
    if(x < -maxa || y < -maxb) return 0;
    if(vis[x + M][y + M]) return dp[x + M][y + M];
    vis[x + M][y + M] = true;
    return dp[x + M][y + M] = (dp[x + M][y + M] + DP(x, y - 1) + DP(x - 1, y)) % mod;
}
inline void init(int m){
    fac[0] = 1;
    for(Rint i = 1;i <= m;i ++) fac[i] = (LL) i * fac[i - 1] % mod;
    inv[1] = 1;
    for(Rint i = 2;i <= m;i ++) inv[i] = (LL) (mod - mod / i) * inv[mod % i] % mod;
    inv[0] = 1;
    for(Rint i = 1;i <= m;i ++) inv[i] = (LL) inv[i] * inv[i - 1] % mod;
}
int main(){
    scanf("%d", &n);
    for(Rint i = 1;i <= n;i ++){
        scanf("%d%d", a + i, b + i);
        maxa = max(maxa, a[i]);
        maxb = max(maxb, b[i]);
        ++ dp[-a[i] + M][-b[i] + M];
    }
    init(maxa + maxb << 1);
    for(Rint i = 1;i <= n;i ++) ans = (ans + DP(a[i], b[i])) % mod;
   // printf("%d\n" , ans ) ;
    for(Rint i = 1;i <= n;i ++)
        ans = (ans - (LL) fac[a[i] + b[i] << 1] * inv[a[i] << 1] % mod * inv[b[i] << 1] % mod + mod) % mod;
    printf("%d", (LL) ans * inv2 % mod);
}

Measured memory_bytes: 82048
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,f[2010][2010],jc[4000010],ny[4000010],p=1e9+7;
ll C(ll x,ll y){
	return jc[x]*ny[y]%p*ny[x-y]%p;
}
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
int main(){
	ll i,j;
	scanf("%lld%lld",&n,&m);
	if(m==1)return puts("1"),0;
	jc[0]=1;ny[0]=ny[1]=1;
	for(i=1;i<=n*m;i++)jc[i]=jc[i-1]*i%p;
	ny[n*m]=ksm(jc[n*m],p-2)%p;
	for(i=n*m-1;i>=2;i--){
	 ny[i]=ny[i+1]*(i+1)%p;
	 //printf("%lld %lld %lld\n",i,jc[i],ny[i]);
}
	for(i=0;i<=n;i++)f[i][0]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=i;j++){
			f[i][j]=f[i-1][j];
			f[i][j]=(f[i][j]+f[i][j-1]*(n-j+1)%p*C(n*m-i-(j-1)*(m-1)-1,m-2))%p;
			//printf("%lld %lld %lld %lld %lld %lld\n",i,j,f[i][j],f[i-1][j],n*m-i-(j-1)*(m-1)-1,C(n*m-i-(j-1)*(m-1)-1,m-2));
		}
	}
	printf("%lld",f[n][n]);
}
/*
没有想到把当前放的固定在原序列上 
*/

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

int main(){
  int n;
  cin>>n;
  ll x=0,y;
  ll a,b;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a>x){
      x=a;
      y=b;
    }
  }
  cout<<x+y<<endl;
}

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

#define rep(i,x,y) for(int i=(x); i < (y); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " L:" << __LINE__ << ")" << std::endl;
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

using i64=int64_t;

string ryaku(string s, int k) {
	string ret = string(1, s[0]);
	if (k == 1) return ret;
	for(int i = 0; i < s.size() - 1; i++) {
		if (s[i] == 'a' || s[i] == 'i' || s[i] == 'u' || s[i] == 'e' || s[i] == 'o') {
			ret = ret + s[i + 1];
			if (k == ret.size()) break;
		}
	}
	return ret;
}

void solve(vector<string> &S) {
	int n = S.size();
	int kmax = 0;
	for(int i = 0; i < n; i++) {
		kmax = max(kmax, (int)S[i].size());
	}
	for(int k = 1; k <= kmax; k++) {
		set<string> M;
		bool flag = true;
		for(int i = 0; i < n; i++) {
			string r = ryaku(S[i], k);
			if (M.find(r) != M.end()) {
				flag = false;
				break;
			}
			M.insert(r);
		}
		if (flag) {
			cout << k << endl;
			return;
		}
	}
	cout << "-1" << endl;
}

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(16);
	
	int n;
	while(cin >> n, n) {

		vector<string> S;
		for(int i = 0; i < n; i++) {
			string s;
			cin >> s;
			S.push_back(s);
		}
		solve(S);
	}

	return 0;
}

Measured memory_bytes: 3200
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    S=int(input())
    mod0=1000000007
    i=S//3
    ans=1
    if i==0:
        print(0)
        sys.exit()
    if i==1:
        print(1)
        sys.exit()

    sys.setrecursionlimit(100000)
    nCr = {}
    def cmb(n, r):
        if r == 0 or r == n: return 1
        if r == 1: return n
        if (n,r) in nCr: return nCr[(n,r)]
        nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
        return nCr[(n,r)]

    for x in range(2,i+1):
        ans+=cmb(S-x*2-1,x-1)
    print(ans%mod0)
   




if __name__ == '__main__':
    main()

Measured memory_bytes: 162300
A,B,C=map(int,input().split())
K=int(input())

numbers=[A,B,C]

for k in range(K):
    a=numbers[0]
    b=numbers[1]
    c=numbers[2]
    if c<=a or c<=b:
        c*=2
        numbers[2]=c
    elif b <= a:
        b*=2
        numbers[1]=b

if numbers[0]< numbers[1] and numbers[1]<numbers[2]:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 61748
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;




int main() {
	long long int N,H;
	cin >> N >> H;
	int A[100000], B[100000];

	for (int i = 0; i < N; i++) {
		cin >> A[i]>>B[i];
	}

	sort(A, A + N, greater<int>());
	sort(B, B + N, greater<int>());
	int m = 0;
	int M;
	while (true) {
		if (B[m] <= A[0]) {
			M = m;
			break;
		}
		m++;
	}

	long long int Y = 0;
	for (int i = 0; i < M; i++) {
		H -= B[i];
		Y++;
		if (H <= 0)break;
	}
	if (H > 0) {
		Y +=(H+A[0] -1)/ A[0];
	}
	cout << Y << endl;
	return 0;
}



Measured memory_bytes: 1024
program taka
implicit none
integer:: n,i,j,b,d,count
integer,allocatable,dimension(:):: a
 
read(5,*) n
allocate(a(n))
read(5,*) (a(i),i=1,n)

count=0

do j=1,n
  d=a(j)
   do while(mod(d,2)==0)
    count=count+1
    d=d/2
   end do
end do

write(6,*) count
 
end program taka

Measured memory_bytes: 896
turn = "A"
A, B, C, D = map(int, input().split(' '))

while A > 0 and B > 0:
    if turn == "A":
        C -= B
        turn = "C"
        if not C > 0:
            print('Yes')
            break
    else:
        A -= D
        turn = "A"
        if not A > 0:
            print('No')
            break

Measured memory_bytes: 9132
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {

	int h, w;
	cin >> h >> w;
	for (size_t i = 0; i < h; i++)
	{
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256