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

#define ll long long

ll N, X, M;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> X >> M;
	ll curr = X;
	vector < ll > path; path.push_back(curr);
	set < ll > vis; vis.insert(curr);
	ll hf, result = curr, req = N - 1;
	for (int i = 2; i <= N; i ++){
		curr = (curr*curr)%M;
		if (vis.find(curr) != vis.end()){
			hf = curr;
			break;
		}
		result += curr;
		req -= 1;
		path.push_back(curr); vis.insert(curr);
	}
	ll ix = find(path.begin(), path.end(), hf) - path.begin();
	ll sz = path.size() - ix;
	ll score  = accumulate(path.begin() + ix, path.end(), 0ll);
	if (req){
		result += score * (req/sz);
		ll rem = (req % sz), iy = ix;
		while (rem--){
			result += path[iy];
			iy += 1;
		}
	}
	cout << result << "\n";		
}

// 6 1 2 6 1 2 

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

using namespace std;

using int64 = long long;

int main() {
  int N, A[3000];
  cin >> N;
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    ret += A[i] - 1;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, T, A;

int main()
{
	in >> N >> T >> A;
	std::vector<LL>H(N);
	rep(i, N) in >> H[i];
	long double ansN = 1145148101919;
	LL ansP = -1;
	rep(i, N)
	{
		long double temp = T - H[i] * 0.006;
		if (std::abs(temp - (long double)A) < ansN)
		{
			ansN = std::abs(temp - A);
			ansP = i;
		}
	}
	out << ansP + 1 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s="CODEFESTIVAL2016";
string a;
int ans;
int main(){
    cin>>a;
    if(a[0] != 'C') ans++;
    if(a[1] != 'O') ans++;
    if(a[2] != 'D') ans++;
    if(a[3] != 'E') ans++;
    if(a[4] != 'F') ans++;
    if(a[5] != 'E') ans++;
    if(a[6] != 'S') ans++;
    if(a[7] != 'T') ans++;
    if(a[8] != 'I') ans++;
    if(a[9] != 'V') ans++;
    if(a[10] != 'A') ans++;
    if(a[11] != 'L') ans++;
    if(a[12] != '2') ans++;
    if(a[13] != '0') ans++;
    if(a[14] != '1') ans++;
    if(a[15] != '6') ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(int n,string s,int t1,int t2)
{
	vector<int> v;
	v.push_back(t1);
	v.push_back(t2);
	for(int i=2;i<n;i++)
		v.push_back((v[i-1]+v[i-2]+(s[i-1]=='x'))%2);
	if((v[n-2]+v[n-1]+v[0]+(s[n-1]=='x'))%2==0&&(v[n-1]+v[0]+v[1]+(s[0]=='x'))%2==0)
	{
		for(int i=0;i<n;i++)
			cout<<(v[i]?'W':'S');
		exit(0);
	}
}
int n;
string s;
int main()
{
	cin>>n>>s;
	solve(n,s,0,0);
	solve(n,s,0,1);
	solve(n,s,1,0);
	solve(n,s,1,1);
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ans=0;
	cin>>a>>b;
	if((a+b)%3==0) ans++;
	if(a%3==0) ans++;
	if(b%3==0) ans++;
	if(ans!=0)cout<<"Possible";
	else cout<<"Impossible";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k,x;cin>>k>>x;
  YesNo(500*k>=x);
  return 0;
}

Measured memory_bytes: 256
S = list(input().split())

queue = []

for c in S:
    if c == "+":
        b = queue.pop(-1)
        a = queue.pop(-1)
        queue.append(a+b)
    elif c == "-":
        b = queue.pop(-1)
        a = queue.pop(-1)
        queue.append(a-b)
    elif c == "*":
        b = queue.pop(-1)
        a = queue.pop(-1)
        queue.append(a*b)
    elif c == "/":
        b = queue.pop(-1)
        a = queue.pop(-1)
        queue.append(a/b)
    else:
        queue.append(int(c))

print(queue.pop(-1))



Measured memory_bytes: 5592
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('', (N) => {
  rl.question('', (str) => {
    const arr = str.split(' ');
    const nums = arr.map((num) => parseInt(num));
    nums.sort((a, b) => a - b);
    var averSum = nums[0];
    for(var i = 1; i < parseInt(N); i++) {
      averSum = (averSum + nums[i]) / 2;
    }
    console.log(averSum);
  });
});

Measured memory_bytes: 7756
import java.util.Scanner;

public class Main {

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

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final long N = sc.nextLong();
		final long P = sc.nextLong();
		
		long maxGcd = 0;
		
		if(N==1) {
			maxGcd = P;
		}
		else {
			for (int i=1;; i++) {
				long g = (long) Math.pow(i, N);
				if(g>P) {
					break;
				}
				if(P%g == 0) {
					maxGcd = i;
				}
			}
		}
		
		System.out.println(maxGcd);
		//		System.out.println(cnt);
		sc.close();
	}

}


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


int main()
{
	int num;
	deque<int> train;
	while( cin >> num ) {
		if( num == 0 ) {	
			cout << train.back() <<endl;
			train.pop_back();
		}
		else {
			train.push_back( num );
		}
	
	}
	

	return 0;
}

Measured memory_bytes: 0
vec = input().split(' ')
k = int(vec[0])
s = int(vec[1])
count = 0
for x in range(k + 1):
    if x <= s:
        for y in range(k + 1):
            if x + y <= s:
                z = s - x - y
                if z >= 0 and z <= k:
                    count += 1
            else: break
    else: break
print(count)

Measured memory_bytes: 3060
// AOJ ALDS1_10_C Longest Common Subsequence
// 2018.4.27 bal4u

#include <stdio.h>
#include <stdlib.h>

// Longest Common Subsequence
int c[1024][1024];
int LCS(char *x, int m, char *y, int n)
{
	int i, j;

	for (i = 0; i < m; i++)  c[i][0] = 0;
	for (j = 0; j < n; j++)  c[0][j] = 0;

	for (i = 1; i < m; i++) for (j = 1; j < n; j++) {
		if (x[i-1] == y[j-1]) c[i][j] = c[i-1][j-1] + 1;
		else if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
		else                             c[i][j] = c[i][j-1];
	}
	return c[m-1][n-1];
}

char x[1024], y[1024];

int main()
{
	int q, lx, ly;
	char *p;

	fgets(x, 10, stdin);
	q = atoi(x);
	while (q--) {
		fgets(p=x, 1024, stdin);
		while (*p > ' ') p++;
		*p = 0, lx = p-x;

		fgets(p=y, 1024, stdin);
		while (*p > ' ') p++;
		*p = 0, ly = p-y;

		printf("%d\n", LCS(x, lx+1, y, ly+1));
	}
	return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n, q; cin >> n >> q;
    string s; cin >> s;

    vi v(n);
    REP(i, n - 1) {
        if(s[i] == 'A' && s[i + 1] == 'C') {
            v[i + 1]++;
            i++;
        }
    }
    REP(i, n - 1) {
        v[i + 1] = v[i]  + v[i + 1];
    }
    REP(i, q) {
        int l, r; cin >> l >> r;
        cout << v[r - 1] - v[l - 1] << endl;
    }    

    return 0;
}

Measured memory_bytes: 1488
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
main()
{
    int n;cin>>n;
    vector<double> a(n);
    rep(i,n)cin>>a[i];
    sort(begin(a),end(a));
    rep(i,n-1)
    {
        double mid=(a[0]+a[1])/2;
        a[1]=mid;
        a.erase(begin(a));
    }
    cout<<a[0]<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 20

int n;
int A[N];

int solve(int i, int m){
  int res = 0;
  if(m == 0) return 1;
  if(i >= n) return 0;
  
  if(solve(i + 1,m) == 1 || solve(i + 1, m - A[i]) == 1){
    res = 1;
  }
  return res;
}

int main(){
  int i,q,key;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&key);
    if(solve(0,key)) printf("yes\n");
    else printf("no\n");
  }
  

  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (auto& e : a) cin >> e;
  for (auto& e : b) cin >> e;

  vector<vector<ll>> dp(n + 2, vector<ll>(m + 2));
  for (int i = 0; i <= n + 1; i++) dp[i][0] = 1;
  for (int j = 0; j <= m + 1; j++) dp[0][j] = 1;
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 1; j <= m + 1; j++) {
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1] + (mod - dp[i - 1][j - 1]);
      dp[i][j] %= mod;
      if (i - 1 < n && j - 1 < m && a[i - 1] == b[j - 1]) {
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
    }
  }
  cout << dp[n + 1][m + 1] << endl;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[0]){
	    cout<<"No";
	}else{
	    cout<<"Yes";
	}
	return 0;
}


