akhauriyash/Code-Regression huggingface dataset:
// #define pragma

#ifdef pragma
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif // pragma

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define all(x) begin(x), end(x)
#define pb push_back
#define x first
#define y second
#define int long long
#define zero(two) memset(two, 0, sizeof(two))

using namespace std;
using namespace __gnu_pbds;


typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<vi> matrix;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = atan2(0, -1);

void seriy() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    cout << fixed << setprecision(10);
    #if _offline
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

const int MAXN = 5e3 + 10;
const int INF = 1e18 + 7;
const int MAXLOG = 31;
const int MOD = 1e9 + 7;
const int BASE = 47;

bool cmp(int a, int b) {
    return a % 10 == 0 || a % 10 > b % 10;
}

signed main() {
    seriy();
    vi a(5);
    for(int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    sort(all(a), cmp);
    int ans = a[4];
    for(int i = 0; i < 4; i++) {
        ans += a[i];
        if(a[i] % 10 != 0) ans += (10 - a[i] % 10);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N, M, X, Y = list(map(int, input().split()))
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))

if max(x_list) < min(y_list) and max(x_list) > X and min(y_list) <= Y:
    ans = "No War"
else:
    ans = "War"

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int H = in.nextInt();
            int W = in.nextInt();
            int h = in.nextInt();
            int w = in.nextInt();
            System.out.println((H - h) * (W - w));
        }
    }
}


Measured memory_bytes: 23764
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	z := make([]int, n-1)
	ans := make([]int, n)
	for i, _ := range z {
		fmt.Scan(&z[i])
		ans[z[i]-1]++
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 8548
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i, n) is[s[i] - 'a'].insert(i);
    rep(qi,q){
        int type;
        cin >> type;
        if(type == 1){
            int a;
            char b;
            cin >> a >> b;
            a--;
            is[s[a] - 'a'].erase(a);
            s[a] = b;
            is[s[a] - 'a'].insert(a);
        }else{
            int l,r;
            cin >> l >> r;
            l--;
            int ans = 0;
            rep(i,26){
                auto it = is[i].lower_bound(l);
                if (it != is[i].end() && *it < r)
                    ++ans;   
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,q,i,a[100005]={0},b[100005]={0};
    long long int k;
    scanf("%d%lld%d",&n,&k,&q);
    for(i=0;i<q;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<q;i++)
    {
        b[a[i]]++;
    }
    for(i=1;i<=n;i++)
    {
        if(b[i]>q-k)
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
    // FILE;
    SPEED;
    int n;
    cin>>n;
    int arr[n];
    fain(arr);

    int cc=0;
    for(int i=0;i<n;i++){
        if(arr[i]%2==1&&(i+1)%2==1)
            cc++;
    }

    cout<<cc<<endl;

}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
			  //??\???
			  String ab = input.readLine();
		      int a=Integer.parseInt(ab);
		      String an=input.readLine();
		      String[] strAry;
		      //????????????????´?????????????????´?
	          strAry=an.split(" ");
	          //??\??????????????°??????????????????????????§a????????§-1??????????????§??°?????????
	          //a???5?????¨???5.4.3.2.1??§0????????????????????¨???
	          for(int i=a-1; i>=0; i--){
	        	  //Array???????????????????????????????????????
	               int  b=Integer.parseInt(strAry[i]);
	                 //??\??????????????????i???????????°???????????????a?????°????????????
	               if(i>0){
	                    System.out.print(b+" ");
	               }else{
	            	   System.out.print(b);
	               }

	        	}
	          System.out.println("");






		    }catch(IOException e) {   System.out.println("Exception : " + e);
		    }

	}
}

Measured memory_bytes: 24268
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int X;
	int A;
	cin >> X;
	cin >> A;

	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5+5;

