akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
typedef long long ll;
#define INF 1e9



int main(){
    string Sa, Sb, Sc; cin >> Sa >> Sb >> Sc;
    
    char temp = Sa[0];
    
    while (1) {
        switch (temp) {
            case 'a': {
                if(Sa.empty()) {
                    cout << "A" << endl;
                    return 0;
                }
                temp = Sa[0];
                Sa.erase(Sa.begin());
              
                
                break;
                
            }
            case 'b': {
                if(Sb.empty()) {
                    cout << "B" << endl;
                    return 0;
                }
                temp = Sb[0];
                Sb.erase(Sb.begin());
                
                
                break;
            }
            case 'c': {
                if(Sc.empty()){
                    cout << "C" << endl;
                    return 0;
                }
                temp = Sc[0];
                Sc.erase(Sc.begin());
              
                
                break;
            }
        }
    }
    
    
    
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

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

        long a = sc.nextInt();
        long b = sc.nextInt();

        long c = (b*b)-(a*a);
        long d = 2*b-2*a;

        if (c%d == 0)
            System.out.println(c/d);
        else
            System.out.println("IMPOSSIBLE");
    }
}


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

int cnt;
char field[13][13];

void solve(int x,int y)
{
	field[y][x] = '0';
	if(x+1 < 12)
		if(field[y][x+1] == '1')
			solve(x+1,y);
	if(x-1 >= 0)
		if(field[y][x-1] == '1')
			solve(x-1,y);
	if(y+1 < 12)
		if(field[y+1][x] == '1')
			solve(x,y+1);
	if(y-1 >= 0)
		if(field[y-1][x] == '1')
			solve(x,y-1);
}

int main()
{
	while(1){
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				cin >> field[i][j];
				if(cin.eof())
					return 0;
			}
		}
		cnt = 0;
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(field[i][j] == '1'){
					cnt++;
					solve(j,i);
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}
				
		

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

using namespace std;

const int N = 20;
int a[N] = { 0 };

