akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n = int(input())

a=[2,3]
for i in range(5,1400,2):
    maxi = int(math.sqrt(i)) +1
    isprime = 1
    for j in range(3,maxi,2):
        if (i % j) == 0:
            isprime = 0
            break
    if isprime == 1:
        a.append(i)

#print(a)

b=[]
for i in a:
    if i % 5 == 1:
        b.append(i)

# print(b)

for i in range(n):
    print(b[i], end=' ')
print()


Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define dbg() cerr << 
#define show(x) (#x) << ": " << (x) <<

using namespace std;

const int MOD = 998244353;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}

void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

namespace Math {
  const int NMAX = (int)1e7;
  int pow2[1 + NMAX];
  int fact[1 + NMAX], tcaf[1 + NMAX];
  void Precalc() {
    fact[0] = pow2[0] = 1;
    for (int i = 1; i <= NMAX; ++i) {
      pow2[i] = pow2[i - 1];
      Add(pow2[i], pow2[i]);

      fact[i] = fact[i - 1];
      Mul(fact[i], i);
    }
    tcaf[NMAX] = Pow(fact[NMAX], -1);
    for (int i = NMAX - 1; i >= 0; --i) {
      tcaf[i] = tcaf[i + 1];
      Mul(tcaf[i], i + 1);
      assert(1LL * fact[i] * tcaf[i] % MOD == 1);
    }
  }
  int Choose(int n, int k) {
    if (k > n || n < 0) return 0;
    return 1LL * fact[n] * tcaf[n - k] % MOD * tcaf[k] % MOD;
  }
};

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

  Math::Precalc();
  int n; cin >> n;
  int ans = Pow(3, n);
  for (int freq = n / 2 + 1; freq <= n; ++freq) {
    Add(ans, -2LL * Math::Choose(n, freq) * Math::pow2[n - freq] % MOD);
  }
  cout << ans << endl;

  cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}


Measured memory_bytes: 117504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;cin>>n;
	ll a[n],b[n],c[n];

	rep(i,n) {
		cin>>a[i]>>b[i];
		c[i]=-(a[i]%b[i]);
		if(a[i]%b[i]!=0) c[i]+=b[i];
	}
/*
	rep(i,n) cout<<c[i]<<" ";
	cout<<"\n";
*/
	for(int i=n-1;i>0;i--){	
		if(c[i-1]<c[i]){
			ll cnt=(c[i]-c[i-1])/b[i-1];
			if((c[i]-c[i-1])%b[i-1]!=0) cnt++;
			c[i-1]+=b[i-1]*cnt;
		}
	}
/*
	rep(i,n) cout<<c[i]<<" ";
	cout<<"\n";
*/
	cout<<c[0]<<"\n";

}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N, C;
vector<ll> A, B;
ll dp[410][410];
ll a[410][410];
ll pw[410][410];
ll sumPw[410][410];
void make_pw(){
  rep(i, 410)rep(j, 410) pw[i][j] = pow_mod(i, j);
  rep(j, 410){
    rep(i, 405){
      if(i == 0){
        sumPw[i][j] = 1;
        continue;
      }
      sumPw[i][j] = sumPw[i-1][j] + pw[i][j];
    }
  }
}


void make_a(){
  make_pw();
  rep(i, N)rep(j, C + 1){
    a[i][j] = (sumPw[B[i]][j] - sumPw[A[i] - 1][j] + MOD) % MOD;
  }
}

int main(){
  //部分点
  COMinit();
  cin >> N >> C;
  A.resize(N), B.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  make_a();
  dp[0][0] = 1;
  for(ll i = 1; i <= N; i++){
    for(ll j = 0; j <= C; j++){
      for(ll x = 0; x + j <= C; x++){
        dp[i][j+x] += dp[i-1][j] * a[i-1][x] % MOD;
        dp[i][j+x] %= MOD;
      }
    }
  }
  cout << dp[N][C] << endl;
}


Measured memory_bytes: 10240
n = gets.to_i
a = gets.split.map(&:to_i)
b = []
(n/2).times do |i|
  b[i+n/2] = a[i*2]
  b[n/2-1-i] = a[i*2+1]
end
if n%2 == 1
  b << a[-1]
  b.reverse!
end
puts b.join(' ')


Measured memory_bytes: 25348
# @author 

import sys