int n, h, w, x[MAXN], y[MAXN], dp[MAXN];
map<pii, bool> m;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		m[pii(x[i], y[i])] = 1;
	}
	dp[1] = 1;
	for (int i = 2; i <= w; ++i)
		dp[i] = h;
	for (int i = 1; i < w; ++i) {
		int t = dp[i];
		if (dp[i] == h) {
			dp[i+1] = h;
			continue;
		}
		while (true) {
			t++;
			if (t == h) {
				dp[i+1] = h;
				break;
			}
			if (m.count(pii(t, i+1)) == 0) {
				dp[i+1] = t;
				break;
			}
		}
	}

	int ans = h;
	for (int i = 0; i < n; ++i) {
		// cout << y[i] << ' ' << dp[y[i]] << ' ' << x[i] << endl;
		if (dp[y[i]] < x[i])
			ans = min(ans, x[i]-1);
	}

	cout << ans << endl;
}

Measured memory_bytes: 15104
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var count = 0;
        for (int i = 0; i < n; i++)
            if (a[i] >= k) count++;
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 18016
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout<<"No"<<endl;
		return 0;
	}
	if(a!=b&&b!=c&&a!=c){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()
    val aArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    val skipMax = 1 + n % 2

    // dp[インデックス][A_1を起点として開始すると仮定した場合のスキップ済み数][その数を用いたか0:用いていない 1:用いた]
    // 求める物はmax(dp[n - 1][skipMax][1], dp[n - 1][skipMax - 1][0])
    val dp = Array(n) { Array(skipMax + 1) { LongArray(2) { Long.MIN_VALUE } } }

    dp[0][0][1] = aArr[0]
    dp[0][1][0] = 0L

    for (i in 1 until n) {
        dp[i][0][0] = dp[i - 1][0][1]
        if (dp[i - 1][0][0] != Long.MIN_VALUE) {
            dp[i][0][1] = dp[i - 1][0][0] + aArr[i]
        }

        for (j in 1..skipMax) {
            dp[i][j][0] = max(dp[i - 1][j][1], dp[i - 1][j - 1][0])
            if (dp[i - 1][j][0] != Long.MIN_VALUE) {
                dp[i][j][1] = dp[i - 1][j][0] + aArr[i]
            }
        }
    }

    builder.appendln(max(dp[n - 1][skipMax][1], dp[n - 1][skipMax - 1][0]))

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 84032
k,n=map(int,input().split())
a=[int(i) for i in input().split()]
len_array=[]
for i in range(n):
    if i==n-1:
        length=a[0]-a[i]+k
    else:
        length=a[i+1]-a[i]
    len_array.append(length)  
print(sum(len_array)-max(len_array))


Measured memory_bytes: 24908
K = int(input())
S = input()
M = int(10 ** 9 + 7)

fact = [1]
for i in range(1, K + len(S) + 10):
    fact.append(fact[-1] * i % M)

finv = [pow(fact[-1], M - 2, M)]
for i in range(K + len(S) + 9, 0, -1):
    finv.append(finv[-1] * i % M)
finv.reverse()

def comb(a, b, m):
    return fact[a] * finv[b] % m * finv[a - b] % m

def hcomb(a, b, m):
    return comb(a + b - 1, a - 1, m)

ans = 0
for l in range(0, K + 1):
    ans += pow(26, l, M) * pow(25, K - l, M) % M * hcomb(len(S), K - l, M) % M
    ans %= M
print(ans)


Measured memory_bytes: 213648
from sys import *
n = stdin.readline()
things = list(map(int, stdin.readline().split()))

if min(things) == 0:
    print(0)
    exit()
hue = things[0]
for i in range(1, len(things)):
    hue *= things[i]
    if hue > 10**18:
        print(-1)
        exit()
print(hue)


Measured memory_bytes: 21904
#include<stdio.h>
int main(void)
{
  char s[3];
  int i,n;
  n=0;
  scanf("%s",s);
  while(s[i]){
    if(s[i]=='1'){
      n+=1;}
    i++;
  }
  printf("%d",n);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = Long.parseLong(scan.nextLine());
    long tmp = 0;
    long max = 0;
    for(int i = 0;i < 5;i ++){
      tmp = Long.parseLong(scan.nextLine());
      tmp = (tmp + n - 1) / tmp;
      if(tmp > max){
        max = tmp;
      }
    }
    System.out.println(max + 4);
  }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a;cin >> a;
    ld b;cin >> b;
    cout << ll(a*b+0.001) << endl;
}


