akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while( y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z){
  Node *y;
  Node *x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL){
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  } else {
    if(y == y->parent->left){
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != x){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < y->key){
      x = y->left;
    } else {
      x = y->right;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  } else {
    if(z->key < y->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    cin >> com;
    if(com[0] == 'f'){
      scanf("%d", &x);
      Node *t = find(root, x);
      if( t != NIL) printf("yes\n");
      else printf("no\n");
    }else if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com == "delete"){
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 20004
n,m= map(int, input().split())
a= list(map(int, input().split()))
a.sort(reverse=True)
flag=True
x=sum(a)
for i in range(m):
    if a[i]<sum(a)/(4*m):
        flag=False

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T>inline bool chmax(T& a,T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>inline bool chmin(T& a,T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    double r;
    cin >> r;
    double ans = (double)(2*3.141592653589793*r);
    cout << std::fixed << std::setprecision(15) << ans << endl;
}


Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

void solved(){
    int k;cin>>k;
    for(int i = 1; i <= k; i++)cout<<"ACL";
    cout<<endl;
}
int main(){
    solved();
    return 0;
}

Measured memory_bytes: 3044
from itertools import product

N = int(input())

A = N // 4
B = N // 7

ret = False
for a, b in product(range(A + 1), range(B + 1)):
    p = 4 * a + 7 * b
    if p == N:
        ret = True
        break

print('Yes' if ret else 'No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;


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

    vector<pair<int, char>> cnt;
    int c = 1;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != s[i-1]) {
            cnt.emplace_back(c, s[i-1]);
            c = 1;
        } else {
            ++c;
        }
    }
    cnt.emplace_back(c, s.back());

    if (cnt[0].second == '>') cnt.insert(cnt.begin(), make_pair(0, '<'));
    if (cnt.back().second == '<') cnt.emplace_back(0, '>');

    ll ans = 0;
    for (int i = 0; i < cnt.size(); i += 2) {
        ans += max(cnt[i].first, cnt[i+1].first);
        if (cnt[i].first != 0) ans += (ll)cnt[i].first * (cnt[i].first - 1) / 2;
        if (cnt[i+1].first != 0) ans += (ll)cnt[i+1].first * (cnt[i+1].first - 1) / 2;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    /*変数定義，入力*/

    int A, B;cin >> A >> B;
    
    /*演算*/
    int result = A - 2*B; 
    if(result < 0) result = 0;
    /*出力*/
    cout << result << endl;

    /*終了*/
    return 0;
}

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

int main(void){
    int N, number, max_sum = 20;
    std::cin >> N;
    std::vector<std::vector<unsigned long long> > joi(N, std::vector<unsigned long long>(max_sum + 1, 0));
    std::cin >> number;
    joi[0][number] = 1;
    for(int i = 1; i <= N - 2; ++i){
        std::cin >> number;
        for(int j = 0; j <= max_sum; ++j){
                if(j + number <= max_sum)
                    joi[i][j + number] += joi[i - 1][j];
                if(0 <= j - number)
                    joi[i][j - number] += joi[i - 1][j];
        }
    }
    std::cin >> number;
    std::cout << joi[N - 2][number] << std::endl;
}

Measured memory_bytes: 1224
m_list=list(map(int, [input() for i in range(6)]))
flag=0

for i in range(5):
        for j in range(5):
                if abs(m_list[i]-m_list[j])>m_list[5]:
                        flag=1
        
        
if flag==1:
        print(":(")  
else:
        print("Yay!")            


Measured memory_bytes: 2940
def binary_search(A, target):
  left = 0 
  right = len(A)
  while(3 <= right - left):
    index = (left + right) // 2
    if(A[index] < target):
      left = index
    else:
      right = index + 1
  return left
  
N = int(input())
A = list(map(int, input().split()))
A.sort()
target = A[N - 1] / 2
if(target <= A[0]): ai = A[0]
elif(A[N - 2] <= target): ai = A[N - 2]
else:
  index = binary_search(A[:N - 1], target)
  ai = A[index] if(abs(A[index] - target) < abs(A[index + 1] - target)) else A[index + 1]
print(A[N - 1], ai)

Measured memory_bytes: 85768
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	long sum = 0;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		sum += v[i];
	}
	int max = *max_element(v.begin(), v.end());
	int min = *min_element(v.begin(), v.end());
	cout << min << " " << max << " " << sum << endl;
}



Measured memory_bytes: 3132
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,a[5][N],i,j,k,x,y,b[N],c[2];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=3;++i)
		for(j=1;j<=n;++j)
			scanf("%d",a[i]+j);
	for(i=1;i<=n;++i)
	{
		x=y=a[1][i];
		for(j=2;j<=3;++j)
			x=max(x,a[j][i]),y=min(y,a[j][i]);
		if(x-y!=2||y+1!=a[2][i])
		{
			printf("No");
			return 0;
		}
		b[i]=x/3;
		if(a[1][i]!=y)
			c[i&1]=!c[i&1];
		if((x/3-i)%2)
		{
			printf("No");
			return 0;
		}
	}
	for(i=1;i<=n;++i)
	while(i!=b[i])
	{
		swap(b[i],b[b[i]]);
		c[i&1^1]=!c[i&1^1];
	}
	if(c[0]||c[1])
		printf("No");
	else
		printf("Yes");
	return 0;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val S = readLine()!!.toInt()
    var list = arrayListOf(S)
    for (i in 2..1000000) {
        var last = list.last()
        if (last%2 == 0) {
            last /= 2
        } else {
            last = last*3 + 1
        }
        if (list.contains(last)) {
            println(i)
            break
        }
        list.add(last)
    }
 }

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

