akhauriyash/Code-Regression huggingface dataset:
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

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

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back

const int mod = 998244353;

int add(int a, int b) {
    return (a + b >= mod ? a + b - mod : a + b);
}

int sub(int a, int b) {
    return (a >= b ? a - b : mod + a - b);
}

int mult(int a, int b) {
    return (a * int64_t(b)) % mod;
}

int solve(const string& s) {
    static std::map<string, int> cache;
    
    if (cache.count(s))
        return cache[s];

    if (s.empty())
        return 1;

    int res = mult(s[0] == '0' ? 1 : 2, solve(s.substr(1, string::npos)));

    for (int k = 1; k < SZ(s); ++k) {
        string mask = s.substr(0, k);
        
        for (int t = 2; t * k <= SZ(s); ++t) {
            for (int i = 0; i != k; ++i)
                if (s[k * (t - 1) + i] == '0')
                    mask[i] = '0';
            
            res = add(res, mult(solve(mask), solve(s.substr(t * k, string::npos))));
        }
    }

    return cache[s] = res;
}

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    string s = input<string>();
    cout << solve(s) << "\n";
    
    return 0;
}


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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mx 3000
ll n,m;
char gd[mx][mx];
ll solve(ll n,ll m){
   ll dp[n+1][m+1];
    dp[n][m]=1;
   for(int i=n;i>=1;i--){
        for(int j=m;j>=1;j--){
                if(i==n&& j==m)continue;
             if(gd[i][j]=='#')
                dp[i][j]=0;
              else  dp[i][j]=(((i==n)?0:dp[i+1][j])+((j==m)?0:dp[i][j+1]))%mod;

        }
   }
  /* for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){
    cout<<dp[i][j]<<" ";}cout<<endl;
   }*/
   return dp[1][1];
}
int main()
{
    FIO;
    ll c,d,e,f=0,sum=0,ans,ck,k,p,q,r,t,add=0,w,x,y,z;
    cin>>n>>m;

    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
        {cin>>gd[i][j];}
   ck= solve(n,m);
    cout<<ck<<endl;

    return 0;
}

Measured memory_bytes: 14272
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Together
            int N = int.Parse(Console.ReadLine());
            var a = ReadLine();

            var x = new int[100002];

            foreach(var ai in a)
            {
                x[ai]++;
                x[ai + 1]++;
                x[ai + 2]++;
            }

            Console.WriteLine(x.Max());
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 20192
#include<bits/stdc++.h>
 
using namespace std;
 
inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}
 
