akhauriyash/Code-Regression huggingface dataset:
from heapq import*
i=input
for s in[0]*int(i()):
 n,x,*y=int(i()),[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x+=[t]*(l>r);y+=[[n-k,r,l]]*(l<=r)
 for x in x,y:
  x.sort();n,*h=len(x),
  while n:
   while[[n]]<x[-1:]:k,l,r=x.pop();heappush(h,(r-l,l,r))
   if h:s+=heappop(h)[1]
   n-=1
  for*_,r in x+h:s+=r
 print(s)

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,a,b) for(ll i=a-1;i>=b;i--)
#define vi vector<ll>
#define pii pair<int,int>
#define vii vector< pair<int,int> >
#define pb push_back
#define inf 1000000000000
#define hell 1000000007

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    rep(i,0,s.length()){
        ll j=i;
        while(j<s.length()&&s[i]==s[j]){
            j++;
        }
        i=j-1;
        ans++;
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 998244353

ll dp[4][2][200010];

void chmax(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	for (int i = 0;i < 200010;i++) {
		for (int j = 0;j < 4;j++) {
			dp[j][0][i] = dp[j][1][i] = LLONG_MIN / 3;
		}
	}
	int N;
	cin >> N;
	ll A;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (i == 0) {
			//選ぶ
			dp[3][1][0] = A;
			//選ばない
			dp[1][0][0] = 0;
			continue;
		}
		//選ぶ
		chmax(dp[1][1][i], dp[0][0][i - 1] + A);
		chmax(dp[2][1][i], dp[1][0][i - 1] + A);
		chmax(dp[3][1][i], dp[2][0][i - 1] + A);
		//選ばない
		chmax(dp[0][0][i], dp[1][0][i - 1]);
		chmax(dp[0][0][i], dp[1][1][i - 1]);
		chmax(dp[1][0][i], dp[2][0][i - 1]);
		chmax(dp[1][0][i], dp[2][1][i - 1]);
		chmax(dp[2][0][i], dp[3][0][i - 1]);
		chmax(dp[2][0][i], dp[3][1][i - 1]);
	}
	if (N & 1) {
		cout << max(dp[1][0][N - 1], dp[1][1][N - 1]) << endl;
	}
	else {
		cout << max(dp[2][0][N - 1], dp[2][1][N - 1]) << endl;
	}
}

Measured memory_bytes: 16152
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int a[2][230];
//int t[100005] , x[100005] , y[100005];
int gcd(int a , int b , int c)
{
		int x = __gcd(a ,b);
		return __gcd(x , c);
}
vector<int > r , g , b;
int dp[3][5000];
int main(){
	dhoom;
	int n;
	cin >> n;
	cout << n/3 << endl;
	return 0;
}


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

// 插入此處

int a[100005];
bool able[100005];