#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>x(N),L(N);
  vector<pii>p(N);
  for(int i=0;i<N;i++)cin>>p[i].first>>p[i].second;
  sort(rng(p));
  for(int i=0;i<N;i++)x[i]=p[i].first,L[i]=p[i].second;
  vector<pii>arm(N);
  for(int i=0;i<N;i++)arm[i].first=x[i]+L[i],arm[i].second=x[i]-L[i];
  sort(rng(arm));
  ll ans=1;
  int memo=arm[0].first;
  for(int i=0;i<N;i++){
    if(memo<=arm[i].second)ans++,memo=arm[i].first;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC090
{
    class Candies
    {
        public static void Main()
        {
            var n = int.Parse(ReadLine().Trim());
            var upper = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            var lower = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            for (var i = 1; i < n; ++i)
            {
                upper[i] += upper[i - 1];
                lower[n - i - 1] += lower[n - i];
            }
            WriteLine(upper.Zip(lower, (a, b) => a + b).Max());
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
long long ans=0;
long long n,k;
const long long Mod=998244353;
struct sk{
	long long l,r;
}s[25];
long long dp[200005];
long long st[200005];
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		cin>>s[i].l>>s[i].r;
	}
	dp[1]=1;
	st[1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			dp[i]=dp[i]+st[max(0ll,i-s[j].l)]-st[max(0ll,i-s[j].r-1)];
			dp[i]%=Mod;
//			cout<<max(0ll,i-s[j].l)<<"\t"<<max(0ll,i-s[j].r-1)<<"\t"<<dp[i]<<"\t"<<st[max(0ll,i-s[j].l)]<<"\t"<<st[max(0ll,i-s[j].r-1)]<<endl;
		}
		dp[i]%=Mod;
		st[i]=st[i-1]+dp[i];
		st[i]%=Mod;
//		if(dp[i]!=0){
//			cout<<i<<" "<<st[i]<<" "<<dp[i]<<endl;
//		}
	}
	if(dp[n]<0)cout<<dp[n]+Mod;
	else cout<<dp[n];
//	cout<<dp[n]>=0?dp[n]:dp[n]+Mod;
	return 0;
} 

Measured memory_bytes: 6748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k; cin>>n>>k;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    rep(i,n-k){
        if(p[i]<p[i+k]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, res = 0;
    cin>>n;
    rep(i, 1, 10){
        if(n%i==0&&n/i<10){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
N,M=[int(i) for i in input().split()]
A=[]
for i in range(N):
    a=[i for i in input()]
    A.append(a)
B=[]
for i in range(M):
    b=[i for i in input()]
    B.append(b)    
flag=False
for i in range(N-M+1):
    for j in range(N-M+1):
        s=0
        if B[0][0]==A[i][j]:    
            for k in range(M):
                for l in range(M):
                    if B[0+k][0+l]==A[i+k][j+l]:
                        s+=1
            if s==M**2:
                flag=True          
if flag==True:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

bool is_kaibun(string s) {
    // cout << s << endl;
    string t = s;
    reverse(t.begin(), t.end());
    if (t == s)
        return true;
    return false;
}

int main() {
    string s;
    cin >> s;
    if (!is_kaibun(s)) {
        cout << "No" << endl;
    }
    else if (!is_kaibun(s.substr(0, (s.size() - 1) / 2))) {
        cout << "No" << endl;
    }
    else if (!is_kaibun(s.substr((s.size() + 3) / 2 - 1, 100))) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
    int n,r;
    while(cin>>n>>r,n,r){
        int data[50],tmp[50];
        for(int i=0;i<n;i++){
            data[i]=n-i;
            tmp[i]=n-i;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            for(int j=0;j<p+c-1;j++){
                if(j<p-1){
                    tmp[j+c]=data[j];
                }else{
                    tmp[j-p+1]=data[j];
                }
            }
            for(int j=0;j<n;j++){
                data[j]=tmp[j];
            }
        }
        cout<<data[0]<<endl;
    }
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int,int>> V(M);
  for(int i = 0; i < M; ++i) {
    cin >> V[i].first >> V[i].second;
  }
  sort(V.begin(), V.end());
  int ans = N - 1 + 2;
  int index = 0;
  while(index < M) {
    // cerr << V[index].first << " -> ";
    int l = V[index].first;
    int r = V[index].second;
    while(index + 1 < M && V[index + 1].first <= r) {
      index++;
      r = max(r, V[index].second);
    }
    ans += (r - l) * 2;
    // cerr << r << endl;
    index++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double d = sqrt(1. * (x1 - x2) * (x1 - x2) + 1. * (y1 - y2) * (y1 - y2));
    printf("%.6f\n", d);
}


Measured memory_bytes: 3200
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	ll sum = 0;
	priority_queue<ll> plus;
	ll minus = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}
	int ans = 0;
	rep(i,n){
		cin >> b[i];
		if(a[i] > b[i]) plus.push(a[i] - b[i]);
		if(a[i] < b[i]){
			minus += a[i] - b[i];
			++ans;
		}
		sum -= b[i];
	}
	if(sum < 0){
		cout << -1 << endl;
		return 0;
	}
	while(minus < 0){
		minus += plus.top();
		plus.pop();
		++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2428
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <climits>

int solve(int& A, int& B)
{
    int ans = 100001;
    for(int i = 0; i < 100001; i++)
    {
        if(floor(i*0.08)==A && floor(i*0.10)==B) ans = std::min(i, ans);
    }
    if (ans == 100001) return -1;
    else return ans;
}

int main()
{
    int A, B; std::cin >> A >> B;
    
    int ans = solve(A, B);

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum=0,count=0;
    while(cin>>a>>b)
    {
        sum=a+b;
       while(sum>0)
       {
         sum/=10;
            count++;
       }
       cout<<count<<endl;
       count=0;
    }
    return 0;
}



Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int n;
	private int m;
	private int k;
	
	Main() {
		readData();
		
		List<Integer> a = new ArrayList<Integer>();
		
		a.add(n);
		a.add(m);
		a.add(k);
		Collections.sort(a);
		
		String s = "";
		for (int i = 0;i < 2; i++) {
			s += a.get(i) + " ";
		}
		s += a.get(2);
		
		System.out.println(s);
	}
	
	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			n = nextInt();
			m = nextInt();
			k = nextInt();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 16872
#include <bits/stdc++.h>
#define int long long int
#define double long double
#define mod 1000000007
#define PI 3.141592
#define w(t) int t; cin>>t; while(t--)
#define f(i,a,n) for( int i=a;i<n;i++)
#define pb push_back
#define pob pop_back
#define mk make_pair
#define ARMY ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int solve(int a[101][101],int n,int m, int dp[101][101])
   {    
        
         dp[1][1]=a[1][1];
         f(i,2,m+1)
         dp[i][1]=a[i][1]+dp[i-1][1];
         f(j,2,n+1)
         dp[1][j]=a[1][j]+dp[1][j-1];
       int ans=INT_MAX;
         f(i,2,m+1)
          {    int jj=0;
              f(j,2,n+1)
               {
                   dp[i][j]=abs(dp[i-1][j]+a[i][j])<=abs(dp[i][j-1]+a[i][j])? dp[i-1][j]+a[i][j]:dp[i][j-1]+a[i][j];
                   
                     jj+=dp[i][j];
                     if(jj<=0)
                       jj=abs(dp[i][j])+1;;
               }
               ans=min(jj,ans);
          }
          

          return ans;     
         
   }



int32_t main()
  {

  int n;
  cin>>n;
  int a[n],b[n],c[n];
  f(i,0,n)
  cin>>a[i]>>b[i]>>c[i];
  int dp[n][3];
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  f(i,1,n)
   {
     dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
     dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
     dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
   }

  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));


   /* w(t)
     {
        int m,n;
        int a[101][101];
        int dp[101][101];
        cin>>m>>n;
        f(i,1,m+1)
        f(j,1,n+1)
        cin>>a[i][j];
       int  ans=solve(a,n,m,dp);    
        cout<<ans+1<<"\n";


     }*/

  }

Measured memory_bytes: 8224
# -*- coding: utf-8 -*-

def main():

    K = int(input())
    A, B = map(int, input().split())

    numA = (A - 1) // K
    numB = B // K

    if numB - numA > 0:
        ans = 'OK'

    else:
        ans = 'NG'

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std; 
int n;
map<string,int> mp;
string s[200010];
vector<string>ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	int mx=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		mp[s[i]]++;
		mx=max(mx,mp[s[i]]);
	}
	int cnt=0;
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second==mx){
			ans.push_back(it->first);
		}
	}
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
    return 0; 
}/*
*/

