akhauriyash/Code-Regression huggingface dataset:
def resolve():
    k = int(input())
    from collections import deque
    a = [1,2,3,4,5,6,7,8,9]
    b = [1,2,3,4,5,6,7,8,9]
    if k < 10:
        print(a[k-1])
    else:
        a = deque(a)
        b = deque(b)
        while len(b) <= k:
            test = a.popleft()
            mtest = test % 10
            if mtest == 0:
                a.append (test*10)
                a.append (test*10+mtest+1)
                b.append (test*10)
                b.append (test*10+mtest+1)
            elif mtest == 9:
                a.append (test*10 + mtest-1)
                a.append (test*10 + mtest)
                b.append (test*10 + mtest-1)
                b.append (test*10 + mtest)
            else:
                a.append (test*10 + mtest-1)
                a.append (test*10 + mtest)
                a.append (test*10 + mtest+1)
                b.append (test*10 + mtest-1)
                b.append (test*10 + mtest)
                b.append (test*10 + mtest+1)
        print(b[k-1])
resolve()

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n;cin>>n;
  int a[n+10];
  int ma=0,mi=100000;
  rep(i,0,n){
    cin>>a[i];
    ma=max(ma,a[i]),mi=min(mi,a[i]);
  }
  out(ma-mi);

  return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
l = list(map(int, input().split(" ")))
l.sort()
a = 1
for i in range(n):
    if a <= 10**18:
        a = a*l[i]
    elif a > 10**18:
        print("-1")
        sys.exit()
if a > 10**18:
    print("-1")
else:
    print(a)

Measured memory_bytes: 83152
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;
 
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INF=1LL<<60;
 
int main() {
   ll N,W;
   cin>>N>>W;
   ll w[N+1];
   ll v[N+1];
   ll sv=0;
   for(ll i=1;i<=N;i++)cin>>w[i]>>v[i];
   for(ll i=1;i<=N;i++)sv+=v[i];
   ll dp[N+1][sv+1];
   rep(i,N+1)rep(j,sv+1)dp[i][j]=INF;
   dp[0][0]=0;
  
   for(ll i=1;i<=N;i++){
       for(ll j=0;j<=sv;j++){
           if(j>=v[i]){
               dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
           }
           else{
               dp[i][j]=dp[i-1][j];
           }
       }
   } 
   ll ans=0;
   rep(j,sv+1)if(dp[N][j]<=W)ans=j;
   cout<< ans<< endl;
   return 0;
}

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

#define FOR(i,a,b)   for(int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)  for(int i=(b)-1;i>=(a);i--)
#define REP(i,n)     for(int i=0    ;i<(n) ;i++)
#define RREP(i,n)    for(int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)  for(int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b) for(int i=(b)  ;i>=(a);i--)
#define ALL(a)       (a).begin(), (a).end()
#define RALL(a)      (a).rbegin(), (a).rend()

int main() {
  int n, m, price;
  cin >> n;
  vector<string> blue(n);
  REP(i,n) cin >> blue[i];
  
  cin >> m;
  vector<string> red(m);
  price = 0;
  REP(i,m) cin >> red[i];
  
  for(int i=0; i<n; i++){
    string s = blue[i];
    int temp = 0;
    for(int j=0; j<n; j++){
      if(s == blue[j]){
        temp += 1;
      }
    }
    for(int j=0; j<m; j++){
      if(s == red[j]){
        temp -= 1;
      }
    }
    if(price < temp) price = temp;
  }
  cout << price << endl;

  return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int[,] b = new int[a, 4];
        for(int i = 0; i < a; i++)
        {
            int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for(int j = 0; j < 3; j++)
                b[i, j] = c[j];
        }
        for(int i = 0; i < 3; i++)
        {
            int[] d = new int[a];
            int []f = new int[a];
            int z = 0;
            for(int j = 0; j < a; j++) {d[j] = b[j, i]; } 
            Array.Sort(d);
            for(int j = 0; j < a - 1; j++){if (d[j] == d[j + 1]) { f[z] = d[j]; z++; }}
            for(int j = 0; j < a; j++)
            {
                for(int x = 0; x < z; x++)
                {
                    if (b[j, i] == f[x]) goto stop;
                }
                b[j, 3] += b[j, i];
                stop:;
            }
        }
        for (int i = 0; i < a; i++)
        {
            Console.WriteLine(b[i, 3]);
        }
    }
}

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

#define int long long

vector<int> a,b;
  int n;
  int m;
map<pair<pair<pair<int,int>,pair<int,int>>,int>,int> table;