int main() {
    for (int i = 0; i < 100005; i++) {
        able[i] = true;
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int p = 2;
    LL ans = a[0] - 1;
    for (int i = 1; i < n; i++) {
        int times = (a[i] - 1) / p;
        ans += times;
        int r = a[i] - times * p;
        // printf("a[%d] = %d, r = %d, times = %d, p = %d\n", i, a[i], r, times, p);
        if (times == 0) {
            able[r] = false;
            while (!able[p]) { p++; }
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0 ; i < n;++i)
    cin >> v[i];
  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  for (int i = 1; i < n; ++i)
  {
    for (int j = 1; j <= k; ++j)
    {
      if (i-j >= 0)
      {
        dp[i] = min(dp[i-j]+abs(v[i]-v[i-j]), dp[i]);
      }
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int X, ans = 0;
  double P, T, N;
  
  cin >> N;
  vector<int> vec(N);
  
  for(int i = 0; i < N; i++){
    cin >> X;
    T += X;
    vec.at(i) = X;
  }
  P = round(T /N);
  
  for(int j = 0; j < N; j++){
    ans += std::pow((P - vec.at(j)), 2); 
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int D = scan.nextInt();
		String result = null;


		if(D==22) {
			result="Christmas Eve Eve Eve";
		}else if(D==23) {
			result="Christmas Eve Eve";
		}else if(D==24) {
			result="Christmas Eve";
		}else if(D==25){
			result="Christmas";
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
  int a[3][3];
  rep(i,3)rep(j,3)cin>>a[i][j];
  bool ans=true;
  rep(i,2)rep(j,2){
    int x=a[i+1][j+1]+a[i][j]-a[i+1][j]-a[i][j+1];
    if(x!=0)ans=false;
    }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
  }

  
    


Measured memory_bytes: 256
#include<stdio.h>

void swap(int *a, int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
}

int bubbleSort(int A[], int N){
	int i, j;
	int sw = 0;
	unsigned short flag = 1;
	for(i = 0; flag; i++){
		flag = 0;
		for(j = N - 1; j >= i + 1; j--){
			if(A[j] < A[j - 1]){
				swap(&A[j], &A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void){
	int i, A[100], N, sw;
	scanf("%d", &N);
	for(i = 0; i < N; i++) scanf("%d", &A[i]);
	
	sw = bubbleSort(A,N);
	
	for(i = 0; i < N; i++){
		if(i)printf(" ");
		printf("%d", A[i]);
	}
	printf("\n%d\n", sw);
	
	return 0;
}


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

using namespace std;
#define BUF (200005)
#define ll long long 

int n;
ll s[23][BUF];
ll  a[23];

int main(void){
	cin >> n;
	for(int i=1;i<=n;i++){
		ll tmp;
		cin >> tmp;
		for(int j=0;j<22;j++){
			s[j][i] = s[j][i-1] + (tmp>>j)%2;
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;++i){
		int low = i;
		int hi = n+1;
		while(low+1<hi){
			int mid = (low+hi)/2;
			int f=0;
			for(int j=0;j<22;++j){
				a[j] = s[j][mid] - s[j][i-1];
				if(a[j]>1){
					hi = mid;
					f=1;
				}
			}
			if(f) continue;
			low = mid;
		}
//		cout << i << low << "\n";
		ans += low - i + 1; 
	}

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


Measured memory_bytes: 35072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;

int main(){
    int n, w;
    vector<int> weight, value;
    vector<vector<ll>> dp;
    cin >> n >> w;
    weight.resize(n+1); value.resize(n+1); dp.resize(n+1);
    for(int i=1; i<=n; i++){
        cin >> weight[i] >> value[i];
    }
    dp[0].resize(w+1);
    for(int i=0; i<=n; i++){       
        dp[0][i] = 0;
    }
    for(int i=1; i<=n; i++){
        dp[i].resize(w+1);
        for(int j=0; j<=w; j++){
            if(j-weight[i]>=0){
                dp[i][j] = max(dp[i-1][j-weight[i]]+value[i],dp[i-1][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 79488
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

using namespace std;


ll N, P;

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

std::string S;
std::map<ll, ll> mp;

ll ten[200020], iten[200020], sum[200020]; 

int main()
{
  std::cin >> N >> P >> S;

  if( P == 2 )
  {
    ll ans = 0;

    rep( i, N )
    {
      if( (S[i]-'0') % 2 == 0 )
      {
          ans += i+1;
      }
    }

    printf( "%lld\n", ans );

    return 0;
  }

  if( P == 5 )
  {
    ll ans = 0;

    rep( i, N )
    {
      if( (S[i]-'0') % 5 == 0 )
      {
          ans += i+1;
      }
    }

    printf( "%lld\n", ans );

    return 0;
  }


  ten[0] = 1;
  rep( i, N+10 )
    ten[i+1] = ten[i]*10%P;

  rep( i, N+10 )
    iten[i] = (modpow( ten[i], P-2, P )+P)%P;

  sum[N] = 0;
  for( int i = N-1; i >= 0; --i )
    sum[i] = (((S[i]-'0')%P*ten[N-i-1]%P+P)%P+sum[i+1])%P;

  ll ans = 0;

  rep( j, N+1 )
  {
    ++mp[(sum[j]+P)%P];

    if( (iten[N-j]+P)%P == 0 )
    {
      ans += j;
  
      continue;
    }

    ans += mp[(sum[j]+P)%P]-1;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 5764
s = gets.chomp
n = s.size
s1 = s[0, n / 2]
s2 = s[n / 2 + 1, n / 2]
 
if s == s.reverse && s1 == s1.reverse && s2 == s2.reverse
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <cstdio>
const int MAXN = 20005;
int n, p[MAXN], r[MAXN];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &p[i]), r[p[i]] = i;
	for(int i = 1; i <= n; i++) printf("%d\n", 30000 * i + r[i]);
	for(int i = 1; i <= n; i++) printf("%d\n", 30000 * (n + 1 - i));
	return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt();
		int a = 0;
		int b = 0;
		int c = 0;
		boolean flag = false;
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n-i;j++){
				if(y==10000*i+5000*j+1000*(n-i-j)){
					flag = true;
					a = i;
					b = j;
					c = n-i-j;
				}
			}
		}
		if(flag){
			System.out.println(a+" "+b+" "+c);
		}
		else{
			System.out.println((-1)+" "+(-1)+" "+(-1));
		}
	}
}



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

using namespace std;

class node{
public:
	int id;
	node* left, * right;
	int parent;
	int sibling;
	int depth;
	int height;
};

bool operator<=(node a, node b) {
	return a.id <= b.id;
}
bool operator<(node a, node b) {
	return a.id < b.id;
}

bool operator==(node a, node b) {
	return a.id == b.id;
}

bool operator!=(node a, node b) {
	return a.id != b.id;
}

node* MakeTreeFromPreAndInOrder(int* pre, int* in, int n) {
	node* root= new node;
	int* pretmp, * intmp;
	root->id = pre[0];
	int i;
	for (i = 0;i <n;i++) {
		if (in[i] == pre[0])break;
	}
	if (i != 0) {
		pretmp = new int[i];
		intmp = new int[i];
		for (int j = 0;j < i;j++) {
			pretmp[j] = pre[j + 1];
			intmp[j] = in[j];
		}
		root->left = MakeTreeFromPreAndInOrder(pretmp, intmp, i);
	}
	else {
		node *ntemp = new node;
		ntemp->id = -1;
		root->left = ntemp;
	}
	if (i != n - 1) {
		pretmp = new int[n - 1 - i];
		intmp = new int[n - 1 - i];
		for (int j = 0;j < n - 1 - i;j++) {
			pretmp[j] = pre[i + j + 1];
			intmp[j] = in[i + j + 1];
		}

		root->right = MakeTreeFromPreAndInOrder(pretmp, intmp, n - i - 1);
	}
	else {
		node *ntemp = new node;
		ntemp->id = -1;
		root->right = ntemp;
	}
	return root;
}

string postorder(node* nod) {
	string msg="";
	if (nod->left->id != -1) {
		msg += postorder(nod->left);	
	}
	if (nod->right->id != -1) {
		msg += postorder(nod->right);	
	}
	msg += to_string(nod->id) + " ";
	return msg;
}



int main() {
	int  n,tmp2,index_root;
	cin >> n;
	int* pre = new int[n];
	int* in = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> pre[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> in[i];
	}
	node* root = MakeTreeFromPreAndInOrder(pre, in, n);
	string msg = postorder(root);
	
	cout << msg.substr(0, msg.size() - 1) << endl;
}






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

constexpr int MAX_N = 1e5;
int a[MAX_N];

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;

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

    // 累積和
    vector<int> s(n + 1, 0);
    for (int i{}; i < n; ++i) {
      s[i + 1] = s[i] + a[i];
    }

    int ans{};
    for (int i{k}; i <= n; ++i)
      ans = max(ans, s[i] - s[i-k]);

    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3548
S = input()
Nocount = 0

for i in range(len(S)):
  if(i%2==0 and S[i]=="L"):
    Nocount = 1
  elif(i%2==1 and S[i]=="R"):
    Nocount = 1
if(Nocount == 1):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;

priority_queue<P> q;
signed main(){
	int w, h, n;
	scanf("%lld%lld%lld",&w, &h, &n);
	rep(i,n){
		int x, y;
		scanf("%lld%lld", &x, &y);
		q.push(P(y, x));
	}
	
	int ans = INF;
	rep(i,w){
		P p = P(-1, -1);
		while(!q.empty()){
			P t = q.top();
			if(t.se <= i){q.pop();continue;}
			p = t;break;
		}
		if(p.fi == -1)chmin(ans, i);
		else chmin(ans, i+p.fi);
		//printf("%lld\n", p.fi);
	}
	if(ans == INF)ans = 0;
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 4932
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		
		int num = N;
        int s = 0;
        while(num != 0){
            s += num % 10;
            num /= 10;
            //System.out.println("s:"+s);
            //System.out.println("num:"+num);
        }
        System.out.println(N % s == 0? "Yes":"No");
		

	}

}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);
    ll A,B,C,D;

    Scll2(A,B);
    Scll2(C,D);
    
    bool ans = false;
    ll L,R;
    Rep(i,N){
        R = A+i*(C+D) - C*(N-1);
        L = A+i*(C+D) - D*(N-1);
        if( L <= B && B <= R ) ans = true;
    }
  
    YESNO(ans);
    
}



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

int main(){
  int x, y; cin >> x >> y;
  int ans = 0;
  if(x == 1&&y == 1) ans += 400000;
  
  
  	
  if(x == 3) ans += 100000;
  if(x == 2) ans += 200000;
  if(x == 1) ans += 300000;
  if(y == 3) ans += 100000;
  if(y == 2) ans += 200000;
  if(y == 1) ans += 300000;
  
  	cout << ans << endl;
  
}


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

double dist(P p1, P p2) {
  return sqrt((p1.first - p2.first) * (p1.first - p2.first) +
              (p1.second - p2.second) * (p1.second - p2.second));
}
int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    p[i] = P(x, y);
  }

  vector<int> idx(n);
  rep(i, n) idx[i] = i;
  double ans = 0;
  int cnt = 0;
  do {
    cnt++;
    rep(i, n - 1) ans += dist(p[idx[i]], p[idx[i + 1]]);
  } while (next_permutation(idx.begin(), idx.end()));

  ans /= cnt;
  printf("%.10lf\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    stack<int> st;
    int n = s.size();
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        if(st.empty()){
            st.push(s[i]-'0');
            continue;
        }
        int tmp=st.top();
        if(tmp!=(s[i]-'0')){
            st.pop();
        }
        else st.push(s[i]-'0');
    }
    /*while(!st.empty()){
        cout<<st.top()<<endl;
        st.pop();
    }*/
    cout<<n-st.size()<<endl;
}


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

typedef long long ll;
using namespace std;

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

    int m2 = 0;
    int m4 = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 0) m2++;
        if (a[i] % 4 == 0) m4++;
    }
    // 4の倍数2の倍数の項でペアを作り全体から取り除く
    int m2Pairs = ((m2 - m4) / 2) * 2;
    int r = n - m2Pairs;
    // 残りの項の半分以上が4の倍数であれば目標達成
    if (r / 2 <= m4) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if ((a + b) == (c + d)) {
		cout << "Balanced\n";
	} else if (a + b > c + d) {
		cout << "Left\n";
	} else {
		cout << "Right\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int n;
  string c;
  cin >> n >> c;
  int red=0,white=0;
  int flag = 0;
  for(int i = 0;i < n;i++){
    if(c.at(i) == 'W'){
      white++;
      //cout <<  "W";
      flag = 1;
    }
    if(flag == 1 && c.at(i) == 'R'){
      //cout <<  'R';
      red++;
    }
  }
  int x=0;
  int j = 0;
  for(j = 0;j < n;j ++){
    if(c.at(j) == 'W'){
      break;
    }
  }
  for(int i = 0;i < red;i++){
     if(c.at(i+j) == 'R'){
       x++;
     }
  }
  cout << red - x << endl;
}
    

Measured memory_bytes: 3748
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
for c in C.keys():
    for i in range(-1, 2):
        j = c + i
        ans = max(ans, sum([C[j - 1], C[j], C[j + 1]]))
print(ans)

Measured memory_bytes: 14556
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int two=0;
                int four=0;
                int j=0;
                int n=scanner.nextInt();
                for(int i=0;i<n;i++){
                        j=scanner.nextInt();
                        if(j%2==0){
                                two++;
                                if(j%4==0){
                                        four++;
                                }
                        }
                }
                two-=four;
                /*
                if(two==0){
                        if(four!=0){
                                four=four*2+1;
                        }
                }else{
                        if(four!=0){
                                four*=2;
                        }
                }
                if(two<2){
                        two=0;
                }
                if(n>two+four){
                        System.out.println("No");
                }else{
                }
                */

                if(two==0){
                        if((n-four)>four+1){
                                System.out.println("No");
                        }else{
                                System.out.println("Yes");
                        }
                }else{
                        if((n-two-four)>four){
                                System.out.println("No");
                        }else{
                                System.out.println("Yes");
                        }
                }

        }
}


Measured memory_bytes: 46164
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

int n;
long long a[500000];

long long g(vector<long long> & c, int all, int useodd)
{
    vector<long long> suff(c.size() + 1);
    for (int i = c.size() - 1; i >= 0; i--)
    {
        suff[i] = suff[i + 1] + c[i];
    }
    long long even = 0, opt = 0, ans = suff[0];
    for (int i = 0; i < c.size(); i++)
    {
        if (c[i] % 2 == 0) even++;
        opt += (c[i] % 2 == 1) * 1 + (c[i] == 0) * 2;
        if (useodd) if (even < opt) opt = even;
        ans = min(ans, opt + suff[i + 1]);
    }
    if (all == 0)
        return ans;
    else
        return opt;
}

map<pair<int, int>, int> calc[4];

long long solve(int l, int r, int LR)
{
    if (l + 1 >= r)
    {
        return 0;
    }
    if (calc[LR].find({l, r}) != calc[LR].end()) return calc[LR][{l, r}];
    int m = (l + r) / 2;
    long long dl = 0, dr = 0;
    for (int i = m; i < r; i++) dr += a[i];
    for (int i = l; i < m; i++) dl += a[i];
    long long ans = 1e18;
    vector<long long> b1(m - l), b2(r - m);
    for (int i = l; i < m; i++) b1[i - l] = a[i];
    for (int i = m; i < r; i++) b2[i - m] = a[i];
    reverse(b1.begin(), b1.end());
    if (LR == 0)
    {
        ans = min(ans, solve(l, m, 0) + dr);
        ans = min(ans, solve(m, r, 0) + dl);
        ans = min(ans, g(b1, 0, 1) + g(b2, 0, 1));
        ans = min(ans, solve(l, m, 1) + g(b2, 0, 0));
        ans = min(ans, solve(m, r, 2) + g(b1, 0, 0));
    }
    if (LR == 1)
    {
        ans = min(ans, solve(m, r, 1) + dl);
        ans = min(ans, solve(m, r, 3) + g(b1, 0, 0));
        ans = min(ans, g(b1, 0, 1) + g(b2, 1, 1));
        ans = min(ans, solve(l, m, 1) + g(b2, 1, 0));
    }
    if (LR == 2)
    {
        ans = min(ans, solve(l, m, 2) + dr);
        ans = min(ans, solve(l, m, 3) + g(b2, 0, 0));
        ans = min(ans, g(b2, 0, 1) + g(b1, 1, 1));
        ans = min(ans, solve(m, r, 1) + g(b1, 1, 0));
    }
    if (LR == 3)
    {
        ans = min(ans, g(b1, 1, 1) + g(b2, 1, 1));
        ans = min(ans, solve(m, r, 3) + g(b1, 1, 0));
        ans = min(ans, solve(l, m, 3) + g(b2, 1, 0));
    }
    calc[LR][{l, r}] = ans;
    return ans;
}

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


Measured memory_bytes: 56552
// garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a,ll b,ll p){ll res=1;a%=p;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b>>=1;}return res;}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
 
int r[4004], g[4004], b[4004];
 	int rs[4004], gs[4004], bs[4004];

ll count(int a[], int b[], int c[], int d[]) {
	ll ans = 0;

	for(int i=0;i<4001;i++) {
		for(int j=i+1;j<4001;j++) {
			if(a[i] && b[j]) {
				int nk = 2*j-i;
				//cout<<i.F<<" "<<j.F<<" "<<nk<<"\n";
				ans+=d[j+1];
				if(nk<4001) ans -= c[nk];

			}
		}
	}

	return ans;
}

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

 	int n;
 	cin>>n;
	string s;
	cin>>s;

	for(int i=0;i<n;i++) {
		if(s[i]=='R') r[i]=1;
		else if(s[i]=='G') g[i]=1;
		else b[i]=1;
	}

	for(int i=n-1;i>=0;i--) {
		rs[i]=r[i]+rs[i+1];
		gs[i]=g[i]+gs[i+1];
		bs[i]=b[i]+bs[i+1];
	}

	ll ans = 0;

	//RGB
	ans += count(r,g,b, bs);
	//RBG
	ans += count(r,b,g, gs);
	//GBR
	ans += count(g,b,r, rs);
	//GRB
	ans += count(g,r,b, bs);
	//BRG
	ans += count(b,r,g, gs);
	//BGR
	ans += count(b,g,r, rs);

 	cout<<ans;
 
	return 0;
}

Measured memory_bytes: 3684
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).ok();
    return word.trim().to_owned();
}

fn main() {
    let (n, m) = {
        let line = get_input();
        let mut split_line = line.split_whitespace();
        let n:u32 = split_line.next().unwrap().parse().unwrap();
        let m:u32 = split_line.next().unwrap().parse().unwrap();
        (n,m)
    };

    let mut l = 0;
    let mut r = n - 1;

    for _i in 0..m {
        let (li, ri) = {
            let line = get_input();
            let mut split_line = line.split_whitespace();
            let l:u32 = split_line.next().unwrap().parse().unwrap();
            let r:u32 = split_line.next().unwrap().parse().unwrap();
            (l-1,r-1)
        };

        l = std::cmp::max(l, li);
        r = std::cmp::min(r, ri);
    }

    let ans = if l <= r { r - l + 1 } else { 0 };

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string a, b;
    cin >> a >> b;
    
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    
    if (a < b) cout << "Yes\n";
    else cout << "No\n";
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

struct str {
    int t;
    int f;
    string c;
};

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

    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<str> p(q);

    int cnt = 0;
    rep(i, q) {
        int t;
        cin >> t;

        if (t == 1) {
            p[i].t = t;
            p[i].f = -1;
            p[i].c = "0";
            cnt++;
        } else {
            int f;
            string c;
            cin >> f >> c;
            p[i].t = t;
            p[i].f = f;
            p[i].c = c;
        }
    }

    if (cnt % 2) {
        reverse(s.begin(), s.end());
    }

    string a, b;

    cnt = cnt % 2;
    rep(i, q) {
        if (p[i].t == 1) {
            cnt++;
        } else {
            if (p[i].f == 1) {
                if (cnt % 2) {
                    // s = s + p[i].c;
                    b += p[i].c;
                } else {
                    a += p[i].c;
                    //s = p[i].c + s;
                }
            } else {
                if (cnt % 2) {
                    a += p[i].c;
                    //s = p[i].c + s;
                } else {
                    b += p[i].c;
                    //s = s + p[i].c;
                }
            }
        }
    }

    reverse(a.begin(), a.end());

    cout << a + s + b << endl;
}

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

int		sign(int num, int *arr, int size)
{
	int		i;

	i = 0;
	while (i < size)
		if (num == arr[i++])
			return (1);
	return (0);
}
	
int		main(void)
{
	int		bingo[3][3];
	int		n;
	int		i;
	int		j;
	int		flag = 0;

	i = 0;
	while (i < 3)
	{
		j = 0;
		while (j < 3)
			cin >> bingo[i][j++];
		i++;
	}
	cin >> n;
	int		arr[n];
	i = 0;
	while (i < n)
		cin >> arr[i++];

	i = 0;
	while (i < 3)
	{
		j = 0;
		while (j < 3)
		{
			if (sign(bingo[i][j], arr, n))
				bingo[i][j] = 0;
			j++;
		}
		i++;
	}
	i = 0;
	while (i < 3)
	{
		if (!(bingo[i][0] + bingo[i][1] + bingo[i][2]))
			flag = 1;
		i++;
	}
	i = 0;
	while (i < 3)
	{
		if (!(bingo[0][i] + bingo[1][i] + bingo[2][i]))
			flag = 1;
		i++;
	}
	if (!(bingo[0][0] + bingo[1][1] + bingo[2][2]))
		flag = 1;
	if (!(bingo[0][2] + bingo[1][1] + bingo[2][0]))
		flag = 1;
	if (flag)
		cout << "Yes";
	else
		cout << "No";
}	


Measured memory_bytes: 256
#両端のりんごの味は、(L, L+N-1)
N, L = map(int, input().split())
sum_all = N*(L+((N+1)/2)-1)

if L*(L+N-1) <= 0:
  print(int(sum_all))
elif L < 0:
  print(int(sum_all - L - N + 1))
else:
  print(int(sum_all - L))

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();
    }
    Arrays.sort(A);
    long top =0;
    long nexttop =0;
    boolean isFindtop=false;
    for(int i=N-1;i>0;i--){
      if(A[i]==A[i-1]){
        top=A[i];
        isFindtop=!isFindtop;
        break;
      }
    }

    if(!isFindtop){
      System.out.println(0);
      return;
    }
    int cnt=0;
    for(int i=N-1;i>0;i--){
      if(A[i]==A[i-1]&&(A[i]!=top||cnt==2)){
        nexttop=A[i];
        System.out.println(top*nexttop);
        return;
      }else if(A[i]==A[i-1]){
        cnt++;
      }else{
        continue;
      }
    }
    System.out.println(0);
    
    
      
        
  }
  

  
}