Measured memory_bytes: 3620
from bisect import bisect_left, bisect_right
from itertools import accumulate

def solve():
    N, M = map(int, input().split())
    As = list(map(int, input().split()))

    As.sort()

    def isOK(x):
        num = 0
        for k, A in enumerate(As, start=1):
            i = bisect_left(As, x-A)
            num += N-i
            if num >= M:
                return True
            elif num + (N-k)*N < M:
                return False
        return num >= M

    ng, ok = 2*10**5+1, 0
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
#    print('ok:', ok)

    score = 0
    num = 0
    accAs = list(accumulate([0]+As))
    for A in As:
        i = bisect_right(As, ok-A)
        score += A*(N-i) + accAs[N] - accAs[i]
        num += N-i
#    print('score:', score, '/ num:', num)

    ans = score + ok*(M-num)
    print(ans)


solve()


Measured memory_bytes: 86308
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;
void solve(){
  char c; cin >> c;
  if(c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o') cout << "vowel\n";
  else cout << "consonant\n";
  return;
}

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


Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
push @a, 0;
unshift @a, 0;
my $sum;
for my $i (0..$#a-1) {
  $sum += abs($a[$i] - $a[$i+1]);
}
for my $i (1..$#a-1) {
  my $m;
  if ($i == 1) {
    $m = $sum - abs($a[1] - $a[0]) - abs($a[2] - $a[1]) + abs($a[2] - $a[0]);
  } elsif ($i == $#a - 1) {
    $m = $sum - abs($a[$i] - $a[$i+1]) - abs($a[$i] - $a[$i-1]) + abs($a[0] - $a[$i - 1]);
  } else {
    $m = $sum - abs($a[$i] - $a[$i+1]) - abs($a[$i] - $a[$i-1]) + abs($a[$i+1] - $a[$i-1]);
  }
  say $m;
}

Measured memory_bytes: 18980
n = int(input())
s = []
for i in range(n):
  s.append(sorted(input()))

s = sorted(s)

ans = 0
cnt = 1

memo = []

from operator import mul
from functools import reduce

def cmb(n, r):
  r = min(n - r, r)
  if r == 0:
    return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1, r + 1))
  return over // under

