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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define arr array

template<typename T> void umin(T& a,T b){a = min(a,b);}
template<typename T> void umax(T& a,T b){a = max(a,b);}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}


void solve(){

    int n,k;
    cin >> n >> k;
    int p[n+1];
    int c[n+1];
    for(int i=1;i<=n;i++)
        cin >> p[i];
    for(int i=1;i<=n;i++)
        cin >> c[i];
    ll ans = -oo;
    for(int i=1;i<=n;i++){
        int ind = i;
        vector<int> cur;
        vector<long long> prefix_score;
        long long tot = 0;
        while(true){
            ind = p[ind];
            tot += c[ind];
            cur.push_back(ind);
            prefix_score.push_back(tot);
            if(ind == i)break;
        } 
        int sz = cur.size();
        for(int j=0;j<sz;j++){
            if( j+1 > k)break;
            int cnt = (k-j-1)/sz;
            if(tot <= 0){
                umax(ans , prefix_score[j]);
            }else{
                umax(ans , prefix_score[j] + cnt*tot);
            }
        }
        
    }
    cout << ans;
    
}


int main(){
    #ifndef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;

template<typename T>
void min_self(T& a, T b)
{
    a = min(a,b);
}

template<typename T>
void max_self(T& a, T b)
{
    a = max(a,b);
}

const int Nax=1000 + 5;

char matrix[Nax][Nax];

void add_self(int& dpTo, int dtFrom)
{
    dpTo += dtFrom;
    if(dpTo >= MOD)
    {
      dpTo -= MOD;
    }
}

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int H, W;
    scanf("%d%d",&H,&W);
    
    for(int i=0; i<H; ++i)
    {
        scanf("%s",matrix[i]);
    }

    vector<vector<int>> dp(H,vector<int>(W));
    
    dp[0][0] = 1;
    
    vector<pair<int,int>> nn = {{0,1},{1,0}};

    for(int i=0; i<H; ++i)
    {
        for(int j=0; j<W; ++j)
        {
            for(auto& n: nn)
            {
                if(i+n.first < H && j+n.second < W && matrix[i+n.first][j+n.second] == '.')
                {
                    add_self(dp[i+n.first][j+n.second],dp[i][j]);
                }
            }
        }
    }
    
    cout << dp[H-1][W-1];
    
}


Measured memory_bytes: 5248
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() {
	ios::sync_with_stdio(false);
    //freopen("input.in","r",stdin);
 	//freopen("output.out","w",stdout);
	ll k;cin>>k;
	if(k == 0) {
		cout<<"2\n0 0\n";
		return 0;
	}

	ll z = (k-1)/50;

	vector<ll> A(50, 50+z);

	ll y = 50-k+50*z;
	while (y--) {
		rep(i, 49) A[i] += 1;
		A[49] -= 50;

		int i = 49;
		while(i > 0 and A[i] < A[i-1]) {
			swap(A[i], A[i-1]);
			i--;
		}
	}

	cout<<"50\n";
	rep(i, 50) cout<<A[i]<<" ";cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 

int  A(int x){
    if(x>=0)return x;
    else return -x;
}

int ans[1010][1010];

int main(void){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans[i][j]=0;
        }
    }
    for(int i=0;i<b;i++){
        for(int j=0;j<a;j++)ans[i][j]=1;
    }
    for(int i=b;i<h;i++){
        for(int j=a;j<w;j++){
            ans[i][j]=1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(j==w-1)cout<<ans[i][j]<<endl;
            else cout<<ans[i][j];
        }
    }
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int wall[208][208];
int rate[10][10];