Measured memory_bytes: 3756
#include<cmath>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100;
inline ll read(){
	ll x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
struct cqz{int x,i;};
inline bool operator<(cqz i,cqz j){
	return i.x>j.x;
}
#include<queue>
priority_queue<cqz>q;
int n,i,j,a[N],x[N];
int main(){
	//freopen("1.out","w",stdout);
	n=read();
	for(i=1;i<=n;i++){
		x[i]=read();
		if(a[x[i]])goto fuck;
		a[x[i]]=i;
		for(j=1;j<i;j++)
		q.push((cqz){x[i],i});
		x[i]=i;
	}
	for(i=1;i<=n*n;i++)
	if(a[i]){
		x[a[i]]--;
		if(x[a[i]])goto fuck;
		for(j=a[i]+1;j<=n;j++)
		q.push((cqz){n*n+1,a[i]});
	}else{
		if(q.empty())goto fuck;
		a[i]=q.top().i;q.pop();
		x[a[i]]--;
	}
	puts("Yes");
	for(i=1;i<=n*n;i++)printf("%d ",a[i]);
	return 0;fuck:puts("No");
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
const ll MAX = 1000100;

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


void combint()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	fr(i,2,MAX+1)
	{
		fac[i]=fac[i-1]*i%mod;
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
ll comb(ll n,ll r)
{
	if(n<r)
		return 0;
	if(n<0||r<0)
		return 0;

	return fac[n]*(finv[r]*finv[n-r]%mod)%mod;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll x,y;
	rl2(x,y);
	combint();
	if((x+y)%3!=0)
	{
		cout<<0<<endl;
		return 0;
	}
	ll n=(2*y-x)/3;
	ll m=(2*x-y)/3;
	if(n<0||m<0)
	{
		cout<<0<<endl;
		return 0;
	}
	ll ans=0;
	ll cnr=comb(n+m,m);
	ans+=cnr;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 23680
import sys
input = sys.stdin.readline
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))+[0]
green = list(map(int,input().split()))+[0]
cless = list(map(int,input().split()))+[0]
red.sort(reverse = True)
green.sort(reverse = True)
cless.sort(reverse = True)
red_ind = 0
green_ind = 0
cless_ind = 0
ans = 0
for _ in range(x+y):
    if red_ind == x:
        red_ind = a
    if green_ind == y:
        green_ind = b
    if max(red[red_ind],green[green_ind],cless[cless_ind]) == red[red_ind]:
        ans += red[red_ind]
        red_ind += 1
    elif max(red[red_ind],green[green_ind],cless[cless_ind]) == green[green_ind]:
        ans += green[green_ind]
        green_ind += 1
    else:
        ans += cless[cless_ind]
        cless_ind += 1

print(ans)


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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	int h, w, k; cin >> h >> w >> k;
	vector<vector<int>> grid(h, vector<int>(w));

	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++){
			char c; cin >> c;
			grid[i][j] = (c=='.'?0:1);
		}

	int mask = 0;
	int ans = 0;

	for(int mask = 0; mask < (1<<(h+w)); mask++)
	{
		int sum = 0;
		for(int i = 0; i < h; i++)
		{
			if(mask & (1<<i)) continue;
			for(int j = 0; j < w; j++)
			{
				if(mask & (1<<(h+j))) continue;
				sum += grid[i][j];
			}
		}
		if(sum == k) ans++;
	}

	cout << ans << '\n';


	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#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 <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> a(100010, 0);
	rep(i, N)
	{
		ll tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		a[tmp1] += tmp2;
	}

	ll ind = 0;
	for(int i=1;i<=100000;i++)
	{
		K -= a[i];
		ind = i;
		if (K <= 0)
		{
			co(i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int n, Q;
int a[maxn];
int cnt[maxn];

lli sum = 0;

void read_input()
{
    cin >> n;
    fill(begin(cnt), end(cnt), 0);
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        sum += a[i];
        ++cnt[a[i]];
    }
}

void solve()
{
    cin >> Q;
    for(; Q > 0; --Q)
    {
        int x, y;
        cin >> x >> y;
        sum -= x * 1LL * cnt[x];
        sum += y * 1LL * cnt[x];
        cnt[y] += cnt[x];
        cnt[x] = 0;
        cout << sum << '\n';
    }
}

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



Measured memory_bytes: 4392
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define LL long long int
using namespace std;
int main()
{
    int s,k,a,b,c;
   scanf("%d %d",&s,&k);
   if(k>s*3)
    printf("0\n");
   else if( k==s*3||k==0)
    printf("1\n");
   else if(k<s*3)
   {
       int ans=0;
       for(a=0;a<=s&&a<=k;a++)
       {
           c=k-a-a;
           if(c>=0&&c!=a&&c<=s)
           ans+=3;
           else if(c>=0&&c==a&&c<=s)
            ans++;
           for(b=a+1;b<=s&&b<=k;b++)
           {
               c=k-a-b;
               if(c>=0&&c>a&&c>b&&c<=s)
                ans+=6;
           }
       }
   printf("%d\n",ans);

   }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    rep(i,n)a[i]--;
    VEC(int,b,n);
    VEC(int,c,n-1);
    int ans=0;
    ans+=b[a[0]];
    rrep(i,1,n){
        ans+=b[a[i]];
        if(a[i]-a[i-1]==1)ans+=c[a[i-1]];
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int MAX_V=110;
struct edge{int to;ll cap;ll cost;int rev;};
int tmp1,tmp2;

int V;//頂点数
vector<vector<edge>> g(MAX_V);
vll h(MAX_V);//ポテンシャル
vll dist(MAX_V);
vin prevv(MAX_V),preve(MAX_V);//直前の頂点と辺

void add_edge(int from,int to,ll cap,ll cost){
    tmp1=g[to].size();tmp2=g[from].size();
    g[from].push_back((edge){to,cap,cost,tmp1});
    g[to].push_back((edge){from,(ll)0,-cost,tmp2});
}

//sからtへの最小費用流を求める
//ながせない場合は-1
ll min_cost_flow(int s,int t,ll f){
    ll res=(ll)0;
    fill(all(h),(ll)0);
    ll d;
    while(f>0){
        //dijkstraを用いてhを初期化
        priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
        fill(all(dist),(ll)inf);
        dist[s]=(ll)0;
        pq.push(mp((ll)0,s));
        while(pq.size()){
            auto p=pq.top();pq.pop();
            int v=p.second;
            if(dist[v]<p.first)continue;
            for(int i=0;i<g[v].size();i++){
                auto& e=g[v][i];
                if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                    dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                    prevv[e.to]=v;
                    preve[e.to]=i;
                    pq.push(mp(dist[e.to],e.to));
                }
            }
        }
        if(dist[t]==inf)return -1;
        rep(v,V)h[v]+=dist[v];
        d=f;
        for(int v=t;v!=s;v=prevv[v])d=min(d,g[prevv[v]][preve[v]].cap);
        f-=d;
        res+=d*h[t];
        for(int v=t;v!=s;v=prevv[v]){
            auto& e=g[prevv[v]][preve[v]];
            e.cap-=d;
            g[v][e.rev].cap+=d;
        }
    }
    return res;
}

int main(){
    int e,f;cin>>V>>e>>f;
    int u,v;ll c,d;
    rep(i,e){
        cin>>u>>v>>c>>d;
        add_edge(u,v,c,d);
    }
    cout<<min_cost_flow(0,V-1,f)<<endl;
}


Measured memory_bytes: 3252
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll A(N);
  bool all_same = true;
  REP(i, 0, N) {
    cin >> A[i];
    if (i > 0) {
      if (A[i] != A[i - 1]) {
        all_same = false;
      }
    }
  }

  if (all_same) {
    cout << 1 << endl;
    return 0;
  }

  if (A.size() == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll stat = 0;
  ll ans = 1;
  REP(i, 1, N) {
    if (A[i - 1] < A[i]) {
      if (stat == 1) {
        ans++;
        stat = 0;
      } else {
        stat = -1;
      }
    } else if (A[i - 1] > A[i]) {
      if (stat == -1) {
        ans++;
        stat = 0;
      } else {
        stat = 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll k;
    cin >> k;
    vll vals;
    for(ll i=1;i<=9;i++) {
    	vals.pb(i);
    }
    for(ll i=0;vals.size() <= k;i++) {
    	ll temp = vals[i]*10;
    	ll jj = vals[i]%10;
    	if(jj - 1 != -1) {
    		vals.pb(temp + jj - 1);
    	}
    	vals.pb(temp + jj);
    	if(jj + 1 != 10) {
    		vals.pb(temp + jj + 1);
    	}
    }
    cout << vals[k-1] << "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
      // OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}

int main(){
  string s; cin >> s;
  bool a = false;
  bool b = false;
  REP(i,3){
    if(s[i]=='A'){a =true;}
    else{b=true;}
  }
  if(a*b){cout << "Yes\n";}
  else{cout << "No\n";}
  
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
	int parent;
	int left, right;
} Node;

Node tree[50];

void preorder_walk(int p) /* root -> left -> right */
{
	if (p >= 50 || p == -1) {
		return;
	}
	printf(" %d", p);
	preorder_walk(tree[p].left);
	preorder_walk(tree[p].right);
}
void inorder_walk(int p) /* left -> root -> right */
{
	if (p >= 50 || p == -1) {
		return;
	}
	inorder_walk(tree[p].left);
	printf(" %d", p);
	inorder_walk(tree[p].right);
}
void postorder_walk(int p) /* left -> right -> root */
{
	if (p >= 50 || p == -1) {
		return;
	}
	postorder_walk(tree[p].left);
	postorder_walk(tree[p].right);
	printf(" %d", p);
}

int main()
{
	int i;
	int n;
	int id, left, right;
	int p;
	for (i = 0; i < 50; i++) {
		tree[i].parent = -1;
	}

	scanf("%d", &n);

	/* construct tree */
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		tree[id].left = left;
		tree[id].right = right;
		if (left != -1) {
			tree[left].parent = id;
		}
		if (right != -1) {
			tree[right].parent = id;
		}
	}

	/* find root id */
	for (i = 0; i < n; i++) {
		if (tree[i].parent == -1) {
			p = i;
			break;
		}
	}

	/* preorder - walk */
	puts("Preorder");
	preorder_walk(p);
	printf("\n");

	/* inorder - walk */
	puts("Inorder");
	inorder_walk(p);
	printf("\n");

	/* postorder - walk */
	puts("Postorder");
	postorder_walk(p);
	printf("\n");
}

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

typedef long long int ll;

int main()
{
    ll sum = 0;
    for(ll i = 0;i < 3;i++){
        ll t;
        cin >> t;
        sum += t;
    }

    if(sum >= 22){
        cout << "bust";
    }
    else{
        cout << "win";
    }

    return 0;
}

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

#pragma warning(disable:4996)
using namespace std;

#define Seg_Max_N (1<<20) 

using Value = int;
const Value ini = 0;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return l+r;
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};

int main() {
	int N;cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;++i)cin>>v[i];
	map<int,vector<int>>mp;
	for (int i = 0; i < N; ++i) {
		mp[v[i]].push_back(i);
	}

	long long int answer=0;
	segtree seg(N);
	for (int i = 0; i < N; ++i) {
		seg.update(i,1);
	}
	for (auto m : mp) {
		for (auto p : m.second) {
			seg.update(p, 0);
		}
		for (auto p : m.second) {
			int l_cnt=seg.query(0,p);
			int r_cnt=seg.query(p+1,N);
			answer+=min(l_cnt,r_cnt);
		}
		
	}
	cout<<answer<<endl;
	return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[8]={-1, -1, -1, 0, 0, 1, 1, 1}, dy[8]={-1, 0, 1, -1, 1, -1, 0, 1}; 

int main()
{
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    rep(y, H) {
        rep(x, W) {
            if (S[y][x] == '#') {
                cout << S[y][x];
                continue;
            }
            int cnt = 0;
            rep(i, 8) {
                int nx = x + dx[i], ny = y + dy[i];
                if (in_range(nx, ny, W, H)) {
                    cnt += S[ny][nx] == '#';
                }
            }
            cout << cnt;
        }
        cout << endl;
    }
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int A = int.Parse(b[0]); int B = int.Parse(b[1]);
            int an;
            an = (A - 1) * (B - 1);
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 11092
# https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c

s = input()
ans = 0
l = 0
r = len(s) - 1
while l <= r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        l += 1
        ans += 1
    elif s[r] == 'x':
        r -= 1
        ans += 1
    else:
        ans = -1
        break
print(ans)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

ll pow(ll x) {
  return x*x*x*x*x;
}

int main() {
  ll x;
  cin >> x;
  REP(i, 1000) {
    FOR(j, -1000,  1000) {
      ll num = pow(i)-pow(j);
      if(num==x) {
        printf("%d %d", i, j);
        return 0;
      }
    }
  }


  return 0;
}

Measured memory_bytes: 3724
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N;
        cin >> N;
        vector<int> A(N);
        int cnt = 0;
        ll ans = 0;
        int m = (int)1e9 + 10;
        for (int i = 0; i < N; i++)
        {
                cin >> A[i];
                if (A[i] < 0)
                {
                        cnt++;
                }

                m = min(abs(A[i]), abs(m));
                ans += abs(A[i]);
        }

        if (cnt % 2 == 0)
        {
                cout << ans << endl;
        }
        else
        {
                cout << ans - 2 * m << endl;
        }

        return 0;
}


Measured memory_bytes: 640
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
    ll N,Q;
    cin>>N;
    map<ll,ll> A;
    ll s = 0;
    rep(i,N) {ll tmp; cin>>tmp; A[tmp]++; s+=tmp;}
    cin>>Q;
    
    rep(i,Q){
        ll b,c;
        cin>>b>>c;
        // for(auto kv : A){
        //     cout << kv.first << " " << kv.second << endl;
        //     // s+=kv.first*kv.second;
        // }
        s = s + A[b]*c - A[b]*b;
        A[c] += A[b];
        A[b] = 0;
        cout<<s<<endl;
    }
    
    return 0;
}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = 0; i < 2; ++i) {
    if (A >= B) {
      ans += A;
      A--;
    } else {
      ans += B;
      B--;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#!/usr/env/bin ruby

r, c = gets.chomp.split.map(&:to_i)

sheet = []
r.times do
  sheet << gets.chomp.split.map(&:to_i)
end

sheet.map{|e| e << e.inject(:+)}.transpose.map{|e| e << e.inject(:+)}.transpose.map{|e| puts e * ' '}

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

int f(int x)
{
    return x*x;
}

int area(int d) {
   int x,y,sum,i;
   x=600;
   y=f(d);
   sum=0;
   i=1;
   
   while(d*i<=600-d)
   {
       sum+=y*d;
       i++;
       y=f(d*i);
   }
    return sum;
}

int main(void){
    int d;
    while(cin >> d) {
       cout << area(d) << endl;
    }
    return 0;
}




Measured memory_bytes: 3064
/**
* @author Ashini Singha
* IIT,Jahangirnagar University
*/
#include<bits/stdc++.h>
using namespace std;
#define     ll          long long int
#define     fo(i,b,n)   for(int i=(b); i<(n) ; i++)
#define     xx          first
#define     yy          second
#define     pb          push_back
#define     sz(n)       int(n.size())
#define     pii         pair
#define     MP          make_pair
#define     PI          acos(-1.0)

#define read(x)         scanf("%d",&x)
#define read2(x,y)      scanf("%d%d",&x,&y)
#define readl(x)        scanf("%lld",&x)
#define readl2(x,y)     scanf("%lld%lld",&x,&y)
#define readd(x)        scanf("%lf",&x)
#define readd2(x,y)     scanf("%lf%lf",&x,&y)

#define pr(n)           printf("%d",n)
#define prn(n)          printf("%d\n",n)
#define prl(n)          printf("%lld",n)
#define prln(n)         printf("%lld\n",n)
#define prd(x)          printf("%lf",x)
#define prdn(x)         printf("%lf\n",x)
#define TC(n) printf("Case %d: ",n)
/*_____________E_N_D______________*/

vector<string>v;
int vis[100][100];

bool cmp(string a, string b)
{
      return sz(a) < sz(b);
}

int main()
{
      int n;
      read(n);
      fo(i, 0, n) {
            string s;
            cin >> s;
            v.pb(s);
      }
      sort(v.begin(), v.end(), cmp);

      string value = v[0];

      string ans = "";

      fo(i, 0, sz(value)) {
            char ch = value[i];
            int flag = 1;
            fo(j, 1, sz(v)) {
                  int check = 0;
                  int cnt=0;
                  for(auto x : v[j] ) {
                        if(ch == x & !vis[j][cnt] ) {
                              vis[j][cnt]=1;
                              check = 1;
                              break;
                        }
                        cnt++;
                  }
                  if(!check) {
                        flag = 0;
                        break;
                  }
            }
            if(flag) ans.pb(ch);
      }

      sort(ans.begin(),ans.end());
      cout<<ans<<"\n";



      return 0;
}



















Measured memory_bytes: 256
# your code goes here
K, A, B = [int(s) for s in input().split()]
if B-A > 2:
	b = 1
	k_hit = min(K, A-b)
	K -= k_hit
	b += k_hit
	k_trade, k_hit = divmod(K, 2)
	b += k_trade*(B-A) + k_hit
else:
	b = K+1

print(b)

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

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec){
    os << "[";
    for(int i=0;i<vec.size();i++){
        os << (i==0?"":" ") << vec[i];
    }
    os <<  "]";
    return os;
}


int main(){
    long long n, x;
    cin >> n >> x;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    // 魔法の回数
    long long minx = 1000000000000000000;
    for(int i=0;i<n;i++){
        long long accum = 0;
        multiset<long long> hozon;
        for(int j=0;j<n+i;j++){
            hozon.insert(a[j%n]);
            if(hozon.size() == i+1){
                accum += *(hozon.begin()); 
                auto itr = hozon.find(a[(j+n-i)%n]);
                hozon.erase(itr);
            }
        }
        long long up = accum + x * i;
        if(minx > up){
            minx = up;
        }
    }
    cout << minx << endl;
    return 0;
}


Measured memory_bytes: 384
n = int(input())

T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    total = T+A
    x = -(-total//(a+t))
    x = max(x, -(-T//t))
    x = max(x, -(-A//a))
    T = t*x
    A = a*x

print(T+A)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int n, m, x;
vector<int> mem(1<<13, 1e9);

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

    
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];
    }
    
    //int visited = 0;
    //vector<int> cur(m, 0);
    //int res = f(c, a, visited, cur);
    
    int res = 1e9;
    int state = 0;
    while (state <= (1<<n) - 1) {
        ++state;
        
        int cost = 0;
        int ss = state;
        int i = 0;
        vector<int> cur(m, 0);
        while (ss && i < n) {
            if ((ss & 1) == 1) {
                cost += c[i];
                for (int j = 0; j < m; ++j)
                    cur[j] += a[i][j];
            }
            ++i;
            ss >>= 1;    
        }
        
        int cnt = 0;
        for (int j = 0; j < m; ++j) {
            if (cur[j] >= x)
                ++cnt;
        }
        if (cnt == m)
            res = min(res, cost);

    }
    
    if (res >= 1e9)
        cout << "-1" << endl;
    else
        cout << res << endl;
    return 0;
}

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

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  string ans = "APPROVED";
  for (int i = 0; i < n; i++) {
    if (a[i] & 1) continue;
    if (a[i] % 3 == 0 || a[i] % 5 == 0) continue;
    ans = "DENIED";
    break;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long n,k;
  	n=sc.nextLong();
  	k=sc.nextLong();
  	int f=0;
  	while(f==0){
  		if(n>k){
  			n%=k;
  		}else{
  			if(n<=k-n){
  				break;
  			}else{
  				n=k-n;
  				break;
  			}
  		}
  	}
  	System.out.print(n);
  }
}

Measured memory_bytes: 22608
d,g = map(int, input().split())
pc = [0] + [[int(i) for i in input().split()] for _ in range(d)]

def dfs(G, i):
    if i == 0:
        return 1e9
    n = min(G // (i*100), pc[i][0])
    s = n * i * 100
    if n == pc[i][0]:
        s += pc[i][1]
    if s < G:
        n += dfs(G-s, i-1)
    return min(n, dfs(G, i-1))

print(dfs(g, d))

Measured memory_bytes: 3064
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N;
  invec<int> X(N);
  int avg = bst::accumulate(X, 0) / N;
  int r = 0, r2=0;
  for (auto i : X)
    r += (i-avg)*(i-avg);
  avg++;
  for (auto i : X)
    r2 += (i-avg)*(i-avg);


  return min(r, r2);
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	ll n, ans=0;
	cin >> n;
	vector<ll> a(n+1, 1);
	for (ll i = 2; i < n+1; i++)
	{
		for(ll j=i; j<n+1; j+=i){
			a[j]++;
		}
	}
	loop(k, 1, n+1){
		ans+=k*a[k];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 81380
#include <stdio.h>
int main(){
	int H,W;
	while(1){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else	printf(".");
				
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n + 120), h(n + 120);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	a[0] = 0;
	a[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		int m = 1e9+1;
		for (int j = 1; j <= k; j++) {
			if (i - j < 0) {
				break;
			}
			m = min(m, a[i - j] + abs(h[i] - h[i-j]));
		}
	//	cout << i << "  " << m << endl;
		a[i] = m;
	}
	cout << a[n - 1];
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int vs[3];

int main(void) {
  REP(i, 3) {
    cin >> vs[i];
  }
  sort(vs, vs + 3);
  int res = vs[2]*10+vs[1] + vs[0];
  cout << res << endl;
  
  return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var S, prevStr string
	fmt.Scanf("%s", &S)
	out := 0
	tmprange := 1 //判定に使用する文字列の長さ
	prevStr = ""  // 判定に使用する文字列
	for i := 0; i < len(S); {
		if prevStr != S[i:i+tmprange] {
			prevStr = S[i : i+tmprange]
			i += tmprange // 今回の文字列の長さ分判定対象をシフトする
			out++         // 個数を追加する
			tmprange = 1  //今回の文字列数を1+0に戻す

		} else {
			if len(S[i:]) == 1 {
				i++
			}
			tmprange++ // 前回の文字とかぶるため一文字追加する。

		}
	}
	fmt.Println(out)
}


Measured memory_bytes: 1920