for ss in s:
  if memo == ss:
    cnt += 1
  else:
    if cnt != 1:
      ans += cmb(cnt, 2)
    cnt = 1
    memo = ss

if cnt != 1:
  ans += cmb(cnt, 2)

print(ans)


Measured memory_bytes: 100648
#include <stdio.h>

int main(int argc, char *argv[])
{
  int b, f, r, v;
  int n, i, j, k;
  int res[4 + 1][3 + 1][10 + 1];

  for (i = 0; i < 5; i++) {
    for (j = 0; j < 4; j++) {
      for (k = 0; k < 11; k++) {
        res[i][j][k] = 0;
      }
    }
  }

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    res[b][f][r] += v;
  }

  for (i = 1; i <= 4; i++) {
    for (j = 1; j <= 3; j++) {
      for (k = 1; k <= 10; k++) {
        printf(" %d", res[i][j][k]);
      }
      printf("\n");
    }
    if (i != 4) printf("####################\n");
  }
  
  return 0;
}

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

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

int N;

int main() {
	cin >> N;

	unsigned int Max = 0;
	unsigned int Min = INT32_MAX;

	for (int i = 0; i < N; i++) {
		unsigned a;
		cin >> a;

		Max = max(Max, a);
		Min = min(Min, a);

	}

	cout << Max - Min << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int r; cin >> r;
	cout << (r * r * 3) / 3 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int a,b,c,i;
 while( c=scanf("%d",&a) != EOF){
  if(a<=0 || a>1023) break;
  b=1;
  for(i=0;i<=9;i++){
   if((a & b)!=0){
    printf("%d",b);
    a-=b;
    if(a!=0) printf(" ");
   }
   b=b*2;
  }
  printf("\n");
 }
 return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  cout << min(N * A, B) << endl;
  return 0;
}

Measured memory_bytes: 3584
n,m=map(int,input().split());li=[]
for i in range(m):
  li.append(list(map(int,input().split()))+[i])
li.sort()
cac=li[0][0];o=2
li[0][1]=1
for g in li[1:]:
  if g[0]!=cac:
    cac=g[0]
    o=1
  g[1]=o
  o+=1
li.sort(key=lambda x:x[-1])
for g in li:
  print("%06d"%g[0]+"%06d"%g[1])

Measured memory_bytes: 25236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1 << 30;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

ll a_list[55];
ll a(int k){
    if(a_list[k] != 0) return a_list[k];
    if(k == 0){a_list[k]=1;return 1;}
    else{a_list[k]=2*a(k-1)+3; return a_list[k];}
}

ll p_list[55];
ll p(int k){
    if(p_list[k] != 0) return p_list[k];
    if(k == 0){p_list[k]=1;return 1;}
    else{p_list[k]= 2*p(k-1)+1;return p_list[k];}
}

ll f(int k,ll y){
    if(k==0 && y==1) return 1;
    if(k>=1){
        if(y==1) return 0;
        if(2<=y && y<=1+a(k-1)) return f(k-1,y-1);
        if(y==2+a(k-1)) return p(k-1)+1;
        if(3+a(k-1)<=y && y<= a(k)-1) return p(k-1)+1+f(k-1,y-(a(k-1)+2));
        if(y==a(k)) return p(k);
    }
    else return -1;
}

int main(){
    FOR(i,0,55) a_list[i]=0;FOR(i,0,55) p_list[i]=0;
    int n; ll x;
    cin >> n >> x;
    ll res = 0LL;
    cout << f(n,x) << endl;
}

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

