akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
    // long double x;
    // cin >> x;
    // 結果がオーバーフローするためllにする必要がある
    // ll sum = 100;
    // logで式変形しながらやろうとした時のコード
    // int n = log(x/100)/log(1.01);
    // int i = 1;
    // cout << n+58 << endl;
    // cout << (ll)100*pow(1.01,n) << endl;

    // 後で思いついた時のコード
    // int i = 1;
    // while (1) {
    //     sum*=1.01;
    //     if (sum>x){
    //         cout << i << endl;
    //         cout << sum << endl;
    //         return 0;
    //     }
    //     i++;
    // }
    // return 0;

    // 回答
    // 切り捨てにしなければならない
    // 掛け算なのでオーダー的には
    // O(log(n))
    ll x;
    cin >> x;
    ll ans = 0, a = 100;
    while (a < x) {
        a += a/100;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(c,b/a)<<endl;



}


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

typedef long long LL;

const int N=200000;
const double pi=acos(-1);

int n,l;
double a[N+9];

void into(){
  scanf("%d%d",&n,&l);
  for (int i=1;i<=n;++i)
	scanf("%lf",&a[i]);
}

double ans[2];

void Get_ans(){
  for (int i=1;i<=n;++i)
	for (int j=i+1;j<=n;++j){
	  ans[0]+=cos(pi*(a[i]+a[j])/l)*(n-(j-i+1));
	  ans[1]+=sin(pi*(a[i]+a[j])/l)*(n-(j-i+1));
	  ans[0]+=cos(pi*(a[i]+a[j]+l)/l)*(j-i-1);
	  ans[1]+=sin(pi*(a[i]+a[j]+l)/l)*(j-i-1);
	}
  double t=1.0*n*(n-1)*(n-2)/6;
  ans[0]/=t;ans[1]/=t;
}

void work(){
  Get_ans();
}

void outo(){
  printf("%.10lf %.10lf\n",ans[0],ans[1]);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4128
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()

    if K % 2 == 1:
        t = N // K
        ans = t ** 3
    else:
        t = N // K
        ans = t ** 3
        t = (N - K // 2) // K + 1
        ans += t ** 3

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9048
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;
int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return s + n;
}
int main() {
    ll A, B, C, D;
    ll ans=-1000000000000000000;
        cin >> A >> B >> C >> D;
        if (ans < A * C) {
            ans = A * C;
        }
        if (ans < A * D) {
            ans = A * D;
        }
        if (ans < B * C) {
            ans = B * C;
        }
        if (ans < B * D) {
            ans = B * D;
        }
        cout << ans;
}


Measured memory_bytes: 3672
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <cmath>
#define ll long long
using namespace std;

void ask(ll x){
	cout << "? " << x << endl;
	fflush(stdout);
}
bool rec(){
	char x;
	cin >> x;
	return (x == 'Y');
}

int main(){
	//确定N是否为10^k
	bool is10;
	ask(1000000000);
	is10 = rec();
	
	//确定位数
	ll wei = 1;
	if(is10){
		ask(2);
		ll a = 20;
		while(!rec()){
			ask(a);
			a *= 10;
			wei++;
		}
		cout << "! " << a / 20 << endl;
		return 0;
	}
	
	ll l,r,mid;
    for(ll i = 0;i <= 18;i++){
    	ask(pow(10,i));
        if(!rec()){
            l = pow(10,i-1);
            r = pow(10,i);
            break;
        }
    }
 
    while(r - l > 1){
        mid = (l + r) / 2;
        ask(mid * 10);
        if(rec()) r = mid;
        else l = mid;
    }
	
	cout << "! " << r << endl;
	return 0;
}


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

typedef unsigned long long int lli;

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

    lli n;
    cin >> n;

    vector<lli> v(n+1);
    vector<lli> frequency(1000001);

    lli sum = 0;

    for(int i = 1; i <= n; i++)
    {
        cin >> v[i];
        frequency[v[i]]++;
        sum += v[i];
    }

    lli q;
    cin >> q;

    while(q--)
    {
        lli b, c;
        cin >> b >> c;

        sum += -frequency[b]*b + frequency[b]*c;

        cout << sum << endl;

        frequency[c] += frequency[b];
        frequency[b] = 0;
    }

}