Measured memory_bytes: 46400
while True:
    a, op, b = input().split()

    if op == "?":
        break

    a = int(a)
    b = int(b)

    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)


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

class Segment_tree_Lazy:
    
    def __init__(self, n):
        
        self.init(n)
        
        #この次の処理は、求められる動作に応じて変化させる。ここでは区間最小問題のコードを書く。
        self.node = [self.inf]*self.size
        
        self.lazy = [self.inf]*self.size
        
        
    def init(self, n):
        
        self.inf = pow(2, 60)
        self.n = n
        
        self.N = 1
        while self.N < self.n:
            self.N *= 2
            
        self.size = self.N * 2 - 1
        self.N -= 1
        
        
    def evalate(self, k, l, r):
        
        if self.lazy[k] != self.inf:
            self.node[k] = min(self.lazy[k], self.node[k])
            
            if r-l > 1:
                if self.lazy[2*k+1] > self.lazy[k]:
                    self.lazy[2*k+1] = self.lazy[k]
                if self.lazy[2*k+2] > self.lazy[k]:
                    self.lazy[2*k+2] = self.lazy[k]
                
            self.lazy[k] = self.inf
         
            
    def update(self, a, b, x, k=0, l=0, r=-1):
        
        if r < 0:
            r = self.size - self.N
        
        if b <= l or r <= a:
            return 0
        
        if a <= l and r <= b:
            self.lazy[k] = x
            self.evalate(k, l, r)
            return 0
        
        self.update(a, b, x, 2*k+1, l, (l+r)//2)
        self.update(a, b, x, 2*k+2, (l+r)//2, r)
        self.node[k] = min(self.node[2*k+1], self.node[2*k+2])
        
        
    def find(self, a, b, k, l, r):
        
        if r <= a or b <= l:
            return self.inf
        
        self.evalate(k, l, r)
        
        if a <= l and r <= b:
            return self.node[k]
        
        find_l = self.find(a, b, 2*k+1, l, (l+r)//2)
        find_r = self.find(a, b, 2*k+2, (l+r)//2, r)
        return min(find_l, find_r)
    
    
    def count(self, l, r):
        
        return self.find(l, r, 0, 0, self.size-self.N)
    
    
    
    

def main():
    n, m = map(int, input().split())
    
    inf = pow(2, 60)
    dp = [inf]*(n)
    dp[0] = 0
    
    node = [[] for _ in range(n)]
    segment = Segment_tree_Lazy(n)
    
    segment.update(0, 1, 0)
    for i in range(m):
        s, t, c = map(int, input().split())
        node[t-1].append((s-1, c))
        segment.update(s, t, c)
    
    for i in range(n-1):
        dp[i+1] = dp[i] + min(segment.node[segment.N+i+1], segment.lazy[segment.N+i+1])
        for (v, c) in node[i+1]:
            dp[i+1] = min(dp[i+1], dp[v]+c)
        index = i
        while True:
            if dp[index] > dp[index+1]:
                dp[index] = dp[index+1]
                index -= 1
            else:
                break
    
    print(dp[n-1] if dp[n-1] < inf else -1)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 100800
from collections import deque
que = deque([])

def bfs(sy,sx):
    d = [[float("inf")] * W for i in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que.append((sy,sx))
    d[sy][sx] = 0
    route = []
    while que:
        p = que.popleft()
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if 0<=ny<H and 0<=nx<W and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                que.append((ny,nx))
                d[ny][nx] = d[p[0]][p[1]] + 1
                route.append(d[ny][nx])
    return max(route)

H,W = map(int,input().split())
maze = []
for _ in range(H):
    line = list(input())
    maze.append(line)

M = 0
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] != "#":
            num = bfs(sy,sx)
            if M <= num:
                M = num
print(M)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    vi a(N);
    REP(i, N) cin >> a[i];

    sort(ALL(a), greater<>());
    ll ans = a[0];
    int ai = 1;
    int cnt = 0;
    FOR(i, 2, N) {
        if (cnt == 0 or cnt == 1) {
            ans += a[ai];
            cnt++;
        } else {
            cnt = 1;
            ai++;
            ans += a[ai];
        }
    }

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


Measured memory_bytes: 3972
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=1e5+5;
const int MOD=1e9+7;
const int INF=1e9;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define pow2(a) a*a
#define pow3(a) a*a*a
#define lcm(a,b) (a*b)/__gcd(a,b)

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

vector<int> movy={0,0,1,-1};
vector<int> movx={1,-1,0,0};

void solve(){
    int n, x, ans=0;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        cin>>x;
        a.push_back(x);
    }
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
                    if((a[i]+a[j])>a[k] && (a[i]+a[k])>a[j] && (a[k]+a[j])>a[i]){
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    //freopen("OUT.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3664
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
class Main{
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
      	char c=in.next().charAt(0);
		if(c>=65 && c<=90)
			System.out.println('A');
		else
			System.out.println('a');
	} 
}


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

int A, B, C;

void solve()
{
	long long ans = 0;
	if(C <= (long long) A + B){
		ans = C+B;
	}else{
		ans = A+2*B+1;
	}
	cout << ans << endl;
}

int main()
{
	cin >> A >> B >> C;
	solve();
	return 0;
}

Measured memory_bytes: 256
use std::io::{StdinLock, Read, stdin};
use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut scan = Scan::new(stdin.lock());
    let n = scan.next::<usize>();
    let mut a = scan.nexts::<i64>(n);
    let mut ret = 0i64;
    for i in 0..n {
        ret += a[i] / 2;
        if a[i] % 2 == 1 && i+1<n && a[i+1] >= 1 {
            ret += 1;
            a[i+1]-=1;
        }
    }
    println!("{}", ret);
}

struct Scan<'a> {
    stdin_lock: StdinLock<'a>
}

impl<'a> Scan<'a> {
    fn new(stdin_lock: StdinLock<'a>) -> Scan<'a> {
        Scan { stdin_lock: stdin_lock }
    }

    fn next<T: FromStr>(&mut self) -> T {
        let token = self.stdin_lock.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok().unwrap()
    }

    fn nexts<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n {
            ret.push(self.next());
        }
        ret
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem2508 : King's Inspection **/
int main()
{
	int N;
	while (cin>>N, N) {
		vector<int> key(N);
		rep(i, N) cin>>key[i];
		string s; cin>>s;
		
		rep(i, s.size()) {
			char c = s[i];
			for (int j=0; j<key[i%key.size()]; j++) {
				if (c=='a') c='Z';
				else if (c=='A') c='z';
				else c--;
			}
			cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1204
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

G = gcd(N, M)
L = N * M // G
n = N // G
m = M // G

ans = True
for k in range(G):
    if S[k * n] != T[k * m]:
        ans = False
        break
print(L if ans else -1)


Measured memory_bytes: 5432
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>



const int mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int*a = new int[N];
	int*b = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", b + i);
	}
	bool can = true;
	for (int i = 0; i < N; i++) {
		bool did = false;
		for (int j = N - i - 1; j >= 0; j--) {
			if (b[j] == j + 1) {
				did = true;
				a[N - i - 1] = j + 1;
				for (int k = j; k < N - i - 1; k++) {
					b[k] = b[k + 1];
				}
				break;
			}
		}
		if (!did) {
			can = false;
			break;
		}
	}
	if (can) {
		for (int i = 0; i < N; i++) {
			printf("%d\n", a[i]);
		}
	}
	else {
		printf("-1");
	}
}





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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll A,V,B,W,T;
    cin >> A >> V >> B >> W >> T;
    // corner(W>=V,"NO");
    ll X = 0, Y = abs(A-B);
    YN(T*V >= T*W+Y);
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int b[100005];
ll a[25][25],val[100005],dp[100005];
vector<int>vec,used[25];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) 
		cin>>a[i][j];
	for(int i=0;i<(1<<n);i++)
	{
		vector<int>v;
		vec=v;
		for(int j=0;j<n;j++)
			if(i&(1<<j))vec.push_back(j+1);
		for(int x=0;x<(int)vec.size();x++)
			for(int y=x+1;y<(int)vec.size();y++)
				val[i]+=a[vec[x]][vec[y]];
	}
	for(int i=0;i<(1<<n);i++)
	{
		b[i]=b[i>>1]+(i&1);
		used[b[i]].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)used[i].size();j++)
		{
			int k=used[i][j];
			dp[k]=val[k];
			for(int sub=k;sub;sub=(sub-1)&k)
				dp[k]=max(dp[k],dp[sub]+val[k^sub]);
		}
	}
	cout<<dp[(1<<n)-1];
	return 0;
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;

void solve() {
	int n, a, b;
	cin>>n;
	vector<pair<int, int>> A;
	for(int i=0; i<n; i++) {
		cin>>a>>b;
		A.push_back({a, b});
	}
	int res = 0;
	int cnt = 0;
	for(int i=0; i<n; i++) {
		if(A[i].first == A[i].second) {
			cnt++;
			if(cnt >= 3) {
				cout<<"Yes";
				return;
			}
		}
		else cnt = 0;
	}
	cout<<"No";
}

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

Measured memory_bytes: 3628
def d(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**(1/2)
n= int(input())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
    for j in range(n):
        ans+=d(x[i],x[j])
print(ans/n)

Measured memory_bytes: 3060
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力
        MyScanner sc = new MyScanner(System.in);
        long N = Long.parseLong(sc.nextString());

        // 初期化
        int min_len = String.valueOf(N).length();

        // 主処理
        // 1からNまで繰り返す
        for (long A = 1; A*A <= N; A++) {
            // N を A で割った余りが0なら桁数を求める
            long amari = N % A;
            if (amari == 0) {
                long B = N / A;
                int len = F(A, B);
                // 桁数が最小かどうかを判定する
                min_len = Math.min(min_len, len);
                // System.out.println(String.format("A=%s, B=%s, len=%s, min_len=%s", A, B, len, min_len));
            }

        }

        // 出力
        System.out.println(min_len);
    }

    // 10進表記における、Aの桁数とBの桁数のうち大きい方を返却
    public static int F(long A, long B) {
        int A_len = Long.toString(A).length();
        int B_len = Long.toString(B).length();
        return Math.max(A_len, B_len);
    }

    static class MyScanner {
        BufferedReader br;
        // 標準入力から入力値を取得
        MyScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        // 標準入力を文字列で取得
        public String nextString() throws IOException {
            return br.readLine();
        }
        // 標準入力を文字列の配列で取得
        public String[] nextStringArray() throws IOException {
            return nextString().split(" ");
        }
        // 標準入力を数値で取得
        public int nextInt() throws IOException {
            return Integer.parseInt(nextString());
        }
        // 標準入力を数値の配列で取得
        public int[] nextIntArray() throws IOException {
            String[] strArr = nextStringArray();
            int[] intArr = new int[strArr.length];
            for(int i = 0; i < strArr.length; i++) {
                intArr[i] = Integer.parseInt(strArr[i]);
            }
            return intArr;
        }
    }

}


Measured memory_bytes: 21332
A=[x for x in input().split()]
c5=0
c7=0
for i in range(3):
  if A[i]=='5':
    c5=c5+1
  elif A[i]=='7':
    c7=c7+1
if c5==2 and c7==1:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,sum=0;

int main(){
    cin>>N;
    int L[N];
    rep(i,N){
        cin>>L[i];
    }
    sort(L,L+N);
    rep(i,N-1){
        sum+=L[i];
    }
    if(L[N-1]<sum){
        out("Yes");
    }
    else{
        out("No");
    }
}


Measured memory_bytes: 256