void a()
{
    int n;
    cin >> n;
    string n_str = to_string(n);
    for (int i = 0; i < 3; i++)
    {
        if (n_str[i] == n_str[i + 1])
        {
            cout << "Bad";
            return;
        }
    }
    cout << "Good";
    return;
}
void b()
{
    int n, l;
    cin >> n >> l;
    int lmax = l + n - 1;
    int lmin = l;
    int sum = (l - 1) * n + n * (n + 1) / 2;
    if (lmax > 0 && lmin < 0)
    {
    }
    else if (lmax <= 0)
        sum -= lmax;
    else
        sum -= lmin;
    cout << sum;
    return;
}
long long int gcd(long long int c, long long int d)
{
    long long int temp;
    if (c < d)
    {
        temp = d;
        d = c;
        c = temp;
    }
    if (c % d == 0)
        return d;
    else
        return gcd(d, c % d);
}
long long int unable_to_div(long long int l, long long int c, long long int d)
{
    long long int x = l / c;
    long long int y = l / d;
    long long int z = l / (c * d / gcd(c, d));
    return l - x - y + z;
}
void c()
{
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int l = a - 1;
    long long int m = b;
    long long int sum_l = unable_to_div(l, c, d);
    long long int sum_m = unable_to_div(m, c, d);
    cout << sum_m - sum_l;
}
int main(void)
{
    c();
    return 0;
}

Measured memory_bytes: 256
'use strict'

function Main(input) {
  const K = Number(input.split(" ")[0])
  const X = Number(input.split(" ")[1])

  const min = X - K + 1
  const max = X + K - 1

  let answer = ""

  for (let i=min; i<=max; i++) {
    answer += (String(i) + " ")
  }

  console.log(answer.trim())

}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

Measured memory_bytes: 7500
#include <stdio.h>
#include <stdlib.h>

struct node_t {
	int x;
	struct node_t* next;
};

int main(void) {
	int n, q;
	struct node_t *head[1024], **tail[1024];
	int i;
	if (scanf("%d%d", &n, &q) != 2) return 1;
	for (i = 0; i < n; i++) {
		head[i] = NULL;
		tail[i] = &head[i];
	}
	for (i = 0; i < q; i++) {
		int query, s, t, x;
		if (scanf("%d", &query) != 1) return 1;
		switch (query) {
			case 0:
				if (scanf("%d%d", &t, &x) != 2) return 1;
				*tail[t] = malloc(sizeof(struct node_t));
				if (*tail[t] == NULL) return 1;
				(*tail[t])->x = x;
				(*tail[t])->next = NULL;
				tail[t] = &(*tail[t])->next;
				break;
			case 1:
				if (scanf("%d", &t) != 1) return 1;
				{
					struct node_t* itr = head[t];
					while (itr != NULL) {
						if (itr != head[t]) putchar(' ');
						printf("%d", itr->x);
						itr = itr->next;
					}
					putchar('\n');
				}
				break;
			case 2:
				if (scanf("%d%d", &s, &t) != 2) return 1;
				*tail[t] = head[s];
				if (head[s] != NULL) tail[t] = tail[s];
				head[s] = NULL;
				tail[s] = &head[s];
				break;
		}
	}
	for (i = 0; i < n; i++) {
		while (head[i] != NULL) {
			struct node_t* next = head[i]->next;
			free(head[i]);
			head[i] = next;
		}
	}
	return 0;
}



Measured memory_bytes: 17344
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int abs( int a ) { return a < 0 ? -a : a; }