int main(){
	int t=read();
	while(t--){
		int a=read(),b=read(),c=read(),d=read();
		int n=a+b;
		int k=(max(a,b)-1)/(min(a,b)+1)+1;
		int l=0,r=n+1,x,y;
		while(l<r){
			int mid=l+r>>1;
			x=a-mid/(k+1)*k-mid%(k+1);
			y=b-mid/(k+1);
			if(y<=1ll*x*k) l=mid+1;
			else r=mid;
		}
		x=a-l/(k+1)*k-l%(k+1);y=b-l/(k+1);r=l+y-x*k+1;
		for(int i=c;i<=min(d,l);i++) {
			if(i%(k+1)) cout<<'A';
			else cout<<'B';
		} 
		for(int i=max(c,l+1);i<=d;i++){
			if((i-r)%(k+1)) cout<<'B';
			else cout<<'A';
		}
		cout<<endl;
	}  
 
 
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
        using namespace std;
         
        #define f first
        #define s second
        #define p pair<int,int>
        #define ll long long
        #define db double
        #define db double
         
        const int maxn=1e6+5;
        const int inf=1e9;
         
        ll n,m,k,flag,ok,a[maxn],b[maxn],ans,sum;
        string s;
         
        int main()
        {
            ios::sync_with_stdio(0),cin.tie(0);
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            if(c>=b||a>=d)cout<<0;
            else cout<<min(b,d)-max(a,c);
            return 0;
        }

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

int main()
{
  int num = 0;
  int i = 2;
  int d = 0;
  cin >> num;
  
  while(i <= num)
  {
    d = i;
    if(i % 3 == 0)
    {
      cout << " " << i;
    }
    else
    {
    while(d >= 10)
    {
      if(d % 10 == 3 || d / 10 == 3)
      {
        cout << " " << i;
        break;
      }
      d = d / 10;
    }
    }
    
    i++;
  }
  cout << endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}

/*

両者からの距離が同じかそれよりフェネックに近い色のが多ければふぇね

*/

void dfs(int u, vector<int> &d,vector<vector<int> > &G, int N) {
    for (int i = 0; i < G[u].size(); i++) {
        if (d[G[u][i]] == -1) {
            d[G[u][i]] = d[u] + 1;
            dfs(G[u][i],d,G,N);
        }
    }
}


int main() {
    int N; cin >> N;
    int res = 0;
    vector<vector<int> > G(N, vector<int> {});
    vector<int> d1(N,-1), d2(N,-1);
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    
    d1[0] = d2[N-1] = 0;
    dfs(0,d1,G,N);
    dfs(N-1,d2,G,N);
    for (int i = 0; i < N; i++) {
        if (d1[i] > d2[i]) res++;
    }
    if (N % 2 == 0) {
    if (res < N/2) {
        cout << "Fennec\n";
    } else {
        cout << "Snuke\n";
    }
    } else {
    if (res <= N/2) {
        cout << "Fennec\n";
    } else {
        cout << "Snuke\n";
    }
    }
}


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

using namespace std;
typedef long long ll;


class BinaryIndexedTree {
    int N;
    vector<ll> data;
public:
    BinaryIndexedTree(int N) : N(N) {
        data.resize(N + 1, 0);
    }

    ll sum(int k) {
        ll res = 0;
        for (; k > 0; k -= k & -k) {
            res += data[k];
        }
        return res;
    }

    void add(int k, ll x) {
        for (; k <= N; k += k & -k) {
            data[k] += x;
        }
    }
};


int main() {
    int N;
    cin >> N;
    BinaryIndexedTree bit(210000);
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < N; ++i) {
        A[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    }

    ll ans = 0;
    for (ll i = 0; i < N; ++i) {
        int a = A[i];
        ans += i - bit.sum(a+1);
        bit.add(a+1, 1);
    }
    cout << ans << '\n';
}



Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define INT long long
using namespace std;
INT n, ans = 9999987654321ll;
INT f(INT x)
{
    INT ret = 0;
    while( x )
    {
        ret += x%10;
        x/=10;
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 1 ; i < n ; i++ )
    {
        ans = min( ans, f(i)+f(n-i) );
    }
    cout<<ans;
    return 0;
}


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


int manju[10000];
int dp[20010];

int main(){
	int M,N;
	cin >> M >> N;
	for(int i = 0 ; i < M ; i++) cin >> manju[i];
	sort(manju,manju+M);
	reverse(manju,manju+M);
	for(int i = 0 ; i < 20010 ; i++)
		dp[i] = 1e9;
	dp[0] = 0;
	for(int i = 0 ; i < N ; i++){
		int t; cin >> t;
		int c; cin >> c;
		for(int j = 20000 ; j >= t ; j--){
			dp[j] = min(dp[j],dp[j-t]+c);
		}
	}
	for(int k = 20000 ; k >= 0 ; k--){
		dp[k] = min(dp[k],dp[k+1]);
	}
	int ans = 0;
	int sum = 0;
	for(int i = 0 ; i < M ; i++){
		sum += manju[i];
		ans = max(sum-dp[i+1],ans);
	}
	cout << ans<< endl;
	
}

Measured memory_bytes: 1292
// [AT2684 K-City] https://www.luogu.org/problem/AT2684
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

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


	int N = getint(), M = getint();
	int to[100001], ne[100001], he[100001] = {};
	rep1(i, M) {
		int u = getint();
		to[i] = getint();
		ne[i] = he[u];
		he[u] = i;
	}
	int S = getint(), T = getint();

	int D[300004];
	rep(i, 300004) D[i] = 1e9;
	D[3 * S] = 0;

	queue<int> que;
	que.push(3 * S);
	while (que.size()) {
		int i = que.front();
		que.pop();
		int i2 = i / 3;
		int d = D[i] + 1;
		for (int j = he[i2]; j; j = ne[j]) {
			int j2 = to[j] * 3 + (i + 1) % 3;
			if (D[j2] > d) {
				D[j2] = d;
				que.push(j2);
			}
		}
	}

	if (D[3 * T] == 1e9) printf("-1");
	else printf("%d", D[3 * T] / 3);

	Would you please return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstring>

int main()
{
  char a[11], b[11], c[11];
  scanf("%s %s %s", a, b, c);
  puts(a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0] ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 128
var input= require('fs').readFileSync('/dev/stdin', 'utf8').split("\n").map(Number);
var part = [];
input.some(function(x) {
  if (x == 0) return true;
  part.push(x);
});
console.log(part.map(function(x, i) {
  return x == 0 ? '' : 'Case ' + (i + 1) + ': ' + x;
}).join('\n'));

Measured memory_bytes: 19408
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string s;
        while (n > 0) {
            int m = (n - 1) % 26;
            s += (char)(m + 97);
            n = (n - m) / 26;
        }
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

#define p 3.14159265359

int main()
{
	int a, b;
	char op;
	while (1)
	{
		while (1)
		{
			scanf("%d %c %d", &a, &op, &b);
			if (0 <= a, b&&a, b <= 20000&&!(op=='/'&&b==0))
				break;
		}
		switch (op)
		{
		case '+':printf("%d\n", a + b);
			break;
		case '-':printf("%d\n", a - b);
			break;
		case '*':printf("%d\n", a * b);
			break;
		case '/':printf("%d\n", a / b);
			break;
		default:break;
		}
		if (op == '?')
			break;
	}

	return 0;
}

Measured memory_bytes: 600
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

n = I()
if n == 0:
    print(0)
    quit()
ans = ""
while n:
    m = n%2
    if m:
        ans += "1"
        n -= 1
    else:
        ans += "0"
    n //= -2
print(ans[::-1])


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

int main() {
string S;
cin >> S;
int N = S.size();
int co =0;
for(int i=0; i<N; i++){
    if(S.at(i) != S.at(N-1-i)){
        co++;
    }    
}
cout << co / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
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;
}


int main() {
    int n,r,l;
    cin >> n;
    vector<pair<int,int>> rl;
    rep(i,n) {
        cin >> l >> r;
        rl.eb(l,r);
    }
    int total = 0;
    rep(i,n) {
        total += rl[i].second - rl[i].first +1;
    }
    cout << total << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

struct BellmanFord{
  typedef ll T;
  const T tinf = linf;
//#####################################
  bool solve(vector<vector<pair<int, T> > >&G, vector<T>&d, vector<int>&p, int s){
    int n = sz(G);
    d.resize(n);
    fill(d.begin(), d.end(), tinf);
    d[s] = 0;
    p.resize(n);
    fill(p.begin(), p.end(), -1);
    FOR(i, 0, n-1)FOR(j, 0, n)each(itr, G[j])if(d[itr->fi] > d[j] + itr->se){
      d[itr->fi] = d[j] + itr->se;
      p[itr->fi] = j;
    }
    ll a = d[n-1];
    FOR(i, 0, n)FOR(j, 0, n)each(itr, G[j])if(d[itr->fi] > d[j] + itr->se){
      d[itr->fi] = d[j] + itr->se;
      p[itr->fi] = j;
    }
    return a == d[n-1];
  }
  bool solve(vector<vector<pair<int, T> > >&G, vector<T>&d, int s){
    vector<int> v;
    return solve(G, d, v, s);
  }
};
BellmanFord bf;
int n, m;
vector<vector<pair<int, ll> > > G;
vl v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  G.resize(n);
  FOR(i, 0, m){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].pb(mp(b, -c));
  }
  if(bf.solve(G, v, 0)){
    cout << -v[n-1] << endl;
  }else{
    cout << "inf" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
n = int(input())
nums = []
c = []
for _ in range(n):
    i = int(input())
    nums.append(i)
    c.append(i)

c.sort()
MAX = c[-1]
second = c[-2]

for num in nums:
    if num == MAX:
        print(second)
    else:
        print(MAX)


Measured memory_bytes: 82008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	ll a[30];
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	set<ll> st;
	int bit;
	for (bit = 1; bit < (1 << n); bit++) {
		ll LCM = 1;
		for (i = 0; i < n; i++) {
			if (1 & (bit >> i)) LCM = lcm(LCM, a[i]);
		}
		st.insert(LCM);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 3976
#include<stdio.h>
int main(void){
  int a,b,c,d,i,e,f;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  for(i=1;i<=100;i++){
    a=a-d;
    c=c-b;
    /*printf("%d %d\n",a,c);*/
    if(c<=0){
      printf("Yes\n");
        break;
    }else if(a<=0){
      printf("No\n");
        break;
    }
  }
  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
int N;
ll ans;
int main(){
    
    scanf("%d",&N);
    for (int i = 1; i < N; i++)
    {
        ans += i;
    }
    printf("%lld", ans);
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s,t;
    cin>>s>>t;
    int ans=0;

    if(s[0]==t[0])ans++;
    if(s[1]==t[1])ans++;
    if(s[2]==t[2])ans++;

    cout<<ans;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;
const int N = 100010;
int r, c, n, bit[2 * N], tot;

struct Point {
    int x, y;

    Point() {}

    void read() {
        scanf("%d%d", &x, &y);
    }

    int check() {
        return (x == 0 || y == 0 || x == r || y == c);
    }

    int calc() const {
        if (x == 0) return y;
        if (y == c) return c + x;
        if (x == r) return r + c + c - y;
        return r + c + c + r - x;
    }
};

class cmp {
public:
    int operator()(const Point &a, const Point &b) const {
        return a.calc() < b.calc();
    }
};

typedef pair<Point, Point> ppp;
typedef pair<int, int> pii;
typedef tree<Point, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update> bbt;

int low(int x) {
    return x & -x;
}

void change(int x) {
    while (x <= tot) {
        bit[x]++;
        x += low(x);
    }
}

int ask(int x) {
    if (x <= 0) return 0;
    int ans = 0;
    while (x) {
        ans += bit[x];
        x -= low(x);
    }
    return ans;
}

bbt pls;
ppp link[N];
vector<pii> e;

void err() {
    puts("NO");
    exit(0);
}

int main() {
    cin >> r >> c >> n;
    for (int i = 0; i < n; i++) {
        Point a, b;
        a.read();
        b.read();
        link[i] = ppp(a, b);
        if (!a.check() || !b.check()) continue;
        pls.insert(a);
        pls.insert(b);
    }
    for (int i = 0; i < n; i++) {
        if (!link[i].first.check() || !link[i].second.check()) continue;
        int a = pls.order_of_key(link[i].first), b = pls.order_of_key(link[i].second);
        if (a > b) swap(a, b);
        e.push_back(pii(a + 1, b + 1));
    }
    sort(e.begin(), e.end(), [](const pii &a, const pii &b) {
        return a.first < b.first;
    });
    tot = (int) e.size() * 2;
    for (int i = 0; i < tot / 2; i++) {
        int cnt = ask(e[i].second - 1) - ask(e[i].first);
        if (cnt > 0) err();
        change(e[i].second);
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 15988
# https://atcoder.jp/contests/arc067/tasks/arc067_b

n, a, b = map(int, input().split())
nums = [int(i) for i in input().split()]

cost = 0
for i in range(n - 1):
    d = nums[i + 1] - nums[i]
    if d * a > b:
        cost += b
    else:
        cost += d * a
print(cost)

Measured memory_bytes: 62832
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        double ans = 0;
        if(k <= n){
            ans = (double)(n-k+1)/n;
        }

        int x = 1;
        int tw = 2;
        for(int i = Math.min(n,k-1);i > 0;i--){
            while(i * tw < k){
                x++;
                tw *= 2;
            }
            ans += (double)1/n * (double)1/tw;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>

using namespace std;

int main() {
	int N;
	int H[100];
	int max = 0;
	int ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (H[i] >= max) {
			ans++;
			max = H[i];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
judge_kind = ['AC', 'WA', 'TLE', 'RE']
C = [0, 0, 0, 0]
for i in range(N):
    if S[i] == 'AC':
        C[0] += 1
    elif S[i] == 'WA':
        C[1] += 1
    elif S[i] == 'TLE':
        C[2] += 1
    else:
        C[3] += 1
for i in range(4):
    print('{} x  {}'.format(judge_kind[i], C[i]))

Measured memory_bytes: 16240
N, M = map(int, input().split())
Q = [tuple(map(int, input().split())) for _ in range(M)]

# 右側が小さい順にソート、制約a<bなのでそのまま使ってよい
Q = sorted(Q, key=lambda x: x[1])
# 境界、右側の区間の始まり
border = -1
ans = 0

for a, b in Q:
    # 既存の境界で分けられないときは右にずらす
    if border <= a:
        ans += 1
        border = b

print(ans)

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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p){
  for(long long i = 1; i < N; i++){
    if(p[i-1] > p[i]) goto nosort;
  }

  cout << YES << endl;
  return;

  nosort:
  for(long long i = 0; i < N; i++){
    for(long long j = (i+1); j < N; j++){
      vector<long long> vec = p;
      long long tmp;
      tmp = vec[i];
      vec[i] = vec[j];
      vec[j] = tmp;
      for(long long k = 1; k < N; k++){
        if(vec[k-1] > vec[k]) goto nosort2;
      }

      cout << YES << endl;
      return;
      nosort2:
      continue;
    }
  }


  cout << NO << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void)
{
  vector<int> a(10);
  for(int i=0;i<10;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  /*
    ±êÍ
    sort(a.begin(),a.end(),greater<int>());
    ÆµÄàÇ¢
   */
  for(int i=0;i<3;i++){
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int H, W, N;
  cin >> H >> W >> N;

  if(N == 0){
    cout << (H-2)*(W-2) << endl;
    REP(i, 9) cout << 0 << endl;
    return 0;
  }

  int a, b;
  map<pair<int, int>, int> m;
  REP(i, N){
    cin >> a >> b;
    a--; b--;

    if(a-2 >= 0){
      if(b-2 >= 0) m[make_pair(a-2, b-2)]++;
      if(b-1 >= 0) m[make_pair(a-2, b-1)]++;
      m[make_pair(a-2, b)]++;
    }
    if(a-1 >= 0){
      if(b-2 >= 0) m[make_pair(a-1, b-2)]++;
      if(b-1 >= 0) m[make_pair(a-1, b-1)]++;
      m[make_pair(a-1, b)]++;
    }
    if(b-2 >= 0) m[make_pair(a, b-2)]++;
    if(b-1 >= 0) m[make_pair(a, b-1)]++;
    m[make_pair(a, b)]++;
  }

  vector<int> ans(10, 0);
  for(auto i : m){
    auto p = i.first;
    if(p.first <= H-3 && p.second <= W-3){
      ans[i.second]++;
    }
  }

  ans[0] = (H-2)*(W-2);
  FOR(i, 1, 10){
    ans[0] -= ans[i];
  }
  REP(i, 10){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 56448
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = Math.min(b,a*n);
        System.out.println(ans);
    }
    
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

signed main() {
  uint64_t h1,h2,m1,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  uint64_t minuteDiff = m2 - m1 + (h2 - h1)*60;
  
  cout << minuteDiff - k << endl;
  
  return 0;
}

Measured memory_bytes: 3692
char*p,r['~~'];w;i;main(h){for(;scanf("%d%d",&h,&w)*w++;i=!printf(h?"%d %d\n":"LOOP\n",(p-r)%w,(p-r)/w)){for(p=r;i<h;scanf("%s",r+i++*w));for(h*=w;*p>46&&--h;)p+=*p%5?*p&8?*p<63?1:-w:w:-1;}}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().split()))
c = 0

while True:
  for i in range(0,n):
    if(a[i]%2 != 0):
      print(c)
      exit()
    else:
      a[i] = int(a[i]/2)
  c = c + 1
print(c)

Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

int main() {
  int n;
  cin >> n;
  n = n % 10;
  
  if(n == 3) {
    cout << "bon" << endl;
  } else if( n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int count = 0;
		for (int i=a;i<=b;i++) {
			StringBuilder sb = new StringBuilder();
			sb.append(String.valueOf(i));
			sb.reverse();
			if(sb.toString().equals(String.valueOf(i))) {
				count++;
			}

		}
		System.out.println(count);
	}

}


Measured memory_bytes: 38740
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val (a, b) = br.readLine().split(' ').map { it.toInt() }
    val c = a*b
    println(if (c%2 == 0) "Even" else "Odd")
}

Measured memory_bytes: 33964
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  int m = 2019;
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  int x = 1;
  int total = 0;
  vector<int> count(m);
  ll ans = 0;

  rep(i, n)
  {
    count.at(total)++;
    total += (s.at(i) - '0') * x;
    total %= m;
    ans += count.at(total);
    x = x * 10 % m;
  }
  
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3864
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>
#include<math.h>

int main(){
	int n;
	std::vector<int> aList;

	std::cin>>n;
	aList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	int ans=0;
	int tmp=0;
	int prev=aList[0];

	for(int i=1; i<n; i++){
		if(prev<aList[i]){
			ans= std::max(ans, tmp);
			tmp=0;
		}
		else{
			tmp++;
		}

		prev= aList[i];
	}

	ans= std::max(ans, tmp);


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

	return 0;
		
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define scanf scanf_s


int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		char c = s[i] + n;
		if (c > 'Z')
			c -= 26;
		cout << c;
	}
	return 0;
}


Measured memory_bytes: 384
from collections import deque
N, M = map(int, input().split())
g = [[] for i in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    g[A].append(B)
    g[B].append(A)
Q = deque()
vstd = [0]*(N+1)
mark = [0]*(N+1)
vstd[1] = 1
Q.append(1)
while Q:
    par = Q.popleft()
    for r in g[par]:
        if vstd[r]:
          continue
        mark[r]=par
        vstd[r]=1
        Q.append(r)
print('Yes')
for mk in mark[2:]:
    print(mk)


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

string S;
int N;

void input(){
    cin >> N;
    cin >> S;
}

void solve(){
    input();
    string tmp = "No";
    int K = N / 2;
    if(N % 2 == 0 && S.substr(0,K) == S.substr(K,K)) tmp = "Yes";
    cout << tmp << endl;

    return;
}

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

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, p=10**9+7):
    A.sort()
    if N % 2 == 1:
        if A[0] != 0:
            return 0
        for i in range(1, N):
            if A[i] != i + i%2:
                return 0
    else:
        for i in range(0, N):
            if A[i] != i + (1-i%2):
                return 0
    return pow(2, N//2, p)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 20584
#include <iostream>
#include <cstdio>
using namespace std;
int cont = 0;
 
int L[250005], R[250005];
 
 
void merge(int S[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int t = 0; t < n1; t++)L[t] = S[left + t];
    for (int t = 0; t < n2; t++)R[t] = S[mid + t];
    L[n1] = R[n2]= 2000000000;
 
    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        cont++;
        if (L[i] <= R[j]) {
            S[k] = L[i];
            i++;
        }
        else {
            S[k] = R[j];
            j++;
        }
    }
 
}
 
void mergeSort(int S[],int n,int left,int right) {
    int mid = (left + right) / 2;
    if (left + 1 < right) {
        mergeSort(S, n, left, mid);
        mergeSort(S, n, mid, right);
        merge(S, n, left, mid,right);
    }
}
 
int main() {
    int n;
    cin >> n;
    int S[500005];
    for (int t = 0; t < n; t++) {
        scanf("%d", &S[t]);
    }
 
    mergeSort(S,n,0,n);
 
    for (int t = 0; t < n; t++) {
        if (t)cout << " ";
        cout << S[t];
    }
    cout << "\n";
    cout <<cont << "\n";
 
    return 0;
}


Measured memory_bytes: 7004
import java.util.*;

public class Main{

    ArrayList<char[]> color,list;
    ArrayList<String> clist;

    void solve(){
        Scanner sc = new Scanner(System.in);

        clist = new ArrayList<String>();
        clist.add("Red");
        clist.add("Yellow");
        clist.add("Blue");
        clist.add("Magenta");
        clist.add("Green");
        clist.add("Cyan");

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            color = new ArrayList<char[]>();
            int cnt = 0;
            for(int i=0; i<n; i++){
                char[] c = new char[6];
                for(int j=0; j<6; j++) c[j] = (char)clist.indexOf(sc.next());
                if(same(c)) cnt++;
                else color.add(c);
            }

            System.out.println(cnt);
        }
    }

    int[][] rotate = {{1,2,4,3},{0,4,5,1},{0,2,5,3}};

    boolean same(char[] dice){
        list = new ArrayList<char[]>();
        for(int i=0; i<4; i++){
            dice = rotate(dice,0);
            for(int j=0; j<4; j++){
                dice = rotate(dice,1);
                for(int l=0; l<4; l++){
                    dice = rotate(dice,2);
                    list.add(dice);
                }
            }
        }

        for(int i=0; i<list.size(); i++){
            char[] s1 = list.get(i);
            for(int j=0; j<color.size(); j++){
                boolean boo = false;
                char[] s2 = color.get(j);
                for(int k=0; k<6; k++){
                    if(s1[k]!=s2[k]){
                        boo = false;
                        break;
                    }
                    boo = true;
                }
                if(boo) return true;
            }
        }
        return false;
    }

    char[] rotate(char[] dice, int idx){
        char[] res = new char[6];
        for(int i=0; i<6; i++) res[i] = dice[i];

        char tmp = res[rotate[idx][3]];
        for(int i=3; i>0; i--) res[rotate[idx][i]] = res[rotate[idx][i-1]];
        res[rotate[idx][0]] = tmp;
        return res;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <queue>

using namespace std;

const int MAXN = 2e5+5;

int n, a[MAXN];
deque<int> q;

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

	for (int i = 0; i < n; ++i) {
		if ((i&1) == 0) q.push_back(a[i]);
		else q.push_front(a[i]);
	}

	while (!q.empty()) {
		if ((n&1) == 0) {
			printf("%d ", q.front());
			q.pop_front();
		} else { 
			printf("%d ", q.back());
			q.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>

int main(void)
{
  long int N,i;
  long int A[200001];
  scanf("%ld\n",&N);
  for(i=1;i<=N;i++){
    scanf("%ld",&A[i]);
  }
  
  long int S=0;
  for(i=1;i<=N;i++){
    S=S+A[i];
  }
  
  i=1;
  long int T=0;
  while(T*2<=S){
    T=T+A[i];
    i++;
  }
  
  long int P;
  if(T*2>S+A[i-1]){
    P=S-(T*2)+(2*A[i-1]);
  }else{
    P=2*T-S;
  }
  
  printf("%ld",P);
  
  return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector< int > p( n );
  
  int diff_num = 0;
  int diff[ n ];

  for ( int i = 0; i < n; i++ ){
    cin >> p.at( i );
    if ( i + 1 != p.at( i ) ){
      diff[ diff_num ] = i;
      diff_num++;
    }
  }
  
  if ( diff_num == 0 ){
    cout << "YES" << endl;
    return 0;
  }
  if ( diff_num != 2 ){
    cout << "NO" << endl;
    return 0;
  }
  if ( p.at( diff[ 0 ] ) == diff[ 1 ] + 1
        && p.at( diff[ 1 ] ) == diff[ 0 ] + 1 ){
    cout << "YES" << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int x = abs(a-c), y = abs(b-d);

    d = __gcd(x, y);

    int ans;
    if (x == 0 || y == 0) ans = 0;
    else{
        ans = d * (x / d + y / d - 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

n = int(input())
aa = list(map(int, input().split()))

# def findsame(aa):
#     s = 0
#     for a in aa:
#         s += (len([x for x in aa if x == a]) - 1)
#     return int(s / 2)

# for k in range(len(aa) - 1):
#     print(findsame(aa[:k] + aa[k+1:]))
# print(findsame(aa[:len(aa)-1]))

# aaa = dict()
# for a in aa:
#     if a not in aaa:
#         aaa[a] = len([x for x in aa if x == a])

# sum = 0
# for k in aaa:
#     sum += int(aaa[k] * (aaa[k] - 1) / 2)

# for a in aa:
#     print(sum - (aaa[a] - 1))

aaa = dict()
for a in aa:
    if a not in aaa:
        aaa[a] = 1
    else:
        aaa[a] += 1

sum = 0
for k in aaa:
    sum += int(aaa[k] * (aaa[k] - 1) / 2)

for a in aa:
    print(sum - (aaa[a] - 1))


Measured memory_bytes: 26140
s = input()
t = input()
temp = s[:]
cnt = 0
strmax = len(t)
ans = 0

for i in t:
	if s.find(i)==-1:
		print("-1")
		exit(0)

while cnt<strmax:
	num = temp.find(t[cnt])
	if num != -1:
		ans+=num+1
		temp = temp[num+1:]
		cnt+=1
	else:
		ans+=len(temp)
		temp = s[:]

print(ans)


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

#define MAX_N 10

int x[MAX_N][MAX_N], G1[MAX_N][MAX_N], G2[MAX_N][MAX_N][4], h, w, gx, gy, cnt, C, c, X, Y;
stack<int>S;

void hantei() {
	X = S.top() % 10; Y = S.top() / 10; c = 0;
	if (G2[Y][X][0] == 0) {
		G2[Y][X][0] = 1;
		for (int i = Y; i < h; i++) {
			if (G1[i][X] == 1 && x[i][X] == 1) {
				G1[i][X] = 0;
				S.push(i * 10 + X);
				return;
			}
		}
	}
	if (G2[Y][X][1] == 0) {
		G2[Y][X][1] = 1;
		for (int i = X; i < w; i++) {
			if (G1[Y][i] == 1 && x[Y][i] == 1) {
				G1[Y][i] = 0;
				S.push(Y * 10 + i);
				return;
			}
		}
	}
	if (G2[Y][X][2] == 0) {
		G2[Y][X][2] = 1;
		for (int i = Y; i >= 0; i--) {
			if (G1[i][X] == 1 && x[i][X] == 1) {
				G1[i][X] = 0;
				S.push(i * 10 + X);
				return;
			}
		}
	}
	if (G2[Y][X][3] == 0) {
		G2[Y][X][3] = 1;
		for (int i = X; i >= 0; i--) {
			if (G1[Y][i] == 1 && x[Y][i] == 1) {
				G1[Y][i] = 0;
				S.push(Y * 10 + i);
				return;
			}
		}
	}
	c = 1;
	return;
}

int bfs() {
	cnt = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			G1[i][j] = 1;
		}
	}
	S.push(gy * 10 + gx);
	G1[gy][gx] = 0;
	while (!S.empty()) {
		if (S.size() == C + 1 && (S.top() / 10 == gy || S.top() % 10 == gx) ) {
			cnt++;
		}
		hantei();
		if (c == 1) {
			G1[Y][X] = 1;
			G2[Y][X][0] = 0;
			G2[Y][X][1] = 0;
			G2[Y][X][2] = 0;
			G2[Y][X][3] = 0;
			S.pop();
		}
	}
	return cnt;
}

int main() {
	while (true) {
		C = 0;
		cin >> w >> h;
		if (h == 0 && w == 0) { break; }
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> x[i][j];
				if (x[i][j] == 1) { C++; }
				if (x[i][j] == 2) { gy = i; gx = j; }
			}
		}
		cout << bfs() << endl;
	}
	return 0;
}

Measured memory_bytes: 3060