int get_score(int i,int j,int s,int t,int turn){
  if(table.count({{{i,j},{s,t}},turn})){
    return table[{{{i,j},{s,t}},turn}];
  }
  bool astop=false;
  bool bstop=false;
  int res=0;
  for(int card=0;card<(i-s)+(j-t);card++){
    
    if(card%2==turn){
      int bindex=j-card/2-1;
      assert(t<=bindex);
      if(b[bindex]==-1){
	astop=true;
      }
      else if(!bstop){
	res-=b[bindex];
      }
    }
    else{
      int aindex=i-card/2-1;
      assert(s<=aindex);
      if(a[aindex]==-1){
	bstop=true;
      }
      else if(!astop){
	res+=a[aindex];
      }
     
    }
  }
  
  return table[{{{i,j},{s,t}},turn}]=res;
}

int dfs(int i,int j,int s,int t,int turn,int time,map<pair<pair<pair<int,int>,pair<int,int>>,pair<int,int>>,int> &dp){
    if(time==2) return 0;
  if(i==n && j==m && s==n && t==m) return 0;
  if(dp.count({{{i,j},{s,t}},{turn,time}})){
    return dp[{{{i,j},{s,t}},{turn,time}}];
  }
  int res;
  if(i!=s || j!=t) res=get_score(i,j,s,t,turn)+dfs(i,j,i,j,!turn,0,dp);
    else res=dfs(i,j,i,j,!turn,time+1,dp);
  if((turn==0 && i==n) || (turn==1 && j==m)) return dp[{{{i,j},{s,t}},{turn,time}}]=res;
  if(turn==0){
res=max(res,dfs(i+1,j,s,t,!turn,0,dp));

  }
  else{
   res=min(res,dfs(i,j+1,s,t,!turn,0,dp));
  }
  return dp[{{{i,j},{s,t}},{turn,time}}]=res;
}
signed main(){

  cin>>n>>m;
  a.resize(n);b.resize(m);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];
  map<pair<pair<pair<int,int>,pair<int,int>>,pair<int,int>>,int> dp;

  int res=dfs(0,0,0,0,0,0,dp);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 36772
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	long double n,m;
 	cin >> n>>m;
 	long double ans=0;
 	for (int i = 1; i < n+1; i++){
 		long double x=1/n;
 		for (int j = i; j<m;j=j*2){
 			x=x/2;
 		}
 		ans+=x;
 	}
 	cout << setprecision(20)<<ans << endl;
 }

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const string alp = "abcdefghijklmnopqrstuvwxyz";

string child(string x){
	int n = x.size();
	if(n == 26) return "XXX";

	bool used[26];
	rep(i, 26) used[i] = false;

	for(int i = 0; i < n; i++) used[x[i] - 'a'] = true;

	char c;
	for(int i =0; i < 26; i++){
		if(!used[i]){
			c = alp[i];
			break;
		}
	}

	/*
	rep(i, 26) cout << used[i];
	cout << endl;
	cout << (x + (""s + c)) << endl;
	*/

	return x + (""s + c);
}

string nextchild(string x){
	int n = x.size();

	bool used[26];
	rep(i, 26) used[i] = false;

	for(int i = 0; i < n-1; i++) used[x[i] - 'a'] = true;

	char c = x[n-1];
	int idx = c - 'a';
	for(int i = idx + 1; i < 26; i++){
		if(!used[i]){
			idx = i;
			break;
		}
	}

	if(idx == c - 'a') return "XXX";
	return (x.substr(0, n-1) + (""s + alp[idx]));
}

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

	string s;
	cin >> s;

	if(s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}

	int n;
	n = s.size();

	vector<string> v;
	for(int i = 1; i <= n; i++){
		string nc = nextchild(s.substr(0, i));
		if(nc != "XXX") v.push_back(nc);
	}

	string ch = child(s);
	if(ch != "XXX") v.push_back(ch);

	cout << v[v.size()-1] << endl;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>

//
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
constexpr ll    BIGP = 1000000007;
constexpr ll    INF_I = std::numeric_limits<ll>::max();
constexpr float INF_F = std::numeric_limits<float>::infinity();
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    vector<ll> p;
    cin >> N;
    rep(i, N)
    {
        ll t;
        cin >> t;
        p.push_back(t);
    }
    vector<ll> dp(N, INF_I);
    dp[0] = 0;
    dp[1] = dp[0] + abs(p[1]-p[0]);
    for (ll i = 2; i < N; ++i)
    {
        chmin(dp[i], dp[i - 1] + abs(p[i-1] - p[i]));
        chmin(dp[i], dp[i - 2] + abs(p[i-2] - p[i]));
    }
    cout << dp.back();
}

Measured memory_bytes: 4484
from collections import deque
import sys
input = sys.stdin.readline
h, w, k = map(int, input().split())
x1, y1, x2, y2 = [int(a) - 1 for a in input().split()]
c = [input() for _ in range(h)]