int main() {
	int n, m;
	cin >> n >> m;
	int a = 0, b = 100000;
	for ( int i = 0; i < m; i++ ) {
		int l, r;
		cin >> l >> r;
		if ( a < l ) a = l;
		if ( r < b ) b = r;
	}
	cout << ( a <= b ? b - a + 1 : 0 ) << endl;
	return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
//const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

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

    map<string, int> m;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s]++;
    }
    ll ans = 0;
    for (auto e : m) {
        ll count = e.second;
        ans += (count * (count - 1)) / 2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

ll mod(ll a)
{
	if(a<inf)return a;
	else 
	return a%inf;
}
 void test_cases()
{




	ll n1;
	cin>>n1;
	if(n1<1200)cout<<"ABC";
	else cout<<"ARC";

 
}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


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

const ll MOD = 998244353;

ll DP[3030][3030];

//A の部分集合 T、Tの部分集合U で数える
int main(){
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i,N) cin >> A[i];

  DP[0][0] = 1;
  REP(i,N) REP(j,S+1) {
    // Ai が T に選ばれない場合
    DP[i+1][j] += DP[i][j];
    // Ai が T には選ばれているけど、Uには選ばれてない場合
    DP[i+1][j] += DP[i][j];
    DP[i+1][j] %= MOD;
    // Ai が選ばれた場合
    if ( A[i] + j <= S ) 
      DP[i+1][j+A[i]] += DP[i][j];
    DP[i+1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}


Measured memory_bytes: 74644
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = [(a_i, b_i, c_i) for a_i in range(a+1) for b_i in range(b+1) for c_i in range(c+1) \
      if a_i*500+b_i*100+c_i*50==x]
print(len(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  map<ll,ll> mp;
  for(int i = 0;i < N;i++){
    ll a;
    cin >> a;
    mp[a]++;
  }

  ll ans = 0;

  for(auto itr : mp){
    if(itr.first > itr.second)ans += itr.second;
    else ans += itr.second - itr.first;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6272
#include <iostream>
using namespace std;
int main(){
    int N, ans, i, j, flag=0;
    cin >> N;
    for(i=0; i<25; i++){
        for(j=0; j<13; j++){
            ans = 4*i+7*j;
            if(ans==N){
                flag=1;
                break;
            }
        }
    }
    if(flag==0){
        cout << "No" << '\n';
    }else{
        cout << "Yes" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a==b)
    cout<<"Draw";
else if (a==1)
    cout<<"Alice";
else if (b==1)
    cout<<"Bob";
else if(a>b)
    cout<<"Alice";
else
    cout<<"Bob";

return 0;
}



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

typedef long long int ll;

int main()
{
    ll ans = 0;
    bool f = false;
    string s;
    cin >> s;
    for(ll i = 0;i < s.size() - 1;i++){
        if(s[i] == s[i + 1]){
            f = true;
            ans++;
        }
        else if(f){
            break;
        }
    }

    if(ans >= 2){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

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

int N, Q;
int V[270000], W[270000], v[22], w[22];
int dp[2048][100001]; // n까지로 i를 만들었을 때 가능한 최대 가중치

void DFS(int n)
{
	if (n < 2048) // cal dp
	{
		for(int i=0; i<=100000; i++)
		{
			dp[n][i] = dp[n>>1][i];
			if (i >= W[n]) dp[n][i] = max(dp[n][i], dp[n>>1][i-W[n]]+V[n]);
		}
	}
	else return;
	if (n*2 <= N) DFS(n*2);
	if (n*2+1 <= N) DFS(n*2+1);
}

int main()
{
	scanf("%d", &N);
	for(int i=1; i<=N; i++)
		scanf("%d %d", &V[i], &W[i]);
	DFS(1);
	scanf("%d", &Q);
	while(Q--)
	{
		int n, L, p = 0;
		scanf("%d %d", &n, &L);
		while(n >= 2048)
		{
			v[p] = V[n]; w[p] = W[n]; p++;
			n>>=1;
		}

		int res = 0;
		for(int b=0; b<(1<<p); b++)
		{
			int sv = 0, sw = 0;
			for(int i=0; i<p; i++)
			{
				if (b&(1<<i)) sv += v[i], sw += w[i];
			}
			if (sw > L) continue;
			int val = dp[n][L-sw] + sv;
			res = max(res, val);
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 805508
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		Combination cmb = new Combination(n + 1);
		long pSum = 0;
		long mSum = 0;
		for (int i = 0; i <= n - k; i++) {
		    long count = cmb.getComb(n - i - 1, k - 1);
		    mSum += (arr[i] + MOD) % MOD * count % MOD;
		    mSum %= MOD;
		    pSum += (arr[n - i - 1] + MOD) % MOD * count % MOD;
		    pSum %= MOD;
		}
		System.out.println((pSum - mSum + MOD) % MOD);
   }

}

class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}



Measured memory_bytes: 58948
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 6 (getl toInt) >>= print

solve :: [Int] -> Int
solve [a,b,c,d,e,f] = (sum . tail . sort) [a,b,c,d] + max e f

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3692
dance = input()
dance1 = [i for i in dance]
check_n = 0
for j in range(len(dance1)):
    if(j%2==0):
        if((dance1[j]=="L")):
            check_n = 1
            break
    else:
        if((dance1[j]=="R")):
            check_n = 1
            break

if(check_n == 0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll  MAX=510000;
const ll MOD=1000000007;
ll fanc[MAX],inv[MAX],finv[MAX];

//n^p(mod M)を繰り返し2乗法で求める
ll Repeat(ll n,ll p,ll m){
  if(p==0)return 1;
  if(p%2==0){
    ll t=Repeat(n,p/2,m);
    return t*t%m;
  }
  return n*(Repeat(n,p-1,m));
}
//前処理
void COMinit(){
  fanc[0]=fanc[1]=1;
  inv[1]=1;
  finv[0]=finv[1]=1;
  for(int i=2;i<MAX;i++){
    fanc[i]=fanc[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
//二項係数
ll COM(ll n,ll k){
  if(n<0||k<0)return 0;
  if(n<k)return 0;
  return fanc[n-k+1]*(finv[n-k]%MOD)%MOD;
}
int main(){
  COMinit();
  ll n,a,b;
  cin>>n>>a>>b;
  ll all=Repeat(2,n,MOD);
  ll v1 = 1;
  for (ll i = n; i > n - a; i--) {
        v1 *= i;
        v1 %= MOD;
  }
  ll v2 = 1;
  for (ll i = n; i > n - b; i--) {
      v2 *= i;
      v2 %= MOD;
    }  
  v1=v1*(finv[a]%MOD)%MOD;
  //cout<<v1<<endl;
  v2=v2*finv[b]%MOD;

  ll ans=all-1-v1-v2;
  while(ans<0){
    ans += MOD;
  }
    
    ans %= MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 12160
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dm = 0
for i in range(n):
    dm += min(a[i], b[i])
    b[i] = b[i] - a[i]
    if b[i] > 0:
        dm += min(b[i], a[i + 1])
        a[i + 1] = max(a[i + 1] - b[i], 0)
print(dm)

Measured memory_bytes: 24256
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  std::vector<usize> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  usize cnt = 1;
  for (const auto e : a) {
    if (e == cnt) {
      cnt += 1;
    }
  }
  if (cnt == 1) {
    std::cout << "-1" << std::endl;
  } else {
    std::cout << n - cnt + 1 << std::endl;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
def dfs0(v, d, p):
    if v == n - 1:
        return d
    for e in es[v]:
        if e != p:
            k = dfs0(e, d + 1, v)
            if k:
                if isinstance(k, int) and k // 2 == d:
                    return v, e
                return k
    return 0

def dfs1(v, p):
    if v == E:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs1(e, v)
    return cnt


V, E = dfs0(0, 0, -1)
if  2*dfs1(0, -1) > n:
    print("Fennec")
else:
    print("Snuke")


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

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for (int i = 0; i < N; ++i) {
      cin >> a[i];
    }
    vector<int>ans(N, 0);
    ans[N-1] = a[N-1];
    for (int i = N-2; i >= 0; --i) {
        int sum = 0;
        for (int j = i; j < N; j+=(i+1)) {
            sum += ans[j];
        }
        if(sum % 2 != a[i]) ans[i] = 1;
    }
    int M = 0;
    for (int i = 0; i < N; ++i) {
        if(ans[i] == 1) M++;
    }
    cout << M << "\n";
    for (int i = 0; i < N; ++i) {
        if(ans[i] == 1) cout << i+1 << " ";
    }
    return 0;
}

Measured memory_bytes: 2432
import itertools

N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
x = list(itertools.permutations(range(N),N))
res = 0
for a in x:
    for i in range(N - 1):
        res += ((X[a[i]][0] - X[a[i + 1]][0]) ** 2 + (X[a[i]][1] - X[a[i + 1]][1]) ** 2) ** 0.5
print(res / len(x))

Measured memory_bytes: 8052
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

int main(void) {
	long long a, b, c, i, j, n;
	cin >> a >> b >> c;
	for (i = 0; i < 101; i++) {
		if ((a*i) % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
		String s1="",s2="";
		while(true){
        	s=s.substring(0,s.length()-2);
			s1=s.substring(0,s.length()/2);
			s2=s.substring(s.length()/2);
			if (s1.equals(s2)){
            	System.out.println(s.length());
				break;
            }
        }
    }
}

Measured memory_bytes: 22868
def main():
    a, b = map(int, input().split())
    palindromic_gen = (
        num for num in range(a, b+1)
        if str(num) == str(num)[::-1]
    )
    print(
        sum(1 for _ in palindromic_gen)
    )

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main(){
   char s[110000],t[110000];
  cin>>s+1>>t+1;
  int s1[110000],t1[110000];

  for(int i=1;s[i];i++){
    s1[i]=s1[i-1]+s[i]-'A'+1;
  }
  for(int i=1;t[i];i++){
    t1[i]=t1[i-1]+t[i]-'A'+1;
  }
  int q;
  cin>>q;

  rep(i,q){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((s1[b]-s1[a-1])%3==(t1[d]-t1[c-1])%3)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int N,M;
  cin>>N>>M;
  
  vector<vector<char>> A(N,vector<char>(N));
  vector<vector<char>> B(M,vector<char>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>A[i][j];
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cin>>B[i][j];
    }
  }
  
  bool check=false;
  
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i+M-1>=N||j+M-1>=N){
        continue;
      }
      
      bool res=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(A[i+k][j+l]!=B[k][l]){
            res=false;
          }
        }
      }
      if(res){
        check=true;
      }
    }
  }
  
  
  if(check){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3608
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/13 17:07:47
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5;

int n, k, c;
char s[N];
int nxt[N], last[N];

void run() {
    cin >> n >> k >> c;
    cin >> (s + 1);
    int t = 0;
    int now;
    for (int i = 1, j; i <= n; i = j) {
        now = i;
        j = i + c + 1;
        while (j <= n && s[j] == 'x') ++j;
        if (j <= n) {
            nxt[i] = j;
            last[j] = i;
            ++t;
        }
    }
    ++t;
    if (t != k) return;
    vector <int> pre(n + 2);
    for (int i = 1; i <= n + 1; i++) {
        pre[i] = pre[i - 1] + (s[i] == 'o');
    }
    vector <int> ans;
    int rb = n + 1;
    for (int i = now; i; i = last[i]) {
        if (rb == i || pre[rb] - pre[i] == 0) {
            ans.push_back(i);
        }
        for (int j = min(rb, i + c); j >= i; j--) {
            if (s[j] == 'o') {
                rb = j - c - 1;
                break;
            }
        }
    }
    sort(all(ans));
    for (auto it : ans) cout << it << '\n';
}

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

Measured memory_bytes: 6800
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
dp = [0] * (N + 1)
dpm = [0] * (N + 1)
dpm[0] = 1000
for i in range(N):
  dp[i + 1] = max(dp[i + 1], dp[i], dpm[i] // a[i] * 1000 + dpm[i] % a[i])
  dpm[i + 1] = max(dpm[i + 1], dpm[i], a[i] * (dp[i] // 1000) + dp[i] % 1000)
print(dpm[-1])

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

const int mxN=100, mxK=1e5, M=1e9+7;
int n, a[mxN], k;
long long dp[mxN+1][mxK+1];

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

	cin >> n >> k;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	dp[0][0]=1;
	for(int i=0; i<n; ++i) {
		for(int j=1; j<=k; ++j)
			dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
		for(int j=0; j<=k; ++j) {
			dp[i+1][j]=dp[i][j];
			if(j-a[i]-1>=0)
				dp[i+1][j]+=M-dp[i][j-a[i]-1];
			dp[i+1][j]%=M;
		}
	}
	cout << dp[n][k];
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
char S[200010];

int main(){
	scanf("%s",S+1);int n=strlen(S+1);
	rep(i,1,n){
		if(S[i]!='?')continue;
		S[i]='D';
	}
	
	rep(i,1,n)putchar(S[i]);
	putchar('\n');
	return 0;
}

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *A = map(int, read().split())

res = pow(3, N)
odd = 1

for a in A:
    if a % 2 == 0:
        odd *= 2

print(res - odd)


Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    string s;
    cin>>s;
    int n=s.length();
    if (s[0]!='A')
    {
        cout<<"WA";
        return 0;
    }
    int c=0;
    for (int i=1;i<n;i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            continue;
        }
        else
        {
            if (s[i]=='C')
            {
                c++;
                if (i<=1||i>=n-1||c>1)
                {
                    cout<<"WA";
                    return 0;
                }
            }
            else
            {
                cout<<"WA";
                return 0;
            }

        }


    }
    if (c==1)
    {
        cout<<"AC";
    }
    else
    {
        cout<<"WA";
    }

    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
ll a[101][101];
ll c[26];
int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) {
		char x; cin >> x;
		a[i][j] = x;
		c[x - 'a']++;
	}
	ll p[4] = {};
	rep(i, 0, 26) {
		p[c[i] % 4]++;
	}

	if (!(h & 1) && !(w & 1)) {
		cout << ((p[1] == 0 && p[3] == 0 && p[2] == 0) ? "Yes" : "No") << endl;
		return 0;
	}
	else if (!(h & 1) || !(w & 1)) {
		if (!(h & 1))swap(h, w);

		if (p[1] == 0 && p[3] == 0 && p[2] <= w / 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	else {
		if (p[1] == 1 && p[3] == 0 && p[2] <= (h - 1) / 2 + (w - 1) / 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	return 0;
}

Measured memory_bytes: 384
// AOJ 0539: Pizza
// 2017.9.1 bal4u@uu
// 2018.1.5

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()

int N;
int d[100002];
int k[10002];

int cmp(int *a, int *b) { return *a - *b; }

int in()
{
	int n, c;

	while ((c = getchar_unlocked()) < '0');
	n = 0;
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bsrch(int l, int x)
{
	int m, r = N;
    while (l < r) {
        m = (l + r) >> 1;
        if (d[m] < x) l = m + 1; else r = m;
    }
	return l;
}

#define THRESHOLD 10
#define STACKSIZE 35		// 2^32 for int
void quicksort(int *a, int n)
{
	int i, j, l, r, m, p;
	int lsp[STACKSIZE], rsp[STACKSIZE];
	int t;
	
	l = 0, r = n-1, p = 0;
	while (1) {
		if (r-l <= THRESHOLD) {
			if (!p--) break;
			l = lsp[p], r = rsp[p];
		}
		m = a[(l+r)>>1];
		i = l, j = r;
		while (1) {
			while (a[i] < m) i++;
			while (m < a[j]) j--;
			if (i >= j) break;
			t = a[i], a[i] = a[j], a[j] = t;
			i++, j--;
		}
		if (i-l > r-j) {
			if (i-l > THRESHOLD) {
				lsp[p] = l;
				rsp[p] = i-1;
				p++;
			}
			l = j+1;
		} else {
			if (r-j > THRESHOLD) {
				lsp[p] = j+1;
				rsp[p] = r;
				p++;
			}
			r = i-1;
		}
	}
	
	// insert sorting
	for (i = 1; i < n; i++) {
		m = a[i];
		for (j = i-1; j >= 0 && a[j] > m; j--) a[j+1] = a[j];
		a[j+1] = m;
	}
}

int main()
{
	int D, M, i, j, t, ans;

	while (D = in()) {
		N = in();
		M = in();

		d[0] = 0; for (i = 1; i < N; i++) d[i] = in();
#if 0
		qsort(d, N, sizeof(int), cmp);
#else
		quicksort(d, N);
#endif
		d[N] = D;

		for (i = 0; i < M; i++) k[i] = in();
#if 0
		qsort(k, M, sizeof(int), cmp);
#else
		quicksort(k, M);
#endif
		k[M] = -1;

		ans = 0, j = 0;
		i = 0; while (!k[i]) i++; 
		while (i < M) {
			if (d[j] < k[i]) j = bsrch(j, k[i]);
			if (k[i] != d[j]) {
				t = k[i]-d[j-1];
				if (d[j]-k[i] < t) t= d[j]-k[i];
				ans += t;
			}
			i++;
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2084
import java.io.*;
import java.util.*;
class Program{
    int solve(int i, int size){
        int temp = i;
        for(int j=1;j<size;j++){
            temp=temp*10+i;
        }
        return temp;
    }
}
class Main{
    public static void main(String[] args) {
        Program obj = new Program();
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        for(int i=1;i<=9;i++){
            if(obj.solve(i,String.valueOf(N).length())>=N) {System.out.println(obj.solve(i,String.valueOf(N).length())); break;}
            //System.out.println(obj.solve(i,String.valueOf(N).length()));
        }
    }
}

Measured memory_bytes: 21844
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}
const MOD: usize = 1000000007;

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let s = it.next().unwrap();
    let mut dp = vec![vec![0; 13]; s.len() + 1];
    dp[0][0] = 1;
    for (i, c) in s.chars().enumerate() {
        if let Some(x) = c.to_digit(10) {
            let x = x as usize;
            for j in 0..13 {
                dp[i + 1][(10 * j + x) % 13] += dp[i][j];
                dp[i + 1][(10 * j + x) % 13] %= MOD;
            }
        } else {
            for x in 0..10 {
                for j in 0..13 {
                    dp[i + 1][(10 * j + x) % 13] += dp[i][j];
                    dp[i + 1][(10 * j + x) % 13] %= MOD;
                }
            }
        }
    }
    println!("{}", dp[s.len()][5]);
}


Measured memory_bytes: 18684
import java.util.*;

public class Main{
  
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    List<String> array = new ArrayList<String>();
        
    for(int i=0;i<N;i++){
      String tmp = sc.next();
      array.add(tmp);
    }
    
    Collections.sort(array);
    
    String output = "";
    
    for(int i=0;i<N;i++){
      output += array.get(i);
    }
    
    System.out.println(output);
  }
}

      

Measured memory_bytes: 26864
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a1, a2, a3, a4;
    int b1, b2, b3, b4;
    int sum1, sum2;
    cin >> a1 >> a2 >> a3 >> a4;
    sum1 = a1 + a2 + a3 + a4;
    cin >> b1 >> b2 >> b3 >> b4;
    sum2 = b1 + b2 + b3 + b4;
    
    if(sum1 > sum2) cout << sum1 << endl;
    else cout << sum2 << endl;
    
}


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

const int NMAX=100;
int candy[2][NMAX],maximum[2][NMAX],n;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			cin >> candy[i][j];
		}
	}
	
	maximum[0][0]=candy[0][0];
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			if(j!=0) maximum[i][j]=max(maximum[i][j],maximum[i][j-1]+candy[i][j]);
			if(i!=0) maximum[i][j]=max(maximum[i][j],maximum[i-1][j]+candy[i][j]);
		}
	}
	
	cout << maximum[1][n-1] << '\n';
	
    return 0;
}


Measured memory_bytes: 256
#他の人の回答をメモのため提出
n = gets.to_i
h = Array.new(10){Array.new(10,0)}
 
(n+1).times do |i|
    next if i % 10 == 0
    x = i.to_s
    h[x[0].to_i][x[-1].to_i] += 1
end
 
ans = 0
1.upto(9) do |i|
    1.upto(9) do |j|
        ans += h[i][j] * h[j][i]
    end
end
 
puts ans

Measured memory_bytes: 1788