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

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

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

  int x;
  cin >> x;

  string ans;
  if (x == 3 || x == 5 || x == 7) {
    ans = "YES";
  } else {
    ans = "NO";
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

const p = 1000000007

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  B := make([]int, N)
  for i := N - 1; i > 0; i-- {
    B[i - 1] = (B[i] + A[i]) % p
  }
  ans := 0
  for i, a := range A {
    ans = (ans + a * B[i]) % p
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 15064
s = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    a, b = int(cmd[1]), int(cmd[2])
    if cmd[0] == 'print':
        print(s[a:b + 1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b + 1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b + 1:]



Measured memory_bytes: 5616
const Main = input => {
  const X = Number(input);

  let n = 0;
  let m = 100;
  while(true) {
    m = Math.floor(m*1.01);
    n++;
    if(m >= X) break;
  }

  console.log(n);
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());
/*Main(`103`);
Main(`1000000000000000000`)
Main(`1333333333`)*/
//Main(Math.pow(10,18))


Measured memory_bytes: 29720
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
//#include <stdio.h>
#define ll long long

int main(void)
{
    ll x;
    cin >> x;
    if(x >= 30)
        cout << "Yes";
    else
        cout << "No";
}

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

int main(){

  int n, min, max;
  int a[10000];
  long long sum = 0;

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

  min = a[0];
  max = a[0];
  sum += a[0];
  
  for(int i = 1; i < n; i++){
    if(a[i] < min)
      min = a[i];
    if(a[i] > max)
      max = a[i];
    sum += a[i];
  }

  cout << min <<" "<< max <<" "<< sum << endl;

  return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<stack>
#include<set>
#include<sstream>
#include<fstream>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main(){
	int N,M;
	cin >> N >> M;
	cEdges Edges(N + M);
	
	for(int i = 0; i < N; ++i){
		int k;
		cin >> k;
		for(int j = 0; j < k; ++j){
			int l;
			cin >> l;
			--l;
			Edges[i].push_back(N + l);
			Edges[N + l].push_back(i);
		}
	}

	vector<bool> Memo(N + M, false);
	queue<int> Q;
	Q.push(0);
	Memo[0] = true;

	while(!Q.empty()){
		int now = Q.front();
		Q.pop();

		for(const auto& edge : Edges[now]){
			if(!Memo[edge]){
				Memo[edge] = true;
				Q.push(edge);
			}
		}
	}

	bool ans = true;
	for(int i = 0; i < N; ++i){
		if(!Memo[i]){
			ans = false;
			break;
		}
	}
	
	if(ans)cout << "YES" << endl;
	else cout << "NO" << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc170/abc170_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int X, Y;
  cin >> X >> Y;

  rep(i, X + 1) {
    if (2 * i + 4 * (X - i) == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3644
a, b = map(int, input().split())

ans1 = ""
ans2 = ""
for i in range(b):
  ans1 = ans1 + str(a)

for i in range(a):
  ans2= ans2 + str(b)
  
list = []
list.append(ans1)
list.append(ans2)

list.sort()

print(list[0])

Measured memory_bytes: 3060
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: isize,
        n: isize,
        ps: [isize; n],
    }

    let mut r: isize = 10isize.pow(4);

    for i in 0..100 {
        let mut j: isize = x - i;

        if !ps.contains(&j) {
            r = j;
            break;
        }

        j = x + i;
        if !ps.contains(&j) {
            r = j;
            break;
        }
    }

    println!("{}", r)
}


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

int main() {
	int d,g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	rep(i,d) cin >> p[i] >> c[i];
	
	int num_lp = (1 << d);
	int ans = 1e9;
	rep(i,num_lp) {
		int tmp = i;
		vector<bool> comp(d); // 全問題を解いたか
		int point = 0;  // 得点
		int solved = 0; // 解いた数
		rep(j,d) {
			if (tmp%2==1) comp[j] = true;
			else comp[j] = false;
			tmp/=2;
			if (comp[j]) {
				point += 100*(j+1)*p[j]+c[j];
				solved += p[j];
			}
		}
		int now_prob = d-1;
		int now_no = 0;
		while((point<g) && (now_prob>=0)) {
			if (!comp[now_prob] && (now_no<=p[now_prob]-1)) {
				point += 100*(now_prob+1);
				solved++;
				now_no++;
			}
			else {
				now_no = 0;
				now_prob--;
			}
		}
		if (point>=g) ans = min(ans, solved);
	}
	cout << ans << endl;

	return 0;
}


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

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int input = Integer.parseInt(sc.nextLine());
		String[] array = sc.nextLine().split(" ");
		int min = Integer.parseInt(array[0]);
		int max = Integer.parseInt(array[1]);
		String result = max/input*input >= min ? "OK" : "NG";
	    System.out.println(result);
	}
}


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


int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll a,b,k;
    
    cin>>a>>b>>k;
    
    cout<<max(0LL,a-k)<<" "<<max(0LL,b-(k-min(a,k)));
    
    
}


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

using namespace std;

int main() {
  int X;
  long long ans;
  
  cin >> X;
  
  ans = floor(X / 500) * 1000;
  X -= floor(X / 500) * 500;
  ans += floor(X / 5) * 5;
  X -= floor(X / 5) * 5;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int

using namespace std;
lli dp[4][200];
int n;
lli x[4][200];
lli dpp( int i,int j)

{

    if(i==2 && j==n)
        return x[i][j];
    else if(i>2 || j>n)
        return -1e7;

      if(dp[i][j]!=-1)
        return  dp[i][j];
      lli ans=x[i][j];
      ans+=dpp(i+1,j);

        ans=max(x[i][j]+dpp(i,j+1),ans);
      return dp[i][j]=ans;

}

int main()
{

    memset(dp,-1,sizeof(dp));

	cin>>n;
	for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
        cin >>x[i][j];

    cout << dpp(1,1)<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define sf(i,s) for(i=0;s[i]!='\0';i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define inf INT_MAX
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,i) for(typeof(v).begin() i = v.begin(); i != v.end(); i++)
#define pre(v,x) (v.find(x) != v.end())
#define vpre(v,x) (find(all(v),x) != v.end())
#define gcd(x,y) __gcd(x,y)
#define bc(x) __builtin_popcountll(x)
//cin.ignore(1, '\n');
ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    if(b==1)
    return a;
    else
    {
        ll t=power(a,b/2);
        if(b%2==0)
        return ((t%mod)*(t%mod))%mod;
        else
        return ((((t%mod)*(t%mod))%mod)*((a%mod)%mod))%mod;
    }
}
void solve()
{
 ll n,ans;
 cin>>n;
 ans=1000-n%1000;
 if(ans==1000)
    ans=0;
 cout<<ans<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3616
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
using ll = long long int;

const int MAXN = 4000;
const ll MOD = 1000000007;
ll C[MAXN+10][MAXN+10], inv[MAXN+10];
map< pair<ll, ll>, ll > rec;

ll mod_pow(ll n, ll k) {
    ll res = 1; n %= MOD;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

void init() {
    for(int i=0; i<=MAXN; i++) {
        inv[i] = mod_pow(i, MOD-2);
        C[i][0] = 1;
        for(int j=1; j<=i; j++) {
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
        }
    }
}

ll nCr(ll n, ll r) {
    if(r < 0 or n < r) return 0;
    if(r > n - r) return nCr(n, n-r);
    if(n <= MAXN and r <= MAXN) return C[n][r];
    if(rec.count(make_pair(n, r))) return rec[make_pair(n, r)];
    
    ll res = 1;
    for(int i=0; i<r; i++) {
        (res *= (n - i) % MOD) %= MOD;
        (res *= inv[i + 1]) %= MOD;
    }
    return rec[make_pair(n, r)] = res;
}

ll nHr(ll n, ll r) {
    if(n == 0 and r == 0) return 1;
    return nCr(n+r-1, r);
}

int solve_testcase() {
    ll N, D, X; cin >> N >> D >> X;
    if(N == 0) return 1;
    rec.clear();
    
    ll Y = min(N, D), ans = 0;

    // 制約違反が i 日ある
    for(int i=0; i<=Y; i++) {
        // 0 個でないところが j 日ある
        for(int j=i; j<=Y; j++) {
            // 1 個以上いれるのが (j-i) 個
            // X 個以上いれるのが i 個
            ll rem = N - i*X - (j-i);
            if(rem < 0) continue;

            // 1 個以上・X 個以上の並び
            ll add = nCr(j, i);

            // j 日に rem 個すきにいれていい
            // j も rem も小さいのでこれは O(1)
            (add *= nHr(j, rem)) %= MOD;

            // 残り D - j 日は 0 にする (毎回計算すると破滅しそう)
            (add *= nHr(j+1, D-j)) %= MOD;

            if(i % 2) (ans -= add) %= MOD;
            else (ans += add) %= MOD;
            if(ans < 0) ans += MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

int main() {
    init();
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 80680
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int N = 505;

int dist[N][N];
bool alive[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
				
int32_t main() {
	fast_cin();
	int n; cin >> n;  
	for (int r = 0; r < n; ++r) {
		for (int c = 0; c < n; ++c) {
			dist[r][c] = min({r, c, n - 1 - r, n - 1 - c});
		}
	}
	memset(alive, true, sizeof alive);
	int ans = 0;
	for (int turn = 0; turn < n * n; ++turn) {
		int who; cin >> who;
		--who;
		int r = who / n, c = who % n;
		ans += dist[r][c];
		alive[r][c] = 0;
		queue<pair<int, int> > q;
		q.push({r, c});
		while (!q.empty()) {
			auto [i, j] = q.front();
			q.pop();
			for (int d = 0; d < 4; ++d) {
				int ni = i + dx[d], nj = j + dy[d];
				if (ni >= 0 and ni < n and nj >= 0 and nj < n) {
					if (dist[ni][nj] > dist[i][j] + alive[i][j]) {
						dist[ni][nj] = dist[i][j] + alive[i][j];
						q.push({ni, nj});
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int gcd(int a,int b){
	if(!(a % b)) return b;
	return gcd(b,a % b);
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	nongetpop(array,&(*size));
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	int n,x = 1;
	scanf("%d",&n);
	while(x * 2 <= n)	x *= 2;
	printf("%d\n", x);
	return 0;
}


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

static const int kCaNum = 100000;
typedef struct {
	int iNumber;
	char cType;
}Card;

bool ReserchStable(Card _caCard[], Card _caCardSample[], int _iCardNum) {
	for (int i = 0; i < _iCardNum; i++) {
		if (_caCard[i].cType == _caCardSample[i].cType) continue;
		return false;
	}
	return true;
}

int Partition(Card _caCard[], int _iStart, int _iLast) {
	int iKey = _caCard[_iLast].iNumber;
	int iMinLast = _iStart - 1;

	for (int i = _iStart; i < _iLast ; i++) {
		if (_caCard[i].iNumber > iKey) continue;
		iMinLast++; //iKey???????°?????????????????¢?????????????

		//???????????????
		Card caTemp = _caCard[iMinLast];
		_caCard[iMinLast] = _caCard[i];
		_caCard[i] = caTemp;
	}
	iMinLast++;
	Card caTemp = _caCard[iMinLast];
	_caCard[iMinLast] = _caCard[_iLast];
	_caCard[_iLast] = caTemp;

	return iMinLast;
}

void QuickSort(Card _caCard[], int _iStart, int _iEnd) {
	if (_iStart >= _iEnd) return;

	int iBorder = Partition(_caCard, _iStart, _iEnd);
	QuickSort(_caCard, _iStart, iBorder-1);
	QuickSort(_caCard, iBorder+1, _iEnd);
}

class Merge {
public:
	void mergeSort(Card A[], int left, int right) {
		if (left + 1 >= right) {
			return;
		}
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}

private:
	void merge(Card A[], int left, int mid, int right) {
		int numL = mid - left;
		int numR = right - mid;

		//?????§A??????????????´??°???????????§??\?????????????????????????????????
		//?????¬?????\????????????????????????
		Card L[50001];
		Card R[50001];
		for (int i = 0; i < numL; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < numR; i++) {
			R[i] = A[mid + i];
		}
		//??????????????¨????????\???????????????
		L[numL].iNumber = 1000000001;
		R[numR].iNumber = 1000000001;
		int iL = 0;
		int iR = 0;
		for (int j = left; j < right; j++) {
			if (L[iL].iNumber <= R[iR].iNumber) {
				A[j] = L[iL];
				iL++;
			}
			else {
				A[j] = R[iR];
				iR++;
			}
		}
	}
};

//????????????????????´????????????
int main() {
	Card caCard[kCaNum];
	Card caCardSample[kCaNum];
	int iCardNum;
	cin >> iCardNum;
	for (int i = 0; i < iCardNum; i++) {
		int iN; char cT;
		cin >> cT; 
		cin >> iN;
		caCardSample[i].cType = caCard[i].cType = cT;
		caCardSample[i].iNumber = caCard[i].iNumber = iN;
	}
	
	//??´???????????????
	QuickSort(caCard, /*iFirst = */0, /*iLast = */iCardNum-1);

	//?????????????????????????????????????????????????????????
	Merge meMerge;
	meMerge.mergeSort(caCardSample, /*iFirst = */0, /*iFirst = */iCardNum);
		
	//??????????????????????????????
	bool bIsStable = ReserchStable(caCard, caCardSample, iCardNum);

	if (bIsStable)	cout << "Stable"       << endl;
	else					cout << "Not stable" << endl;
	for (int i = 0; i < iCardNum; i++) {
		cout << caCard[i].cType      << " " ;
		cout << caCard[i].iNumber << endl;
	}

	return 0;
}

Measured memory_bytes: 5424
/* https://atcoder.jp/contests/abc104/tasks/abc104_c */

#include <iostream>
#include <vector>

int solve(int D, int G, std::vector<int> p, std::vector<int> c)
{
  int min_cnt_problem = 1e5;

  for (int mask = 0; mask < (1 << D); ++mask)
  {
    int sum_score = 0, cnt_problem = 0, idx_max_problem_score = -1;

    for (int i = 0; i < D; ++i)
    {
      if (mask >> i & 1)
      {
        sum_score += 100*(i + 1)*p.at(i) + c.at(i);
        cnt_problem += p.at(i);
      }
      else
      {
        idx_max_problem_score = i;
      }
    }

    if (sum_score < G)
    {
      int sub_problem_score = 100*(idx_max_problem_score + 1);
      int shortage_score = G - sum_score;

      int sub_cnt_problem = -1;
      for (int j = 1; j < p.at(idx_max_problem_score); ++j)
      {
        if (shortage_score <= sub_problem_score*j)
        {
          cnt_problem += j;
          sub_cnt_problem = j;
          break;
        }
      }

      if (sub_cnt_problem == -1)
      {
        continue;
      }
    }

    min_cnt_problem = std::min(min_cnt_problem, cnt_problem);
  }

  return min_cnt_problem;
}

int main(int argc, char *argv[])
{
  // Input
  int D, G;

  std::cin >> D >> G;

  std::vector<int> p(D);
  std::vector<int> c(D);

  for (int i = 0; i < D; ++i)
  {
    std::cin >> p.at(i) >> c.at(i);
  }

  // Output
  std::cout << solve(D, G, p, c) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <cctype>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

    int cnt = (s[0] == '1') + (s[1] == '1') + (s[2] == '1');
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 888
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int n=s.nextInt();
		for(int q=0;q<n;++q) {
			String m=s.next();
			StringBuilder v=new StringBuilder(s.next());
			for(int i=m.length()-1;i>=0;--i) {
				switch(m.charAt(i)) {
				case 'J':
					v.insert(0,v.charAt(v.length()-1)).deleteCharAt(v.length()-1);
					break;
				case 'C':
					v.append(v.charAt(0)).deleteCharAt(0);
					break;
				case 'E':
					String t=v.substring(0,v.length()/2);
					String u=v.substring(v.length()-v.length()/2,v.length());
					v.replace(0,v.length()/2,u);
					v.replace(v.length()-v.length()/2,v.length(),t);
					break;
				case 'A':
					v.reverse();
					break;
				case 'P':
					for(int j=0;j<v.length();++j) {
						char c=v.charAt(j);
						if(Character.isDigit(c))
							v.setCharAt(j,(char)((c-'0'+9)%10+'0'));
					}
					break;
				case 'M':
					for(int j=0;j<v.length();++j) {
						char c=v.charAt(j);
						if(Character.isDigit(c))
							v.setCharAt(j,(char)((c-'0'+1)%10+'0'));
					}
					break;
				}
			}
			System.out.println(v);
		}
	}
}


Measured memory_bytes: 25812
#include <stdio.h>
#include <math.h>
 
int main(){
    long long a,b,c,d;
 
    scanf("%lld%lld%lld",&a,&b,&c);
 
    d = c - a - b;
    if(d > 0 && d*d > 4*a*b)printf("Yes\n");
    else printf("No\n");
 
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x; scanf("%d", &x); return x;	
}
const int maxn = 3e5 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
using namespace std;

char a[maxn];
int prepM[maxn], prepL[maxn];
int n;
int Solve(int x) {
	if (x == 0) return 0;
	int t = __builtin_popcount(x);
	return 1 + Solve(x % t);
}
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	n = read();
	scanf("%s", a + 1);
	int cntone = 0;
	for (int i = 1; i <= n; ++i) cntone += a[i] == '1';
	int curM = 0, curL = 0;
	for (int i = 1; i <= n; ++i) { 
		curM = (curM << 1) + (a[i] == '1'); curM %= (cntone + 1); 
		if (cntone > 1) { curL = (curL << 1) + (a[i] == '1'); curL %= (cntone - 1); }
	}
	prepM[n] = 1; prepL[n] = 1;
	for (int i = n - 1; i >= 1; --i) {
		prepM[i] = (prepM[i + 1] << 1); prepM[i] %= (cntone + 1);
		if (cntone > 1) { prepL[i] = (prepL[i + 1] << 1); prepL[i] %= (cntone - 1); }
	}	
	for (int i = 1; i <= n; ++i) {
		if (a[i] == '1') {
			if (cntone > 1) {
				int nw = ((curL - prepL[i]) % (cntone - 1) + (cntone - 1)) % (cntone - 1);
				printf("%d\n", Solve(nw) + 1);
			}
			else {
				printf("0\n");	
			}
		}
		else {
			int nw = (curM + prepM[i]) % (cntone + 1);
			printf("%d\n", Solve(nw) + 1);
		}
	}
	return 0;	
}


Measured memory_bytes: 5544
import sys
from bisect import bisect
def input():
	return sys.stdin.readline()[:-1]

def calc(x, i, j):
	prev = [s[i-1], s[i], t[j-1], t[j], s[i-1], s[i], t[j-1], t[j]]
	foll = [t[j-1], t[j-1], s[i-1], s[i-1], t[j], t[j], s[i], s[i]]
	res = 10**11
	for p, f in zip(prev, foll):
		res = min(res, abs(p-x) + abs(f-p))
	return res

a, b, q = map(int, input().split())
s, t = [-10**11], [-10**11]
for _ in range(a):
	s.append(int(input()))
s.append(10**11)
for _ in range(b):
	t.append(int(input()))
t.append(10**11)

for _ in range(q):
	x = int(input())
	print(calc(x, bisect(s, x), bisect(t, x)))

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

unsigned long xor128(){
    static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned long t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int a[][4] = {{0, 1, 2, 3},
              {4, 5, 6, 7},
              {0, 1, 5, 4},
              {3, 2, 6, 7},
              {0, 4, 7, 3},
              {1, 5, 6, 2}};

int main()
{
    for(;;){
        vector<string> s(8);
        for(int i=0; i<8; ++i){
            if(!(cin >> s[i]))
                return 0;
        }
        sort(s.begin(), s.end());

        set<vector<string> > x;
        do{
            vector<string> t = s;
            bool ok = true;

            for(int i=0; i<500; ++i){
                int b = xor128() % 3;
                for(int j=0; j<3; ++j){
                    swap(t[a[b*2][j]], t[a[b*2][j+1]]);
                    swap(t[a[b*2+1][j]], t[a[b*2+1][j+1]]);
                }
                if(x.find(t) != x.end()){
                    ok = false;
                    break;
                }
            }

            if(ok)
                x.insert(s);
        }while(next_permutation(s.begin(), s.end()));

        cout << x.size() << endl;
    }
}

Measured memory_bytes: 1432
n = int(input())
a = tuple(map(int, input().split()))

c = 0  # 4の倍数と奇数の出現数の差
f1 = False  # 2の倍数だが4の倍数ではない
for aa in a:
    if aa % 4 == 0:
        c += 1
    elif aa % 2 == 0:
        f1 = True
    elif aa % 2 == 1:
        c -= 1

x = 0 if f1 else -1
print('Yes' if c >= x else 'No')


Measured memory_bytes: 15148
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate など
#include <stdexcept>
#include <cassert> // assert
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll MOD = 1'000'000'007;

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}


Measured memory_bytes: 3580
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X, Y, A, B, C = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    Q = [int(x) for x in input().split()]
    R = [int(x) for x in input().split()]

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    xcnt = 0
    ycnt = 0
    rcnt = 0
    ans = 0

    for r in R:
        p = float("inf")
        if X - 1 - xcnt >= 0:
            p = P[X - 1 - xcnt]
        q = float("inf")
        if Y - 1 - ycnt >= 0:
            q = Q[Y - 1 - ycnt]
        if p >= r and q >= r:
            break

        if (r - p) > 0 and r - p > r - q:
            xcnt += 1
            rcnt += 1
            ans += r
        else:
            ycnt += 1
            rcnt += 1
            ans += r

    ans += sum(P[:X - xcnt])
    ans += sum(Q[:Y - ycnt])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91500
#include<stdio.h>

int main()
{
	int n, m;
	
	while(scanf("%d %d", &n, &m) != EOF)
	{
		int ans = 0;
		
		if(n == 0 && m == 0)
		{
			break;
		}
		for(int i = 1; i < n - 1; i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				for(int k = j + 1; k < n + 1; k++)
				{
					if(m == i + j + k)
					{
						ans++;
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	
	return 0;
}


Measured memory_bytes: 2704
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,p[100005],sz[100005];
vector<int>g[100005];
void dfs(int v){
    sz[v]=1;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(u!=p[v]){
            p[u]=v;
            dfs(u);
            sz[v]+=sz[u];
        }
    }
}
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[--a].PB(--b);
        g[b].PB(a);
    }
    p[0]=-1;
    dfs(0);
    int s=0,t=n-1;
    while(p[t]!=0){
        s++;
        t=p[t];
    }
    s/=2;
    t=n-1;
    while(s){
        t=p[t];
        s--;
    }
    if(n-sz[t]<=sz[t])printf("Snuke\n");
    else printf("Fennec\n");
}


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

int main() {
  int  i,j;
  char op;
  int a,b;
  cin>>a>>op>>b;
  int ret;

  if(op=='+'){
    ret=a+b;
  }else if(op=='-'){
    ret=a-b;
  }

  cout<<ret<<endl;
}


Measured memory_bytes: 256
def factorial_memo(n, p):
  F = [1] * (n + 1)
  for i in range(n):
    F[i + 1] = F[i] * (i + 1) % p
  return F
 
def inverse(F, p):
  Finv = [x for x in F]
  Finv[-1] = pow(Finv[-1], p - 2, p)
  for i in range(len(F) - 2, 0, -1):
    Finv[i] = Finv[i + 1] * (i + 1) % p
  return Finv
 
def comb(*A):
  f = F[sum(A)]
  for a in A:
    f *= Finv[a]
    f %= p
  return f
 
N, K = map(int, input().split())
p = 10 ** 9 + 7
F = factorial_memo(N, p)
Finv = inverse(F, p)
 
for i in range(1, K + 1):
  base = comb(K - i, i - 1)
  if N - K - i + 1 >= 0:
    multi = comb(i, N - K - i + 1)
  else:
    multi = 0
  print((base * multi) % p)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define PI 3.1415


int main() {
    
    int a,b;
    cin >> a >> b;
    
    if((a+b)%2 == 0) {
        cout<<(a+b)/2<<endl;
    }
    else {
        cout<< "IMPOSSIBLE"<<endl;
    }


 return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader fr = new FastReader();
		int[] a = new int[100002];
		int n = fr.nextInt();
		int max = Integer.MIN_VALUE;
		for (int i=0; i<n; i++) {
			int x = fr.nextInt();
			a[x]++;
			a[x+1]++;
			max =Math.max(max, Math.max(a[x], a[x+1]));
			if (x > 0) {
				a[x-1]++;
				max = Math.max(max, Math.max(a[x], a[x-1]));
			}
		}
		System.out.println(max);
	}
	
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


Measured memory_bytes: 39532
n=int(input())
P=list(map(int,input().split()))
a=[]
for i in range(0,n-2):
    a.append([P[i],P[i+1],P[i+2]])
b=0
for i in range(len(a)):
    if a[i][1]!=min(a[i]) and a[i][1]!=max(a[i]):
        b+=1
print(b)

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s;
  cin >>s;
  if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o'){
    cout <<"vowel"<<endl;
  }
  else{
    cout <<"consonant"<<endl;
  }
}
      

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;


template<class Abel> struct UnionFind {
    vi par;
    vi rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        rep(i, 0, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if(par[x] == x) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int N;

signed main() {
    cin >> N;
    UnionFind<int> tree(N);
    rep(i, 0, N-1) {
        int U, V, W; cin >> U >> V >> W;
        tree.merge(U-1, V-1, W);
    }

    int r = tree.root(0);

    rep(i, 0, N) {
        if(i == r) {
            cout << 0 << endl;
            continue;

        }
        if(tree.diff(i, r) % 2 == 0) {
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }
    return 0;
}





Measured memory_bytes: 2816
#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>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
const int64_t INF=10000000000000000;
#include <vector>
#include<cstdint>
#include <iostream>
#include <vector>

template<class T>
void read_1d(std::vector<T>& a,int64_t num){
	a.reserve(num);
	for(int64_t i1=0;i1<num;i1++){
		T temp;
		std::cin>>temp;
		a.push_back(temp);
	}
}
template<class T>
void read_2d(std::vector<std::vector<T> >&a,int64_t x,int64_t y ){
	a.resize(x);
	for(int64_t i1=0;i1<x;i1++){
		a[i1].reserve(y);
		for(int64_t i2=0;i2<y;i2++){
			char temp;
			std::cin>>temp;
			if(temp=='0'){
				a[i1].push_back(0);
			}else{
				a[i1].push_back(1);
			}
		}
	}
}
template<class InputIterator>
void debug(InputIterator first,InputIterator last){
	for(auto i1=first;i1!=last;i1++){
		std::cout<<(*i1);
	}
}

template<class T>
std::vector<T> imos_1d(vector<T>& a){
	std::vector<T> retval;
	retval.reserve(a.size()+1);
	int64_t sum=0;
	retval.push_back(sum);
	for(int64_t i1=0;i1<a.size();i1++){
		sum+=a[i1];
		retval.push_back(sum);
	}
	return retval;
}
template<class T>
std::vector<std::vector<T>> imos_2d(std::vector<std::vector<T> > &a){
	std::vector<std::vector<T> > temp;
	temp.reserve(a.size()+1);
	temp.resize(1);
	temp[0].resize(a[0].size()+1);
	for(int64_t i1=0;i1<a.size();i1++){
		temp.push_back(imos_1d(a[i1]));
	}
	for(int64_t i1=0;i1<a[0].size()+1;i1++){
		int64_t sum=0;
		for(int64_t i2=0;i2<a.size()+1;i2++){
			sum+=temp[i2][i1];
			temp[i2][i1]=sum;
		}

	}
	return temp;

}
int main(){
	int n,m;
	int64_t q;
	cin>>n>>m>>q;
	vector<vector<int64_t> > raw;
	read_2d(raw,n,m);
	vector<vector<int64_t> > edge_x;
	vector<vector<int64_t> >edge_y;
	edge_x.resize(n);
	edge_y.resize(n);
	for(int64_t i1=0;i1<n;i1++){
		edge_x[i1].reserve(n);
		edge_y[i1].reserve(n);
		for(int64_t i2=0;i2<m;i2++){
			if(raw[i1][i2]==1&&i2+1<m&&raw[i1][i2+1]==1){
				edge_y[i1].push_back(1);
			}else{
				edge_y[i1].push_back(0);
			}
			if(raw[i1][i2]==1&&i1+1<n&&raw[i1+1][i2]==1){
				edge_x[i1].push_back(1);
			}else{
				edge_x[i1].push_back(0);
			}
		}
	}
	std::vector<std::vector<int64_t> > temp=imos_2d(raw);
	vector<vector<int64_t> > temp3=imos_2d(edge_x);
	vector<vector<int64_t> > temp2=imos_2d(edge_y);
	for(int64_t i1=0;i1<q;i1++){
		int64_t x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		x1--;
		y1--;
		x2--;
		y2--;
		cout<<temp[x2+1][y2+1]-temp[x2+1][y1]-temp[x1][y2+1]+temp[x1][y1]-(temp2[x2+1][y2]-temp2[x1][y2]-temp2[x2+1][y1]+temp2[x1][y1])-
				(temp3[x2][y2+1]-temp3[x1][y2+1]-temp3[x2][y1]+temp3[x1][y1])<<endl;
		//cout<<temp2[x2+1][y2]-temp2[x1][y2]-temp2[x2+1][y1]+temp2[x1][y1]<<endl;
		//cout<<temp3[x2][y2+1]-temp3[x1][y2+1]-temp3[x2][y1]+temp3[x1][y1]<<endl;
	}






}


Measured memory_bytes: 204928
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();

        if (A.Contains(0L))
        {
            Console.WriteLine(0);
            return;
        }

        var result = 1L;
        foreach (var a in A)
        {
            var temp = result * a;
            if (temp < result || temp > 1000000000000000000)
            {
                Console.WriteLine(-1);
                return;
            }
            result *= a;
        }
        Console.WriteLine(result);
    }
}


Measured memory_bytes: 41380
#include <bits/stdc++.h>
using namespace std;
 
int fcn(int n){
  int sum =0;
  while(n > 0){
    sum += n% 10;
    n /=10;}
  return sum;}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int d=0;
  for(int i=1; i <= N;i++){
    if (fcn(i) >= A && fcn(i) <= B){
      d += i;}
  }
  cout << d << endl;
  
}

Measured memory_bytes: 256
import collections
n=int(input())
s=list(input() for _ in range(n))

s1=collections.Counter(s)
s2=max(s1.values()) 
count=list(s1.values()).count(s2)
values, counts = zip(*s1.most_common(count))
ans=list(values)
ans.sort()
print('\n'.join(ans))

Measured memory_bytes: 59360
#include <iostream>

using namespace std;

const int INF = 10000;

int main() {
	int N, T;
	int ans = INF;

	cin >> N >> T;

	for (int i = 0; i < N; i++) {
		int temp, cost;
		cin >> cost >> temp;
		if (cost < ans && temp <= T)ans = cost;
	}

	if (ans == INF) cout << "TLE" << endl;
	else cout << ans << endl;

	return 0;
}

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

int main() {
  int n;
  long long k;
  cin >> n >> k;

  vector<pair<int, int> > arr;
  for (int i=0; i<n; i++) {
    int a, b;
    cin >> a >> b;
    arr.push_back(make_pair(a,b));
  }

  sort(arr.begin(), arr.end());

  long long sum=0;
  for (int i=0; i<n; i++) {
    sum += arr[i].second;
    if (sum >= k) {
      cout << arr[i].first << endl;
      break;
    }
  }

  return 0;
}


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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<pair<int, int> > rw(n);
		int rsum=0, wsum=0;
		for(int i=0; i<n; i++){
			int r,w;
			cin >> r >> w;
			rsum += r;
			wsum += w;
			rw[i] = make_pair(r, w);
		}
		sort(rw.begin(), rw.end());
		if(2*rw[n-1].first > rsum){
			int t = 2*rw[n-1].first -rsum;
			vector<bool> dp(t+1, false);
			dp[0] = true;
			for(int i=0; i<n-1; i++){
				for(int j=t-1; j>=0; j--){
					if(dp[j] && j+rw[i].second <= t){
						dp[j+rw[i].second] = true;
					}
				}
			}
			int fill=0;
			for(int i=0; i<=t; i++){
				if(dp[i]) fill=i;
			}
			cout << rsum + t + wsum -fill << endl;
		}else{
			cout << rsum +wsum << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define N 55
#define int short
using namespace std;
typedef vector<vector<bool> > V;
typedef pair<int,int> P;
typedef pair<P,P> PP;
string mp[N];
vector<PP> A;
int h,w;

bool compare(PP &a,PP &b){
  int w1 = a.second.first - a.first.first+1;
  int h1 = a.second.second - a.first.second+1; 
  int w2 = b.second.first - b.first.first+1;
  int h2 = b.second.second -b.first.second+1;
  return h1*w1 < h2*w2;
}

V v[50][50];
void visit(int x,int y){
  V &D = v[y][x] = V(N,vector<bool>(N,0));
  D[y][x] = 1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) {
      if(mp[i][j] == '#')continue;
      if(i)D[i][j] = D[i][j]|D[i-1][j];
      if(j)D[i][j] = D[i][j]|D[i][j-1];
    }
}

void pushA(int x,int y){
  V &D = v[y][x];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(!D[i][j]||islower(mp[i][j])||tolower(mp[i][j])!=mp[y][x])continue;
      A.push_back(PP(P(x,y),P(j,i)));
    }
}

void mkA(){
  A.clear();
  V &D = v[0][0];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(D[i][j]&&islower(mp[i][j]))pushA(j,i);
  
  sort(A.begin(),A.end(),compare);
}

bool check(PP a,PP b){
  int x1=a.first.first,y1=a.first.second;
  int X1=a.second.first,Y1=a.second.second;
  int x2=b.first.first,y2=b.first.second;
  int X2=b.second.first,Y2=b.second.second;
  if((a.first==b.first||a.second == b.second)||
     (x1>=0&&y1>=0&&!v[y1][x1][y2][x2])||
     (!v[Y2][X2][h-1][w-1])||
     (X1<w&&X2<h&&!v[Y2][X2][Y1][X1]))return 0;
  return x1<=x2&&X2<=X1&&y1<=y2&&Y2<=Y1;
}

map<PP,int> mem[1000];
int dfs(int idx,PP sta){  
  if(idx == -1) return 0;
  if(mem[idx].count(sta))return mem[idx][sta];
  int res = dfs(idx-1,sta);
  if(check(sta,A[idx])){
    int a = dfs(idx-1,PP(sta.first,A[idx].first));
    int b = dfs(idx-1,A[idx]);
    int c = dfs(idx-1,PP(A[idx].second,sta.second));
    res = max(res,(int)(a+b+c+1));
  }
  return mem[idx][sta] = res;
}

main(){
  while(1){
    cin>>h>>w;
    if(!h&&!w)break;
    for(int i=0;i<h;i++)cin>>mp[i];
    for(int i=0;i<1000;i++)mem[i].clear();

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)visit(j,i);
    
    mkA();
    if(!v[0][0][h-1][w-1]) cout<<-1<<endl;
    else cout<<dfs(A.size()-1,PP(P(-1,-1),P(w,h)))<<endl;
  }
}

Measured memory_bytes: 153096
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <deque>
using namespace std;
const int N = 3000;
string s, t;
int dp[3001][3001];
int strlen(string x) {
	return x.size();
}
main() {
  cin >> s >> t;
  for(int i = 1; i <= (int)strlen(s); i++) {
    for(int j = 1; j <= (int)strlen(t); j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      if(s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
    }
  }

  deque < char > ans;
  int n = strlen(s), m = strlen(t);
  while(n && m) {
    if(dp[n][m] == dp[n - 1][m]) n--;
    else if(dp[n][m] == dp[n][m - 1]) m--;
    else if(dp[n][m] == dp[n - 1][m - 1] + 1) {
      ans.push_front(s[n - 1]); n--; m--;
    }

  }

  for(int i = 0; i < ans.size(); i++) {
    printf("%c", ans[i]);
  }
}

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

even_lst = [A[i] for i in range(N) if i % 2 == 1]
odd_lst = [A[i] for i in range(N) if i % 2 == 0]

if N % 2 == 0:
  progression = even_lst[::-1] + odd_lst
else:
  progression = odd_lst[::-1] + even_lst

ans = ' '.join(list(map(str, progression)))
print(ans)

Measured memory_bytes: 31300
#include <bits/stdc++.h>
#include<limits.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
int main()
{
	ll h,w;
	cin>>h>>w;
	string s[h];
	ll dp[h][w];
	for(ll i=0;i<h;i++)
		cin>>s[i];
	fillv(dp,0);
	dp[0][0]=1;
	for(ll i=0;i<h;i++)
	{
		for(ll j=0;j<w;j++)
		{
			if(i==0&&j==0)
				continue;
			if(s[i][j]=='#')
				continue;
			if(j-1>=0)
				if(s[i][j-1]=='.')
				dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
			if(i-1>=0)
				if(s[i-1][j]=='.')
				dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;


		}
	}
	// for(ll i=0;i<h;i++)
	// {
		// for(ll j=0;j<w;j++)
			// cout<<dp[i][j]<<" ";
		// ln;
	// }
		cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstring>
using namespace std;
int n, c[21][21], mod = 1e9 + 7, dp[21][1 << 21];
int f(int p, int b) {
  if(p == n)
    return 1;
  if(dp[p][b] != -1)
    return dp[p][b];
  int sm = 0;
  for(int i = 0; i < n; ++i)
    if((~b & (1 << i)) && c[p][i])
      sm = (f(p + 1, b | (1 << i)) + sm) % mod;
  return dp[p][b] = sm; 
}
int main() {
  cin >> n;

  memset(dp, -1, sizeof dp);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      cin >> c[i][j];
  cout << f(0, 0);
}

Measured memory_bytes: 172288
///"    "\\\

# include <bits/stdc++.h>

# define pb push_back

using namespace std;

int k , z , o , p ;

	
int main() {

	int a , b , c ;
	cin >> a >> b >> c ;
	if( a + b >= c ){
		cout << b + c ;
	}
	else{
		cout << ( a + b ) + b + 1 ;
	}


}

///"    "\\\

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

using namespace std;

typedef long long ll;

ll bitSize = 0;
ll bit[100001];

void init(ll n) {
	bitSize = n;
	fill(bit, bit+100001, 0);
}
void add(ll pos, ll v) {
	++pos;
	while (pos <= bitSize) {
		bit[pos] += v;
		pos += pos & -pos;
	}
}
ll get(ll pos) {
	++pos;
	ll res = 0;
	while (pos > 0) {
		res += bit[pos];
		pos -= pos & -pos;
	}
	return res;
}

ll N;
bool check(vector<ll> p, vector<ll>& l) {
	for (ll i = N-1; i > 0; --i) {
		p[i] -= p[i-1];
	}
	for (ll i = 0; i < N; ++i) {
		if (p[i] < l[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> N;
	vector<ll> p(N);
	for (ll i = 0; i < N; ++i) {
		cin >> p[i];
	}
	vector<ll> l(N);
	for (ll i = 0; i < N; ++i) {
		cin >> l[i];
	}

/*
		init(N);
		ll ans = 0;
		for (ll i = N-1; i >= 0; --i) {
			add(p[i], 1);
			if (p[i] != 0) {
				ans += get(p[i]-1);
			}
		}
		cout << ans << endl;
return 0;
*/

	for (ll i = 1; i < N; ++i) {
		p[i] += p[i-1];
	}
	vector<ll> to = p;
	sort(p.begin(), p.end());
	if ( !check(p, l) ) {
		cout << -1 << endl;
	}
	else {
		vector<ll> temp = to;
		temp.erase(unique(temp.begin(), temp.end()), temp.end());
		map<ll, ll> tbl;
		for (ll i = 0; i < N; ++i) {
			tbl[to[i]] = i;
		}
		for (ll i = 0; i < N; ++i) {
			to[i] = tbl[to[i]];
			p[i] = tbl[p[i]];
		}
		init(N);
		ll ans = 0;
		for (ll i = N-1; i >= 0; --i) {
			add(p[i], 1);
			if (p[i] != 0) {
				ans += get(p[i]-1);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 11144
#include <cstdio>

int main(){
    int m, f, r;
    while(true){
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }else if(m == -1 || f == -1){
            printf("F\n");
        }else if(m + f >= 80){
            printf("A\n");
        }else if(m + f >= 65){
            printf("B\n");
        }else if(m + f >= 50){
            printf("C\n");
        }else if(m + f >= 30){
            if(r >= 50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else{
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2564