inf = 10 ** 8
d = [[inf for _ in range(w)] for _ in range(h)]
move = [(1, 0), (0, 1), (-1, 0), (0, -1)]


que = deque()
for i in range(4):
    d[x1][y1] = 0
    que.append((x1, y1))
    
while len(que):
    cur_x, cur_y = que.popleft()
    if cur_x == x2 and cur_y == y2:
        break
    for dx, dy in move:
        to_x, to_y = cur_x, cur_y
        for _ in range(k):
            to_x += dx
            to_y += dy
            if 0 <= to_x < h and 0 <= to_y < w and c[to_x][to_y] == '.':
                if d[to_x][to_y] > d[cur_x][cur_y] + 1:
                    d[to_x][to_y] = d[cur_x][cur_y] + 1
                    que.append((to_x, to_y))
                elif d[to_x][to_y] == d[cur_x][cur_y] + 1:
                    continue
                else:
                    break
            else:
                break


print(-1 if d[x2][y2] == inf else d[x2][y2])


Measured memory_bytes: 145000
sub main {
    chomp(my $tmp = <STDIN>);
    my ($N, $M) = split(/ /,$tmp);
    print solver($N, $M);
}
main() unless caller;

sub solver {
    my ($N,$M) = @_;
    my $ans = 0;
    if($M > $N*2){
    	$ans = $N;
        $ans += int(($M - $N*2) / 4);
    } else {
    	$ans = int($M/2);
    }
    return $ans;
}

Measured memory_bytes: 384
w = gets.chomp.to_i
n = gets.chomp.to_i

data = (0...w).map { |i| i}
for i in (0...n)
    a,b = gets.chomp.split(",").map {|k| k.to_i - 1}
    tmp = data[a]
    data[a] = data[b]
    data[b] = tmp
end

data.each do |i|
    puts i + 1
end


Measured memory_bytes: 6852
"""
考え方:
    頂点 n までの最大パスを, y = n である有向パスのすべての x の最大パス n' + 1 の中で最大のものから求める.
    x の最大パスが計算されていない場合は先に x の最大パスを同じ方法で求める.
    y = n となる有効パスが存在しない場合, n の最大パスは 0 とする. 有効閉路は存在しないのでループは発生しない.
    計算量は O(N + M) = O(2n) = O(n) .

提出1回目の反省:
    debug 用の print 外し忘れてた

提出2回目の反省:
    なぜ RE になるんじゃぁ
    -> python の最大再帰回数の問題である可能性. あんまりよくない気もするけど設定変更してみよう.
    
提出3回目の反省:
    10000 に設定してみたけどケース1_01ではじかれる. どうも設定値 - 1回目の呼び出しでエラーになるようだ.
    少し余裕をもって10020と設定.

提出4回目の反省:
    それでもケース1_01がダメ. なぜ...
    
"""

import sys
sys.setrecursionlimit(10 ** 6)


N, M = map(int, input().split())
Y = [[] for _ in range(N + 1)]
# print(len(Y), Y)
for _ in range(M):
    x, y = map(int, input().split())
    Y[y].append(x)

dp = [-1] * (N + 1)

def solve(num):
    re = 0
    if dp[num] != -1:
        # すでに計算済みのパスは再計算しない.
        re = dp[num]
    else:
        for x in Y[num]:
            if dp[x] == -1:
                dp[x] = solve(x)
            re = max(re, dp[x] + 1)
    return re

for n in range(1, N + 1):
    dp[n] = solve(n)

print(max(dp))


Measured memory_bytes: 103984
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/08/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  return a%b == 0 ? b : gcd(b, a%b);
}

int ctz(ll x) {
  return __builtin_popcount((x&(-x))-1);
}

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

  int n,m; cin>>n>>m;
  vector<ll> A(n);
  ll _gcd; cin >> _gcd;
  _gcd /= 2;
  A[0] = _gcd;
  auto _ctz = ctz(_gcd);
  ll _lcm = _gcd;
  for (int i = 1; i < n; i++) {
    auto& a=A[i]; cin>>a; a/=2;
    if (ctz(a) != _ctz) {
      cout << 0 << endl;
      return 0;
    }
    _gcd = gcd(_lcm, a);
    _lcm *= a/_gcd;
  }
  cout << (m/_lcm+1)/2 << endl;

  return 0;
}


Measured memory_bytes: 1152
price, n = [int(i) for i in input().split(' ')]
exclude_nums = [int(i) for i in input().split(' ')]

nums = set([i for i in range(0,10)])

for num in exclude_nums:
    nums.discard(num)