Measured memory_bytes: 28404
//============================================================================
// Name        : n
// Date        : Mon Mar  4 15:57:57 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define jam(x, n) cout << "Case #" << x << ": " << n << "\n"
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const ll inf = (ll) 1e18 + 7;

void solve() {
    int n; cin >> n;
    vi aa(n);
    fori (i, 0, n) {
        cin >> aa[i];
    }

    auto sum = [&](int lo, int hi) {
        ll s = 0;
        fori (i, lo, hi + 1) {
            s += aa[i];
        }
        return s;
    };

    vector<vl> dp(n, vl(n, inf));
    fori (hi, 0, n) ford (lo, hi, -1) {
        if (lo == hi) {
            dp[lo][hi] = 0;
        } else {
            ll s = sum(lo, hi);
            fori (i, lo, hi) {
                dp[lo][hi] = min(dp[lo][hi], dp[lo][i] + dp[i + 1][hi] + s);
            }
        }
    }

    output(dp[0][n - 1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



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

typedef long long ll;

int main(){
    string s;
    cin >> s;
    
    int length;
    int first = s.find_first_of('A');
    int last = s.find_last_of('Z');
    length = last - first +1;

    printf("%d\n",length); 

    return 0;
}


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

using namespace std;

const int mod = (int) 1e9 + 7;

int mult(int a, int b) {
  long long A = a, B = b, M = mod;
  A %= M, B %= M;
  return int((A * B) % M);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  int now = 0;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') ++now;
    if (s[i] == 'D') --now;
    mx = max(mx, now);
  }
  cout << mx << '\n';
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long P, long long Q, long long R){
    cout << min({P+Q, Q+R, R+P}) << endl;
}

int main(){
    long long P;
    scanf("%lld",&P);
    long long Q;
    scanf("%lld",&Q);
    long long R;
    scanf("%lld",&R);
    solve(P, Q, R);
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

vector<int> seg = {0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
                   0b1101101, 0b1111101, 0b0100111, 0b1111111, 0b1101111};

int main() {
    while(true) {
        ll n = IN();
        if(n == -1) return 0;
        int pre = 0;
        REP(i, n) {
            int d = IN();
            cout << bitset<7>(seg[d] ^ pre) << "\n";
            pre = seg[d];
        }
    }
}



Measured memory_bytes: 3076
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-31 13:48:14 +0900
# LastModified: 2020-07-31 14:24:21 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from math import sqrt


def main():
    X = abs(int(input()))
    s = (-1+sqrt(1+8*X))/2
    if s.is_integer():
        s = int(s)
    else:
        s = int(s) + 1
    print(s)



if __name__ == "__main__":
    main()


Measured memory_bytes: 9112
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    string str;
    while(cin >> str, str[0] != '0'){
        int sum = 0;
        rep(i,str.size()){
            sum += str[i] - '0';
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll P = 1000000007;
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> k;
  ll ans = 0;
  n = 3;
  vll num(k+1, 0);
  for(ll i=k;i>0;i--){
    ll tmp = mpow(k/i, n);
    num[i] += tmp;
    for(ll j=2;j*j<=i;j++){
      if(i%j!=0) continue;
      num[j] -= num[i];
      if(j*j!=i) num[i/j] -= num[i];
    }
    if(i!=1) num[1] -= num[i];
  }
  for(ll i=1;i<=k;i++) ans += num[i]*i;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
    std::vector<ll> forword[100003];
    std::vector<ll> backward[100003];
    ll arr[100003];
ll dp(ll k){
    
    if(backward[k].size()==0)return 0;
    else{
        if(arr[k]==-1){
        ll mm=0;
        for(auto i:backward[k]){
            mm=max(dp(i),mm);
        }
        arr[k]=mm+1;
            
        }
        return arr[k];
        
    }
}
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n,m;
    cin>>n>>m;
memset(arr,-1,100003*sizeof(arr[0]));
        for (int i = 0; i < m; ++i)
        {
            ll a,b;
            cin>>a>>b;
            forword[a].push_back(b);
            backward[b].push_back(a);
        }
ll mm=0;
        for (int i = 1; i <=n ; ++i)
        {
            mm=max(mm,dp(i));
        }
cout<<mm;

}

Measured memory_bytes: 19712
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int main(){
  bool compnum[1299710];
  memset(compnum, false, sizeof(compnum));
  for (int i = 2; i*i <= 1299709; i++) {
    for (int j = i+i; j <= 1299709; j+=i) {
      compnum[j] = true;
    }
  }
  while (true) {
    int x;
    cin >> x;
    if (x == 0) break;
    int l, r;
    l = r = x;
    while (l > 2 && compnum[l]) l--;
    while (r < 1299709 && compnum[r]) r++;
    cout << r-l << endl;
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(){
long long A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
 long long nagasa=abs(B-A);
  long double time=V-W;
if(nagasa==0){
cout<<"YES";
}
  else if(time ==0){
  cout<<"NO";
  }
  else if(nagasa <= time *T){
 cout<<"YES";
 }
  else{
  cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#define O 0
#define I 1
#define W 2
#define T 3
#define N 10000

int isPrime(int);

int main(){
  int i,n=O,x,a[N];
  
  scanf("%d",&x);
  for(i=O;i<x;i++){
    scanf("%d",&a[i]);
  }
  for(i=O;i<x;i++){
    if(isPrime(a[i])==I){
      n++;
    }
  }
  printf("%d\n",n);
  return 0;
}

int isPrime(int x){
  int i=T;
  
  if(x==W){
    return I;
  }
  else if(x<W || x%W==O){
    return O;
  }
  else{
    while(i<=sqrt(x)){
      if(x%i==O){
	return O;
      }
      i = i+W;
    }
  }
  return I;
}



Measured memory_bytes: 2088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int n, m, ans, node1, node2, x[9]={1};
vector<int> G[9];

void dfs(int p, int q){
    if(q==n) {
        ans++;
        return;
    }
    for(auto a : G[p]){
        if(!x[a]){
            x[a] = 1;
            dfs(a,q+1);
            x[a] = 0;
        }
    }
}
int main() {
    cin >> n >> m;
    rep(i,m){
        cin >> node1 >> node2;
        node1--; node2--;
        G[node1].push_back(node2);
        G[node2].push_back(node1);
    }
    dfs(0,1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int a, b, c;
    cin >> a >> b >> c;
    if (c > min(a, b) && c < max(a, b))
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
    return 0;
};


Measured memory_bytes: 256
x, k, d = map(int, input().split())
# = list(map(int, input().split()))
x = abs(x)
if x // d > k:
    print(x - d * k)
else:
    if (k - x // d) % 2 == 0:
        print(x % d)
    else:
        print(abs(x % d - d))


Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <numeric>
int main(int argc, char const *argv[]) {
  int N,M;
  std::vector<int> T,P,X;
  std::cin >> N;
  for (size_t i = 0; i < N; i++) {
    int t;
    std::cin >> t;
    T.push_back(t);
  }
  std::cin >> M;
  for (size_t i = 0; i < M; i++) {
    int p,x;
    std::cin >> p >> x;
    P.push_back(p);
    X.push_back(x);
  }
  for (size_t i = 0; i < M; i++)
    std::cout << std::accumulate(T.begin(),T.end(),0) - T[P[i] - 1] + X[i] << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	int a, n, t=0, h=0;
	char c1[101], c2[101];
	scanf("%d", &n);
	for (;n>0;n--) {
		scanf("%s %s", c1, c2);
		a=strcmp(c1, c2);
		if (a == 0) { t++; h++; }
		else if (a > 0) t+=3;
		else h+=3;
	}
	printf("%d %d\n", t, h);
	return 0;
}

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

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

using namespace std;

struct Edge { int src,dst,bitmask; };
struct Data {
  int cur,weight,bitmask,step;
  bool operator < ( const Data &data ) const {
    return weight > data.weight;
  }
};

const int MAX_V = 101;
const int MAX_R = 101;
const int IINF = INT_MAX;
int V,E,M,S,T,R,bits[MAX_V];
vector<Edge> G[MAX_V];
int mini[MAX_V][MAX_R][1<<4];

void compute(){
  //rep(i,V) rep(k,R+1) rep(j,(1<<4)) mini[i][k][j] = IINF;
  rep(i,MAX_V) rep(k,MAX_R) rep(j,(1<<4)) mini[i][k][j] = IINF;
  mini[S][0][bits[S]] = 0;
  priority_queue<Data> Q;
  Q.push((Data){S,0,bits[S],0});
  while( !Q.empty() ){
    Data data = Q.top(); Q.pop();
    if( data.cur == T ) { cout << data.weight << endl; return; }
    rep(i,(int)G[data.cur].size()){
      Edge &v = G[data.cur][i];
      if( v.bitmask != -1 ) {
	if( ( v.bitmask & data.bitmask ) == 0 ) continue;
      }
      int bitmask = data.bitmask | bits[v.dst];
      if( data.step + 1 <= R && mini[v.dst][data.step+1][bitmask] > data.weight + 1 ) {
	mini[v.dst][data.step+1][bitmask] = data.weight + 1;
	Q.push((Data){v.dst,data.weight+1,bitmask,data.step+1});
      }
    }
    if( mini[S][0][data.bitmask] > data.weight + 1 ) {
      mini[S][0][data.bitmask] = data.weight + 1;
      Q.push((Data){S,data.weight+1,data.bitmask,0});
    }
  }
  cout << -1 << endl;
}

int main(){
  cin >> V >> E >> M >> S >> T >> R;
  rep(i,E){
    int s,t;
    cin >> s >> t;
    G[s].push_back((Edge){s,t,-1});
    G[t].push_back((Edge){t,s,-1});
  }
  rep(i,M) {
    int s,t,c;
    cin >> s >> t >> c;
    bits[c] |= (1<<i);
    G[s].push_back((Edge){s,t,(1<<i)});
    G[t].push_back((Edge){t,s,(1<<i)});
  }
  compute();
  return 0;
}

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

#define ll long long
#define dd double
#define scl(n)    scanf("%lld",&n)
#define scd(n)    scanf("%lf",&n)
#define ptl(n)    printf("%lld",n)
#define ptd(n)    printf("%lf",n)
#define nline     printf("\n")
#define vld       vector<ll>
#define vbd       vector<bool>
#define eb        emplace_back
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define pi        2*acos(0.0)

using namespace std;

int main()
{
    ll n,l,i,j,k,eq[100000]={0},cnt=0;
    scl(n);
    for(i=1;i*i+2*i+3<=n;i++)
    {
       for(j=1;j*j+2*j+3<=n;j++)
       {
          for(k=1;k*k+2*k+3<=n;k++)
          {
              eq[i*i+j*j+k*k+i*j+j*k+k*i]++;
          }
       }
    }
    FOR1(i,n)
    {
        ptl(eq[i]);
        nline;
    }
    return 0;
}


Measured memory_bytes: 4532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define N 1000000
int	prime[N+10],cnt=0;
bool num[N+10]={1,1};
int ans=0;
void pre()
{
	for (int i=2;i<=N;i++)
	{
		if (!num[i])
			prime[++cnt]=i;
		for (int j=1;(j<=cnt)&&(i*prime[j]<=N);j++)
		{
			num[i*prime[j]]=true;
			if (i%prime[j]==0)
				break;
		}
	}		
}

void solve()
{
	pre();
	ll n;
	cin>>n; 
	for (int j=1;j<=cnt;j++)
	{
		if (n==1)
			break;
		if (n%prime[j]==0)
		{
			int sum=0;
			while (n%prime[j]==0)
			{
				n/=prime[j];
				sum++;
			}
			int temp=0;
			for (int l=1;l<=100;l++)
			{
				temp+=l;
				if (temp>sum)
				{
					ans+=l-1;
					break;
				}
			}
		}
	}
	if (n!=1)
		ans++;
	cout<<ans<<endl;
//cout<<prime[2]<<endl;
//	for (int i=1;i<=cnt;i++)
//		cout<<prime[i]<<endl;
}



int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--) 
	solve();
	return 0;
}

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


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v(100);
  fill(v.begin(), v.end(), 0);
  a--;
  b--;
  c--;
  v[a]++;
  v[b]++;
  v[c]++;
  int count = 0;
  for(int i = 0; i < 100; i++){
    if(v[i] != 0)count++;
  }
  cout << count << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};

const ll mod=1000000000+7;
const int MAX_N=1000;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,f[100010],w[100010];
vector<pi> a[100010];
L p;
inline int dfs(int i,int j)
{
	int k=0;
	for(auto x:a[i])
	  if(x.aa!=j)
	    {
		 int l=dfs(x.aa,i);
		 k+=l;
		 p+=(L)min(l,n-l)*x.bb*2;
		}
	return f[i]=k+1;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	  {
	   scanf("%d%d%d",&j,&k,&l);
	   a[j].pb(mp(k,l));
	   a[k].pb(mp(j,l));
	  }
	dfs(1,0);
	for(i=1;i<=n;i++)
	  {
	   if((n-f[i])*2>n)
	     w[i]=1;
	   for(auto x:a[i])
	     if(f[x.aa]<f[i] && f[x.aa]*2>n)
	       w[i]=1;
	  }
	for(i=1;i<=n;i++)
	  if(!w[i])
	    {
		 k=1e9;
		 for(auto x:a[i])
		   if(!w[x.aa])
		     {
			  k=x.bb;
			  break;
			 }
		   else
		     k=min(k,x.bb);
		 p-=k;
		 break;
		}
	printf("%lld\n",p);
	return 0;
}


Measured memory_bytes: 9984
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64;n]
    }
    let mut am = a;
    am.sort();
    am.reverse();
    let mut first = 0;
    let mut second = 0;
    for i in 0..n {
        if i % 2 == 0 {
            first += am[i];
        } else {
            second += am[i];
        }
    }
    println!("{}", first - second);
}

Measured memory_bytes: 4352
# AキャンディーとNにんの子供イージー

# 競プロ幼稚園にはN人の子供がいます。えび先生は、子供たちを一列に並べ、一人目にはキャンディーを1個、二人目には2個,...,N人めにはN個あげることにしました。
# 必要なキャンディーの個数の合計は何個でしょう？
# 1 <= N <= 100

# Nは子供の人数
N = int(input())
# print(N)

# answerは合計個数
answer = ((N + 1) * N // 2)

print(answer)

Measured memory_bytes: 9088
/*
 * ABC104 B - AcCepted 
 */

#include	<iostream>
#include	<string>
#include	<ctype.h>

std::string S;

bool test(void)
{
	if (S[0] == 'A') {
		S[0] = '*';
	} else {
		return false;
	}

	int bottom = (int)S.size() - 2;
	int cnt = 0;
	int i;
	for (i = 2;  i <= bottom; i++) {
		if (S[i] == 'C') {
			if (++cnt > 1) {
				break;
			}
			S[i] = '*';
		}
	}

	if (cnt != 1) {
		return false;
	}

	for (i = 0; i < (int)S.size(); i++) {
		if (S[i] == '*') {
			;
		} else {
			if (!islower(S[i])) {
				return false;
			}
		}
	}

	return true;
}

int main(void) {

	std::cin >> S;

	bool ac = test();
	std::cout << (ac ? "AC": "WA") << std::endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKnight solver = new DKnight();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKnight {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int x = in.nextInt();
            int y = in.nextInt();
            int s = ((x + y) / 3 + (y - x)) / 2;
            int t = ((x + y) / 3 - (y - x)) / 2;

            if ((s + 2 * t) == x && (s * 2 + t) == y && s >= 0 && t >= 0) {
                ModComb mc = new ModComb(s + t);
                out.println(mc.combination(s + t, s).getVal());
            } else {
                out.println(0);
            }

        }

    }

    static class ModInt {
        long val;
        int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (i + MOD) % MOD;
        }

        public ModInt mul(long l) {
            return new ModInt(this.val * l);
        }

        public ModInt inv() {
            return this.pow(MOD - 2);
        }

        public ModInt pow(long l) {
            ModInt res = new ModInt(1);
            ModInt v = new ModInt(this.val);
            while (l > 0) {
                if (l % 2 != 0) {
                    res = res.mul(v.val);
                }
                v = v.mul(v.val);
                l /= 2;
            }
            return res;
        }

        public long getVal() {
            return val;
        }

        public String toString() {
            return Long.toString(val);
        }

    }

    static class ModComb {
        private int size;
        private ModInt[] fac;
        private ModInt[] inv;

        public ModComb(int n) {
            size = n;
            fac = new ModInt[n + 1];
            inv = new ModInt[n + 1];
            makeFac();
        }

        private void makeFac() {
            for (int i = 0; i <= size; i++) {
                if (i == 0) {
                    fac[i] = new ModInt(1);
                } else {
                    fac[i] = fac[i - 1].mul(i);
                }
                inv[i] = fac[i].inv();
            }
        }

        public ModInt combination(int n, int k) {
            if (n < k) return new ModInt(0);
            return fac[n].mul(inv[k].getVal()).mul(inv[n - k].getVal());
        }

    }
}



Measured memory_bytes: 318548
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;


int main(){
    int n, sum=0;
    int w[100];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> w[i];
        sum += w[i];
    }
    int s1 = 0;
    int dif = sum;
    for(int i=0; i<n; i++){
        s1 += w[i];
        dif = min(dif, abs(s1- (sum - s1)));
    }
    cout << dif << endl;
    return 0;
    
}

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

def m_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def check(num,k):
    if k==1:
        return False

    while num>=k:
        if num%k==0:
            num=num//k
        else:
            break
    num%=k
    return num==1

n1divs = m_div(n-1)
ndivs  = m_div(n)

ans=[]
for num in n1divs:
    if check(n,num):
        ans.append(num)
for num in ndivs:
    if check(n,num):
        ans.append(num)
print(len(set(ans)))

Measured memory_bytes: 41580
import sys

def preprocessing():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))

    solve(N)

def solve(N: int):
    counts = [[0] * 10 for _ in range(10)]
    for i in range(10, N + 1):
        b = i % 10 
        while i >= 10:
            i //= 10 # Truncated division (i = i // 10)
        counts[i][b] += 1
    ret = 0
    for i in range(1, min(N + 1, 10)):
        ret += 1
        if counts[i][i] > 0:
            ret += counts[i][i] * 2
    for i in range(1, 10):
        for j in range(1, 10):
            ret += counts[i][j] * counts[j][i]
    print(ret)
    return


 
if __name__ == "__main__":
    preprocessing()

Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
	ll x,n;
	cin>>x>>n;
	ll arr[n];
	get(arr,n);
	map <ll,ll> m;
	rep(i,0,n) m[arr[i]]=1;
	//sort(arr,arr+n);
	if(m[x]==0) cout<<x;
	else
	{
		ll f=0;
		for(ll i=1;f==0;i++)
		{
			if(m[x-i]==0)
			{
				cout<<x-i;
				f=1;
			}
			else if(m[x+i]==0)
			{
				cout<<x+i;
				f=1;
			}
		}
	}
		
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


Measured memory_bytes: 3664