class CTsundoku:
    def solve(self, tc=0):
        from bisect import bisect_right
        n, m, k = [int(_) for _ in input().split()]
        a = [int(_) for _ in input().split()]
        b = [int(_) for _ in input().split()]
        prea = [0] * (n + 1)
        preb = [0] * (m + 1)
        for i in range(1, n + 1):
            prea[i] = prea[i - 1] + a[i - 1]
        for i in range(1, m + 1):
            preb[i] = preb[i - 1] + b[i - 1]

        ans = 0
        for i in range(n + 1):
            if prea[i] > k:
                break
            j = bisect_right(preb, k - prea[i]) - 1
            ans = max(ans, i + j)

        print(ans)


solver = CTsundoku()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 49168
use std::io::*;
use std::str::*;
use std::collections::HashSet;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut hs = HashSet::new();

    for _ in 0..n {
        let x: usize = read().unwrap();
        if hs.contains(&x) {
            hs.remove(&x);
        } else {
            hs.insert(x);
        }
    }
    println!("{}", hs.len());
}


Measured memory_bytes: 8444
def main():
    x, y = list(map(int, input().split()))
    ans = abs(y) - abs(x)
    if x > 0 and y > 0 or x < 0 and y < 0:
        if x > y:
            print(x - y + 2)
        else:
            print(y - x)
    elif x < 0 and y >= 0:
        print(min(y - x, abs(y - abs(x)) + 1))
    elif x >= 0 and y < 0:
        print(abs(x - abs(y)) + 1)
    elif x == 0 and y > 0:
        print(y - x)
    else:
        print(x + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long t = Integer.parseInt(sc.next());
		long a = Integer.parseInt(sc.next());
		for (int i = 1; i < n; i++) {
			long tt = Integer.parseInt(sc.next());
			long ta = Integer.parseInt(sc.next());
			long mul = Math.max(t / tt, a / ta);
			while (tt * mul < t || ta * mul < a)
				mul++;
			t = tt * mul;
			a = ta * mul;
		}
		System.out.println(t + a);
	}
}

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



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

	if (n == "Sunny") cout << "Cloudy";
	if (n == "Cloudy") cout << "Rainy";
	if (n == "Rainy") cout << "Sunny";

	cout << endl;

	return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

flag = True
for i in range(n):
    if flag:
        for j in range(n):
            if i + m <= n and j + m <= n:
                aa = []
                for k in range(m):
                    aa.append(a[i + k][j : j+m])
                if aa == b:
                    print('Yes')
                    flag = False
                    break

if flag:
        print('No')

Measured memory_bytes: 3064
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    A, B = read_ints()
    if 2*B >= A:
        return 0
    return A-2*B


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61744
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll a[n];

    rep(i, n) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, n) {
        if(ans > 1000000000000000000 / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }

    cout << ans << endl;
}

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 1e5 + 5;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    int n ;cin >> n;
    vector<ld> v(n);
    int res = 0;
    for(int i = 0 ; i < n ; ++i)cin >> v[i];
    sort(v.begin(),v.end());
    for(int i = 1 ; i < n ; ++i){
        v[i] = (v[i] + v[i - 1]) / 2;
    }
    cout << fixed << setprecision(5) << v.back();
}


Measured memory_bytes: 256
n, as, bs = ARGF.read.split("\n").map { |e| e.split }
xs = as.zip(bs).map { |e|
  a,b = e.map { |ee| ee.to_i }
  a - b
}.sort
ms = xs.select { |e|
  e < 0
}
ps = xs.select { |e|
  e > 0
}
if ms.length == 0
  puts 0
  exit
end

c = ms.length
val = 0
ms.each { |e|
  m = e.abs
  if val <= m
    loop {
      if ps.length == 0
        puts '-1'
        exit
      else
        val += ps.pop
        c += 1
        if val >= m
          val -= m
          break
        end
      end
    }
  else
    val -= m    
  end
}
puts c


Measured memory_bytes: 28012
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = myconv("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",2);
  var n = nextInt();
  myout(s[n-1]);
}

Measured memory_bytes: 21956
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    while (1) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }

        string now, tmp;
        cin >> now;
        int size;
        int cnt = 0;
        char before = ' ';
        for (int i = 0; i< n; i++) {
            tmp = now;
            size = tmp.size();
            for (int j = 0; j < size; j++) {
                if (j == 0) {
                    now = "";
                    cnt = 1;
                } else {
                    if (before == tmp[j]) {
                        cnt++;
                    } else {
                        now += to_string(cnt) + before;
                        cnt = 1;
                    }
                }
                
                before = tmp[j];
                if (j == size-1) {
                    now += to_string(cnt) + before;
                }
            }
        }
        cout << now << "\n";
    }
}