while True:
    safe = True
    for num in str(price):
        if int(num) in nums:
            pass
        else:
            price += 1
            safe = False
            break
    if safe:
        print(price)
        break
    

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const char EOL = '\n';

void solve();

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

void solve() {
    int n;
    cin >> n;
    vector<int> l(n);
    REP(i, n) cin >> l[i];
    sort(ALL(l));
    ll ans = 0;
    REP(i, n - 2) FOR(j, i + 1, n - 1) {
        auto pos = lower_bound(ALL(l), l[i] + l[j]);
        ans += max(0, (int)distance(l.begin(), pos) - (j + 1));
    }
    cout << ans << EOL;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

struct E{
        int to;
        ll w;
    };

const int NMAX = int(1e5);
vector<E> edge[NMAX];
int open[NMAX];

void init_open(){
    memset(open, -1, sizeof(open));
}

void dfs(int s, ll w) {
    if (open[s] != -1) return;

    open[s] = w % 2 ? 0 : 1;

    vector<E> next = edge[s];

    REP(i, next.size()) {
        dfs(next[i].to, w + next[i].w);
    }
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N;
    cin >> N;

    init_open();

    int u, v; ll w;
    REP(i, N - 1) {
        cin >> u >> v >> w;
        --u; --v;
        edge[u].pb({v, w});
        edge[v].pb({u, w});
    }

    dfs(0, 0);


    REP(i, N) {
        cout << open[i] << endl;
    }

}


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

#define ll long long int

using namespace std;

int main() {
    ll x;
    cin >> x;
    ll res = 1;
    for (ll i = 2; i * i <= x; ++i) {
        ll tmp = 1;
        ll y = x;
        while (y/i>0) {
            y /= i;
            tmp *= i;
            res = max(res, tmp);
        }
    }
    cout << res << endl;;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int x; cin >> x;
    cout << (x^1) << '\n';
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cassert>
using namespace std;
const int MOD = 1e9 + 7;
int N, A[101010], occ[101010];
int main(){
	cin >> N;
	for(int i = 0; i < N; i++)cin >> A[i];

	int cnt_ch = 0;
	long long int res = 1;
	
	for(int i = 0; i < N; i++){
		if(A[i] != 0){
			res = res * occ[A[i] - 1];
			res = res % MOD;
			
			if(occ[A[i] - 1] <= 0)return cout << 0 << '\n', 0;
			occ[A[i] - 1]--;
		}
		else cnt_ch++;

		if(cnt_ch > 3)return cout << 0 << '\n', 0;
		occ[A[i]]++;
	}
	res = res * (cnt_ch == 1 ? 3 : 6);
	res = res % MOD;

	cout << res << '\n';
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string , int> m;
int main()
{
  	int n;
  	cin>>n;
  	int ar[n];string s;
  	for(int i=0;i<n;i++)
    {
      cin>>s>>ar[i];
      m[s]=i;   
    }
  	cin>>s;
  	int x=m[s];
  ll ans=0;
  for(int i=x+1;i<n;i++)
  {
    ans=ans+ar[i];
  }
  cout<<ans;
}

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

inline int read()
{
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return -x;
}

const int N = 1e5;
const int lgM = 30;
int p[N+3],q[N+3],pp[N+3],qq[N+3];
int g[N+3],f[N+3],ff[N+3];
int tmp[N+3];
int aux[N+3];
int ans[N+3];
int a[7][N+3];
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++) scanf("%d",&p[i]),pp[p[i]] = i;
    for(int i=1; i<=n; i++) scanf("%d",&q[i]),qq[q[i]] = i;
    for(int i=1; i<=n; i++) a[1][i] = p[i],a[2][i] = q[i];
    for(int k=3; k<=6; k++)
    {
        for(int i=1; i<=n; i++) a[k][a[k-2][i]] = a[k-1][i];
    }
    for(int i=1; i<=n; i++) g[i] = q[pp[qq[p[i]]]],f[i] = i,tmp[i] = g[i];
    int nn = m%6==0?6:m%6; m = (m-1)/6;
    for(int i=0; m; i++)
    {
        if(m&(1<<i))
        {
            m-=(1<<i);
            for(int j=1; j<=n; j++) aux[j] = f[tmp[j]];
            for(int j=1; j<=n; j++) f[j] = aux[j];
        }
        for(int j=1; j<=n; j++) aux[j] = tmp[tmp[j]];
        for(int j=1; j<=n; j++) tmp[j] = aux[j];
    }
    for(int i=1; i<=n; i++) ff[f[i]] = i;
    for(int i=1; i<=n; i++) ans[i] = f[a[nn][ff[i]]];
    for(int i=1; i<=n; i++) printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 7040
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Midnight Teatime
public class Main{

	class R{
		int id, x;
		char ch;
		R l, r;
		boolean leaf;
		public R(int id, boolean leaf) {
			this.id = id;
			this.leaf = leaf;
			l = r = null;
			x = 0;
		}
		int get(){
			if(leaf)return x;
			if(ch=='A')return l.get()&r.get();
			else if(ch=='O')return l.get()|r.get();
			else return l.get()^r.get();
		}
		void f(){
			if(leaf){
				System.out.print(x); return;
			}
			System.out.print("(");
			l.f();
			System.out.print(" "+ch+" ");
			r.f();
			System.out.print(")");
		}
	}
	
	int ID, c;
	R[] v;
	R root;
	List<R> leafs;
	
	char[] s;
	int id;
	char get(){
		return s[id++];
	}
	
	R exp(){
		char ch = get();
		if(ch!='('){
			int x = ch-'0';
			R res = new R(x, true);
			leafs.add(res);
			return res;
		}
		R res = new R(ID, false);
		v[ID++] = res;
		res.l = exp();
		get();
		res.r = exp();
		get();
		return res;
	}
	
	void dfs(int k){
		if(k==ID){
			int x = root.get();
			if(x==15)c++;
//			root.f();System.out.println(" F:"+(x==15));
			return;
		}
		v[k].ch = 'A'; dfs(k+1);
		v[k].ch = 'O'; dfs(k+1);
		v[k].ch = 'X'; dfs(k+1);
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			s = (sc.nextLine()+"$").toCharArray();
			if(s[0]=='E')break;
			id = 0;
			v = new R[8];
			leafs = new ArrayList<R>();
			ID = 0;
			root = exp();
			int n = sc.nextInt();
			for(int i=1;i<=n;i++){
				int x = 0;
				for(int j=0;j<4;j++){
					x += sc.nextInt()<<j;
				}
				for(R r:leafs)if(r.id==i)r.x = x;
			}
			sc.nextLine();
			c = 0;
			dfs(0);
			System.out.println(c);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
  int K, N;
  cin >> K >> N;
  
  int max_, bef, first;
  rep(i, N) {
    int now;
    cin >> now;
    if (i == 0) {
      first = now;
    } 
    max_ = max(max_, now-bef);
    bef = now;
  }
  max_ = max(max_, first + K - bef);

  int ans = K - max_;

  cout << ans << endl;
}


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

using namespace std;

long long cnt[100001];

int main () {
	string s;
	cin >> s;
	for (int i = 0;i < s.size ();i ++) {
		cnt[s[i] - 'a' + 1] ++;
	}
	long long n = s.size ();
	long long ans = (n * (n + 1)) / 2;
	for (int i = 1;i <= 26;i ++) {
		ans -= (cnt[i] * (cnt[i] +	 1)) / 2;
	}
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int a,b,c; cin>>a>>b>>c;
  if(a==b) return cout<<c<<endl, 0;
  if(c==b) return cout<<a<<endl, 0;
  cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := getStdinInt()
	d := getStdinIntArr()

	ans := 0

	for x := 0; x < N; x++ {
		for y := 0; y < N; y++ {
			if x == y || y > x {
				continue
			}
			ans += d[x] * d[y]
		}
	}

	fmt.Printf("%d\n", ans)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)  (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) {
	return (x%mod * 1LL * y%mod) %

		mod;
}
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}

int main()
{
	fastio;
	int n;
	cin >> n;
	VI v(n);
	rep(i, n)cin >> v[i];
	bool is = true;
	rep(i, n) {
	     if(v[i]%2==0)
		{
			 if (v[i] % 3 == 0)
			 {

			 }
			 else if (v[i] % 5 == 0)
			 {

			 }
			 else
			is = false;
		}
	}
	if (is)cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}







Measured memory_bytes: 256
#include<stdio.h>
int n,m,i,k[31],a[31][31],f,flag[31],h,count;
int main(void){
    scanf("%d%d",&n,&m);
    for(i = 0;i < n;i++){
    scanf("%d",&k[i]);
    for(f = 0;f<k[i];f++){
        scanf("%d",&a[i][f]);
    }
    }

    for(i=0;i<n;i++){
        for(f=0;f<k[i];f++){
            flag[a[i][f]] += 1;
        }
        
    }
    for(i=1;i<=m;i++){
        if(flag[i] == n){
            count +=1;
        }
    }
    
printf("%d",count);
return 0;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

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

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 2E5 + 10;

int n;
int a[N];

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	sort(a, a + n);
	int ans = 0;
	set<pii> lst;
	for (int i = 0; i < n; ++i)
		lst.emplace(a[i], i);
	for (int i = n - 1; i >= 0; --i){
		if (a[i] == 0)
			continue;
		lst.erase(pii(a[i], i));

		int t = 1 << 32 - __builtin_clz(a[i]);
		eput(i, a[i], t);
		auto p = lst.lower_bound(pii(t - a[i], 0));
		if (p != lst.end() && p->st == t - a[i]){
			++ans;
			a[p->nd] = 0;
			lst.erase(p);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int a[7]={0};int b[7]={0};
	for(int i=0;i<7;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
	}
	for(int i=0;i<7;i++)
	{
		printf("%d\n",a[i]-b[i]);
	}
	return 0;
}


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

c=a[0]
for i in range(n-1):
    c=c^a[i+1]

ans=[0]*n
for i in range(n):
    ans[i]=c^a[i]
L=[str(a) for a in ans]
L=" ".join(L)
print(L)


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

int n;
vector<long long> a;

int main () {
    while (scanf("%d", &n) == 1) {
        a.assign(n, 0);
        for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
        
        int hasZero = 0;
        for (auto &x : a) hasZero |= x == 0;
        if (hasZero) {
            printf("0\n");
            continue;
        }

        double lg = 0;
        for (auto &x : a) lg += log10(x);

        if (lg > 18.5) printf("-1\n");
        else {
            long long res = 1;
            for (auto &x : a) res *= x;
            if (res > 1ll * 1000000000 * 1000000000) printf("-1\n");
            else printf("%lld\n", res);
        }
    }
}



Measured memory_bytes: 4064
use itertools::Itertools as _;
use itertools_num::ItertoolsNum as _;
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut r#as: [usize; n],
    }

    for _ in 0..k {
        let mut imos = vec![0; n + 1];

        for (i, &a) in r#as.iter().enumerate() {
            let l = i.saturating_sub(a);
            let r = cmp::min(i + a + 1, n);
            imos[l] += 1;
            imos[r] -= 1;
        }

        r#as = imos[..n].iter().map(|&c| c as usize).cumsum().collect();

        if r#as.iter().all(|&a| a == n) {
            break;
        }
    }

    println!("{}", r#as.into_iter().format(" "));
}


Measured memory_bytes: 7116
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch FiveDishes | diff FiveDishes.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address FiveDishes.cpp && ./a.out

/*
 
 4/7/2019
 
 20:01-
 
 */

LL A[5];

void solve() {
  int k=0;
  REP(i,5) {
    int x=A[i]%10; if(x==0) x=11;
    int y=A[k]%10; if(y==0) y=11;
    if(x<y) k=i;
  }
  int res=0;
  REP(i,5) {
    if(i==k) res+=A[i];
    else res+=(A[i]+9)/10*10;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  REP(i,5) cin>>A[i];
  solve();
  
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 1e9;
const ll lINF = 1e18;
const int MOD = 1e9+7;
const int SIZE = 100;


int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length()-1; i++) {
		if (s[i] == 'A' && s[i+1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int S[1010];
        S[0]=0;
        rep(i, 1010-1) S[i+1]=S[i]+i+1;
        int n=0;
        while(scanf("%d", &n) && n){
                int ans=0;
                rep(i, 1010){
                        int idx=lower_bound(S, S+1010, S[i]+n)-S;
                        if(idx!=1010 && S[idx]==S[i]+n) ++ans;
                }
                printf("%d\n", ans-1);
        }
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll gcd(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

ll A[20];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll ans = A[0];
    FOR(i, N, 1)
    {
        ll g = gcd(ans, A[i]);
        ans = (ans / g) * A[i];
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back

bool visited[100005];
int path[100005];

vector<int> adj[100005];

queue<int> q;

int main() {
	memset(visited, false, sizeof(visited));
	int n, m; cin >> n >> m;
	int x, y;
	bool chk = 0;
	for(int i=1; i<=m; ++i){
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x); // bidirectional
		
		if(x==1 || y==1)
			chk = 1;
	}
	
	if(!chk){
		cout << "No";
		return 0;
	}
	
	q.push(1);
	while(q.size()){
		int x = q.front();    //bfs
		q.pop();
		if(!visited[x]){
			visited[x] = true;
			for(int i=0; i<adj[x].size(); ++i){
				q.push(adj[x][i]);
				
				if(!path[adj[x][i]])
					path[adj[x][i]] = x;
			}
		}
	}

	cout << "Yes" << "\n";
	for(int i=2; i<=n; i++)
		cout << path[i] << "\n";
	
}

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

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

    int h, n;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += a;
    }

    cout << (h <= sum ? "Yes" : "No") << endl;
}


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

int main() {
	int n;
	cin >> n;
	set<string>ss;
	queue<string>qs;
	qs.push("a");
	while (qs.size() > 0) {
		string x = qs.front();
		if (x.length() == n) ss.insert(x);
		else {
			int y = 0;
			for (int i = 0; i < x.length(); i++)y = max(y, x.at(i) - 'a');
			for (int i = 0; i <= y+1; i++) {
				char w = 'a' + i;
				string z = x + w;
				qs.push(z);
			}
		}
		qs.pop();
	}
	for (auto a : ss) {
		cout << a << endl;
	}

}

Measured memory_bytes: 14208
s = input()
pre = s[0:2]
post = s[2:]

pre = int(pre)
post = int(post)

if (13 > pre) and (pre > 0):
    s_pre = "M"
else:
    s_pre = "NM"

if (13 > post) and (post > 0):
    s_post = "M"
else:
    s_post = "NM"


# print(s_pre, s_post)

if s_pre == "M":
    if s_post == "NM":
        ans = "MMYY"
    else:
        ans = "AMBIGUOUS"
else:
    if s_post == "NM":
        ans = "NA"
    else:
        ans = "YYMM"
print(ans)

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

int main() {
	string S, T;
	cin >> S >> T;

	bool commonFlag;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == T[0]) {
			commonFlag = true;
			for (int j = 0; j < S.length(); j++) {
				if (S[(i+j)%S.length()] != T[j]) {
					commonFlag = false;
					break;
				}
			}
			if (commonFlag)
				break;
		}
	}
	if (commonFlag) 
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


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

	vector<string> d(h+1, "");
	for (size_t i = 0; i < h; i++)
	{
		cin >> d[i];
		d[i] += "#";
	}
	for (size_t i = 0; i < w + 1; i++)
	{
		d[h] += "#";
	}

	vector<vector<int>> wn(h, vector<int>(w + 1, 0));
	vector<vector<int>> hn(h + 1, vector<int>(w, 0));

	for (size_t y = 0; y < h; y++)
	{
		for (size_t x = 0; x < w+1; x++)
		{
			if (d[y][x] == '.')
			{
				wn[y][x] = x == 0 ? 1 : (wn[y][x-1] + 1);
			}
			else
			{
				wn[y][x] = 0;
				if (x != 0)
				{
					for (size_t i = 1; i < wn[y][x-1]; i++)
					{
						wn[y][x - 1 - i] = wn[y][x - 1];
					}
				}
			}
		}
	}

	for (size_t x = 0; x < w; x++)
	{
		for (size_t y = 0; y < h+1; y++)
		{
			if (d[y][x] == '.')
			{
				hn[y][x] = y == 0 ? 1 : (hn[y-1][x] + 1);
			}
			else
			{
				hn[y][x] = 0;
				if (y != 0)
				{
					for (size_t i = 1; i < hn[y-1][x]; i++)
					{
						hn[y - 1 - i][x] = hn[y - 1][x];
					}
				}
			}
		}
	}

	int ans = 0;
	for (size_t x = 0; x < w; x++)
	{
		for (size_t y = 0; y < h; y++)
		{
			if (d[y][x] != '.')
			{
				continue;
			}
			ans = max(ans, wn[y][x] + hn[y][x] - 1);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 35840
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int ans=0;
  while(n) {
    int x,i;
    scanf("%d",&x);
    for(i=2; i*i<=x; i++) {
      if(x%i==0) break;
    }
    if(i*i>x) ans++;
    n--;
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2028
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        mut aa: [isize; n]
    };
    aa.sort();
    aa.reverse();
    let mut num = 0;
    for (i, a) in aa.iter().enumerate() {
        num += (-1isize).pow(i as u32) * a;
    }
    println!("{}", num);
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main(){
    long long int n,k;
    cin >> n >> k;
    long long int arr[n];

    for (int i=0 ; i<n ; i++){
        cin >> arr[i];
    }

    long long int dp[n][k+1];
    long long int sum[n][k+1];
    for (int i=0 ; i<n ; i++){
        for (int j=0 ; j<=k ; j++){
            dp[i][j] = 0;
            if (i==0){
                if (j<=arr[0]){
                    dp[i][j] = 1;
                }
                else{
                    dp[i][j] = 0;
                }

                if (j==0){
                    sum[i][j] = dp[i][j];
                }
                else{
                    sum[i][j] = (sum[i][j-1] + dp[i][j])%MOD;
                }

            }
            else{
                
                if (arr[i] >= j){
                    dp[i][j] = sum[i-1][j]%MOD;
                }
                else{
                    dp[i][j] = ((sum[i-1][j] - sum[i-1][j-arr[i]-1])%MOD + MOD)%MOD;
                }


                if (j==0){
                    sum[i][j] = dp[i][j]%MOD;
                }
                else{
                    sum[i][j] = (sum[i][j-1] + dp[i][j])%MOD;
                }

            }
            //cout << dp[i][j] << " " << sum[i][j] << "  ";
        }
        //cout << "\n";
    }
    cout << dp[n-1][k]%MOD << "\n";
    return 0; 
}

Measured memory_bytes: 156544
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
        return "Possible".to_string();
    }

    return "Impossible".to_string();
}


Measured memory_bytes: 2128
from collections import Counter
n=input()
a=sorted(list(map(int,input().split())))[::-1]
ca=Counter(a).most_common()
if ca[1][1]<2:
    if ca[0][1]<4:print(0)
    else:print(ca[0][0]**2)
else:
    l=[]
    for i,j in ca:
        for _ in range(j//2):l.append(i)
    l.sort()
    print(l[-1]*l[-2])

Measured memory_bytes: 21540
import scala.io.Source.stdin
 
object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1
 
    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
      primes(i) = primes(i) + primes(i-1)
      primes(i+1) = primes(i)
    }
 
    for(i<-Math.sqrt(n).toInt+1 to n)
      primes(i) = primes(i)+primes(i-1)
 
    primes
  }
 
  def main(args:Array[String]) = {
    val p = sieve(1000000)
    for(i <- stdin.getLines) 
      println(p(i.toInt))
  }
}

Measured memory_bytes: 63680
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	int n,p,a,b,x;
	int c1 = 0,c2 = 0,c3 = 0;
	cin >> n >> a >> b;
	FER(i,0,n){
		cin >> x;
		if(x <= a) c1++;
		else if(x <= b) c2++;
		else c3++;
	}

	cout << min(c1,min(c2,c3)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	map<int, int> solved;
	vector<int> rank;
	int a, b;
	while (true)
	{
		scanf("%d,%d\n", &a, &b);
		if (a == 0 && b == 0)
			break;
		solved.insert(make_pair(a, b));
		rank.push_back(b);
	}

	sort(rank.begin(), rank.end(), greater<int>());
	vector<int>::iterator e = unique(rank.begin(), rank.end());
	rank.erase(e, rank.end());

	while (scanf("%d\n", &a) != EOF)
	{
		int s = solved[a];
		int r;
		for (r = 1; r <= rank.size(); ++r)
		{
			if (s == rank[r-1])
				break;
		}
		printf("%d\n", r);
	}
	
	return 0;
}

Measured memory_bytes: 0
function main(input) {
  const inputs = input.split('\n')[0].split('').map( x => parseInt(x, 10))
  const length = inputs.length

  surface = 0;
  reverse = 0;
  for(i=0; i<length; i++){
    current_char = inputs[i]
    if(i%2==0){
      if(current_char==0){
        surface++;
      }else{
        reverse++;
      }
    }else{
      if(current_char==0){
        reverse++;
      }else{
        surface++;
      }
    }
  }

  console.log(Math.min(surface, reverse));
}

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


Measured memory_bytes: 9664
// Problem : A - Children and Candies (ABC Edit)
// Contest : AtCoder - AtCoder Beginner Contest 043
// URL : https://atcoder.jp/contests/abc043/tasks/abc043_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	cout << n*(n+1)/2;
	return 0;
}

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