int main() {
	int n, ans = 0, highest = 0;
	cin >> n;
	for(int i(0);i < n;++i) {
		cin >> a[i];
		highest = max(a[i], highest);
		a[i] -= highest;
	}
	for(int i(0);i < n;++i){
		if(a[i] >= 0) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

struct Bitset {
  vector<unsigned long long> a;
  Bitset() {}
  Bitset(const vector<unsigned long long>& a) : a(a) {}

  Bitset f(const Bitset &o) {
    vector<unsigned long long> vec(max(o.a.size(), a.size()));
    for (int i = 0; i < vec.size(); i++) {
      unsigned long long x = 0, y = 0;
      if (i < a.size()) x = a[i];
      if (i < o.a.size()) y = o.a[i];
      vec[i] = (x | y);
    }
    return Bitset(vec);
  }

  int count() {
    int ret = 0;
    for (auto x : a) {
      ret += __builtin_popcountll(x);
    }
    return ret;
  }

  void reset() {
    for (auto& x : a) {
      x = 0;
    }
  }

  void set(int v) {
    int p = v / 64;
    while (a.size() <= p) a.push_back(0);
    a[p] |= (1ULL << (v % 64));
  }
}a[2][501][10];

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  vector<int> c(11);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0, now = 0; i < n; i++, now ^= 1) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= 9; k++) {
        a[now][j][k].reset();
      }
    }
    string s;
    cin >> s;
    for (int j = 1; j <= n; j++) {
      if (s[j - 1] == '#') continue;
      int v = s[j - 1] - '0';
      for (int k = 1; k <= 9; k++) {
        a[now][j][k] = a[now][j - 1][k].f(a[now ^ 1][j][k]);
        ans += a[now][j][k].count() * k * v;
      }
      a[now][j][v].set(c[v]++);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int N, K, get_person, temp, count = 0;
    cin >> N >> K;

    vector<int> sunuke(100);

    for (int i = 0; i < K; i++)
    {
        cin >> get_person;
        for (int j = 0; j < get_person; j++)
        {
            cin >> temp;
            sunuke.at(temp - 1)++;
        }
    }

    for (int i = 0; i < N; i++)
    {
        if (sunuke.at(i) == 0)
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] kn = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long k = kn[0];
        long n = kn[1];
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long[] w = new long[n];
        for (int i = 0; i < n; i++)
        {
            if ( i != n-1)
            {
                w[i] = a[i+1] - a[i];
            }
            else
            {
                w[i] = k - a[i] + a[0];
            }
        }

        long ans = w.Sum() - w.Max();
 
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 36084
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

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

int H,W;
char masu[400][400];
bool visited[400][400];
ll black = 0LL, white = 0LL;

void dfs(int i, int j){

    if(visited[i][j]) return;


    if(masu[i][j] == '#') black++;
    if(masu[i][j] == '.') white++;

    visited[i][j] = true;

    REP(k,4){
        if(i+dx[k]<0 || i+dx[k]>=H || j+dy[k]<0 || j+dy[k]>=W) continue;
        if(masu[i][j] == masu[i+dx[k]][j+dy[k]]) continue;
        dfs(i+dx[k], j+dy[k]);
    }
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin >> H >> W;

    REP(i,H){
        string s; cin >> s;
        REP(j,s.length()){
            masu[i][j] = s[j];
            visited[i][j] = false;
        }
    }
    ll ans = 0LL;

    REP(i,H){
        REP(j,W){

            if(visited[i][j]) continue;
            black = 0; white = 0;
            dfs(i, j);
            ans+=black*white;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8064
#include <iostream>

using namespace std;

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

    string s;
    cin >> s;

    bool flag = false;
    for (int i = 0; i < 2; ++i) {
        if (s[i] == s[i + 1] && s[i + 1] == s[i + 2]) {
            flag = true;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	vector<string> W(N);
	bool flg = false;
	char end_w;
	rep(i, N) {
		cin >> W[i];
		if (!flg) {
			if (i != 0 && W[i][0] != end_w) flg = true;
			rep(j, i - 1) {
				if (W[i] == W[j]) flg = true;
			}
		}
		end_w = W[i][W[i].size()-1];
	}
	cout << (flg ? "No" : "Yes") << endl;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


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


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


int main() {
    ll X, N;
    cin >> X >> N;

    vector<bool> canuse(101+1, true);

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

    ll min = 99999;
    ll minv = 0;
    for(int i = 0; i < canuse.size(); i++) {
        if(canuse[i] == false) continue;
        if(min > abs(i-X)) {
            min = abs(i-X);
            minv = i;
        }
    }


    cout << minv << endl;
    return 0;    
}



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

const int N=2e5+20,MOD=1e9+7;

int n,k;
long long a[N],ans=1;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);

	sort(a,a+n);
	int l=0,r=n-1,sign=1;
	if(k&1)
	{
		ans=a[r--];
		k--;
		if(ans<0) sign=-1;
	}

	while(k)
	{
		long long x=a[l]*a[l+1],y=a[r]*a[r-1];
		if(x*sign>y*sign)
		{
			x%=MOD;
			ans=(ans*x)%MOD;
			l+=2;
		}
		else
		{
			y%=MOD;
			ans=(ans*y)%MOD;
			r-=2;
		}
		k-=2;
	}

	printf("%lld",(ans+MOD)%MOD);
}

Measured memory_bytes: 5392
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll K; cin >> K;
    ll N = 50; ll rem = K%50, quo = K/50;
    
    cout << N << endstr;
    rep(i, N){
        if(i < rem){
            cout << N+quo-i << " ";
        }
        else{
            cout << N+quo-i-1 << " ";
        }
    }
    cout << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
    #include <stdlib.h>
     
    int main(){
       int A,B;
       char c;
       scanf("%d %c %d",&A,&c,&B);
       if( c == '+'){
          printf("%d\n",A+B);
       }else if (c == '-'){
          printf("%d\n",A-B);
       }
       return EXIT_SUCCESS;
    }

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (a, b) = readLongList()
    println(lcm(a, b))
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun gcd(p: Long, q: Long): Long = if (p % q == 0L) q else gcd(q, p % q)

fun lcm(p: Long, q: Long): Long = p / gcd(p, q) * q

Measured memory_bytes: 37720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	long long ba=0;
	cin>>s;
	for(int t=0;t<s.size();t++)
	{
		ba+=s[t]-'0';
	}
	if(ba%9)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
	return 0; 
} 

Measured memory_bytes: 3660
#include <stdio.h>

int land[50][50]={0};

void dfs(int a, int b, int c, int d){

  int i,j;
  
  land[a][b]=0;

  for(i = -1; i <= 1; i++) for(j = -1; j <= 1; j++) if(a+i >= 0 && b+j >= 0 && a+i < c && b+j < d) if(land[a+i][b+j] == 1) dfs(a+i,b+j,c,d);

}

int main(){

  int w,h,result=0,i,j;

  while(1){
    
    scanf("%d %d",&w,&h);
    
    if(w == 0 && h == 0) return 0;
    
    result=0;
    
    for(i = 0; i < h; i++) for(j = 0; j < w; j++) scanf("%d",&land[j][i]);
    
    for(i = 0; i < h; i++){
      
      for(j = 0; j < w; j++){
	
	if(land[j][i] == 1){
	  
	  result++;
	  
	  dfs(j,i,w,h);
	  
	}
	
      }
      
    }
    
    printf("%d\n",result);
    
  }
  
}

Measured memory_bytes: 828
#include<stdio.h>

int main(){

  int sum[2], in, i, j;


  sum[0] = 0;
  sum[1] = 0;

  for(i = 0; i < 2; i++){
    for(j = 0; j < 4; j++){
      scanf("%d",&in);
      sum[i] += in;
    }
  }

  if(sum[0] > sum[1]){
    printf("%d\n",sum[0]);
  }else{
    printf("%d\n",sum[1]);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
ll points(string &s,ll r,ll p,ll s1)
{
    if(s.size()==0)
        return 0;
    ll ans=0;
    ll n=s.size();
    vv dp(n,vi(3,0));
    if(s[0]=='r')
    {
        dp[0][0]=0;
        dp[0][1]=p;
        dp[0][2]=0;
    }
    else if(s[0]=='p')
    {
        dp[0][0]=0;
        dp[0][1]=0;
        dp[0][2]=s1;

    }
    else
    {
        dp[0][0]=r;
        dp[0][1]=0;
        dp[0][2]=0;
    }
    for(ll i=1;i<s.size();i++)
    {
        if(s[i]=='r')
        {
            dp[i][0]=max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=p+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=max(dp[i-1][0],dp[i-1][1]);
        }
        else if(s[i]=='p')
        {
            dp[i][0]=max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=s1+max(dp[i-1][0],dp[i-1][1]);
        }
        else
        {
            dp[i][0]=r+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=max(dp[i-1][0],dp[i-1][1]);
        }
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    vs b(k,"");
    for(ll i=0;i<n;i++)
    {
        b[i%k].pb(t[i]);
    }
    ll ans=0;
    for(ll i=0;i<k;i++)
    {
        ans+=points(b[i],r,p,s);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5888
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}

namespace SOLVE {
	vector<VI> edges;
	VI visited;
	VI onstack;


	int children = 0;

	void dfs(int at) {
		onstack[at] = 1;

		visited[at] = 1;

		for (int to : edges[at]) {

			if (visited[to] && onstack[to]) {
				cout << 1 << endl;
				exit(0);
			}
			if (!visited[to]) {
				dfs(to);

			}
		}
		onstack[at] = 0;


	}


	void main() {
		int n, m, a, b;
		cin >> n >> m;
		edges.resize(n);
		REP(i, 0, m) {
			cin >> a >> b;
			edges[a].push_back(b);
			// edges[b].push_back(a);
		}
		
		visited.resize(n);
		onstack.resize(n);


		REP(i, 0, n) {
			if (!visited[i]) {
				dfs(i);
			}
		}
		
		cout << 0 << endl;
		return;


	}
}


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

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 3216
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val a, b = sc.nextInt()
    (a, b)
  }

  def max(a: Int, b: Int, c: Int): Int = Math.max(Math.max(a, b), c)


  def main(args: Array[String]): Unit = {
    val (a, b) = read()
    val add = a + b
    val sub = a - b
    val mul = a * b
    val result = max(add, sub, mul)
    println(result)
  }
}

Measured memory_bytes: 27212
def calc(x,y):
    if y == 0:
        return x
    return calc(y,x%y)

k = int(input())
ab = 0
abc = 0
ans = 0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ab = calc(b,a)
            abc = calc(c,ab)
            ans += abc

print(str(ans))

Measured memory_bytes: 74696
function Main(input: string) {
    let splited = input.split('\n');
    let A = parseInt(splited[0]);
    let B = parseInt(splited[1]);

    console.log([1, 2, 3].filter((v) => (v !== A) && (v !== B))[0]);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(void){
    int n;
    cin>>n;
    vector<ll> b(n);
    int mid = n/2;
    for (int i=0;i<n;i++) {
        ll a;
        cin>>a;
        if (n%2==1) {
            if (i%2==0) {
                b[mid - i/2] = a;
            }
            else {
                b[mid + (i+1)/2] = a;
            }
        }
        else {
            if (i%2==0) {
                b[mid + i/2] = a;
            }
            else {
                b[mid - (i+1)/2] = a;
            }
        }
    }
    //if (n%2 == 1) reverse(b.begin(),b.end());
    for (int i=0;i<n;i++) cout<<b[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3712
import collections

N = int(input())
A = list(map(int, input().split()))
ans = collections.deque()
for i in range(N):
    if N % 2 == 0:
        if i % 2 == 0:
            ans.append(A[i])
        else:
            ans.appendleft(A[i])
    else:
        if i % 2 == 0:
            ans.appendleft(A[i])
        else:
            ans.append(A[i])
print(*ans)


Measured memory_bytes: 98872
#include <stdio.h>
#include <array>
#include <algorithm>
 
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using lli = long long int;
constexpr lli inf = 2e18;
constexpr int L = 2e5;
std::array<std::array<lli, 5>, L+1> DP;

int diff(int a, int phase){
    if(phase == 0 or phase == 4) return a;
    if(phase == 2) return (a & 1) ^ 1;
    if(a == 0) return 2;
    return a & 1;
}

int main(void){
    int n; scanf("%d", &n);
    // 0 ... 0 | 偶 ... 偶 ≥ 2 | 奇 ... 奇 | 偶 ... 偶 ≥ 2| 0 ... 0
    DP[0] = {0, 0, 0, 0, 0};
    lli V;
    REP(i, n){
        int a; scanf("%d", &a);
        V = inf;
        for(int j = 0; j < 5; ++j){
            if(V > DP[i][j]) V = DP[i][j];
            DP[i+1][j] = V + diff(a, j);
        }
    }
    lli res = inf; for(int j = 0; j < 5; ++j) if(res > DP[n][j]) res = DP[n][j];
    printf("%lld\n", res);
    return 0;
}

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

namespace ABC055B_TrainingCamp
{
    class Program
    {
        static void Main(string[] args)
        {
            var m = 1000000007;
            var N = int.Parse(Console.ReadLine());

            var power = 1L;
            for (var i = 1; i <= N; i++)
            {
                power = i * (power % m);
            }
            Console.WriteLine(power % m);
        }
    }
}


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

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



    cin.tie(0);
    ios::sync_with_stdio(false);

    int N,K;
    cin>>N>>K;
    if(N%K==0)cout << 0 <<endl;
    else cout<< 1 <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// #define int long long;

int main() {
	int i, j, d1, d2, d3, d4;
	int c[3][3];
	for(i=0; i<3; i++){
		for(j=0; j<3; j++){
			scanf("%d", &c[i][j]);
		}
	}
	d1=c[0][1]-c[0][0];
	d2=c[0][2]-c[0][1];
	d3=c[1][0]-c[0][0];
	d4=c[2][0]-c[1][0];
	(c[1][1]-c[1][0]==d1 && c[2][1]-c[2][0]==d1 && c[1][2]-c[1][1]==d2 && c[2][2]-c[2][1]==d2 && c[1][1]-c[0][1]==d3 && c[1][2]-c[0][2]==d3 && c[2][1]-c[1][1]==d4 && c[2][2]-c[1][2]==d4) ? printf("Yes") : printf("No");
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
string s;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> s;
    n = s.size();
    ll ans = 0;
    pair < int, int > tt = make_pair(0, 0);
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'A') {
            if (tt.second == 1) {
                tt = make_pair(0, 0);
                continue;
            }
            ans += tt.first;
            continue;
        }
        if (tt.second == 0) {
            if (s[i] == 'C') {
                tt.second = 1;
            }
            else {
                tt = make_pair(0, 0);
            }
        }
        else {
            if (s[i] == 'B') {
                tt.first++;
                tt.second = 0;
            }
            else {
                tt = make_pair(0, 1);
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  double n,a,ans=0;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>s;
    if(s=="JPY") ans+=a;
    else ans+=a*380000;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

let count = 0;
var numberOfStudents = 0;
var totalStudents = 0;

while(count < lines.length) {
	

	if(count%2 == 0) {
		numberOfStudents = +lines[count];
		if (numberOfStudents==0) {
			break;
		} else if(numberOfStudents>1000) {
			console.log('Number of students must not be greater than 1,000.');
			break;
		} else if(numberOfStudents<2) {
			console.log('Number of students must not be less than 2.');
			break;
		} else {
			totalStudents += numberOfStudents;
			if(totalStudents>50000) {
				break;
			}
		}
	} else {
		let scoresString = lines[count].split(' ');
		
		if(scoresString.length != numberOfStudents) {
			console.log(`Number of students is not equal to number of scores at line ${count+1}`);
			break;
		} else {
		let scores = scoresString.map(score => +score);
			var leastDiff = null;
			var currentDiff;
			for (let i = scores.length - 1; i >= 0; i--) {
				if(isNotGreaterThanMillion(scores[i])) {
					break;
				} else {
					for(j=i; j>=0; j--) {
					if(i) {
						if (leastDiff != null) {
							currentDiff = Math.abs(scores[i] - scores[j-1]);
						if (currentDiff < leastDiff) {
							leastDiff = currentDiff;
						}
					} else {
						leastDiff = Math.abs(scores[i] - scores[j-1]);
					}

				}		
					}
				}



			}
			console.log(leastDiff);
		}
	}

count++;

}

function isNotGreaterThanMillion(number) {
	if (number>1000000) {
		return true;
	}
}


Measured memory_bytes: 18484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vector<Pll> tasks;
  rep(i,n){
    ll a, b;
    cin >> a >> b;
    tasks.pb(mp(b, a));
  }
  sort(all(tasks));
  ll sum = 0;
  rep(i,n){
    sum += tasks[i].second;
    if(sum>tasks[i].first){
      print("No");
      return 0;
    }
  }
  print("Yes");
}

Measured memory_bytes: 7420
s = input()
flag1 = 0 
flag2 = 0
if int(s[:2]) == 0 or int(s[:2]) >= 13:
  flag1 = 1
if int(s[2:]) == 0 or int(s[2:]) >= 13:
  flag2 = 1
if flag1 == 0 and flag2 == 0:
  print("AMBIGUOUS")
elif flag1 == 0 and flag2 == 1:
  print("MMYY")
elif flag1 == 1 and flag2 == 0:
  print("YYMM")
else:
  print("NA")  

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	long long a,b,c,k,sum;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
	if(k <= a){
		sum = k;
	}else if(k <= a + b){
		sum = a;
	}else{
		sum = a-(k -a -b);
	}
	printf("%lld",sum);
	return 0;
} 

Measured memory_bytes: 1732
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
char s[500005];
int fail[500005];
int fail1[500005],n;
bool f[500005],g[500005];
bool all_same(){
	for(int i=2;i<=n;i++)if(s[i-1]!=s[i])return false;
	return true;
}
void get(bool *ff){
	memset(fail,-1,sizeof(fail));
	fail[0]=-1;
	for(int i=1,j=-1;i<=n;i++){
		while(j>=0&&s[i]!=s[j+1])j=fail[j];
		fail[i]=++j;
	}
	for(int i=1;i<=n;i++)if(fail[i]==0||i%(i-fail[i])!=0)ff[i]=true;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(all_same()){
		printf("%d\n%d\n",n,1);
		return 0;
	}
	get(f);
	reverse(s+1,s+n+1);
	get(g);
	if(f[n]){
		printf("1\n1\n");
		return 0;
	}
	printf("2\n");
	int cnt=0;
	for(int cut=1;cut<n;cut++){
		//cut between cut&&cut+1
		if(f[cut]&&g[n-cut])cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

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


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

    int N,M;
    cin >> N >> M;
    int a[M],b[M];
    rep(i,M){
        cin >> a[i] >> b[i];
    }
    int C[N];
    rep(i,N){
    C[i]=0;
    }
    rep(i,M){
        C[a[i]-1]++;
        C[b[i]-1]++;
    }

    rep(i,N){
        cout << C[i] << endl;
    }



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<long>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long n,W;
  cin >> n >> W;
  vector<long> w(n);
  vector<long> v(n);
  rep(i,n){
    cin >> w.at(i) >> v.at(i);
  }
  vvi dp(n+1,vi(n*1000+1,1e14));
  dp.at(0).at(0) = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=n*1000;j++){
      if(j - v.at(i) >= 0){
        dp.at(i+1).at(j) = min(dp.at(i+1).at(j), dp.at(i).at(j-v.at(i)) + w.at(i));
      }
      dp.at(i+1).at(j) = min(dp.at(i+1).at(j),dp.at(i).at(j));
    }
  }
  long rec;
  rep(i,n*1000+1){
    if(dp.at(n).at(i) <= W){
      rec = i;
    }
  }
  cout << rec << endl;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

int main() {
  int N, C, D[30][30];
  cin >> N >> C;
  for(int i = 0; i < C; i++) {
    for(int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }
  int sum[3][30] = {{}};
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      int x;
      cin >> x;
      sum[(i + j) % 3][--x]++;
    }
  }
  int64 ret = INF;
  for(int i = 0; i < C; i++) {
    for(int j = 0; j < C; j++) {
      for(int k = 0; k < C; k++) {
        if(i == j || i == k || j == k) continue;
        int64 cost = 0;
        for(int l = 0; l < C; l++) cost += 1LL * sum[0][l] * D[l][i];
        for(int l = 0; l < C; l++) cost += 1LL * sum[1][l] * D[l][j];
        for(int l = 0; l < C; l++) cost += 1LL * sum[2][l] * D[l][k];
        ret = min(ret, cost);
      }
    }
  }
  cout << ret << endl;
}

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

class AizuOnlineJudge {
    static void Main() {
        var i = Enumerable.Range(0, 2).Select(_ => Console.ReadLine().Trim().Split().Select(int.Parse).ToArray()).ToArray();
        Console.WriteLine(i[0][1] + (i[1][0] * i[0][1] - (i[0][1] - i[0][0]) * i[1][1]) / (double)(i[1][1] + i[1][2]));
    }
}



Measured memory_bytes: 20528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};


void solve(long long H, long long W){
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return;
    }
    ll ans = (H * W + 1) / 2;
    cout << ans << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  int maxData = max(x, y);
  int minData = min(x, y);
  int amari = minData;
  while (amari > 0) {
    amari = maxData % minData;
    maxData = minData;
    minData = amari;
  }
  cout << maxData << endl;
}


Measured memory_bytes: 3080
# https://atcoder.jp/contests/arc071/submissions/6325840

from itertools import accumulate

convert = {'A': 1, 'B': 2}
S = tuple(convert[x] for x in input())
T = tuple(convert[x] for x in input())
# maspyさんのやり方

acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

ans = []
Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
    # 添え字-1は変数再代入しない方が20ms速い
    ans.append('YES' if diff % 3 == 0 else 'NO')

print(*ans, sep='\n')
# 逐次printだと1000ms
# 一括だと500ms


Measured memory_bytes: 15772
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
typedef long long int ll;
int main()
{
    string s;
    cin>>s;
    ll i,j;
    ll n=s.length();
    ll dp[n+1][13];
    memset(dp,0,sizeof(dp));
    if(s[0]=='?')
    {
        for(i=0;i<10;i++)
            dp[1][i]++;
    }
    else
    {
        dp[1][s[0]-'0']++;
    }
    for(i=2;i<=n;i++)
    {
        if(s[i-1]=='?')
        {
            for(int k=0;k<10;k++)
            {
                for(j=0;j<13;j++)
                {
                    dp[i][(j*10+k)%13]+=dp[i-1][j];
                    dp[i][(j*10+k)%13]%=M;
                }
            }
        }
        else
        {
            int p=s[i-1]-'0';
            for(j=0;j<13;j++)
            {
                dp[i][(j*10+p)%13]+=dp[i-1][j];
                dp[i][(j*10+p)%13]%=M;
            }

        }
    }
    cout<<dp[n][5];
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define mod (ll)(1e9+7)
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int main()
{
        
    ll n;
    cin >> n;
    if(n <= 599)
        cout << 8 << endl;
    else if ( n <= 799)
        cout << 7 << endl;
    else if ( n <= 999)
        cout << 6 << endl;
    else if ( n <= 1199)
        cout << 5 << endl;
    else if ( n <= 1399)
        cout << 4 << endl;
    else if ( n <= 1599)
        cout << 3 << endl;
    else if ( n <= 1799)
        cout << 2 << endl;
    else if ( n <= 1999)
        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main{
    public static void main(String[] av){
         Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a[]=new int[n+1];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        for(int i=1;i<n;i++){
            for(int k=0;k<n;k++){
                System.out.print(a[k]);
                if(k!=n-1) System.out.print(" ");
            }
            System.out.println("");
            int v=a[i];
            int j=i-1;
            while(j>=0&&a[j]>v){
                a[j+1]=a[j];
                j--;
            }
            a[j+1]=v;
        }
        for(int k=0;k<n;k++){
             System.out.print(a[k]);
            if(k!=n-1) System.out.print(" ");
        }
        System.out.println("");
    }
}


Measured memory_bytes: 34604
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];





int main(){
   long long a;
   cin>>a;
   vector <long long> vec(100,0);
   vec.at(0)=2;
   vec.at(1)=1;
   for(long long i=2;i<=86;i++){
       vec.at(i)=vec.at(i-2)+vec.at(i-1);
       //cout<<vec.at(i)<<endl;
   }
   cout<<vec.at(a)<<endl;
}



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

int main() {
    string n;
    cin >> n;
    n += '0';
    n = string("0") + n;
    int r = 0;
    for(int i = n.length() - 1; i--;) {
        int a = n[i] - '0';
        if(n[i + 1] >= '6' || n[i + 1] == '5' && n[i] >= '5')
            a++;
        r += n[i] < '5' ? a : 10 - a;
        n[i] = a + '0';
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 2308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 5;
int vis[N];

int main(){
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		vis[x]++;
		sum += x;
	}
	int q;
	cin >> q;
	while(q--){
		int b,c;
		cin >> b >> c;
		if(b < c){
			sum += vis[b] * (c - b);
			vis[c] += vis[b];
			vis[b] = 0;
		}
		else if(b > c){
			sum -= vis[b] * (b - c);
			vis[c] += vis[b];
			vis[b] = 0;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4020
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int L=133,A=66;
template<class o>void qr(o&x) {
	char c=gc;int f=1;x=0;
	while(!isdigit(c)){if(c=='-')f=-1;c=gc;}
	while(isdigit(c))x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o>void qw(o x) {
	if(x/10)qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o>void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x);puts("");
}

char s[A][L],ch[A],t[L];
int len[A],n,cnt;
int ask(char *s,int l) {
	s[l+1]=0; printf("? "); puts(s+1); fflush(stdout);
	int x; qr(x); return x;
}

void solve(int l,int r) {
	if(l==r) return ;
	int mid=(l+r)>>1;
	solve(l,mid); if(len[l]^n) solve(mid+1,r);
	int a=len[l],b=len[++mid],i=1,j=1,x;
	len[l]=0;
	while(i<=a&&j<=b) {
		t[++len[l]]=s[l][i];
		x=len[l]; for(int k=j;k<=b;k++) t[++x]=s[mid][k];
		if(n-ask(t,x)==x) i++;
		else t[len[l]]=s[mid][j++];
	}
	while(i<=a) t[++len[l]]=s[l][i++];
	while(j<=b) t[++len[l]]=s[mid][j++];
	memcpy(s[l],t,sizeof t);
}

int main() {
	for(int i=0;i<26;i++) ch[++cnt]='a'+i,ch[++cnt]='A'+i;
	for(int i=0;i<=9;i++) ch[++cnt]='0'+i;
	for(int i=1;i<=cnt;i++) {
		for(int j=1;j<=128;j++) t[j]=ch[i];
		len[i]=128-ask(t,128);
		n+=len[i];
		for(int j=1;j<=len[i];j++) s[i][j]=ch[i];
	}
	solve(1,A);  s[1][n+1]=0; printf("! %s\n",s[1]+1);
	return 0;
}


Measured memory_bytes: 3800
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max 101

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main()
{
    int n, i, cnt=0, flag=0;
    char s[max];
    
    scanf("%d%s", &n, s);
    
    if (n%2==0) {
        for (i=0; i<n/2; i++) {
            if (s[i]==s[i+n/2]) {
                cnt++;
            }
        }
    } else {
        flag++;
    }
    
    if (flag==0&&cnt==n/2) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}



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

int main() {  
	int b,a;
	string s,t,tmp;
	cin >> s >> t;
	cin >> a >> b;
	cin >> tmp;
	string res;
	if (tmp == s)  printf("%d %d",a-1,b);
	else printf("%d %d",a,b-1);
	
  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

X, N = map(int, input().split())

p = list(map(int, input().split()))

if N == 0:
    print(X)
    exit()

set_p = set(p)

up = down = X
if X not in set_p:
    print(X)
    exit()
    
while True:
    up = up+1
    down = down-1

    if down not in set_p:
        print(down)
        exit()
    if up not in set_p:
        print(up)
        exit()

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  map<char, int> varied;
  bool yes=true;
  for(int i=0; i<N; i++){
    if(varied.count(S.at(i))){
      yes=false;
      break;
    }
    else{
    varied[S.at(i)] = 1;
    }
  }
  if(yes) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_1_a
{
    class Program
    {
        static void Main()
        {
            for (int i = 1; i > 0; i ++)
            {
                int x = int.Parse(Console.ReadLine());
                if (x == 0) break;
                else Console.WriteLine("Case {0}: {1}",i,x);
            }
        }
    }
}



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

typedef long long ll;

int main(){
  ll n,m;
  cin >> n >> m;
  ll ans=1;
  if(n==1){
    cout << m << endl;
  }
  else{
    for(ll i=2;i*i<=m;i++){
      int count=0;
      ll k=m;
      while(k%i==0&&count<n){
        k/=i;
        count++;
      }
      if(count==n){
        ans=i;
      }
    }
    cout << ans << endl;
  }
}


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

using namespace std;


vector<int> a;

void print_a() {
  for(unsigned long i  = 0; i < a.size(); i++) {
    cout << a.at(i);
    if(i < a.size() - 1) {
      cout << " ";
    }
    else {
      cout << endl;
    }
  }
}

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

  a.resize(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  print_a();
  
  for(int i = 0; i < n - 1; i++) {
    for(int j = i; j >= 0; j--) {
      if(a[j + 1] < a[j]) {
	int t = a[j + 1];
	a[j + 1] = a[j];
	a[j] = t;
      }
      else {
	break;
      }
    } 
    print_a();
 }

  return 0;
}



Measured memory_bytes: 3088
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=2e5+5;
int a[N],b[N],nm,n,m,ans,p[N],f[N][35],sum[N];
double val[N];

bool cmp(int x,int y){
	return val[x]<val[y];
}

signed main(){
	read(n,m);
	for(int i=1;i<=n;i++) read(a[i],b[i]),p[i]=i,val[i]=a[i]?1.0*(b[i]+1)/a[i]:1e15;
	sort(p+1,p+1+n,cmp);
	for(int i=0;i<=n;i++) for(int j=1;j<=30;j++) f[i][j]=m+1;
	for(int i=1;i<=n;i++){
		int x=p[i];
		if(!a[x]){
			sum[++nm]=b[x]+1;
			continue;
		}
		for(int j=1;j<=30&&j<=i;j++) f[i][j]=min(f[i-1][j],f[i-1][j-1]+1+(f[i-1][j-1]*a[x]+a[x]+b[x]));
	}
	sort(sum+1,sum+1+nm);
	for(int i=1;i<=nm;i++) sum[i]+=sum[i-1];
	for(int i=0;i<=nm;i++) for(int j=0;j<=30&&j<=n;j++) if(f[n-nm][j]+sum[i]<=m) ans=max(ans,j+i); else break;
	write(ans);
}

Measured memory_bytes: 66040
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n = int(input())
    S = input()

    l = 0
    r = n-1
    ans = 0
    while l<r:
        while l<n and S[l] != "W":
            l += 1
        while r>0 and S[r] != "R":
            r -= 1
        # log(l,r)
        if l<r:
            ans += 1
        l+=1
        r-=1
    print(ans)

main()

Measured memory_bytes: 69148
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

#define MOD 1000000007

using namespace std;

int main()
{
	string a, b;
	char input[12];

	scanf("%s", input);
	a = input;
	scanf("%s", input);
	b = input;

	if (a.size() != b.size() - 1)
	{
		printf("No\n");

		return 0;
	}

	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] != b[i])
		{
			printf("No\n");

			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 3212
/*
[abc122] D - We Like AGC
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100;
const ll MOD = 1e9 + 7;
// const char cs[4] = {'A', 'C', 'G', 'T'};

int N;
ll dp[MAX_N + 1][4][4][4];

vector<int> to_arr(int p) {
    return {p & 3, (p >> 2) & 3, (p >> 4) & 3, (p >> 6) & 3};
}

bool is_ok(int p) {
    vector<int> s = to_arr(p);
    for (int i = 0; i < 4; i++) {
        if (i > 0) {
            swap(s[i - 1], s[i]);
        }
        for (int j = 0; j < 2; j++) {
            if (s[j] == 0 && s[j + 1] == 2 && s[j + 2] == 1) {
                return false;
            }
        }
        if (i > 0) {
            swap(s[i - 1], s[i]);
        }
    }

    return true;
}

ll solve() {
    dp[0][3][3][3] = 1;
    for (int i = 1; i <= N; i++) {
        for (int p = 0; p < 256; p++) {
            if (is_ok(p)) {
                vector<int> s = to_arr(p);
                (dp[i][s[1]][s[2]][s[3]] += dp[i - 1][s[0]][s[1]][s[2]]) %= MOD;
            }
        }
    }

    ll ans = 0;
    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            for (int l = 0; l < 4; l++) {
                (ans += dp[N][j][k][l]) %= MOD;
            }
        }
    }

    return ans;
}

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256