Measured memory_bytes: 3464
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
using namespace std;
const int MAXN=1000005;
int N;
int a[MAXN],temp,now,tag;
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",a+i);
	}
	for(int i=2;i<=N;i++)
	{
		if(a[i-1]>a[i])
		{
			a[i]++;
		}
		if(a[i-1]>a[i])
		{
			tag=1;
			break;
		}
	}
	if(tag)
	{
		printf("No");
	}
	else
	{
		printf("Yes");
	}
	return 0;
}

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

int main(){
int a[3]={};//配列の定義

for(int i=0;i<3;i++){
cin >> a[i] ;//配列に文字を入力
}

for (int i = 0; i <3; ++i)
{
if(a[1]<a[0])swap(a[0],a[1]);
if(a[2]<a[1])swap(a[1],a[2]);
}

cout << a[0] <<" " << a[1] << " " << a[2] << endl;;
return 0;
}


Measured memory_bytes: 3088
import sys

cand = set()
for i in range(0, 20+1, 4):
    for j in range(0, 20-i+1, 7):
        cand.add(i + j)

n = int(sys.stdin.readline().rstrip())

def main():
    return 'Yes' if n in cand or n >= 21 else 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000007;

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

int main() {
  int N;
  cin >> N;
  int l[N];
  int r[N];
  for(int i = 0; i < N; i++) {
    cin >> l[i] >> r[i];
  }
  int sum = 0;
  for(int i = 0; i < N; i++) {
    sum += r[i] - l[i] + 1;
  }
  cout << sum << endl;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = (c + b - 1) / b;
  int y = (a + d - 1) / d;
  cout << (x <= y ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3608
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        String g = in.next();
        while (!"#".equals(g)) {
            int y = in.nextInt(), m = in.nextInt(), d = in.nextInt();
            if (y <= 30 || (y == 31 && m <= 4)) {
                out.print("HEISEI ");
            } else {
                out.print("? ");
                y -= 30;
            }
            out.println(y + " " + m + " " + d);

            g = in.next();
        }
        out.flush();
    }
}



Measured memory_bytes: 27168
#include <stdio.h>