Measured memory_bytes: 11844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int N, M;
    cin >> N >> M;
    
    vector<int> H(N);
    rep(i, N)
    {
        cin >> H[i];
    }

    vector<bool> Nice(N);
    rep(i, N)
    {
        Nice[i]=true;
    }
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        --a;--b;
        if(H[a]<H[b])
        {
            Nice[a]=false;
        }
        else if(H[a]>H[b])
        {
            Nice[b]=false;
        }
        else
        {
            Nice[a]=false;
            Nice[b]=false;
        }        
    }

    int cnt=0;
    rep(i, Nice.size())
    {
        cnt += Nice[i]==true?1:0;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3728
import sys

def main():
    input = sys.stdin.readline
    N, Y = map(int, input().split())

    if Y // 10000 > N:
        print('-1 -1 -1')
    else:
        flag = False
        for i in range(Y//10000 + 1):
            for j in range(N-i+1):
                if 10000 * i + 5000 * j + 1000 * (N-i-j) == Y:
                    x, y, z = i, j, N-i-j
                    flag = True
                    break
        if flag:
            print('{} {} {}'.format(x, y, z))
        else:
            print('-1 -1 -1')
    


if __name__ == '__main__':
    main()


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


def main():
    A, B = map(int, input().split())

    # まずは最大公約数を求める
    G = gcd(A, B)

    # 最大公約数を素因数分解して素因数の数を求める
    result = factorizer(G)
    print(result)


# ユークリッド互除法
def gcd(a, b):
    # print("a:{0},b:{1}".format(a, b))
    if b == 0:
        return a
    return gcd(b, a % b)


def factorizer(n):
    """
    素因数分解するということは、
    2 ~ Nまでの数で割り続けるということ　試し割り
    割れなくなったら次の数で割る。
    素数を除いて、素因数の最大値は√nなので、それを超えたらやめる
    """
    res = {1: 1}  # １は必ずある
    calcEnd = n ** 0.5

    for i in range(2, int(calcEnd) + 2, 1):
        while n % i == 0:
            if res.get(i) is None:
                res[i] = 1
            else:
                res[i] += 1
            n /= i
            # print("n:{0}".format(n))

    # GCDが素数だった時の処理
    if n > 1:
        res[int(n)] = 1

    # print("res is {}".format(res))
    return len(res)


if __name__ == '__main__':
    main()


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

#define PI 3.14159265359

void solve() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double mangle = m*6.0; 
    double hangle = (h + m/60.0) * 30.0;

    double btwn = abs(mangle - hangle);

    double ans = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(btwn*PI/180));

    cout << setprecision(15) << ans;


}


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

    solve();
    return 0;
}

Measured memory_bytes: 4136
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin>>s;
    if (s[0]=='7'||s[1]=='7'||s[2]=='7')
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>0)printf("Positive");
    else if(a==0||(a<0&&b>0))printf("Zero");
    else if((abs(b)-abs(a))%2!=0)printf("Positive");
    else printf("Negative");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
ll dp[110][310][110];
ll n,W;
ll w[101],v[101];
bool f[110][310][110];
int main(){
  cin>>n>>W;
  rep(i,n){
    cin>>w[i]>>v[i];
  }
  ll w0=w[0];
  rep(i,n){
    w[i]-=w0;
  }
  int m=3*(n-1);
  fill(dp,0);
  rep1(i,n){
    rep(j,m+1){
      rep1(k,n){
	if(j-w[i-1]<0){
	  dp[i][j][k]=dp[i-1][j][k];
	}
	else{
	  dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-w[i-1]][k-1]+v[i-1]);
	}
      }
    }
  }
  ll res=0;
  rep(k,n+1){
    ll ww=W-k*w0;
    if(ww<0) continue;
    else if(ww>m) ww=m;
    res=max(res,dp[n][ww][k]);
  }

  prin(res);
	

  return 0;
}


Measured memory_bytes: 31232
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[400005];
llint c[400005];
llint Size[400005];

vector<llint> G2[400005];
llint pre[400005];
vector<llint> vec[400005];
llint ans[400005];

llint dfs(llint v, llint p)
{
	Size[v] = 1;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		Size[v] += dfs(G[v][i], v);
	}
	return Size[v];
}

void dfs2(llint v, llint p)
{
	G2[pre[c[v]]].push_back(v);
	
	llint tmp = pre[c[v]];
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		llint u = G[v][i];
		pre[c[v]] = u;
		dfs2(u, v);
	}
	pre[c[v]] = tmp;
}