int main(){
    int N; cin>>N;
    string s; cin>>s;
    int a = 0, b = 0;
    int c = 0;
    rep(i,N){
        if(s[i] == '(')a++;
        else b++;
        c = max(c,b-a);
    }
    rep(i,c){
        cout<<'(';
    }
    cout<<s;
    rep(i,a+c-b){
        cout<<')';
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define RD(v,n) for(ll i =0;i<n;i++ ) cin>>v[i]
#define bolt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
	bolt;
    ll a,b,c;
    cin>>a>>b>>c;
    ll sum = a+b+c;
    if( sum  >= 22 ){
        cout<<"bust\n";
    }
    else{
        cout<<"win\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;

 struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ
    vector<int>sz;//要素数

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
            sz[i]=1;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
            sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
            sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};

void solve(){
	int n,q;
	cin>>n>>q;
	UF tree(n);
	while(q--){
		int t,u,v;
		cin>>t>>u>>v;
		if(t==0)tree.unite(u,v);
		else{
			cout<<tree.same(u,v)<<"\n";
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 5480
import java.util.*;

class Main{

    public static void main(String[] args){
	int[] a = new int[3];
	int[] b = new int[2];
	Scanner in = new Scanner(System.in);

	a[0] = in.nextInt();
	a[1] = in.nextInt();
	a[2] = in.nextInt();
	b[0] = in.nextInt();
	b[1] = in.nextInt();

	int min1=5000,min2=5000;

	for(int i=0;i<3;i++){
	    if(min1>a[i])min1=a[i];
	}
	for(int i=0;i<2;i++){
	    if(min2>b[i])min2=b[i];
	}

	System.out.println(min1+min2-50);


    }

}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTaxIncrease solver = new CTaxIncrease();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTaxIncrease {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int a = in.nextInt();
            int b = in.nextInt();
            int i = 1;
            while (i < 10000) {
                int e = (int) ((double) i * 0.08);
                int t = (int) ((double) i * 0.1);
                if (e == a && t == b) break;
                i++;
            }

            out.println(i == 10000 ? -1 : i);

        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>> 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double 
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
bool prime (lli k)
{
    if (k==1||k==0) return 0;
    bool flag=1;
    lli a=sqrt(k);
    for (int i=2;i<=a;i++)
    {
        if (k%i==0)
        {flag=0;break;}
    }
    return flag;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    fio;
    lli t;
    t=1;
    while (t--)
    {
        lli n;
        cin>>n;
        if (n>=400&&n<=599)
        {cout<<"8";exit(0);}
        if (n>=600&&n<=799)
        {cout<<"7";exit(0);}
        if (n>=800&&n<=999)
        {cout<<"6";exit(0);}
        if (n>=1000&&n<=1199)
        {cout<<"5";exit(0);}
        if (n>=1200&&n<=1399)
        {cout<<"4";exit(0);}
        if (n>=1400&&n<=1599)
        {cout<<"3";exit(0);}
        if (n>=1600&&n<=1799)
        {cout<<"2";exit(0);}
        if (n>=1800&&n<=1999)
        {cout<<"1";exit(0);}
    }
    return 0;
}

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

#define maxn 10010
int n,sum,eve,cnt;
int num[maxn];

int main()
{
    while(cin>>n&&n)
    {
        sum=0;  eve=0;  cnt=0;
        for(int i=0;i<n;i++)
        {
            cin>>num[i];
            sum+=num[i];
        }
        eve=sum/n;
        for(int i=0;i<n;i++)
        {
            if(num[i]<=eve) cnt++;
        }
        cout<<cnt<<'\n';
    }
    getchar();getchar();
    return 0;
}


Measured memory_bytes: 3108
def L(l,a):
    return ((l-1)//a)*a+a

def R(r,a):
    return (r//a)*a+a-1
K = int(input())
x = list(map(int,input().split()))
l=2
r=2
for i in range(K):
    a = x.pop()
    l = L(l,a)
    r = R(r,a)
    if l > r:
        l = r = -1
        print(l)
        exit()

print(l,r)


Measured memory_bytes: 14252
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    n++;
    V<int> a(n);
    int cnt=0;
    for(int i=1;i<n;i++)cin>>a[i];
    V<int> ans(n,0);
    for(int i=n-1;i>=1;i--){
        int sum=0;
        for(int j=1;i*j<n;j++){
            sum^=ans[i*j];
        }
        if(sum!=a[i]){
            ans[i]=1;
            cnt++;
        }
    }
    cout<<cnt<<"\n";
    for(int i=1;i<n;i++)if(ans[i])cout<<i<<" ";
    if(cnt)cout<<"\n";
}

Measured memory_bytes: 2560
// finish date: 2018/09/24
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int N, M;
vi fact;


//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}


//割り算(分母だけ)  -  逆元(求めたい数とbigmodを渡す)
int divide(int a, int p = bigmod, int b = -1) {
    if (b < 0) b = p - 2;  //int gyakugen(int a, int p, int b = p - 2とできなかったため。)
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        int d = divide(a, p, b / 2);
        return mul(d, d);
    } else {
        return mul(a, divide(a, p, b - 1));
    }
}


//nやkが大きな場合nCkをO(1)で求めるようにプログラムを適切に変更する。
int nCk_gyakugen(int n, int k, int p = bigmod) {
    if (k == 0) return 1;
    if (n == 0) 0;
    if (n < k) return 0;
    int denominator = fact[n];
    int molecule1 = fact[k];
    int molecule2 = fact[n - k];
    return mul(denominator, mul(divide(molecule1), divide(molecule2)));
}


//重複組み合わせ
int nHk(int n, int k) {
    return nCk_gyakugen(n + k - 1, k);
}


//素因数分解
map<int, int> p_fact(int n) {
    map<int, int> mp;
    int i = 2;
    while (n >= i * i) {
        while (n % i == 0) mp[i]++, n /= i;
        i++;
    }
    if (n != 1) mp[n]++;
    return mp;
}


int main() {
    cin >> N >> M;
    map<int, int> mp = p_fact(M);
    fact = vi(N + 50, 0);
    fact[0] = 1;
    FOR(i, 1, fact.size()) {
        fact[i] = mul(fact[i - 1], i);
    }
    int ans = 1;
    for (auto e:mp) {
        ans = mul(ans, nHk(N, e.second));
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
s = [int(i) for i in list(input())]

num_li = []
for i in range(len(s)-2):
    num_li.append(s[i]*100+s[i+1]*10+s[i+2])
if 753 in num_li:
    print(0)
else:
    print(min([abs(753-n) for n in num_li]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef std::vector<ll> vi;
typedef pair < ll , ll > pll;
 
ll MOD = 1e9+7;
 
#define pb push_back
#define mp make_pair
 
ll mx(ll a , ll b){if (a > b) return a;return b;}
ll mx(ll a , ll b , ll c){if (mx(a,c) > b) return mx(a,c);return b;}
ll mn(ll a , ll b){return a + b - mx(a , b);}
ll mod (ll x ){if (x % MOD < 0) return(mod (x + MOD));return x % MOD;}
 
ll gcd (ll x , ll y){
	if (y == 0)return x;
	return gcd( y , x%y );
}
 
ll lcm(ll x, ll y, ll z){
 	
 	if (x <= 0 or y <= 0 or z <= 0) return 0 ;

	ll l = x * y / gcd(x , y);
	return l * z / gcd( l , z); 
}
 
bool ip(ll x){
 
	for (ll i = 2; i <= sqrt(x) ; i ++){
		if (x % i == 0 )return false;
	}
	return true;
}
 

ll n;

ll loc[300005];


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

 	for (ll i = 0 ;  i < n ; i ++){
 		ll x; cin >> x;
 		loc[x] = i;
 	}

 	ll c = 0;
 	ll l = -1;
 	ll res = 0;
 	for (ll i = 1 ; i <= n ; i ++){
 		
 		if (loc[i] > l ){
 			c ++;
 			l = loc[i];
 		}else{
 			l = loc[i];
 			c = 1;
 		}

 		res = mx(res , c);
 	}

 	cout << n -res;

	return 0;
 
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int n, a, b, c, d;
  int count;

  while (scanf("%d", &n) != EOF) {
    count = 0;
    if (n > 36) {
      printf("%d\n", count);
    } else {
      for(a = 0 ; a <= 9 ; a++)
        for(b = 0 ; b <= 9 ; b++)
          for(c = 0 ; c <= 9 ; c++)
	    for(d = 0 ; d <= 9 ; d++)
	      
	      if(n == a + b + c + d) count++;
      printf("%d\n", count);
    }
  }

  return 0;
}

Measured memory_bytes: 596
const N = parseInt(require("fs").readFileSync("/dev/stdin", "utf8"), 10);

var total = 0;
for (var i = 0; i <= N; i++) {
  if ((Math.floor(Math.log10(i)) + 1) % 2 == 1) {
    total++;
  }
}
console.log(total);


Measured memory_bytes: 9036
let n = read_int ()
let cs = Array.make n 0
let rec f n a = if n <= 0 then a else f (n - 1) (2 * a mod 1000000007)
let _ = for i = 1 to n do Scanf.scanf " %d" @@ fun a -> cs.(a / 2) <- cs.(a / 2) + 1 done; for i = 0 to n / 2 + n mod 2 - 1 do if i = 0 && cs.(i) <> 2 - n mod 2 || i > 0 && cs.(i) <> 2 then (print_endline "0"; exit 0) done; Printf.printf "%d\n" @@ f (n / 2) 1

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    int bit;
    bit = 0;
    int A[N];
    rep(i,N) {
        int tmp;
        cin >> tmp;
        bit = bit ^ tmp;
        A[i] = tmp;
    } 
    rep(i,N) {
        int ans = bit ^ A[i];
        cout << ans << endl;
    }
} 


Measured memory_bytes: 4384
def merge(A, left, mid, right, c):
    global counter
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1)
    R = [0] * (n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = 1000000000
    R[n2] = 1000000000
    i = 0
    j = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else : 
            A[k] = R[j]
            j += 1
    L.pop()
    R.pop()
    return c

def mergeSort(A, left, right, c):
    if left+1 < right:
        mid = int((left + right)/2)
        c = mergeSort(A, left, mid, c)
        c = mergeSort(A, mid, right, c)
        c = merge(A, left, mid, right, c)
    return c

if __name__ == '__main__':
    num = int(input())
    m = list(map(int,input().split()))
    c = 0
    c = mergeSort(m, 0, num, c)
    print(' '.join(map(str,m)))
    print(str(c))


Measured memory_bytes: 66524
#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}


vector<pair<int, string> > gen(int n, string const&s){
    vector<pair<int, string> > ret;
    ret.reserve(1<<n);
    for(int m=0;m<(1<<n);++m){
        string a, b;
        for(int i=0;i<n;++i){
            if((m>>i)&1){
                a.push_back(s[i]);
            } else {
                b.push_back(s[i]);
            }
        }
        reverse(b.begin(), b.end());
        ret.emplace_back(a.size(), a+b);
    }
    sort(ret.begin(), ret.end());
    return ret;
}
vector<pair<int, string> > gen2(int n, string const&s){
    vector<pair<int, string> > ret;
    ret.reserve(1<<n);
    for(int m=0;m<(1<<n);++m){
        string a, b;
        for(int i=0;i<n;++i){
            if((m>>i)&1){
                a.push_back(s[i]);
            } else {
                b.push_back(s[i]);
            }
        }
        reverse(b.begin(), b.end());
        ret.emplace_back(b.size(), b+a);
    }
    sort(ret.begin(), ret.end());
    return ret;
}

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

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

    auto A = gen(n, s.substr(0, n));
    auto B = gen2(n, s.substr(n, n));
    ll ans = 0;
    for(auto &e:B){
        ll add = upper_bound(A.begin(), A.end(), e) - lower_bound(A.begin(), A.end(), e);
        //cerr << e.first << " " << e.second << " : " << add << "\n";
        ans+=add;
    }
    cout << ans << "\n";



    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


Measured memory_bytes: 45796
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>

#include <string>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  
  cout << a[0] + a[1] << endl;
  return (0);
}

Measured memory_bytes: 256
N, *A = map(int, open(0).read().split())

x = [0] * (N + 1)
ans = []
for i in reversed(range(1, N + 1)):
    tmp = 0
    for j in range(i, N + 1, i):
        tmp += x[j]

    if tmp % 2 != A[i - 1]:
        x[i] += 1
        ans.append(i)

print(len(ans))
if ans:
    print(*ans)



Measured memory_bytes: 102488
n = int(input())
AB = []
for i in range(n):
    a,b = map(int,input().split())
    ab = (a,b)
    AB.append(ab)

AB.sort(key = lambda x : x[1])

sum = 0
flag = 0
for i in range(n):
    sum = sum + AB[i][0]
    if sum > AB[i][1]:
        flag = 1
        break

if flag == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 31860
#include<bits/stdc++.h>
using namespace std;
int n,m,a[81][81],b[81][81],c[81][81];
bool f[81][81][6401];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf("%d",&b[i][j]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	c[i][j]=abs(a[i][j]-b[i][j]);
	f[1][1][c[1][1]]=1;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	for(int k=0;k<=6400;k++)
	if(f[i][j][k])
	{
		if(i!=n)
		{
			f[i+1][j][abs(k-c[i+1][j])]=1;
			if(k+c[i+1][j]<=6400)
			f[i+1][j][k+c[i+1][j]]=1;
		}
		if(j!=m)
		{
			f[i][j+1][abs(k-c[i][j+1])]=1;
			if(k+c[i][j+1]<=6400)
			f[i][j+1][k+c[i][j+1]]=1;
		}
	}
	for(int i=0;i<=6400;i++)
	if(f[n][m][i])
	{
		printf("%d",i);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 40704
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S;
    cin >> S;
    vector<int> A(3);
    for (int i = 0; i < S.size(); i++) {
        A.at(S.at(i) - 'a')++;
    }
    sort(ALL(A));
    if (A.at(2) - A.at(0) >= 2) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	int k,a,b;cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;return 0;
		}
	}
	cout<<"NG"<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

void a()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b)
    {
        cout << c << endl;
    }else if(a == c)
    {
        cout << b << endl;
    } else{
        cout << a << endl;
    }
    return;
}

void b()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        s[i] = temp;
    }
    for(int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; ++j) {
            int count = 0;
           if(s[i][j] == '.')
           {
               int up, down, right, left;
               up = i > 0 ? i - 1 : -1;
               down = i < h - 1 ? i + 1 : -1;
               right = j < w -1 ? j + 1 : -1;
               left = j > 0 ? j -1 : -1;
               if(up != -1)
               {
                   if(s[up][j] == '#')
                   {
                      count++;
                   }
                   if(right != -1)
                   {
                       if(s[up][right] == '#')
                       {
                           count++;
                       }
                   }
                   if(left != -1)
                   {
                       if(s[up][left] == '#')
                       {
                           count++;
                       }
                   }
               }
               if(down != -1)
               {
                   if(s[down][j] == '#') {
                      count++;
                   }
                   if(right != -1) {
                       if(s[down][right] == '#')
                       {
                           count++;
                       }
                   }
                   if(left != -1)
                   {
                       if(s[down][left] == '#')
                       {
                           count++;
                       }
                   }
               }
               if(right != -1)
               {
                   if(s[i][right] == '#') count++;
               }
               if(left != -1)
               {
                   if(s[i][left] == '#') count++;
               }
               s[i][j] = '0' + count;
           }
        }
    }
    for(int i = 0; i < h; i++)
    {
        for(int j =0; j < w ; j++)
        {
            cout << s[i][j];
        }
        cout << endl;
    }
}

void c()
{

}

void d()
{

}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char c;
  cin >> c;

  string s = "aeiou", t = "consonant";
  for (int i = 0; i < 6; i++) {
    if (c == s[i]) t = "vowel";
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
const int mod = 998244353;
vector<int> fac;
long long inv(long long a, long long b = mod){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int choose(int a, int b){
//    cout << a << " " << b <<endl;
    assert(b <= a && b >= 0);
    int ans = fac[a] * inv(fac[b]);
    assert(ans >= 0);
    ans %= mod;
    ans *= inv(fac[a-b]);
    assert(ans >= 0);
    ans %= mod;
    assert(ans >= 0);
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n,m;cin >> n >> m;
    fac.resize(n+m*5 + 2);
    fac[0] = 1;
    FOR1(i, n+m*5)fac[i] = fac[i-1]*i, fac[i] %= mod;

    int ans = choose(n-1 + 3*m, n-1);
    ans -= choose(m-1 + n-1, n-1)*n;
    ans %= mod;
    for(int odds = m+1; odds <= min(n, 3*m); odds++){
        if((3*m - odds) % 2)continue;
        //debug(odds);
        int distribute = choose(n, odds);
        int remains = 3*m - odds; 

        int toSub = choose((remains/2) + n-1, n-1);
        //cout << odds << " " << distribute << " " << toSub <<endl;
        int temp = toSub * distribute;
        temp %= mod;
        ans -= temp;
        ans %= mod;
        //while(ans < 0)ans += mod;
    }
    //debug(ans);
    while(ans < 0)ans += mod;
    cout <<ans;

}

Measured memory_bytes: 27648
#include<deque>
#include<queue>
#include<map>
#include<string>
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define scanf_s scanf
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);

int main(void){
	llint N,na,i,j;
	deque<llint> retuz;//mae
	deque<llint> retuk;//usiro
	scanf("%lld",&N);
	na=N;i=1;
	while(true){
		if(na==1){retuz.pub(i);i++;break;}
		if(na%2==0){
			na--;retuz.pub(i);
		} else{
			na--;na=na/2;retuk.push_front(i);
		}
		i++;
	}
	na=retuz.size()+retuk.size();
	printf("%lld\n",na*2);
	for(i=na;i>0;i--){
		printf("%lld ",i);
	}
	for(i=0;i<retuz.size();i++){
		printf("%lld ",retuz[i]);
	}
	for(i=0;i<retuk.size();i++){
		if(i!=retuk.size()-1){
			printf("%lld ",retuk[i]);
		} else{
			printf("%lld\n",retuk[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200010)

mod = 1000000007

def pow_mod(x, y):
    res = 1
    while y > 0:
        if y % 2:
            res *= x
            res %= mod
        x *= x
        x %= mod
        y //= 2
    return res


def inverse(x):
    return pow_mod(x, mod-2)

N = int(input())
E = []
for i in range(N):
    E.append([])
for i in range(N-1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)
kai = [1] * (N+1)
fkai = [1] * (N+1)

for i in range(N):
    kai[i+1] = kai[i] * (i+1) % mod

fkai[N] = inverse(kai[N])

for i in range(N-1, 0, -1):
    fkai[i] = fkai[i+1] * (i+1) % mod

child = [0] * N
dp = [0] * N
ans = [0] * N

def dfs1(now, par):
    res = 1
    for to in E[now]:
        if to == par:
            continue
        res += dfs1(to, now)
    child[now] = res
    return res

def dfs2(now, par):
    res = kai[child[now]-1]
    for to in E[now]:
        if to == par:
            continue
        res *= fkai[child[to]]
        res %= mod
        res *= dfs2(to, now)
        res %= mod
    dp[now] = res
    return res

def dfs3(now, par):
    ans[now] = dp[now]
    seki = 1
    for to in E[now]:
        if to == par:
            continue
        seki *= dp[to]
        seki %= mod
    for to in E[now]:
        if to == par:
            continue
        m_now = dp[now]
        m_to = dp[to]
        m_c_now = child[now]
        m_c_to = child[to]
        dp[now] *= kai[N-1-child[to]] * kai[child[to]] % mod * fkai[N-1] % mod * inverse(dp[to]) % mod
        dp[now] %= mod
        dp[to] *= kai[N-1] * dp[now] % mod * fkai[N-child[to]] % mod * fkai[child[to]-1] % mod
        dp[to] %= mod
        child[now] -= child[to]
        child[to] = N
        dfs3(to, now)
        dp[now] = m_now
        dp[to] = m_to
        child[now] = m_c_now
        child[to] = m_c_to

dfs1(0, -1)
dfs2(0, -1)
dfs3(0, -1)

for i in range(N):
    print(ans[i])


Measured memory_bytes: 151384
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    if(k>=n){cout<<0<<endl;return 0;}
    vector<long long>h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    cout<<accumulate(h.begin(),h.end()-k,0LL)<<endl;
    return 0;
}

Measured memory_bytes: 1792
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>str;

      if(str[2]==str[3] && str[4]==str[5])
        cout<<"Yes"<<endl;

      else cout<<"No"<<endl;













}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 1e6+6;
const ll inf =1e9;

int main(){
	fastio;
	ll tc,n,m,a,b;
	tc=1;
//	cin>>tc;
	while(tc--){
		cin>>n>>m;
		ll sum=0;
		f(i,0,m) cin>>a, sum+=a;
		if(sum>n) cout<<"-1\n";
		else cout<<n-sum<<endl;
	}
}

Measured memory_bytes: 3656
h, w = gets.split.map(&:to_i)
a = [[?#] * (w + 2)] + (1..h).map { [?#] + gets.chomp.split("") + [?#] } + [[?#] * (w + 2)]

xs = ys = xp = yp = nil
soldiers = []
(1..h).each do |y|
  (1..w).each do |x|
    if a[y][x] == ?#
      next
    elsif a[y][x] == ?%
      xs, ys = x, y
    elsif a[y][x] == ?@
      xp, yp = x, y
    elsif a[y][x] == ?$
      soldiers << [x, y]
    end
    a[y][x] = ?.
  end
end

dist = { [xs, ys] => 0 }
queue = [[xs, ys]]
until queue.empty?
  x, y = queue.shift
  d = dist[[x, y]]
  [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dx, dy|
    u, v = x + dx, y + dy
    next if a[v][u] == ?# or dist[[u, v]]
    dist[[u, v]] = d + 1
    queue << [u, v]
  end
end

puts dist[[xp, yp]] < (soldiers.map {|x, y| dist[[x, y]]}.compact.min || Float::INFINITY) ? 'Yes' : 'No'



Measured memory_bytes: 15140
fun main(args: Array<String>) {
    val n = readInt()
    val s = List(n) { readInt() }.sorted()

    var sum = s.sum()

    if (sum % 10 != 0) {
        println(sum)
        return
    }

    val a = s.firstOrNull() { it % 10 != 0 }
    if (a == null) {
        println(0)
        return
    }

    println(sum - a)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

Measured memory_bytes: 39152
#include<iostream>

using namespace std;

long long f[10000009];

int main()
{
  long long n, s=0;
  cin >> n;
  for(int i=1;i<=n;i++)
  {
    for(int j = i;j<=n;j+=i)
    {
      f[j]++;
    }
  }
  
  for(int i = 1;i<=n;i++)
  {
    s+=f[i]*i;
  }
  cout<<s<<endl;
  
}

Measured memory_bytes: 81308
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
typedef long long ll;
using namespace std;
 

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    vector<int> c(n-1);
    rep(i,n-1) cin >> c[i];
    int ans=0; int pre=-11;
    rep(i,n){
        ans+=b[a[i]-1];
        if(pre+1==a[i]) ans+=c[pre-1];
        pre=a[i];
    }
    cout << ans << endl;
    return 0;
}


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

void calcGCDLCM(unsigned int in1, unsigned int in2,
    unsigned int* GCD, unsigned int* LCM) {
  unsigned int num1, num2;
  unsigned int denom=2;
  unsigned int tempGCD=1;

  if(in1>in2) {
    num1=in2;
    num2=in1;
  } else {
    num1=in1;
    num2=in2;
  }

  while(denom <= num1) {
    if(num1 % denom == 0 && num2 % denom == 0) {
      tempGCD *= denom;
      num1 /= denom;
      num2 /= denom;
    } else {
      denom++;
    }
  }

  *GCD = tempGCD;
  *LCM = tempGCD*num1*num2;
}

int main() {
  unsigned int in1, in2;
  unsigned int GCD, LCM;

  while(cin >> in1 >> in2) {
    calcGCDLCM(in1,in2,&GCD,&LCM);
    cout << GCD << " " << LCM << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        if(s.equals("SUN")){System.out.println(7);}
        if(s.equals("MON")){System.out.println(6);}
        if(s.equals("TUE")){System.out.println(5);}
        if(s.equals("WED")){System.out.println(4);}
        if(s.equals("THU")){System.out.println(3);}
        if(s.equals("FRI")){System.out.println(2);}
        if(s.equals("SAT")){System.out.println(1);}
	}
}


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

int main(){
    ll n,k;
    cin>>n>>k;
    ll A[n+1];
    for(ll i = 1; i <= n; i++){
        cin>>A[i];
    }
    ll dp[n+1];
    memset(dp,MOD,sizeof dp);
    dp[0] = 0;
    dp[1] = 0;
    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= k && i+j <= n; j++){
            dp[i+j] = min(dp[i+j],dp[i]+abs(A[i]-A[i+j]));
        }
    }
    cout<<dp[n];
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


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

int main(){
  int n,i;
  cin >> n;
  vector<string> s(n);
  for(i=0;i<n;i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(),s.end());
  
  vector<int> a(n);
  a.at(0)=1;
  int m=1;
  for(i=1;i<n;i++){
    if(s.at(i-1)==s.at(i)){
      a.at(i)=a.at(i-1)+1;
    }else{
      a.at(i)=1;
    }
    if(m<a.at(i)){
      m=a.at(i);
    }
  }
  
  for(i=0;i<n;i++){
    if(a.at(i)==m){
      cout << s.at(i) << endl;
    }
  }
}

Measured memory_bytes: 15104
a = []
for i in range(26):
    a.append(chr(97+i))
for i in range(26):
    a.append(chr(65+i))

while 1:
    n = int(input())
    if n == 0: break
    k = list(map(int, input().split()))
    s = input()
    for i in range(len(s)):
        print(a[(a.index(s[i]) - k[i%n])%52], end='')
    print()



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef priority_queue<int> maxpq;
const long double PI = 3.14159265358979323846264338327950;
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vi arr(n);
    unordered_map<int,int>m;
    int sum=0ULL;
    fo(i,n){
        cin>>arr[i];
        m[arr[i]]++;
        sum+=arr[i];
    }
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        auto temp = m.find(a);
        if(temp!=m.end()){
            int freq = m[a];
            sum = sum - freq*a + freq*b;
            m.erase(a);
            m[b]+=freq;
        }

        cout<<sum<<endl;

    }




}


Measured memory_bytes: 7368
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int A,B;
int main() {
	cin>>A>>B;
	if(abs(A-B)%2) {
		puts("IMPOSSIBLE");
	}else {
		cout<<(A+B)/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a,int b){
    if(b>a){
        int tmp=a;
        a=b;
        b=tmp;
    }
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
long long lcm(int a,int b){
    long long tmp=gcd(a,b);
    return (long long)a*b/tmp;
}
int main()
{   int a,b;
    scanf("%d%d",&a,&b);
    long long ans=lcm(a,b);
    printf("%lld",ans);
    return 0;
}


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

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

ll findGCD(ll arr[], int n)
{
    ll result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}
int main()
{
    ll k;
    ll sum = 0;
    cin>>k;
    for(ll i =1;i<=k;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            for(ll p=1;p<=k;p++)
            {
                ll a[3] = {i,j,p};
                //cout<<i<<" "<<j<<" "<<k<<endl;
                sum = sum+findGCD(a,3);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main() 
    { 
        ll n, a, b;
        ll s=0,q=0,p=0;
        cin>>n>>a>>b;
        
        cout<<n/(a+b)*a+min(n%(a+b),a);
    }

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

typedef pair<int, int> P;

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (int i=0; i<h; i++) cin >> s[i];
    int ans = 0;

    for (int si = 0; si < h; si++) {
        for (int sj = 0; sj < w; sj++) {
            if (s[si][sj] == '#') continue;
            vector<vector<int>> dist(h, vector<int>(w, INF));
            queue<P> q;
            auto update = [&](int i, int j, int x) {
                if (dist[i][j] != INF) return;
                dist[i][j] = x;
                q.push(P(i, j));
            };
            update(si, sj, 0);
            while (!q.empty()) {
                int i = q.front().first;
                int j = q.front().second; q.pop();
                for (int dir=0; dir<4; dir++) {
                    int ni = i+di[dir], nj = j+dj[dir];
                    if (ni<0 || ni>=h || nj<0 || nj>=w) continue;
                    if (s[ni][nj] == '#') continue;
                    update(ni, nj, dist[i][j]+1);
                }
            }
            for(int i=0; i<h; i++) {
                for(int j=0; j<w; j++) {
                    if (dist[i][j] == INF) continue;
                    ans = max(ans, dist[i][j]);
                }
            }
        }
    }

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

Measured memory_bytes: 256
/* ex3_2
   moka223711 */

#include <stdio.h>

int main(void){
	int N, d = 0;
	scanf("%d", &N);

	// Nを1から9で割って、余りが0かつ商が9以下になっているものを探す
	// 割れるものが見つかったらdを1に変える
	for(int i = 1; i <= 9; i++){
    	if(N % i == 0 && N / i <= 9){
        	d = 1;
			break;
		}
	}
	
	// 上のfor文で1から9で割り切れるものが見つかったときd == 1となっているため
	// if文が実行される、なかったときはelse文の実行
	if(d){
		printf("Yes");
	}
	else{
		printf("No");
	}
  
	return 0;
}

Measured memory_bytes: 128
import scala.language.postfixOps

object Main {
  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(' ') map { _.toInt }

    val inputs = Stream.continually( io.StdIn.readLine().split(' ') ) take n
    val whites = inputs.filter( x => x(2) == "W" ) map { _.take(2) map { _.toInt } }
    val blacks = inputs.filter( x => x(2) == "B" ) map { _.take(2) map { _.toInt } }

    var w_arr = Array.ofDim[Int](k+1, 2*k+1)
    var b_arr = Array.ofDim[Int](k+1, 2*k+1)

    for (Array(x, y) <- whites) {
      w_arr(x % k + 1)((y + (x/k%2)*k) % (2*k) + 1) += 1
    }

    for (Array(x, y) <- blacks) {
      b_arr(x % k + 1)((y + (x/k%2)*k) % (2*k) + 1) += 1
    }

    for (x <- 1 to k) {
      for (y <- 2 to 2*k) {
        w_arr(x)(y) += w_arr(x)(y-1)
        b_arr(x)(y) += b_arr(x)(y-1)
      }
    }

    for (x <- 2 to k) {
      for (y <- 1 to 2*k) {
        w_arr(x)(y) += w_arr(x-1)(y)
        b_arr(x)(y) += b_arr(x-1)(y)
      }
    }

    def eval_offset(x:Int, y:Int):Int = {
      if (y < k) {
        return b_arr(x)(2*k) + b_arr(k)(y + k) - 2 * b_arr(x)(y + k) -
          b_arr(k)(y) + 2 * b_arr(x)(y) + w_arr(k)(2*k) - w_arr(x)(2*k) -
          w_arr(k)(y+k) + 2 * w_arr(x)(y+k) + w_arr(k)(y) - 2 * w_arr(x)(y)
      } else {
        return w_arr(x)(2*k) + w_arr(k)(y) - 2 * w_arr(x)(y) -
          w_arr(k)(y-k) + 2 * w_arr(x)(y-k) + b_arr(k)(2*k) - b_arr(x)(2*k) -
          b_arr(k)(y) + 2 * b_arr(x)(y) + b_arr(k)(y-k) - 2 * b_arr(x)(y-k)
      }
    }

    var max = 0
    for (x <- 0 to k-1; y <- 0 to 2*k-1) {
      val a = eval_offset(x, y)
      if (a > max)
        max = a
    }

    println(max)
  }
}

Measured memory_bytes: 150472
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;
 
typedef long long ll;
 
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;
 
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 1000
 
struct tur{
   int w,s,v;
}ar[N+5];
ll dp[N+5][N*10+5];
 
bool com(tur A,tur B){
   return A.s+A.w<B.s+B.w;
}
 
int n;
 
ll call(int idx,int taken){
   if(idx>n||taken>N*10) return 0ll;
   ll &ret=dp[idx][taken];
   if(ret!=-1) return ret;
   ll op1=0,op2=0;
   op1=call(idx+1,taken);
   if(ar[idx].s>=taken) op2=ar[idx].v+call(idx+1,taken+ar[idx].w);
   return ret=max(op1,op2);
}
 
int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin>>n;
   for(int i=1;i<=n;i++) cin>>ar[i].w>>ar[i].s>>ar[i].v;
   sort(ar+1,ar+1+n,com);
   memset(dp,-1,sizeof dp);
   cout<<call(1,0)<<"\n";
   return 0;
}
 

Measured memory_bytes: 82228