akhauriyash/Code-Regression huggingface dataset:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N, K = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

skip = K
ans = 0
for a, cnt in Counter(A).most_common():
    skip -= 1
    if skip < 0:
        ans += cnt
print(ans)


Measured memory_bytes: 49144
import collections

h, w = [int(x) for x in input().split()]
M = [input() for _ in range(h)]

p = [[None] * w for _ in range(h)]
q = collections.deque()
reachable = False

p[0][0] = 0
q.append((0, 0))

while len(q) > 0:
    x, y = q.popleft()
    for dx, dy in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
        if x + dx == w - 1 and y + dy == h - 1:
            reachable = True
            break
        if 0 <= x + dx < w and 0 <= y + dy < h:
            if M[y + dy][x + dx] == '.':
                if p[y + dy][x + dx] is None:
                    p[y + dy][x + dx] = p[y][x] + 1
                    q.append((x + dx, y + dy))

    if reachable:
        print(sum(row.count('.') for row in M) - p[y][x] - 2)
        break
else:
    print(-1)


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

int main()
{
	int n, m = 0;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;

		if (p != i + 1)
			m++;
	}

	if (m <= 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  int a, b;
  string s;
  cin >> a >> b;
  cin >> s;

  for(int i = 0; i < a; ++i){
    int value = s[i] - '0';
    if(!(value >= 0 && value <= 9)){
      cout << "No" << endl;
      return 0;
    }
  }
  if(s[a] != '-'){
    cout << "No" << endl;
    return 0;
  }

  for(int i = a + 1; i < a + b; ++i){
    int value = s[i] - '0';
    if(!(value >= 0 && value <= 9)){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

int main(){
  ll W,H,x,y;
  cin >> W >> H >> x >> y;
  if(W%2==0&&x==W/2&&H%2==0&&y==H/2){
    ll ans = H*W/2;
    cout << ans << ' ' << 1 << endl;
  }else{
    float ans;
    ans = (float)H*W/2;
    cout << ans << ' ' << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;

int main() {
	ll i, j;
	ll N;
	cin >> N;
	ll ans = N * (N - 1);
	ans /= 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    long double r;
    cin >> r;
    cout << 2 * r * PI << endl; 
    return 0;
}

Measured memory_bytes: 3808
#include <cstdio>
#include <cmath>

int Q;
int li, ri;
int res;
int n = 100000;
int n2;
int Left[300000], Right[300000];
int Tree[300000];
int Pr[100010];

int isS(int x)
{
	if(Pr[x]==1 && Pr[(x+1)/2]==1)
		return 1;
	else
		return 0;
}

void addTree(int x)
{
	int i = n2+x;
	while(i>=1){
		Tree[i] ++;
		i /= 2;
	}
}

void pre()
{
	int i, j, l;
	Pr[2] = 1;
	for(i=3; i<=100000; i++){
		l = ((int)sqrt(i))+1;
		for(j=2; j<=l; j++){
			if(i % j == 0)
				break;
		}
		if(j==l+1)
			Pr[i] = 1;
	}
	n2 = 1;
	while(n2<n)
		n2 *= 2;
	for(i=0; i<n2; i++){
		Left[n2+i] = i;
		Right[n2+i] = i;
	}
	for(i=n2-1; i>=1; i--){
		Left[i] = Left[2*i];
		Right[i] = Right[2*i+1];
	}
	for(i=1; i<=n; i++){
		if(isS(i) )
			addTree(i);
	}
}

int srch(int nd)
{
	if(Left[nd]>=li && Right[nd]<=ri)
		return Tree[nd];
	else if(Left[nd]>ri || Right[nd]<li)
		return 0;
	else{
		int v1 = srch(2*nd);
		int v2 = srch(2*nd+1);
		return v1+v2;
	}
}

int calc()
{
	int rr = srch(1);
	return rr;//	
}

int main()
{
	int i;
	pre();
	scanf("%d", &Q);
	for(i=0; i<Q; i++){
		scanf("%d%d", &li, &ri);
		res = calc();
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
const int N = 2e5 + 10;

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int a[3 * n];
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(a, a + 3 * n);
    int ans = 0;
    for(int i = n; i < 3 * n; i += 2) {
        ans += a[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    string str, result;
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            if(S[i]>S[j]){
                str = S[i];
                S[i] = S[j];
                S[j] = str;
            }
        }
    }
    for(int i = 0; i < N; i++){
        result+=S[i];
    }
    cout << result << endl;
}

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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()
#define all(x) x.begin(),x.end()


ll ans;
int arr[300009];
vi vr;
void solve()
{
    int n;  cin>>n;
    int nax = 0, cnt = 0;
    for(int i = 0; i < n; ++i){
        int x,y;    cin>>x>>y;
        if(x == y)
            cnt++;
        else{
            nax = max(nax,cnt);
            cnt = 0;
        }
    }
    nax = max(nax,cnt);
    cout<<(nax>=3? "Yes":"No");

    cout<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testc;  testc = 1;
    for(int t = 0; t < testc; ++t){
        solve();
    }
    return 0;
}

	//Sat 19 Sep 2020 05:36:55 PM IST


		/***astrainL3gi0N***/


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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

int main() {
    int N,K;
    cin>>N>>K;
    vector<ll> x(N,0);

    for (int i = 0; i <N; ++i) {
        cin>>x[i];
    }
    int ans=1e9;
    for(int i=0;i<=N-K;i++){
        int tmp;
        if(x[i+K-1]<0){
            tmp=-x[i];
        }else if(x[i]>0){
            tmp=x[i+K-1];
        }else{
            tmp=x[i+K-1]-x[i]+min(-x[i],x[i+K-1]);
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 1024
from itertools import accumulate
n, C = map(int, input().split())

U = 10**5
channels = [[0]*(U+1) for _ in range(C)]
for _ in range(n):
    s, t, c = map(lambda x: int(x)-1, input().split())
    channels[c][s] += 1
    channels[c][t] -= 1


for i in range(C):
    for j in range(U):
        channels[i][j+1] += channels[i][j]

schedules = [0]*(U+1)
for i in range(C):
    L = None
    for j in range(U+1):
        if channels[i][j] and L is None:
            L = j-1
            continue

        if not channels[i][j] and L is not None:
            schedules[max(L, 0)] += 1
            schedules[j] -= 1
            L = None

print(max(accumulate(schedules)))


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }

    vector< vector< vector<int> > > v(h, vector< vector<int> >(w, vector<int>(4, 0)));
    int cnt = 0;
    rep(i, h){
        cnt = 0;
        rep(j, w){
            v[i][j][0] = cnt;
            if(s[i][j] == '.'){
                ++cnt;
            }else{
                cnt = 0;
            }
        }
    }

    rep(i, h){
        cnt = 0;
        rrep(j, w){
            v[i][j][1] = cnt;
            if(s[i][j] == '.'){
                ++cnt;
            }else{
                cnt = 0;
            }
        }
    }

    rep(j, w){
        cnt = 0;
        rep(i, h){
            v[i][j][2] = cnt;
            if(s[i][j] == '.'){
                ++cnt;
            }else{
                cnt = 0;
            }
        }
    }

    rep(j, w){
        cnt = 0;
        rrep(i, h){
            v[i][j][3] = cnt;
            if(s[i][j] == '.'){
                ++cnt;
            }else{
                cnt = 0;
            }
        }
    }

    int ans = 0;
    rep(i, h){
        rep(j, w){
            if(s[i][j] == '.'){
                int tmp = 0;
                rep(k, 4){
                    tmp += v[i][j][k];
                }
                ans = max(ans, tmp + 1);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 224896
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Integer[] a = new Integer[n];
		int alice = 0;
		int bob = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}

		Arrays.sort(a, Comparator.reverseOrder());
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				alice += a[i];
			} else {
				bob += a[i];
			}
		}
		System.out.println(alice - bob);

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,k,ans,a[1005];
int main(){
	n=read(),k=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	sort(a,a+n);
	for(int i=0;i<k;i++)
		ans+=a[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**6)

N,M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
list.sort(key=lambda x:x[0])

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Measured memory_bytes: 116468
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((C-A)*(B-C)>=0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const tuple = <T extends unknown[]>(...ts: T) => ts;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [cin, nCin, biCin] = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return tuple(
    cin,
    () => Number(cin()),
    () => BigInt(cin())
  );
})();
type NumberOrBigintOrElse<T> = number | bigint extends T
  ? undefined
  : T extends number
  ? number
  : T extends bigint
  ? bigint
  : undefined;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isNumber = (x: unknown): x is number => typeof x === "number";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isBigint = (x: unknown): x is bigint => typeof x === "bigint";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const max = <T>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : typeof ts[0] === "number"
    ? Math.max(...((ts as unknown) as number[]))
    : ((ts as unknown) as bigint[]).reduce((acc, t) =>
        acc >= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const min = <T>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : typeof ts[0] === "number"
    ? Math.min(...((ts as unknown) as number[]))
    : ((ts as unknown) as bigint[]).reduce((acc, t) =>
        acc <= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const abs = <T>(t: T): NumberOrBigintOrElse<T> =>
  (typeof t === "number"
    ? t >= 0
      ? t
      : -t
    : typeof t === "bigint"
    ? t > 0n
      ? t
      : -t
    : undefined) as NumberOrBigintOrElse<T>;

/**
 * Program
 */
type Color = "R" | "W";

const getAnswer = (N: number, cs: Color[]): number => {
  const rNum = cs.filter((c) => c === "R").length;
  return min(rNum, N - rNum, cs.slice(0, rNum).filter((c) => c === "W").length);
};

{
  const N = nCin();
  const cs = cin()
    .split("")
    .map((c) => c as Color);
  const ans = getAnswer(N, cs);
  console.log(ans);
}


Measured memory_bytes: 41176
#include <iostream>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(int argc, char const *argv[])
{
    int n, x;
    while(true) {
        cin >> n >> x;
        if(n==0 && x==0) break;
        int ans = 0;
        for(int i=1; i<n-1; i++){
            for(int j=i+1; j<n; j++) {
                for(int k=j+1; k<n+1; k++){
                    if(i+j+k==x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){

  long long int N;
  long long int K;
  cin>>N>>K;
  long long int ans1=N%K;
  long long int ans2=(N%K-K)*-1;
  long long int ans= ans1<=ans2?ans1:ans2;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
#define rep(i, m, n) for (int i = m; i < n; ++i)

vector<vector<int>> next(const string &S) {
    int n = (int)S.size();
    vector<vector<int>> res(n + 1, vector<int>(26, n));
    for(int i = n - 1; i >= 0; --i) {
        for(int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
        res[i][S[i] - 'a'] = i;
    }
    return res;
}

int64 solve() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    vector<vector<int>> nx = next(S + S);
    int64 ans = 0;
    int i = 0;
    for(auto &c : T) {
        c -= 'a';
        if(nx[i][c] == 2 * N) return -1;
        ans += nx[i][c] - i + 1;
        i = (nx[i][c] + 1) % N;
    }
    return ans;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 27264
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n,a,b,c;
	cin >> n;
	if(n==2){
		cin >> a >> b;
		cout << 1 << endl;
		for(int i=2; i<=min(a,b); ++i)if(a%i==0 && b%i==0)	cout << i << endl;
	}else if(n==3){
		cin >> a >> b >> c;
		cout << 1 << endl;
		for(int i=2; i<=min(a,min(b,c)); ++i)if(a%i==0 && b%i==0 && c%i==0)	cout<< i << endl;
	}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;


int main(int argc, char *argv[])
{
  int x = 0, ans = 0, N;
  char c;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> c;
    if (c == 'I') {
      x++;
      ans = max(ans, x);
    } else {
      x--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n, a;
    int b[200009]={};
    
    cin >> n;
    
    for(int i=1; i<=n; i++){
        
        cin >> a;
        
        if(n%2==0){
            
            if(i%2==1){
                
                b[n/2+(i+1)/2] = a;
                
            } else {
                
                b[n/2-i/2+1] = a;
                
            }
            
        } else {
            
            if(i%2==0){
                
                b[n/2+1+i/2] = a;
                
            } else {
                
                b[n/2-(i+1)/2+2] = a;
                
            }
            
        }
        
    }
    
    for(int i=1; i<=n; i++){
        
        cout << b[i] << " ";
        
    }
    
    return 0;
    
}

Measured memory_bytes: 2944
a1,b0,cn1,d=map(int,input().split())
Output = 0

if a1 < d:
    Output = a1
    if a1+b0 < d:
      c = d-a1-b0
      Output = Output - c
    elif a1 + b0 >= d:
      pass
elif a1 >= d:
    Output = d
else:
  print("weird")
print(Output)

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

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    rep(i, 0, 5) {
        int val;
        cin >> val;
        if (val == 0) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

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

  if(n == 1){
    cout << "Hello World" << endl;
    return 0;
  }

  if(n == 2){
    int a, b; cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int a = kbd.nextInt();
        int b = kbd.nextInt();
        if(a>=13){
            System.out.println(b);
        }else if(a<=5){
            System.out.println(0);
        }else{
            System.out.println(b/2);
        }
    }
}

Measured memory_bytes: 23380
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n;
int inds[114514];
vi a;
int main(){
	cin>>n;
	cout<<3*n*n<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

/*
高速ゼータ変換を使う（２次元配列を使った遷移を１次元配列に落とし込む）
このスライドがとても分かりやすい．
https://www.ioi-jp.org/joi/2017/2018-ho/2018-ho-t5-review.pdf
*/

mp f(mp a,mp b){//大きい順に２つとるだけ
	ll c[4]={a.first,a.second,b.first,b.second};
	sort(c,c+4);
	return make_pair(c[3],c[2]);
}

int main(void){
	ll n,c[1<<18];
	mp b[1<<18];
	cin>>n;
	rep(i,1<<n){
		ll a;
		cin>>a;
		b[i]=make_pair(a,0);
	}
	//高速ゼータ変換
	rep(i,n){//注目bit
		rep(m,1 << n){
			if(0 == (m & (1<<i))){//mのibitが0なら遷移
				b[m|(1<<i)] = f(b[m|(1<<i)],b[m]);//ないやつをあるやつに送る
			}
		}
	}
	rep(i,1<<n)c[i]=b[i].first+b[i].second;
	rep(i,(1<<n)-1)c[i+1]=max(c[i],c[i+1]);
	reg(i,1,(1<<n)-1)cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }
ll N, M, Q;
vll a, b, c, d;
ll ans = 0;

ll calValue(vll &A){
    ll res = 0;
    REP(i, Q){
        if(A[b[i]]- A[a[i]] == c[i])
            res += d[i];
    }
    return res;
}

void dfs(vll A){
    if(A.size()==N){
        ll tmp = calValue(A);
        chmax(ans, tmp);
        return;
    }
    ll last = A.back();
    for(ll i=last; i <= M; i++){
        vll Atmp = A;
        Atmp.push_back(i);
        dfs(Atmp);
    }
    return;
}

int main(){
    cin >> N >> M>> Q;
    a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); 
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        a[i]--; b[i]--;
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }

    vll A(1);
    for(ll i = 1; i <= M; i++){
        A[0] = i;
        dfs(A);
    }

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


Measured memory_bytes: 3232
#include <stdio.h>
int main() {
    int n,k;
    char s[11];
    scanf("%d\n",&n);
    scanf("%s\n",s);
    scanf("%d",&k);
    char moji=s[k-1];
    for (int i=0; i<n; i++) {
        if (s[i]!=moji) {
            s[i]='*';
        }
    }
    printf("%s",s);
    return 0;
}

Measured memory_bytes: 128
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	string s;int n,out=114;
	cin>>s;n=s.size();
	for(char c='a';c<='z';c++){
		string t=s+c;int pre=-1,ma=0;
		rep(j,n+1){
			if(t[j]==c){
				ma=max(ma,j-pre-1);pre=j;
			}
		}
		out=min(out,ma);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll N;
  cin >> N;

  vector<ll> A(N);
  REP(i,N){ cin >> A[i]; }

  //　各bitで処理
  ll ans = 0;
  REP(b, 60){
    vector<ll> B(N); // kth-bit values of A[]
    REP(i,N) { B[i] = ((A[i]>>b) & 1); }
    vector<ll> dp(2); // dp[k]はiがkのときのi以降の数とのXORの和

    ll sum_b = 0;
    if (B[N-1]==1){
      dp[0]=1;
    } else {
      dp[1]=1;
    }
    
    for(ll i=N-2;i>=0;i--){
      if (B[i]==0){
        sum_b += dp[0]; sum_b%=MOD;
        dp[1]++; dp[1]%=MOD;
        //cout << (1<<b) << " " << A[i] << ": " << B[i] << " sum:" << sum_b << "\n";
      } else {
        sum_b += dp[1]; sum_b%=MOD;
        dp[0]++; dp[0]%=MOD;
        //cout << (1<<b) << " " << A[i] << ": " << B[i] << " sum:" << sum_b << "\n";
      }
    }

    ans += (sum_b * (((ll)1<<b) % MOD)) % MOD;
    ans %= MOD;
  }

  cout << ans << "\n";
  return 0;
}


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

using namespace std;

int gcd(int a, int b) {
    if (a < b) swap(a, b);

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

int main() {
    int N, X; cin >> N >> X;
    vector<int> x(N); for (int i = 0; i < N; i++) cin >> x[i];

    for (int i = 0; i < N; i++) {
        x[i] = abs(x[i] - X);
    }

    int ans = x[0];
    if (N > 1) {
        for (int i = 1; i < N; i++) ans = gcd(ans, x[i]);
    }

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

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

using namespace std;

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

  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> s(n, vector<int>(m)), ans(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      s[i][j] = c == '#';
    }
  }
  for (int i = 0; i < n; ++i) {
    int L = -1, R = m;
    for (int j = 0; j < m; ++j) {
      if (!s[i][j] or L != -1) {
        continue;
      }
      int x = i - 1, y = j;
      while (x >= 0) {
        bool ok = true;
        for (int it = 0; it < m; ++it) {
          ok &= ans[x][it] == 0;
        }
        if (!ok) {
          break;
        }
        --x;
      }
      L = max(L, x + 1);
      x = i + 1;
      while (x < n) {
        bool ok = true;
        for (int it = 0; it < m; ++it) {
          ok &= s[x][it] == 0;
        }
        if (!ok) {
          break;
        }
        ++x;
      }
      R = min(R, x - 1);
    }
    for (int j = 0; j < m; ++j) {
      if (!s[i][j]) {
        continue;
      }
      int y = j;
      while (y >= 0) {
        if (ans[i][y]) {
          break;
        }
        for (int it = L; it <= R; ++it) {
          ans[it][y] = k;
        }
        --y;
      }
      y = j + 1;
      while (y < m) {
        if (s[i][y]) {
          break;
        }
        for (int it = L; it <= R; ++it) {
          ans[it][y] = k;
        }
        ++y;
      }
      --k;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << ans[i][j] << ' ';
    }
    cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 1536
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  negative=[False]*n
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
        if cnt==n-1:
          negative[q]=True
    cnt+=1
    if not update:
      break
    if cnt==n:
      if negative[n-1]:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n-1])
        sys.exit()
        
  print(d[n-1])
  
Bellmanford(n,m,0,es)  
    
    
      
  
  

  

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

int main(){
 int m,ans=0;
  cin>>m;
  vector<int> a(m);

for(int i=0;i<a.size();i++){
  cin>>a.at(i);
    ans+=a.at(i)-1;
}

cout<<ans;
  
  
 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		int n = in.nextInt();
		int[][] A = new int[m][n];
		int b;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				int a=in.nextInt();
				A[i][j] = a;
			}
		}
		
	
		for (int j = 0; j < n; j++)
		{
			b = in.nextInt();
			for (int i = 0; i < m; i++)
			{
				A[i][j] *= b;
			}
		}
		for (int i = 0; i < m; i++)
		{   int a=0;
			for (int j = 0; j < n; j++)
			{
				a+=A[i][j];
				//System.out.println(A[i][j]);
			}
			System.out.println(a);
		}

	}
}

Measured memory_bytes: 40792
S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] != X[-1][0]:
    print(sum(x[1] // 2 for x in X) * K)
else:
    s = X[0]
    e = X.pop(-1)
    if (s[1] + e[1]) % 2 == 0:
        X.append(e)
        print(sum(x[1] // 2 for x in X) * K + (K - 1))
    else:
        X[0] = [s[0], s[1] + e[1]]
        print(sum(x[1] // 2 for x in X) * K)


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

int main(void)
{
    int n, w, h;
    int koto_w[100005] = {};
    int koto_h[100005] = {};
    int i, j, k, l;
    int a, b, c;
    int flag1 = 1;
    int flag2 = 1;
    l = 1;
    cin >> n >> w >> h;
    for(i = 0; i < n; i++){
        cin >> a >> b >> c;
        if(koto_w[a] < c){ koto_w[a] = c;}
        if(koto_h[b] < c){ koto_h[b] = c;}
    }
    /*for(i = 0; i <= w; i++){
        cout << koto_w[i] << " ";
    }
    cout << endl;
    for(i = 0; i <= h; i++){
        cout << koto_h[i] << " ";
    }
    cout << endl;
    */
    i = 0;
    j = -1;
    while(1){
        if(koto_w[i] != 0){
            //テ・ツ可催」ツδ?」ツつァテ」ツδε」ツつッ
            if(j >= koto_w[i]){
                i++;
                j++;
                if(i == w){
                    flag1 = 0;
                    break;
                }
                continue;
                } //テァツ?。テ」ツ?凝」ツ?」テ」ツ?淌」ツ?禿」ツ?ィテ」ツ?ォ
            if(j > -1-koto_w[i]){
                j = -1-koto_w[i];
            }
        }
        i++;
        j++;
        //cout << i << endl;
        //テヲツ慊?ァツオツづ」ツδ?」ツつァテ」ツδε」ツつッ
        if(i == w){
            j = j - koto_w[i];
            if(j >= 0){
                flag1 = 0;
                break;
            }else{
                break;
            }
        }
    }

    i = 0;
    j = -1;
    while(1){
        if(koto_h[i] != 0){
            //テ・ツ可催」ツδ?」ツつァテ」ツδε」ツつッ
            if(j >= koto_h[i]){
                i++;
                j++;
                if(i == h){
                    flag2 = 0;
                    break;
                }
                continue;
                } //テァツ?。テ」ツ?凝」ツ?」テ」ツ?淌」ツ?禿」ツ?ィテ」ツ?ォ
            if(j > -1-koto_h[i]){
                j = -1-koto_h[i];
            }
        }
        i++;
        j++;
        //テヲツ慊?ァツオツづ」ツδ?」ツつァテ」ツδε」ツつッ
        if(i == h){
            j = j - koto_h[i];
            if(j >= 0){
                flag2 = 0;
                break;
            }else{
                break;
            }
        }
    }
    if(flag1 || flag2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 3888
'use strict'

const Main = (input) => {
  const tmp = input.trim().split(' ')
  let A = parseInt(tmp[0])
  let B = parseInt(tmp[1])
  let C = parseInt(tmp[2])

  let result = 0

  if (A === B && B === C && A % 2 === 0) {
    result = -1
  } else {
    for (let i = 1; A % 2 === 0 && B % 2 === 0 && C % 2 === 0; i++) {
      const Arr = [A, B, C]
      A = Arr[1] / 2 + Arr[2] / 2
      B = Arr[0] / 2 + Arr[2] / 2
      C = Arr[0] / 2 + Arr[1] / 2
      result = i
    }
  }

  console.log(result)
  return result
}

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

Measured memory_bytes: 21064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    ans = (n - k + 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;

int main(){
  string t;
  cin>>t;
  int sum=0;
  for(int i=0;i<3;i++){
    if(t[i]=='R'){
      sum++;
    }
    if(t[1]=='S'&&sum==2)sum=1;
    
  }
  cout<<sum;
    
   
    
  

}


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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


//naosu
long int gcd(long int a,long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


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


long int f(long int n,long int c,long int d){
  long int cnt=n/c+n/d-n/lcm(c,d);
  return n-cnt;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n,m;
  scanf("%d%d",&n,&m);

  long long int A[m];
  for(int i=0;i<m;i++){
    scanf("%lld",&A[i]);
  }

  if(n>=m){
    printf("0\n");
    
    return 0;
  }

  sortup(A,m);

  long long int ans=0;
  long long int B[m-1];
  for(int i=0;i<m-1;i++){
    B[i]=A[i+1]-A[i];
    ans+=B[i];
  }
  
  sortdown(B,m-1);

  for(int i=0;i<n-1;i++){
    ans-=B[i];
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	vector<vector<int>>b(a);
	for(int c=0;c<a;c++){
		vector<int>d(3);
		cin>>d[0]>>d[1]>>d[2];
		b[c]=d;
		}
		vector<int>s(a);
		for(int e=0;e<3;e++){
			map<int,vector<int>>n;
			for(int f=0;f<a;f++){
				n[b[f][e]];
				n[b[f][e]].push_back(f);
				}
				for(auto g=n.begin();g!=n.end();g++){
					if(g->second.size()==1)s[g->second[0]]+=g->first;
					}
			}
			for(auto k:s)cout<<k<<endl;
}

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

#define sc(a) scanf("%d",&a)
#define scm(a,b) scanf("%d%d",&a,&b)
#define fl(c,i,n) for(int i=c;i<n;i++)
#define f(i,n) for(int i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long int
#define ull unsigned long long int
#define inf INT_MAX
#define linf LLONG_MAX
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
//#define mp make_pair
#define nl printf("\n")
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define pii pair<int,int>
#define MAXN 500005
#define MOD 1000000007

template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
/*int fact[MAXN];
int invfact[MAXN];
int inv(int a, int b){
    if(b==0)
        return 1;
    if(b&1)
        return (long long)a*inv(a, b-1)%MOD;
    else{
        int res = inv(a, b>>1);
        return (long long)res*res%MOD;
    }
}
void init(){
    fact[0] = 1;
    for(int i=1;i<MAXN;i++){
        fact[i] = (long long)fact[i-1]*i%MOD;
    }
    invfact[MAXN-1] = inv(fact[MAXN-1], MOD-2);
    for(int i=MAXN-1;i>0;i--){
        invfact[i-1] = (long long)invfact[i]*i%MOD;
    }
}
int C(int n, int r){
    if(r>n || r<0)
        return 0;
    return (long long)((long long)fact[n]*invfact[r]%MOD)*invfact[n-r]%MOD;
}*/
int n;
map<char, int> mp;
string alph = "abcdefghijklmnopqrstuvwxyz", s;
void solve(){
    sc(n);
    for(int i=0;i<26;i++){
        mp[alph[i]] = 100;
    }
    for(int t=0;t<n;t++){
        map<char, int> tmp;
        cin>>s;
        for(int j=0;j<s.length();j++){
            tmp[s[j]]++;
        }
        for(int j=0;j<26;j++){
            mp[alph[j]] = min(mp[alph[j]], tmp[alph[j]]);
        }
    }
    string ans = "";
    for(int i=0;i<26;i++){
        for(int j=0;j<mp[alph[i]];j++){
            ans+=alph[i];
        }
    }
    cout<<ans;
}
int main(){
    /*FILE *fin = freopen("C-small-attempt0.in", "r", stdin);
	assert( fin!=NULL );
	FILE *fout = freopen("C-small.out", "w", stdout);*/
	//init();
    solve();
    return 0;
}


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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  int x, a, b;
  cin >> x >> a >> b;
  string ans = "A";
  if (abs(x - b) < abs(x - a)) ans = "B";
  cout << ans << endl;
  return 0;
}


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

from collections import defaultdict
N, M = [int(_) for _ in input().split()]
V = defaultdict(list)
for i in range(M):
    A, B = [int(_) for _ in input().split()]
    V[A].append(B)
    V[B].append(A)

def solve(N, M, V):
    result = [1, V[1][0]]
    used = [False] * (N + 1)
    for x in result:
        used[x] = True

    def check_edge(i):
        for e in V[result[i]]:
            if not used[e]:
                if i == -1:
                    result.append(e)
                else:
                    result.insert(i, e)
                used[e] = True
                return True
        return False

    while True:
        if check_edge(0): continue
        if check_edge(-1): continue
        return result

result = solve(N, M, V)
print(len(result))
print(*result)


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

int c[255];

int main() {
        string s, t;
        cin >> s >> t;

        sort(s.begin(), s.end());
        sort(t.begin(), t.end(), greater<char>());

        bool f = false;
        bool is_same = true;
        const int m = min(s.size(), t.size());
        for (int i = 0; i < m; ++i) {
                if (is_same && s[i] != t[i]) {
                        is_same = false;
                }
                if (s[i] < t[i]) {
                        f = true;
                        break;
                }
        }
        if (!f && is_same && m == s.size() && m != t.size()) {
                f = true;
        }

        cout << (f ? "Yes" : "No") << endl;
        return 0;
}

Measured memory_bytes: 256
import Control.Applicative

type Vector = [Int]

type Matrix = [Vector]

type Problem = (Matrix, Vector)

type Result = Vector

solve :: Problem -> Result

solve (matrix, vector)
    = [sum $ zipWith (*) row vector | row <- matrix]

input :: IO Problem

input
    = do
        [n, m] <- map read.words <$> getLine
        matrix <- inputMatrix n []
        vector <- inputVector m []
        return (matrix, vector)
        
inputMatrix :: Int -> Matrix -> IO Matrix

inputMatrix 0 matrix
    = return $ reverse matrix
    
inputMatrix n matrix
    = do
        row <- map read.words <$> getLine
        inputMatrix (n - 1) $ row : matrix
        
inputVector :: Int -> Vector -> IO Vector

inputVector 0 vector
    = return $ reverse vector
    
inputVector m vector
    = do
        row <- read <$> getLine
        inputVector (m - 1) $ row : vector
    
output :: Result -> String

output xs
    = concat [show x ++ "\n" | x <- xs]
    
main :: IO ()

main = putStr.output =<< solve <$> input

Measured memory_bytes: 7680
while True:
    n, x = map(int,input().split())
    if n == 0 and x == 0:
        break
    
    ans = 0
    for i in range(1,n + 1):
        for j in range(1,i):
            for k in range(1,j):
                if i + j + k == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >> m;
    string s;cin >> s;
    vl ans;
    rev(all(s));
    ll now=0;
    while(now!=n){
        ll pre=now;
        per(i,m){
            if(now+i+1>n)continue;
            if(s[now+i+1]=='0'){
                ans.pb(i+1);
                now+=i+1;
                break;
            }
        }
        if(pre==now)cout << -1 <<endl,exit(0);
    }
    rev(all(ans));
    for(auto p:ans)cout << p <<" ";
    cout << endl;
}

Measured memory_bytes: 1528
import java.util.*;

class Main{
    Scanner sc = new Scanner(System.in);
    
    Main(){
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.print( (a/b) + " " +(a%b)+" ");
    System.out.printf("%.8f\n" , (double)a/b);
    }
    
    public static void main(String[] args){
    new Main();
    }
    
}


Measured memory_bytes: 26528
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
long long power(long long x, long long y, long long p)
{
	long long res = 1;	 	x = x % p; 
	while (y > 0)
	{
		if (y & 1)
			res = (res*x) % p;

		y = y>>1; 
		x = (x*x) % p;
	}
	return res;
}

long long modInverse(long long n, long long p)
{
	return power(n, p-2, p);
}

long long nCrModPFermat(long long n, long long r, long long p)
{
if (r==0)
	return 1;

	long long fac[n+1];
	fac[0] = 1;
	for (long long i=1 ; i<=n; i++)
		fac[i] = fac[i-1]*i%p;

	return (fac[n]* modInverse(fac[r], p) % p *
			modInverse(fac[n-r], p) % p) % p;
}



int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long x, y;
    cin>>x>>y;

    if((x+y)%3)
    {
       cout<<0<<endl;
       return 0;
    }

    long long a=(x+y)/3;
    long long b=(x-y);
    long long m=(a+b)/2;
    long long n=(a-b)/2;
    if(m<0 || n<0)
    {
       cout<<0<<endl;
       return 0;
    }
    cout<<nCrModPFermat(n+m, n, 1000000007)<<endl;

    return 0;
}



Measured memory_bytes: 5504
#include <stdio.h>

int main(){
  long long int A,B;
  int K;
  scanf("%lld%lld%d",&A,&B,&K);
  while(K>0){
    if(A%2==0){
      B=B+A/2;
      A=A/2;
    }else{
      B=B+(A-1)/2;
      A=(A-1)/2;
    }
    K=K-1;
    if(K==0){break;}
    if(B%2==0){
      A=A+B/2;
      B=B/2;
    }else{
      A=A+(B-1)/2;
      B=(B-1)/2;
    }
     K=K-1;
  }
  printf("%lld %lld",A,B);
  return 0;
}




Measured memory_bytes: 128