void dfs3(llint v, llint p)
{
	llint ret = Size[v];
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		llint u = G[v][i], sum = Size[u];
		for(int j = 0; j < G2[u].size(); j++){
			sum -= Size[G2[u][j]];
		}
		vec[c[v]].push_back(sum);
	}
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		llint u = G[v][i];
		dfs3(u, v);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> c[i];
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1);
	
	for(int i = 1; i <= n; i++) pre[i] = n+i;
	for(int i = 1; i <= n; i++) Size[n+i] = n+1;
	
	dfs2(1, -1);
	
	dfs3(1, -1);
	for(int i = 1; i <= n; i++){
		llint sum = n;
		for(int j = 0; j < G2[n+i].size(); j++){
			sum -= Size[G2[n+i][j]];
		}
		vec[i].push_back(sum);
	}
	
	for(int i = 1; i <= n; i++){
		ans[i] = n*(n+1)/2;
		for(int j = 0; j < vec[i].size(); j++){
			llint m = vec[i][j];
			ans[i] -= m*(m+1)/2;
		}
	}
	
	/*for(int i = 1; i <= n; i++){
		for(int j = 0; j < vec[i].size(); j++) cout << vec[i][j] << " ";  cout << endl;
	}*/
	
	for(int i = 1; i <= n; i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 74984
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



int main() {
	while(1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<string, long double>>pls;
		for (int i = 0; i < N; ++i) {
			string st;
			int p, a, b, c, d, e, f, s, m; cin >> st>>p >> a >> b >> c >> d >> e >> f >> s >> m;
			int initime = a + b + c;
			int rooptime = d + e;
			int money = m*s*f-p;
			long double eff = static_cast<long double>(money) / static_cast<long double>(initime + rooptime*(m));
			pls.push_back(make_pair(st, eff));
		}
		sort(pls.begin(), pls.end(), [](const pair<string, long double>&l, const pair<string, long double>&r) {return abs(l.second-r.second)<1e-66?l.first<r.first:l.second > r.second; });
		for (int i = 0; i < pls.size(); ++i) {
			cout << pls[i].first << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int zhan[4000],ans[4000];
char s[100];
bool query(int x,int y)
{
    printf("? %d %d\n",x-1,y-1);
    fflush(stdout);scanf("%s",s);
    return s[0]=='Y';
}
int main()
{
    int a,b,n,ding=0;
    cin>>a>>b;
    if(a<=b)
    {
        puts("Impossible");
        exit(0);
    }
    n=a+b;
    for(int i=1;i<=n;++i)
    {
        if(ding&&!query(i,zhan[ding]))--ding;
        else zhan[++ding]=i;
    }
    int tmp=zhan[1];
    ans[tmp]=1;
    for(int i=1;i<=n;++i)
        if(i!=tmp)
        {
            if(query(tmp,i)) ans[i]=1;
            else ans[i]=0;
        }
    cout<<"! ";
    for(int i=1;i<=n;++i)
        printf("%d",ans[i]);
    puts("");
    fflush(stdout);
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

const int maxh = 2010, maxw = 2010;
int csum[maxh][maxw];
void init(VVI vec) {
  assert(vec.size());
  REP(i, vec.size()) REP(j, vec[0].size()) {
    if(!i && !j) csum[i][j] = vec[i][j];
    else if(!i) csum[i][j] = csum[i][j-1] + vec[i][j];
    else if(!j) csum[i][j] = csum[i-1][j] + vec[i][j];
    else csum[i][j] = csum[i-1][j] + csum[i][j-1] - csum[i-1][j-1] + vec[i][j];
  }
}
// 閉区間, 0-indexedで矩形範囲の合計
int cumsum(int sx, int sy, int gx, int gy) {
  if(!sx && !sy) return csum[gy][gx];
  if(!sx) return csum[gy][gx] - csum[sy-1][gx];
  if(!sy) return csum[gy][gx] - csum[gy][sx-1];
  return csum[gy][gx] - csum[gy][sx-1] - csum[sy-1][gx] + csum[sy-1][sx-1];
}

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

  int n, k;
  cin >> n >> k;
  VVI v(2*k, VI(2*k));
  REP(i, n) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if(c == 'B') y += k;
    x %= 2*k;
    y %= 2*k;
    v[y][x]++;
  }

  init(v);

  int ans = 0;
  REP(l, k+1) REP(u, k+1) {
    int r = l+k-1, d = u+k-1;
    int tmp = 0;
    if(l!=0 && u!=0) tmp += cumsum(0, 0, l-1, u-1);
    if(l!=0 && d!=2*k-1) tmp += cumsum(0, d+1, l-1, 2*k-1);
    if(r!=2*k-1 && u!=0) tmp += cumsum(r+1, 0, 2*k-1, u-1);
    if(r!=2*k-1 && d!=2*k-1) tmp += cumsum(r+1, d+1, 2*k-1, 2*k-1);
    tmp += cumsum(l, u, r, d);
    chmax(ans, tmp);
    chmax(ans, n-tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 94336
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
  fastIO();
  ll a,b,n;
  cin>>a>>b>>n;
  ll c = min(n,b-1);
  cout<<((a*c)/b) - (a*(c/b));
  return 0;
}

Measured memory_bytes: 3644
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
#R = 10**9 + 7
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,s = inm()
a = inl()
dp = [[0]*(s+1) for i in range(n+1)]
for i in range(n):
    for j in range(1,s):
        dp[i+1][j] = dp[i][j]
    for j in range(1,s-a[i]+1):
        if dp[i][j]>0:
            dp[i+1][j+a[i]] = (dp[i+1][j+a[i]]+dp[i][j])%R
    if a[i]<=s:
        dp[i+1][a[i]] = (dp[i+1][a[i]]+i+1)%R
if False and DBG:
    for i in range(n+1):
        ddprint(dp[i])
sm = 0
for i in range(1,n+1):
    sm = (sm+dp[i][s]*(n+1-i))%R
print(sm)


Measured memory_bytes: 134736
#include <bits/stdc++.h>
using namespace std;
int n = 0;
int a[210];

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

    int res = 0;
    bool exist_odd = false;
    while (true)
    {
        for (int i = 0; i < n; i++)
        {
            if (a[i] % 2 != 0)
            {
                exist_odd = true;
            }
            a[i] /= 2;
        }
        if (exist_odd)
        {
            break;
        }
        res++;
    }

    cout << res << "\n";
    return 0;
}

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

int x, y, d, HW, H, W;
string input[100];
bool orLoop[100][100];

bool loop(int a, int b){
	if(orLoop[b][a]){
		return true;
	}
	char i = input[b][a];
	if(i=='>'){
		orLoop[b][a] = true;
		if(loop(a + 1, b)){
			return true;
		}
		else
			return false;
	}
	else if(i=='v'){
		orLoop[b][a] = true;
		if(loop(a, b + 1)){
			return true;
		}
		else
			return false;
	}
	else if(i=='<'){
		orLoop[b][a] = true;
		if(loop(a - 1, b)){
			return true;
		}
		else
			return false;
	}
	else if(i=='^'){
		orLoop[b][a] = true;
		if(loop(a, b - 1)){
			return true;
		}
		else
			return false;
	}
	else{
		x = a;
		y = b;
		return false;
	}
}

int main(){
	while(cin >> H >> W){
		if (H == 0 && W == 0) { break; }
		else { HW = H*W + 2; }

		for (int i = 0; i < 100;i++){
			for (int j = 0; j < 100;j++){
				orLoop[i][j] = false;
			}
		}
			for (int i = 0; i < H; i++)
			{
				cin >> input[i];
			}
		if(loop(0, 0)){
			cout << "LOOP" << endl;
		}
		else{
			cout << x << " " << y << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3128
def get_gcd(a,b):
	if a > b: a, b = b, a
	if b % a == 0:
		return a
	else:
		return get_gcd(a, b % a)

def get_lcm(a,b,g):
	return a * b / g

while True:
	try:
		a,b = map(int, sorted(raw_input().split()))
		GCD = get_gcd(a,b)
		LCM = get_lcm(a,b,GCD)
		print "{} {}".format(GCD, LCM)
	except EOFError:
		break

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

int main() {
  bool isC = false, isF = false;
  string s;
  cin >> s;
  for(char a: s){
      if(isC){
          if(a == 'F'){
              isF = true;
              
              break;
          }
      }
      else{
          if(a == 'C'){
              isC = true;
          }
      }
  }
    
  if(isC && isF){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define int long long

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> sumwest(n,0);
	std::vector<int> sumeast(n,0);
	std::string s;
	std::cin >> s;
	int sum = 0;
	for(int i=0;i<n;i++) {
		sumwest[i] = sum;
		if(s[i]=='W') sum ++;
	}
	sum = 0;
	for(int i=n-1;i>=0;i--) {
		sumeast[i] = sum;
		if(s[i]=='E') sum ++;
	}
	int min = 10101001010;
	for(int i=0;i<n;i++) min = std::min(min,sumeast[i]+sumwest[i]);
	std::cout << min << std::endl;
}


Measured memory_bytes: 5508
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 1e6 + 5;

long long inv[N], fact[N], ifact[N];
void pre()
{
	inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
	for (int i = 2; i < N; i++)
	{
		inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
		fact[i] = mul(i * 1ll, fact[i - 1], MOD);
		ifact[i] = mul(inv[i], ifact[i - 1], MOD);
	}
	return;
}

long long nCr(long long n, long long r)
{
	if (n >= 0 && r >= 0 && n >= r)
		return mul(fact[n], mul(ifact[r], ifact[n - r], MOD), MOD);
	return 0;
}

long long binpow(long long x, long long y)
{
	long long res = 1;
	x %= MOD;
	while (y)
	{
		if (y & 1)
			res = mul(res, x, MOD);
		y = (y >> 1);
		x = mul(x, x, MOD);
	}
	return res;
}

void solve()
{
	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = 0;
	pre();
	for (ll p = n - k; p < n + 1; p++)
	{
		ll temp = nCr(n - 1, p - 1);
		temp = mul(temp, m, MOD);
		temp = mul(temp, binpow(m - 1, p - 1), MOD);
		ans = add(ans, temp, MOD);
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 27088
/*-In the name of God-
 
Author : Syed Mujtaba
Seek knowledge from the Cradle to the Grave !!
https://www.linkedin.com/in/syed-mujtaba
*/

#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define ld              long double
#define ll              long long
#define pb              push_back
#define fi              first
#define se              second
#define MAXN            200064
#define mod             1000000007  //998244353 // 1e9 + 7
#define MAX             8000000000000000064LL
#define MIN            -8000000000000000064LL
#define mt              make_tuple
#define eps             1e-6
#define endl            '\n'
#define test            int T_T; cin>>T_T; while(T_T--)
#define fast_io         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main()
{
   fast_io
   int n;
   int ans = 0;
   cin >> n;
   int a[n + 1];
   for(int i = 1; i <= n; i++)
   {
      cin >> a[i];
      if(a[i] % 2 && i % 2)
      {
         ans++;
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N (200000)
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

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

ll pow(ll x, int y){
  ll r = 1;
  for(int i = 0; i < y; i++) r *= x;
  return r;
}

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

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

  ll sum = pow(n / k, 3);
  if(k % 2 == 0){
    int c = n / k;
    if(n % k > 0 && (n % k) >= (k / 2)) ++c;
    sum += pow(c, 3);
  }

  cout << sum << endl;

  return 0;
}


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

using namespace std;

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

    int h, n;
    cin >> h >> n;
    while (n--) {
    	int x;
    	cin >> x;
    	h -= x;
    }
    if (h <= 0) {
    	cout << "Yes\n";
    } else {
    	cout << "No\n";
    }
}   


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int a[5] = {};
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	int aaaa = a[0] + a[1] + a[2] + a[3] + a[4];

	rep(i, 5) {
		if (a[i] % 10 != 0) {
			a[i] = (((a[i] / 10) * 10)+10) - a[i];
		}
		else {
			a[i] = 0;
		}
	}
	sort(a, a + 5,greater<int>());
	
	cout << aaaa + a[1] + a[2] + a[3] + a[4] << endl;


	return 0;
}




Measured memory_bytes: 256
//JSD
#include<iostream>
#include<limits.h>
#define ll long long 
#include<cmath>
using namespace std;
ll n,k;
ll h[100005],ans[100005];
ll solve(ll i){
	ll mi=INT_MAX;
	if(i==(n-1)) return 0;
	if(ans[i]!=-1) return ans[i];
	for(ll x=i+1;x<=i+k;x++){
		if(x<n){
			ll p=solve(x)+abs(h[i]-h[x]);
			mi=min(mi,p);
		}
	}
	ans[i]=mi;
	return ans[i];
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) ans[i]=-1;
	for(int i=0;i<n;i++) cin>>h[i];
	cout<<solve(0);
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int a,b;
	char c;
	cin>>a>>c>>b;
	cout<<(c=='+'?a+b:a-b)<<'\n';
}




Measured memory_bytes: 3620
from collections import deque

S = input()
Q = int(input())
query = [input().split() for _ in range(Q)]

ans = deque(list(S))
flag = 0

for q in range(Q):
    if len(query[q]) == 1:
        flag = 1 - flag
    else:
        if query[q][1] == '1':
            if flag:
                ans.append(query[q][2])
            else:
                ans.appendleft(query[q][2])
        else:
            if not flag:
                ans.append(query[q][2])
            else:
                ans.appendleft(query[q][2])

if not flag:
    print(''.join(ans))
else:
    print(''.join(ans)[::-1])

Measured memory_bytes: 44772
#include<stdio.h>
int main()
{
    char s[100005],a[100005],b[100005];
    int n,i,j,cnt=0,cnt1=0;
    scanf("%s",s);
    n=strlen(s);
    if(s[0]=='0')
    {
        a[0]='0';
        b[0]='1';
    for(i=1;i<n;i++)
    {
        if(i%2==0){
            a[i]='0';
            b[i]='1';
        }
            else{
            a[i]='1';
            b[i]='0';
            }
    }
    }
    else
    {
        a[0]='1';
        b[0]='0';
        for(i=1;i<n;i++)
    {
        if(i%2==0){
            a[i]='1';
            b[i]='0';
        }
            else{
            a[i]='0';
            b[i]='1';
            }
    }
    }
    for(i=0;i<n;i++)
    {
        if(s[i]!=a[i])cnt++;
        if(s[i]!=b[i])cnt1++;
    }
    if(cnt<cnt1)
        printf("%d\n",cnt);
    else printf("%d\n",cnt1);
    return 0;

}


Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ARegistration {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s, t; cin >> s >> t;
      rep(i, s.size()) {
        if (s[i] != t[i]) {
          cout << "No" << endl;
          return;
        }
      }
      cout << "Yes" << endl;
    }
};

signed main() {
  ARegistration solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define DEBUG 1
#define ll         long long
#define REP(i, n) for (long long i = 0; i < (n); i++) 
static const ll INF = 1000000000000000000LL;
static const int MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int N = s.size();
    vector <vector<ll> > dp(N+1,vector<ll>(2, INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; ++i)
    {
        //0:ぴったり/1:余分
        for(int q = 0; q < 2; ++q)
        {
            int now = s[N-1-i] - '0';
            now += q;
            if(now == 10)
            {
                //10になる場合は、支払わない(1個前で余分に払った分が返ってくる91)
                dp[i+1][1] = min(dp[i+1][1], dp[i][q]);
                continue;
            }
            dp[i+1][0] = min(dp[i+1][0], dp[i][q] + now);
            dp[i+1][1] = min(dp[i+1][1], dp[i][q] + (10 -now));

        }
    }

    cout << min(dp[N][0], dp[N][1] + 1) << endl;

    return 0;

}

Measured memory_bytes: 55940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stack>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

int main() {
  int n;
  string s;

  cin >> n;
  cin >> s;

  stack<char> st;
  int rb = 0, lb = 0;

  for (auto itr : s) {
    if (itr == ')') rb++;
    else lb++;

    if (st.empty()) {
      st.push(itr);
      continue;
    }

    if (itr == ')' && st.top() == '(') {
      lb--, rb--;
      st.pop();
    } else {
      st.push(itr);
    }
  }

  rep(i,rb) {
    cout << '(';
  }

  cout << s;

  rep(i,lb) {
    cout << ')';
  }

  cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main(){
    int a, b, k;
    cin >> k >> a >> b;
    bool f = false;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            f = true;
            break;
        }
    }
    if(f) cout << "OK" << ln;
    else cout << "NG" << ln;
}


Measured memory_bytes: 3652
from collections import deque, defaultdict, Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
s = list(set(c))

dp = [True] * (10 ** 6 + 1)

for x in s:
  num = x * 2
  while num <= 10 ** 6:
    dp[num] = False
    num += x

ans = 0
for a in A:
  if c[a] == 1 and dp[a] == True:
    ans += 1
    
print(ans)

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

const int MAXN = 1e3 + 5;
const ll MOD = 1e9 + 7;
ll dp[MAXN][MAXN];
char board[MAXN][MAXN];

int main() {
    int H, W;
    cin >> H >> W;
    for(int i = 0; i < H; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++)
            board[i][j] = s[j];
    }
    dp[0][0] = 1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(board[i][j] == '#')
                continue;
            if(i > 0)
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            if(j > 0)
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
        }
    }
    cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 9088
#include<stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d",&a, &b, &c);
  if((a==b&&b==c&&c==a)||(a!=b&&b!=c&&c!=a)){
    printf("No");
    return 0;
  } else {
    printf("Yes");
    return 0;
  }
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double argh = 30 * (h + (double) m / 60);
    double argm = 6 * m;

    argh = argh / 360 * 2 * M_PI;
    argm = argm / 360 * 2 * M_PI;

    debug(argh);
    debug(argm);

    cout << fixed << setprecision(15) << sqrt(a*a + b*b - 2*a*b*std::cos(argh - argm)) << endl;
    return 0;
}


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

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

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

vector<ll> dp(100001, -1);
vector<ll> G[100001];

ll solve(ll v) {
	if (dp[v] != -1) {
		return dp[v];
	}

	ll res = 0;

	REP(i, G[v].size()) {
		res = max(res, solve(G[v][i]) + 1);
	}

	dp[v] = res;

	return res;
}

signed main() {
	ll n, m, x, y;

	cin >> n >> m;

	REP(i, m) {
		cin >> x >> y;
		G[x].push_back(y);
	}

	ll ans = 0;

	FOR(i, 1, n + 1) {
		ans = max(ans, solve(i));
	}

	cout << ans << endl;
}

Measured memory_bytes: 8576
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	char ball='A',s1,s2;
	string s;
	while(cin >> s)
	{
		if(s[0]==ball)ball=s[2];
		else if(s[2]==ball)ball=s[0];
	}
	cout << ball << endl;
	return 0;
}

Measured memory_bytes: 1172
from collections import deque

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

ans=0
for i in range(m):
    ll=l[:i]+l[i+1:]
    tree=[[] for i in range(n)]
    for i in ll:
        tree[i[0]-1].append(i[1]-1)
        tree[i[1]-1].append(i[0]-1)
    seen=[]
    seen.append(0)
    dq=deque()
    dq.append(0)
    cnt=1
    while dq:
        x=dq.pop()
        for i in tree[x]:
            if i not in seen:
                seen.append(i)
                dq.append(i)
                cnt+=1
    if cnt!=n:
        ans+=1
print(ans)

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n;
string s;
string sa = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

inline bool isLower(char c){ return 'a' <= c && c <= 'z'; }
inline bool isUpper(char c){ return 'A' <= c && c <= 'Z'; }

int main()
{
  while(cin >> n, n){
    vi k(n);
    rep(i, n) cin >> k[i];
    cin >> s;
    int p = 0;
    vrep(v, s){
      rep(i, sa.size()) if(*v == sa[i] && i - k[p] >= 0){
        cout << sa[i - k[p]];
        break;
      }
      p = (p + 1) % k.size();
    }
    cout << endl;
  }


  /*
  while(cin >> n, n){
    vi k(n);
    rep(i, n) cin >> k[i];
    cin >> s;
    int p = 0;
    vrep(v, s){
      if(isLower(*v)){
        if(isLower(*v - k[p])){
          cout << (char)(*v - k[p]);
        }
        else{
          cout << (char)('Z' - 'a' + *v - k[p] + 1);
        }
      }
      else{
        if(isUpper(*v - k[p])){
          cout << (char)(*v - k[p]);
        }
        else{
          cout << (char)('z' - 'A' + *v - k[p] + 1);
        }
      }
      p = (p + 1) % k.size();
    }
    cout << endl;
  }
  */
  return 0;
}

Measured memory_bytes: 1216
n, k = map(int, input().split())
s = input()
rev_s = s + s[::-1]
mido = "z" * n
for i in range(n + 1):
    if mido > rev_s[i:i + n]:
        mido = rev_s[i:i + n]
ind = float("inf")
for i in range(n):
    if mido[i] != mido[0]:
        if i < ind:
            ind = i
ans = ind * (2 ** min(k - 1, 20))
print((mido[0] * ans + mido[ind:ind + n - ans])[:n])

Measured memory_bytes: 199328
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[200005];
ll vis[200005];
int main(){
    
		ll n,k;
		cin>>n>>k;
		for(ll i=1;i<=n;i++)cin>>a[i],vis[i]=0;
		vector<ll> cyc;
	    ll i=1;
		while(vis[i]==0){
			cyc.pb(i);
			vis[i]=1;
			i=a[i];
		}
		ll cyce=i;
		ll ind1=cyc.size();
		ll ind2;
	    for(ll i=0;i<cyc.size();i++){
	        if(cyc[i]==cyce)ind2=i;
		}
	    if(k<ind2){
	    	cout<<cyc[k];
		}
		else{
		   ll cyclen=(ind2-ind1);
		   ll ind=ind2+(k-ind2)%cyclen;
		   cout<<cyc[ind];	
	    }
		
	
	
}


Measured memory_bytes: 8488
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;



void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

long long p(long long x, long long y)
{
    long long res = 1;
    while (y > 0)
    {
        if (y & 1) res *= x;
        y >>= 1;
        x *= x;
    }
    return res;
}

int main()
{
    usaco();
    long long n, d, x, y, ans = 0;
    cin >> n >> d;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        if (p(x, 2)+p(y, 2)<=p(d, 2)) ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3652
N = int(input())
W = list(map(int, input().split()))

S  = sum(W)
S0 = 0
St = 0
Stt = W[0]
i = 0

while St * 2 < S:
    S0 = St
    St = St + W[i]
    Stt = Stt + W[i + 1]
    i = i + 1

print(min(abs(S0 * 2 - S), abs(St * 2 - S), abs(Stt * 2 - S)))

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int a,b,c,temp;
  scanf("%d%d%d",&a,&b,&c);
  temp=a,a=b,b=temp;
  temp=a,a=c,c=temp;
  printf("%d %d %d",a,b,c);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int a, b, x;

int calc(int n){
    if(n == -1) return 0;
    return n / x + 1;
}

signed main(){
    cin >> a >> b >> x;
    cout << calc(b) - calc(a - 1) << endl;
}

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

template <typename Arg1>
void pn(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pn(args...); }

template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)pn(arg1[i]); }

ll lcm(ll a,ll b) 
{ return (a*b)/__gcd(a,b); }

ll mulmod(ll a,ll b,ll mod) 
{ ll res=0; a=a%mod; 
    while(b>0)
    { if(b%2==1) res=(res+a)%mod; 
      a=(a*2)%mod; b/=2; }
    return res % mod; } 

ll mulpow(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 

ll modInverse(ll n, ll p) 
{ return mulpow(n, p-2, p); } 

ll log(ll n, ll b)
{ ll c=0;
	while(n>(b-1))
	{ c++; n/=b; } return c; }

ll fib(ll n) 
{ double phi=(1+sqrt(5))/2; 
  return round(pow(phi,n)/sqrt(5)); } 

vector<bool> prime;
void sieve(int n)
{ prime.resize(n,true);
	for(int p=2;p*p<=n;p++)
		if(prime[p])
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false; }

#define MOD 1000000007 //10^9+7
#define pi 3.14159265358979323846
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fd(i,n) for(i=n-1;i>=0;i--)
#define fn(i,s,d) for(i=s;i<d;i++)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define vl vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vvl vector<vl>
#define vs vector<string>
#define vvs vector<vs>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define vpl vector<pl>
#define vpd vector<pd>
#define vvpl vector<vpl>
#define ff first
#define ss second
#define um unordered_map
#define dsort(v) sort(v); reverse(v);


void solve()
{
	ll i,j;
	ll n;
	cin>>n;
	ll ans=0;
	f0(i,n)
	{
		ll x;
		cin>>x;
		if(i%2==0)
		{
			if(x%2==1)
				ans++;
		}
	}
	pn(ans);
	return;
}

int main()
{
	#ifdef Deeksha
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
	std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	solve();/* 
	ll t;
	cin>>t;
	for(ll tt=1;tt<=t;tt++)
	{
		//cout<<"Case #"<<tt<<": ";
		solve();
	}
	//*/
}



Measured memory_bytes: 3696
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n, nn, a[201], b[201], tmp, p, q, r, s, t, f;

int main(void) {
  while(cin >> n, n != 0) {
    nn = n * 2;

    REP(i, 1, nn + 1) {
      a[i] = 0;
      b[i] = 1;
    }
    REP(i, 0, n) {
      cin >> tmp;
      a[tmp] = 1;
      b[tmp] = 0;
    }

    r = n;
    s = n;
    t = 0;
    f = 0;

    while(r > 0 && s > 0) {
      if(t == 0) {
        REP(i, 1, nn + 1) {
          if(i > f && a[i] == 1) {
            a[i] = 0;
            r--;
            t = 1 - t;
            f = i;
            goto CONTA;
          }
        }
        t = 1;
        f = 0;
        CONTA: continue;
      } else {
        REP(i, 1, nn + 1) {
          if(i > f && b[i] == 1) {
            b[i] = 0;
            s--;
            t = 1 - t;
            f = i;
            goto CONTB;
          }
        }
        t = 0;
        f = 0;
        CONTB: continue;
      }
    }

    cout << s << endl;
    cout << r << endl;
  }

  return 0;
}

Measured memory_bytes: 1160