int main(){
    string x;
    cin >> x;
    int cnt = 0, ans = 0;
    for(int i=0;i<x.size();++i){
        if(x[i] == 'S')cnt++;
        else if(cnt > 0){
            cnt--;
            ans++;
        }
    }

    cout << x.size() - 2 * ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
//A[i]+A[j] == i-j;
//j+A[i] == i-A[j]
signed main(){
    int N;
    cin >> N;
    vector<int>A(N);
    map<int,int>Map;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        Map[i+1-A[i]]++;
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans+=Map[A[i]+i+1];
    }
    cout << ans << endl;
}
//4 0 1 -2 3 2
//6 4 7 6 13 14

Measured memory_bytes: 27344
# coding: utf-8

n, m = map(int, input().split())
z = 10**9 + 7

ans = [1]
if m != 0:
    a_i = int(input())
else:
    a_i = 0
m_count = 1
if a_i == 1:
    ans.append(0)
    if m_count < m:
        a_i = int(input())
        m_count += 1
else:
    ans.append(1)
        
for i in range(2, n+1):
    if a_i == i:
        ans.append(0)
        if m_count < m:
            a_i = int(input())
            m_count += 1
    else:
        ans.append(ans[i-1]+ans[i-2])
        
# print(ans, ans[67])
print(int(ans[-1]%z))

Measured memory_bytes: 460020