int main(){
	int a=0;
	int b=0;
	
	printf("");
	scanf("%d %d",&a,&b);
	
	while(1){
		if(a>=-1000 && a<=1000 && b>=-1000 && b<=1000){
			break;
		}else{
			printf("");
			scanf("%d %d",&a,&b);
			continue;
		}	
	}
	
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else if(a==b){
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int64_t N,C,K;
  cin>>N>>C>>K;
  vector<int64_t>T(N);
  for(int i=0;i<N;i++){
    cin>>T[i];
  }
  sort(T.begin(),T.end());
  int cnt=0;
  for(int i=0;i<N;i++){
    int64_t BT=T[i]+K;
    int64_t cap=C-1;
    cnt++;//cout<<BT<<" "<<cap<<endl;
    while(i+1<N&&cap-1>=0&&T[i+1]<=BT){
      //cout<<i+1<<" "<<cap-1<<endl;;
      i++;
      cap--;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    int ans = 0;
    REP(i, 0, s.size() - 1) {
        if (s[i] != s[i + 1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
INF = float('inf')

def rec(i, a, b, c):
    if i==N:
        if not a or not b or not c:
            return INF
        return abs(a-A) + abs(b-B) + abs(c-C)

    res = rec(i+1, a, b, c)

    res = min(res, rec(i+1, a+L[i], b, c) + (10 if a else 0))
    res = min(res, rec(i+1, a, b+L[i], c) + (10 if b else 0))
    res = min(res, rec(i+1, a, b, c+L[i]) + (10 if c else 0))

    return res

N, A, B, C = map(int, input().split())
L = [0]*N
for i in range(N):
    L[i] = int(input())

print(rec(0,0,0,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp> 
using namespace std;
int main()
{
    long int n;
    cin>>n;
    int a[n+1];
    //boost::math::lcm(1.0,20)
    int L=1;
    for(int i=0;i<n;i++)
     {cin>>a[i];
     L=boost::math::lcm(L,a[i]);
     }float sk=0;
     for(int i=0;i<n;i++)
     {
        sk=sk+L/a[i]; 
     }
     float ans=L/sk;
     cout<<ans;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  map<int,int>deta;
  for(int i=0;i<n;i++)
    deta[a.at(i)]++;
  vector<int>kazu(deta.size()); 
  {int i=0;
  for(auto x:deta){
    kazu.at(i)=x.second;
    i++;
  }
  }
  sort(kazu.begin(),kazu.end());
  int ans = 0;
  for(int i=0;i<int(kazu.size())-k;i++)
    ans += kazu.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13928
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int next_comb(int k) {
    int x = k & -k;
    int y = k + x;
    return (((k & ~y) / x) >> 1) | y;
}

int main()
{
    while (1) {
    int N, K;
    cin >> N >> K;
    if (N == 0 && K == 0) break;
    vector<int> vi(N);
    for (int n = 0; n < N; ++n) {
        cin >> vi[n];
    }

    set<ll> Set;
    int bit = (1<<K) - 1;
    for (; bit < (1<<N); bit = next_comb(bit)) {
        vector<int> tmp;
        for (int n = 0; n < N; ++n) {
            if (bit & (1<<n)) {
                tmp.push_back(vi[n]);
            }
        }
        vector<int> ind;
        for (int k = 0; k <K; ++k) {
            ind.push_back(k);
        }
        do {
            ostringstream oss;
            for (int k = 0; k < K; ++k) {
                 oss << tmp[ind[k]];
            }
            Set.insert(stoll(oss.str()));
        } while (next_permutation(ind.begin(), ind.end()));
    }

    cout << Set.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3288
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int dig(LL x) {
  return (x < 10) ? 1 : (1 + dig(x/10));
}

int main() {
  LL x;
  cin >> x;
  int ans = 11;
  for(LL i = 1; i * i <= x; i++) if(x % i == 0) {
    ans = min(ans, max(dig(i), dig(x/i)));
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > Pi;
const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    if((A + B) % 2) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return (0);
}

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

dp = [[0,0,0] for i in range(N)]
dp[0] = lis[0]

for idx, val in enumerate(lis[1:], start=1):
	a = val[0] + max([dp[idx-1][i] for i in range(3) if 0 != i ])
	b = val[1] + max([dp[idx-1][i] for i in range(3) if 1 != i ])
	c = val[2] + max([dp[idx-1][i] for i in range(3) if 2 != i ])
	dp[idx] = [a,b,c]
print(max(dp[-1]))

Measured memory_bytes: 48176
# import sys
# input = sys.stdin.readline
import itertools


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n, m = input_list()
    balls = [1] * n
    reds = [False] * n
    reds[0] = True
    for _ in range(m):
        x, y = input_list()
        if reds[x-1]:
            reds[y-1] = True
        balls[x-1] -= 1
        balls[y-1] += 1
        if balls[x-1] == 0:
            reds[x-1] = False
    c = 0
    for v in reds:
        if v:
            c += 1
    print(c)


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 76324
#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;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int m,n;
    cin >> m >> n;
    int count=0;
    rep(p,-256,256){
        rep(q,-256,256){
            if(p==0 and q==0) continue;
            if((m*p+n*q)%(p*p+q*q)==0 and (p*n-q*m)%(p*p+q*q)==0){
                ++count;
                if(count>8){
                    cout << "C" << endl;
                    return;
                }
            }
        }
    }
    print(count);
    if(count==8) cout << "P" << endl;
    else cout << "C" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    int n;
    cin >> n;
    rep(i,0,n) solve();
    return 0;
}

Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = in.nextInt();
            }

            int sum = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    sum += d[i] * d[j];
                }
            }

            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 27032
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;cin >> h >> w;
    char c[h*w];
    vector<vector<int>> d(h*w,vector<int>(h*w,1e9));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c[i*w+j];
            if(i){
                if(c[(i-1)*w+j]=='.'&&c[i*w+j]=='.'){
                    d[(i-1)*w+j][i*w+j]=d[i*w+j][(i-1)*w+j]=1;
                }
            }
            if(j){
                if(c[i*w+j-1]=='.'&&c[i*w+j]=='.'){
                    d[i*w+j-1][i*w+j]=d[i*w+j][i*w+j-1]=1;
                }
            }
        }
    }
    for(int i=0;i<h*w;i++){
        d[i][i]=0;
    }
    for(int i=0;i<h*w;i++){
        if(c[i]=='.'){
            for(int j=0;j<h*w;j++){
                if(c[j]=='.'){
                    for(int k=0;k<h*w;k++){
                        if(c[k]=='.'){
                            d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<h*w;i++){
        for(int j=i+1;j<h*w;j++){
            if(c[i]=='.'&&c[j]=='.'){
                ans=max(ans,d[i][j]);
            }
        }
    }
    cout << ans << endl;
}

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

{
    long long N, K, min = 10000000000;
    cin >> N >> K;
    vector<long long> h(N);
    rep(i, N)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    long long i = 0;
    for (int j = K - 1; j <= N - 1; j++)
    {
        if (min > h[j] - h[i])
        {
            min = h[j] - h[i];
        }
        i++;
    }
    cout << min << endl;
}


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

int main() {
  int N, K; cin >> N >> K;
  long long a[5010];
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  sort(a, a + N);

  long long sum = 0;
  int ans = N;
  for(int i = N-1; i >= 0; --i) {
    if(sum + a[i] < K) sum += a[i];
    else ans = min(ans, i);
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> d(n);
  vector<int> vec(100, 0);
  int tmp;
  rep(i, n) {
    cin >> tmp;
    vec[tmp - 1] = 1;
  }

  int ans = 0;
  rep(i, 100) {
    if (vec[i] == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0, ans = inf;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') cnt++;
	}
	//cout << cnt << "\n";
	ans = min(cnt, n - cnt);
	int r = 0, w = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'R') {
			r++;
		}
		else {
			w++;
		}
		ans = min(ans, max(cnt - r, w));
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int a, b, W; cin >> W >> a >> b;
	int t = ((a > b) ? a - b : b - a);

	cout << ((t - W < 0) ? 0 : (t - W)) << endl;

	return 0;
}

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

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  vector<int> l(N+1),r(N+1);
  l.at(0)=0;
  r.at(N)=0;

  for(int i=0;i<N;++i){
    if(S.at(i)=='W'){
      l.at(i+1)=l.at(i)+1;
    }
    else{
      l.at(i+1)=l.at(i);
    }
  }

  for(int i=0;i<N;++i){
    if(S.at(N-i-1)=='E'){
      r.at(N-i-1)=r.at(N-i)+1;
    }
    else{
      r.at(N-i-1)=r.at(N-i);
    }
  }

  int ans=3*pow(10,5);
  for(int i=0;i<=N;++i){
    ans=min(ans,r.at(i)+l.at(i));
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(){
  int n, i, j;
  long long s=0;
  cin >> n;
  int d[n];
  for(i=0; i<n; i++) cin >> d[i];
  for(i=0; i<n; i++)
    for(j=0; j<i; j++)
      s+=d[i]*d[j];
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll mod=1e9+7;
const ll N = 2e5+10;




void solve(){
        
        ll n=0,m=0,sum=0,x=0;
        cin>>n;
        ll cnt[n+1];
        memset(cnt,0,sizeof(cnt));
        for (int i = 0; i <n-1; i++) {
            cin>>x;
            cnt[x]++;
            
        }
        for (int i = 1; i <=n ; i++) {
            cout<<cnt[i]<<"\n";
        }
        
        
        
       
        
}


int main(){

        
            ios_base::sync_with_stdio(0);
            cin.tie(0);cout.tie(0);

            ll T=1;
            //cin>>T;
            while(T--){
                solve();
            }
            
            
        return 0;
}

Measured memory_bytes: 5220
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    if(b <= a+w && a <= b+w) cout << '0' << endl;
    else if(a+w < b) cout << b - (a+w) << endl;
    else cout << a - (b+w) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int n,x,w; int  min = 1000; int p = 0;

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

for(int i = 0; i < n; i++){
scanf("%d",&w);
p += w;
if(min > w) min = w;
}

printf("%d",n + (x - p) / min);

return 0;

}

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

int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  int i,k;
  int count = 0;
  for(i=0;i<=N/R;i++)
    for(k=0;k<=(N-R*i)/G;k++)
      if((N-R*i-k*G)%B == 0) count++;
  cout << count << endl;
}

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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


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

   string s; cin >> s;
   int L = 0;
   int R = s.size()-1;
   int h = 0;
   while(L < R){
      if(s[L] != s[R]) h++;
      L++;
      R--;
   }

   cout << h;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if(x/d>=k){
		cout<<x-d*k<<endl;
		return 0;
	}
	long long kai=x/d;
	if((k-kai)%2==0)cout<<x-d*kai<<endl;
	else cout<<abs(x-d*kai-d)<<endl;
}

Measured memory_bytes: 3596
import math

n = list(map(int, input().split()))
lista = []

for i in range(n[0]):
    a,m = list(map(str, input().split()))
    m = int(m)
    lista.append([a,m,i+1])

list.sort(lista, key = lambda x:x[1], reverse=True)
list.sort(lista, key = lambda x:x[0])

for i in range(n[0]):
    print(lista[i][2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int x,y; cin>>x>>y;
  //string s; cin>>s;
  
  rep(i,150)rep(j,150){if(i+j==x&&2*i+4*j==y){cout<<"Yes"; return 0;}}
  
  
  cout<<"No" <<endl;
}

Measured memory_bytes: 3616
from sys import stdin
import math


def isPrime(x):
    if x == 1:
        return False
    for i in range(2, int(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True


x = int(stdin.readline().rstrip())
while not isPrime(x):
    x += 1
print(x)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int a, b, c; cin >> a >> b >> c;
	puts(a == b && b == c ? "Yes" : "No");
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]
maxval = 10 ** 6
factor_cnt = [0] * (maxval+1)
for i in range(n):
    if factor_cnt[a[i]] > 1:
        continue
    for k in range(a[i], maxval+1, a[i]):
        factor_cnt[k] += 1

result = sum(factor_cnt[v] <= 1 for v in a)
print(result)

Measured memory_bytes: 95700
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

int A[100000];
int main(){
  int N;
  int K;
  cin >> N >> K;

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

  if((N - K) % (K - 1) == 0){
    cout << 1 + (N - K) / (K - 1) << endl;
  } else {
    cout << 2 + (N - K) / (K - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int i,n,s[1024],p[1024],q[1024],r[1024],Q,R,P,C,m;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d%d%d%d",&s[i],&p[i],&q[i],&r[i]);
		}
		scanf("%d%d%d%d",&P,&Q,&R,&C);
		m=1;
		for(i=0;i<n;i++){
			if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&4*p[i]+9*q[i]+4*r[i]<=C){
				printf("%d\n",s[i]);
				m=0;
			}
		}
		if(m){
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2720
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
  const int BIG = 1000000;
  const int CMAX = 20000;
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> ps;
    for(int i = 0; i < n; i++) {
      int p; cin >> p; ps.push_back(p);
    }
    // shop : at most 100
    // change : at most 49900... too much?
    // # of 500 got so far : at most 100
    // value : minimum payment
    
    vector<vector<int>> dp(CMAX+1, vector<int>(101, BIG));
    vector<vector<int>> dpnew(CMAX+1, vector<int>(101, BIG));
    dpnew[0][0] = 0;
    int cmax = 0;
    for(int i = 0; i < n; i++) {
      const int ii = i + 1;
      for(int j = 0; j <= cmax; j++) { // not buying
        for(int k = 0; k <= i; k++) {
          dp[j][k] = dpnew[j][k];
        }
      }
      // buying
      const int p = ps[i] % 1000;
      if(p != 0 && p <= 500) { // got 500!
        for(int j = 0; j <= cmax; j++) {
          const int jj = min(j + 500 - p, CMAX);
          cmax = min(max(cmax, jj), CMAX);
          for(int k = 0; k <= i; k++) {
            const int kk = k + 1;
            dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
          }
        }
      } else {
        // get 500 if possible!
        const int q = (p == 0 ? 1000 : p) - 500;
        for(int j = 0; j <= cmax; j++) {
          if(j >= q) {
            const int jj = j - q;
            for(int k = 0; k <= i; k++) {
              const int kk = k + 1;
              dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
            }
          } else { // get change
            const int jj = j + 1000 - p;
            cmax = min(max(cmax, jj), CMAX);
            if( jj < 1000) {
              for(int k = 0; k <= i; k++) {
                const int kk = k;
                dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
              }
            }
          }
        }
      }
    }
    for(int k = 100; k >= 0; k--) {
      int p = BIG;
      for(int j = 0; j <= cmax; j++) {
        p = min(p, dpnew[j][k]);
      }
      if(p != BIG) {
        cout << k << " " << p << endl;
        break;
      }
    }
  }
  return 0;
}



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

using namespace std;

const int N = 1e5 + 1;
const int INF = 1e9;

int n;
int a[N], cache[N];

int dp(int i) {
    if (cache[i] != -1) return cache[i];

    int ans = INF;
    if (i - 1 > 0) ans = min(ans, abs(a[i] - a[i - 1]) + dp(i - 1));
    if (i - 2 > 0) ans = min(ans, abs(a[i] - a[i - 2]) + dp(i - 2));
    
    if (ans == INF) ans = 0;
    return cache[i] = ans;
}

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

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    fill(cache, cache + N, -1);

    cout << dp(n);

    return 0;
}



Measured memory_bytes: 9028
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main() {
   fast();
   long long n;
   cin>>n;
   long long sum=0;
   long long t=5;
   
   long long k=10;
   long long j=1;
   if(n%2==1){
    cout<<0<<"\n";
    return 0;
   }else{
      while(t<=n){
        sum+=n/(2*t);
        t*=5;
        j++;
      }
      cout<<sum<<"\n";
      return 0;
   }

   

}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	int W, H, N; cin >> W >> H >> N;
	vector<int>x(N), y(N), a(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> a[i];
	}
	int tmpx1 = 0;
	int tmpx2 = W;
	int tmpy1 = 0;
	int tmpy2 = H;
	for(int i=0; i<N;i++){
		if (a[i] == 1) {
			if (x[i]>tmpx1) {
				tmpx1 = x[i];
			}
			
		}else if (a[i] == 2) {
			if (x[i] < tmpx2) {
				tmpx2 = x[i];
			}
			
		}else if (a[i] == 3) {
			if (y[i] > tmpy1) {
				tmpy1 = y[i];
			}
		}else if (a[i] == 4) {
			if (y[i] < tmpy2) {
				tmpy2 = y[i];
			}
		}
	}
	int w1 = tmpx2 - tmpx1;
	if (w1 < 0) w1 = 0;
	int h1 = tmpy2 - tmpy1;
	if (h1 < 0)h1 = 0;
	cout << w1 * h1 << endl;
}


    

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

int main()
{
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  for (auto i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int max_swing = *max_element(begin(a), end(a));
  sort(begin(b), end(b), greater<>());
  int count = 0;
  for (auto&& e : b) {
    if (e > max_swing) {
      count++;
      h -= e;
      if (h <= 0) break;
    }
  }
  if (h > 0) {
    count += (h + max_swing - 1) / max_swing;
  }
  cout << count << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin>>s;
		vector<char>v;
		int l ,r;
		r= l = 3e5;
		for(int i =0;i<2e6;i++)v.pb('0');
		for(int i = 3e5,j=0;j<s.size();j++,i++){
			v[i]=s[j];	
			r++;
		}
		int qw;
		cin>>qw;
		int f =0;
		l = 3e5-1;
		while(qw--){
			int type;
			cin>>type;
			if(type==1){
				f++;
			}
			else{
				int ff;
				char c;
				cin>>ff>>c;
				if(ff==1){
					if(f%2==0){
						v[l]=c;
						l--;
					}
					else{
						v[r]=c;
						r++;
					}
				}
				else{
					if(f%2==0){
						v[r]=c;
						r++;
					}
					else
						v[l]=c,l--;
				}
			}
		}
		if(f&1){
			for(int i=r-1;i>l;i--)cout<<v[i];
		}
		else
			for(int i =l+1;i<r;i++)cout<<v[i];
		
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 2752
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        if sum < g:
            use = max(nokori)
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100
        if sum >= g:
            ans = min(ans, count)
        return 0
    dfs(i + 1, sum, count, nokori)
    dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})

d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      String[] cs = new String[n];
      for (int ii = 0; ii < n; ii++) {
        int c1 = scanner.nextInt();
        int m1 = scanner.nextInt();
        int s1 = scanner.nextInt();
        int m2 = scanner.nextInt();
        int s2 = scanner.nextInt();
        int m3 = scanner.nextInt();
        int s3 = scanner.nextInt();
        int m4 = scanner.nextInt();
        int s4 = scanner.nextInt();
        int t = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
        cs[ii] = String.format("%05d,%08d", t, c1);
      }
      Arrays.sort(cs);
      String[] works = cs[0].split(",");
      System.out.println(Integer.parseInt(works[1]));
      works = cs[1].split(",");
      System.out.println(Integer.parseInt(works[1]));
      works = cs[cs.length - 2].split(",");
      System.out.println(Integer.parseInt(works[1]));
    }
  }
}

Measured memory_bytes: 74768
#include <iostream>
#include <string>
using namespace std;
int main(void){
 string haiku;
 cin >> haiku;
 haiku.erase(haiku.begin() + 5);
 haiku.insert(haiku.begin() + 5, ' ');  
 haiku.erase(haiku.begin() + 13);
 haiku.insert(haiku.begin() + 13, ' ');  
 cout << haiku << "\n";
 return 0;
}

Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

while N:
    mod = N % 10
    if mod == 7:
        print("Yes")
        exit()
    N //= 10

print("No")

Measured memory_bytes: 65312
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    cout << 180 * (N-2) << "\n";
}

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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	int H, W; cin >> H >> W;
	rep(i, 0, H)rep(j, 0, W) {
		string s; cin >> s;
		if (s == "snuke") {
			cout << char(j + 'A') << i + 1 << endl;
		}
	}
	return 0;
}

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

class Main {

    public static int getMinCost(int[] height, int k, int[] memo) {
        return getMinCostHelper(0, height,k, memo);
    }

    private static int getMinCostHelper(int i, int[] height, int k, int[] memo) {
        if(i == height.length - 1) {
            return 0;
        }

        if(memo[i] != -1) {
            return memo[i];
        }

        int costIncurred = Integer.MAX_VALUE;
        for(int index = i + 1; index <= i + k; index++) {
            if(index < height.length) {
                costIncurred = Math.min(costIncurred, Math.abs(height[index]-height[i]) + getMinCostHelper(index, height, k, memo));
            }
        }
        return memo[i] = costIncurred;
    }

    private static int getMinCostHelperDP(int[] height, int K) {
        int N = height.length;

        int[] dp = new int[N];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i=1; i<N; i++) {
            for(int steps = 1; steps <= K; steps++) {
                if(i - steps >= 0 && dp[i-steps] != Integer.MAX_VALUE) {
                    dp[i] = Math.min(dp[i], dp[i-steps] + Math.abs(height[i] - height[i-steps]));
                }
            }
        }
        return dp[N-1];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numberOfStones = scanner.nextInt();
        int[] height = new int[numberOfStones];
        int k = scanner.nextInt();
        int[] memo = new int[numberOfStones];
        Arrays.fill(memo, -1);
        for(int i=0; i<numberOfStones; i++)
            height[i] = scanner.nextInt();
//      System.out.println(getMinCost(height, k, memo));
        System.out.println(getMinCostHelperDP(height, k));
    }

}


Measured memory_bytes: 57156
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
const int dd[]={0,-1,0,1,0};
using namespace std;
class mod_int{
public:
	int x;
	mod_int():x(0){}
	mod_int(int u):x(u){}
	mod_int operator=(int u){
		x=u;
		return *this;
	}
	mod_int operator+=(mod_int y){
		x+=y.x;
		x=x>=mod?x-mod:x;
		return *this;
	}
	mod_int operator-=(mod_int y){
		x-=y.x;
		x=x<0?x+mod:x;
		return *this;
	}
	mod_int operator*=(mod_int y){
		x*=y.x;
		x%=mod;
		return *this;
	}
	mod_int operator/=(mod_int y){
		mod_int z=1;
		for(int u=1;u<=mod-2;u<<=1){
			if((mod-2)&u)
				z*=y;
			y*=y;
		}
		operator*=(z);
		return *this;
	}
};
mod_int operator+(mod_int x,mod_int y){
	return x+=y;
}
mod_int operator-(mod_int x,mod_int y){
	return x-=y;
}
mod_int operator*(mod_int x,mod_int y){
	return x*=y;
}
mod_int operator/(mod_int x,mod_int y){
	return x/=y;
}
ostream& operator<<(ostream &os,mod_int x){
	return os<<x.x;
}
int a,b,c,d;
mod_int p[1145140];
signed main(){
	int i,j;
	cin>>a;
	mod_int aa=a-1;
	aa*=aa;
	p[0]=1;
	p[1]=a;
	mod_int u=a+1;
	for(i=2;i<=a;i++){
		p[i]+=p[i-1];
		p[i]+=aa;
		p[i]+=u-p[i-1]-p[i-2];
		p[i]+=a-i+1;
		u+=p[i];
	}
	cout<<p[a]<<endl;
}

Measured memory_bytes: 9216