akhauriyash/Code-Regression huggingface dataset:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    s = input()
    ans = 0
    for i in range(len(s)):
        if s[i]=="+":
            ans += 1
        else:
            ans -= 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
l = list(map(int, input().split()))
x = 1
count = 0
no = True
for i in range(n):
    if l[i] == x:
        x += 1
        no = False
    else:
        count += 1
if no == True:
    print(-1)
else:
    print(count)

Measured memory_bytes: 26268
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int N = n[0];
        int M = n[1];
        int X = n[2];
        int Y = n[3];
        int xMax = Console.ReadLine().Split(' ').Select(int.Parse).Max();
        int yMin = Console.ReadLine().Split(' ').Select(int.Parse).Min();

        for(int i = X + 1; i < Y; i++)
        {
            if(xMax < i && i <= yMin)
            {
                Console.WriteLine("No War");
                return;
            }
        }
        Console.WriteLine("War");
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder s = new StringBuilder(sc.next());
        //後ろに追加していくSB
        StringBuilder s1 = new StringBuilder();
        //前に追加するSB
        StringBuilder s2 = new StringBuilder();
        int q = sc.nextInt();
        boolean isreversed = false;
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            if (t == 1) {
                isreversed = !isreversed;
            } else {
                int f = sc.nextInt();
                String c = sc.next();
                if (f == 1) {
                    if (isreversed)
                        s1.append(c);
                    else
                        s2.append(c);
                } else {
                    if (isreversed)
                        s2.append(c);
                    else
                        s1.append(c);
                }
            }
        }
        
        s.append(s1);
        s.insert(0, s2.reverse());
        if (isreversed)
            s = s.reverse();
        System.out.println(s.toString());
    }
}


Measured memory_bytes: 125984
//AtCoder ABC094 C - Many Medians
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
struct Dat{
    ll x;
    ll base; //元のid
    ll cur; //sort済のid
};
int main() {
    ll N;cin>>N;
    vector<Dat> xn(N+1);
    for(ll i=1;i<=N;++i){
        auto&& d=xn[i];
        cin>>d.x;
        d.base=i;
    }
    sort(xn.begin(),xn.end(),[](const auto& a,const auto& b){
        return (a.x<b.x);
    });
    unordered_map<ll,ll> mp;
    for(ll i=1;i<=N;++i){
        auto&& d=xn[i];
        d.cur=i;
        mp[d.base]=i;
    }

    ll cent=(N-1+1)/2; //1つ数字をとるので
    auto ctdno = [&](ll d){
       if(d<cent){
           return cent+1;
       } else if(d==cent){
           return cent+1;
       } else {
           return cent;
       }
    };
    for(ll i=1;i<=N;++i){
        cout<<xn[ctdno(mp[i])].x<<endl;
    }
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    bool temp = false;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(n == (i*j)){
                temp = true;
            }
        }
    }
    if(temp){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

#define NIL NULL

struct node {
  struct node *p;
  struct node *l;
  struct node *r;
  int key;
};

typedef struct node * Node;
Node root;

void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int m,k,i;
  char str[10];

  scanf("%d",&m);

  for(i = 0; i < m; i++){
    scanf("%s",str);

    if(str[0] == 'i') {
      scanf("%d",&k);
      insert(k);
    }
    else if(str[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int z){
   Node x,y,a;

  y = NIL;
  x = root;
  a = (Node)malloc(sizeof(struct node));

  a->key = z;
  a->l = NIL;
  a->r = NIL;

  while(x != NIL){
    y = x;
    if(a->key < x->key) x = x->l;
    else x = x->r;
  }
  a->p = y;

  if( y == NIL) root = a;
  else if(a->key < y->key) y->l = a;
  else y->r = a;
  
}

void inorder(Node root){
  if(root == NIL) return;
  inorder(root->l);
  printf(" %d",root->key);
  inorder(root->r);
}

void preorder(Node root){
  if(root == NIL){
    return;}
  printf(" %d",root->key);
  preorder(root->l);
  preorder(root->r);
}

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

int main()
{
  long long N, K;
  cin >> N >> K;
  
  long long ans;
  
  if (K % 2 == 0)
  {
    ans = pow((N + K / 2) / K , 3) + pow(N / K, 3); 
    // a,b,c = K/2 + mK, K + nK
  } else
  {
    ans = pow(N / K, 3); // a,b,c = K + nK
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;

int main(){
  string s;
  cin >>s;
  ll a=0,b=0;
  
  for(int i=0; i<s.size(); i++){
    if(s[i] == 'B')a++;
    else b += a;
  }
  
  cout << b;
  
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
int main() {

  ll N;
  ll A[200000];
  ll B[200000];

  cin >> N;

  for (int i = 0; i < N; i++) cin >> A[i];

  for (int i = 0; i < N; i++) B[i] = A[i] - i - 1;

  sort(B, B + N);

  ll mid = N/2;
  ll res = 0;
  ll b = B[mid];
  for (int i = 0; i < N; i++) res += abs(B[i] - b);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    n*=2;
    vector<int> v(n);
    for(auto &i:v) cin>>i;
    sort(v.begin(), v.end());
    int sum = 0;
    for(int i=0;i<n;i+=2) sum+=v[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
sub = {(i+1):"Trick" for i in range(N)}
for i in range(K):
  d = int(input())
  prepare = map(int, input().split())
  for j in prepare:
    sub[j] = "Treat"
ans = 0
for v in sub.values():
  if v == "Trick":
    ans += 1
print(ans)
  

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum=0,ave1,ave2,s=0,t=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  ave1=sum/n;
  ave2=(sum+n-1)/n;
  for(int i=0;i<n;i++){
    s+=(a[i]-ave1)*(a[i]-ave1);
    t+=(a[i]-ave2)*(a[i]-ave2);
  }
  cout << min(s,t) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,l;
  cin>>n>>l;
  Int v=10000000,sum=0;
  for(Int i=0;i<n;i++){
    if(abs(v)>abs(l+i)) v=l+i;
    sum+=l+i;
  }
  
  cout<<sum-v<<endl;
  return 0;
}


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

using namespace std;

const int N = 234567;

int n, limit;
vector<pair<int, int>> adj[N], states[N];

void dfs(int x) {
  states[x].clear();
  if (!adj[x].size()) {
    states[x].emplace_back(0, 0);
  } else {
    int l = adj[x][0].first, r = adj[x][1].first;
    dfs(l);
    dfs(r);
    for (auto e : adj[x]) {
      int y = e.first;
      for (auto& state : states[y]) {
        state.first += e.second;
        state.second += e.second;
      }
    }
    if (states[l].size() > states[r].size()) {
      swap(l, r);
    }
    vector<pair<int, int>> all;
    auto cmpy = [&] (const pair<int, int>& a, const pair<int, int>& b) {
      return a.second > b.second;
    };
    auto cmpx = [&] (const pair<int, int>& a, const pair<int, int>& b) {
      return a.first < b.first;
    };
    auto solve = [&] () {
      sort(states[l].begin(), states[l].end(), cmpy);
      sort(states[r].begin(), states[r].end(), cmpx);
      for (int i = 0, j = 0, k = 1e7; i < states[l].size(); ++i) {
        int y = states[l][i].first, z = states[l][i].second;
        while (j < states[r].size() && z + states[r][j].first <= limit) {
          k = min(k, states[r][j].second);
          ++j;
        }
        if (j) {
          all.emplace_back(y, k);
          all.emplace_back(k, y);
        }
      }
    };
    /*
    solve();
    for (auto& state : states[l]) {
      swap(state.first, state.second);
    }*/
    solve();
    sort(all.begin(), all.end());
    /*cout << x << '\n';*/
    for (int i = 0; i < all.size(); ++i) {
      if (i && all[i].first == all[i - 1].first) {
        continue;
      } else {
        states[x].push_back(all[i]);
        /*cout << all[i].first << ' ' << all[i].second << '\n';*/
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2, x, y; i <= n; ++i) {
    cin >> x >> y;
    adj[x].emplace_back(i, y);
  }
  auto check = [&] (int x) {
    limit = x;
    dfs(1);
    return states[1].size() > 0;
  };
  int l = 0, r = 1e7;
  while (l != r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << '\n';
  return 0;
}

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


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = "";
    int r=0,l=0;

    rep(i,n){
        if(s[i] == ')'){
            if(r == 0) ans.insert(0,"(");
            else{
                r--;
            }
            ans+=")";

        }
        if(s[i] == '('){
            ans+="(";
            r++;
        }
    }
    rep(k,r) ans+=")";
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 H, W;
  cin >> H >> W;
  v(string) S(H);
  cin >> S;

  vvi D(H, vi(W, INF));
  rep(i, H) rep(j, W){
    if(i + j == 0) D[i][j] = (S[i][j] == '#');
    else{
      if(i > 0) chmin(D[i][j], D[i - 1][j] + (S[i - 1][j] == '.' and S[i][j] == '#'));
      if(j > 0) chmin(D[i][j], D[i][j - 1] + (S[i][j - 1] == '.' and S[i][j] == '#'));
    }
  }
  cout << D[H-1][W-1] << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
sushis = [] #[美味しさ,種類]
for _ in range(n):
    a,b = inpl()
    sushis.append([b,a])
sushis.sort(reverse = True)
sushis = deque(sushis)
cnt = [0] * (n+1)
kind = 0
ois_sum = 0
eats = []
for i in range(k):
    ois,knd = sushis.popleft()
    if cnt[knd] == 0:
        kind += 1
    cnt[knd] += 1
    ois_sum += ois
    eats.append([ois,knd])
eats.sort()
res = ois_sum + kind**2
ind = 0
while sushis and ind < k:
    while ind < k:
        eat_knd = eats[ind][1]
        if cnt[eat_knd] <= 1: 
            ind += 1
        else: break
    if ind >= k: break
    ois,knd = sushis.popleft()
    if cnt[knd]: continue
    eat_ois,eat_knd = eats[ind]
    cnt[knd] += 1; cnt[eat_knd] -= 1
    ois_sum -= eat_ois - ois
    kind += 1
    res = max(res, ois_sum + kind**2)
    ind += 1
print(res)


Measured memory_bytes: 106076
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  String po=sc.nextLine();
  String[]s=po.split("",0);
  for(int i=0;i<s.length;i++)System.out.print((i%2==0)?s[i]:"");System.out.println();
}
}


Measured memory_bytes: 36568
# https://atcoder.jp/contests/abc106/tasks/abc106_b
def yc(n):
    y = []
    for i in range(1, n + 1):
        if n % i == 0:
            y.append(i)
    return(len(y))


n = int(input())
c = 0
for i in range(1, n + 1, 2):
    if yc(i) == 8:
        c += 1
print(c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define up upper_bound
#define lo lower_bound
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define umap unordered_map

ll ans=0;

void solve(ll w,ll wt[],ll cnt[],ll p){
    if(w<=0){
        ans=max(ans,p);
        return;
    }

    if(cnt[0]>0){
        cnt[0]--;
        // cout<<p<<endl;
        solve(w-wt[0],wt,cnt,p+1);
    }
    if(cnt[1]>0){
        cnt[1]--;
        // cout<<p<<endl;
        solve(w-wt[1],wt,cnt,p+1);
    }
    return;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ll s,d,t;
    cin>>d>>t>>s;

    if(s*t>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, p;
  cin >> n >> p;
  int ans = 1;
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      int c = 0;
      while (p % i == 0) {
        p /= i;
        c++;
      }
      for (int j = 1; j <= c / n; j++) {
        ans *= i;
      }
    }
  }
  if (p > 1 && n == 1) ans *= p;
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{/// Standing in The hall of Fame
    ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
    string s;
    cin >> s;
    int n = s.length() , x = 0;
    for(int i = 0 ; i < n/2 ; i++)
        x += (s[i] != s[n-1-i]);
    cout << x << "\n";
    return 0;
}

Measured memory_bytes: 256
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
c1=0
c2=0
for i in range(n):
    for j in range(n):
        if a[i]<a[j]:
            if i>j:
                c1+=1
            else:
                c2+=1
x1=(k*(k+1)//2)
x2=((k-1)*(k)//2)
print((c1*x1+c2*(x2))%mod)

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

using namespace std;

int main() {
    char x[6];
    for(int i=0;i<6;i++){
        cin >> x[i];
    }
    if((x[2] == x[3]) && (x[4] == x[5])){
        cout<<"Yes";    
    }else{
        cout << "No";
    }
    
    
}

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

int main() {
  double x = 0;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    double y;
    scanf("%lf", &y);
    x += 1.0 / y;
  }
  printf("%.12lf\n", 1.0 / x);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/*long gcd(long x, long y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}*/

int main() {
	long A, B, G_Common, k, cnt, i, j;
	scanf("%ld %ld",&A,&B);
	//G_Common = gcd(A,B);
	while ((k = A%B) > 0) {
		A = B;
		B = k;
	}

	G_Common = B;
	cnt = 1;
	for (i = 2; G_Common > 1 && G_Common >= i*i; ) {
		for (j = 0; G_Common % i == 0; j++) G_Common /= i;
		if (j > 0) cnt++;
		if (i == 2) i++;
		else i += 2;
	}
	if (G_Common >= i) cnt++; //残りの素因数が2乗より小さい時
	printf("%ld\n",cnt);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		for(int i = 1; i <= n; i++) {
			int cnt = 0;
			for(int x = 1; x * x <= i; x++) {
				for(int y = 1; y * y <= i; y++) {
					long a = 1, b = x + y;
					long c = 1l * x * x + 1l * y * y + 1l * x * y - i;
					if(1l * b * b - 4l * a * c > 0) {
						double ans = (-1.0 * b + Math.sqrt(1.0 * b * b - 4.0 * a * c)) / 2.0;
						if((Math.abs(ans - Math.round(ans)) <= 1e-6) && (ans > 0) && (Math.abs(ans - 0.0) > 1e-6))
							cnt++;
					}
				}
			}
			pw.println(cnt);
		}
		
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


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

int main()
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    string s;
    int num[3] = {a, b, c};
    int obje[n][2];
    map<int, string> alph;
    alph[0] = "A";
    alph[1] = "B";
    alph[2] = "C";
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s == "AB")
            obje[i][0] = 0, obje[i][1] = 1; //AB
        else if (s == "BC")
            obje[i][0] = 1, obje[i][1] = 2; //BC
        else
            obje[i][0] = 2, obje[i][1] = 0; //CA
    }

    string ans;

    for (int i = 0; i < n; i++)
    {
        if (num[obje[i][0]] == 0 && num[obje[i][1]] == 0)
        {
            puts("No");
            exit(0);
        }
        else if (num[obje[i][0]] == 1 && num[obje[i][1]] == 1)
        {
            if (i == n - 1 || obje[i][0] == obje[i + 1][0] || obje[i][0] == obje[i + 1][1])
                goto part0;
            else
                goto part1;
        }

        if (num[obje[i][0]] >= num[obje[i][1]])
        {
        part1:
            ans += alph[obje[i][1]];
            num[obje[i][1]]++;
            num[obje[i][0]]--;
        }
        else
        {
        part0:
            ans += alph[obje[i][0]];
            num[obje[i][1]]--;
            num[obje[i][0]]++;
        }
    }

    puts("Yes");
    for (auto v : ans)
    {
        cout << v << endl;
    }
}

Measured memory_bytes: 4520
readInt() = parse.(Int,split(readline()))

const MOD = 998244353

function solve()
   N,K = readInt()
   L = Vector{Int}(undef,K)
   R = Vector{Int}(undef,K)
   dp = zeros(Int,N)
   dp[1]+=1; dp[2]-=1
   for i in 1:K
      L[i],R[i] = readInt()
   end
   for i in 1:N-1
      for j in 1:K
         i+L[j]<=N && (dp[i+L[j]]=mod(dp[i+L[j]]+dp[i],MOD))
         i+R[j]+1<=N && (dp[i+R[j]+1]=mod(dp[i+R[j]+1]-dp[i]+MOD,MOD))
      end
      dp[i+1]+=dp[i]
      dp[i+1]%=MOD
   end
   println(dp[N])
end
solve()

Measured memory_bytes: 177388
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{   int n,i,j,k,l,c=0;
vector <int>a;
 cin>>n;
 for(i=0;i<n;i++){
        cin>>l;
 a.push_back(l);
}
sort(a.begin(),a.end());
for(i=0;i<n-2;i++){
    for(j=i+1;j<n-1;j++){
        for(k=j+1;k<n;k++){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]<a[i]+a[j] &&a[j]<a[i]+a[k]&&a[i]<a[k]+a[j])
                c++;
        }
        }
    }
cout<<c;

}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    int res = 1;
    for( int i = 1; i*i <= m; i++ ) {
        if( m%i == 0) {
            if( m/i >= n ) res = max(res, i);
            if( i >= n ) res = max(res, m/i);
        }
    }
    dump(res);
    return 0;  
}

Measured memory_bytes: 384
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

draws = [True] * K
d = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
    if draws[i % K] or T[i] != T[i - K]:
        result += d[T[i]]
        draws[i % K] = False
    else:
        draws[i % K] = True
print(result)


Measured memory_bytes: 3956
a,b=map(int, input().split())
A=[a]*b
B=[b]*a
As="".join(map(str,A))
Bs="".join(map(str,B))
Ai=int(As)
Bi=int(Bs)
if a>b:
    print(str(Bi))
else:
    print(str(Ai))

Measured memory_bytes: 3060
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	static FastScanner sc = new FastScanner(System.in);
	public static void main(String[] args) {
		long m = sc.nextLong();
		long n = sc.nextLong();
		out.println(modPow(m,n,1000000007));
	}
	public static final long modPow(long x, long n, final long mod) {
		long sum = 1;
		while (n > 0) {
			if ((n & 1) == 1) {sum = sum * x % mod;}
			x = x * x % mod; 
			n >>= 1;
		}
		return sum;
	}
}



class FastScanner implements Closeable {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	public FastScanner(InputStream in) {this.in = in;}
	private boolean hasNextByte() {
		if (ptr < buflen) {return true;}
		else{
			ptr = 0;
			try {buflen = in.read(buffer);}
			catch (IOException e) {e.printStackTrace();}
			if (buflen <= 0) {return false;}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {throw new NumberFormatException();}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}
			else{throw new NumberFormatException();}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public void close() {
		try {in.close();}
		catch (IOException e) {}
	}
}


Measured memory_bytes: 24468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long num, k_atk_count;
  cin >> num >> k_atk_count;
  vector<long long> v;
  for(long long i = 0; i < num; i++){
    long long a;
    cin >> a;
    v.push_back(a);
  }
  
  sort(v.rbegin(), v.rend());
  
  long long result = 0;
  if(k_atk_count > v.size()){
    cout << "0" << endl;
    return 0;
  } else {
    long long index = k_atk_count;
    v.erase(v.begin(), v.begin() + index);
    result = accumulate(v.begin(), v.end(), 0LL);
   } 
  cout << result << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    
        string s3="";
        int n1=s1.length(),n2=s2.length(),mx=0;
        int dp[n1+1][n2+1];
        for(int i=0;i<=n1;i++)
        for(int j=0;j<=n2;j++)
        {
            dp[i][j]=0;
        }
        vector<int> v1,v2;
        for(int i=1;i<=n1;i++)
        for(int j=1;j<=n2;j++){
            if(s1[i-1]!=s2[j-1])
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else{
                dp[i][j]=dp[i-1][j-1]+1;
               
        
            }    
        }
       
        int y=n1,z=n2;
        while(y>0 and z>0)
        {
            if(s1[y-1]==s2[z-1])
            {
                s3+=s1[y-1];
                y--;
                z--;
                
            }
            else
            {
                if(dp[y][z]==dp[y-1][z])
                y--;
                else
                z--;
            }
            
        }
        reverse(s3.begin(),s3.end());
        cout<<s3;
        
        
        
    
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int n,x,t; cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << "\n";
}

Measured memory_bytes: 3620
//20190907
//MaximalValue
//Naru
#include<iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  int* B = new int[N+2];
  for(int i=0; i<N+2; i++) B[i] = 100001;
  for(int i=1; i<=N-1; i++) {
    cin >> B[i];
  }
  int sum = 0;
  for(int i=0; i<=N-1; i++)
    sum += min(B[i], B[i+1]);
  cout << sum << endl;
  delete[] B;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 300000
int t[4*N+20];
void update(int v,int tl,int tr,int pos,int val)
{
	int tm=(tl+tr)/2;
	if(tl==tr)
	{
		t[v]=max(t[v],val);
		return ;
	}
	if(pos<=tm)
		update(2*v,tl,tm,pos,val);
	else if(pos>tm)
		update(2*v+1,tm+1,tr,pos,val);
	t[v]=max(t[2*v],t[2*v+1]);
}
int query(int v,int tl,int tr,int l,int r)
{
	if(tr<l||tl>r)
		return 0;
	if(l<=tl&&tr<=r)
		return t[v];
	int tm=(tl+tr)/2;
	return max(query(2*v,tl,tm,l,r),query(2*v+1,tm+1,tr,l,r));
}
int32_t main()
{
 
  	int n,k;
  	cin>>n>>k;

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

  	int temp;
  	for(int i=0;i<n;i++)
  	{
  		temp=query(1,0,N,max(arr[i]-k,0ll),min(arr[i]+k,300000ll));
  		update(1,0,N,arr[i],temp+1);
  	}
  	cout<<query(1,0,N,0,N)<<endl;
return 0;
}

Measured memory_bytes: 14148
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}

int getMax(int n) {
    int count = 0;
    while(n % 2 == 0) {
        count ++;
        n /= 2;
    }
    return count;
}
  
void solve() {
    int n, q;
    cin >> n;
    int a[n];
    map<int, int> freq;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        freq[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    while(q--) {
        int a, b;
        cin >> a >> b;
        sum += freq[a] * (b - a);
        cout << sum << endl;
        freq[b] += freq[a];
        freq.erase(freq.find(a));
    }
    
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

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

int Sum(int n){
    int ret = 0;
    for (int i = 0; i < 10; i++)
    {
        ret += n%10;
        n /= 10;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    int ans = 1000000000;
    for (int i = 1; i < N; i++)
    {
        int s = Sum(i) + Sum(N-i);
        if(ans > s) ans = s;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void) {
  int N, K;
  int l[55];
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> l[i];
  
  sort(l, l+N, greater<int>());
  int sum = 0;
  for (int i = 0; i < K; i++) sum += l[i];
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
int N;
Graph G;
vector<int> res;

void dfs(int v,int p,int c){
  res[v] = c;
  for(auto e:G[v]){
    if(e.first==p) continue;
    if(e.second&1) dfs(e.first,v,1-c);
    else dfs(e.first,v,c);
  }
}

int main(){
  cin >> N;
  G.assign(N,vector<Edge>());
  for(int i=0;i<N-1;i++){
    int u,v,w;cin >> u >> v >> w;
    --u,--v;
    G[u].push_back(Edge(v,w));
    G[v].push_back(Edge(u,w));
  }
  res.assign(N,0);
  dfs(0,-1,1);
  for(auto &v:res) cout << v << endl;
}

Measured memory_bytes: 8960
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

using QWORD = unsigned long long;
using SQWORD = long long;
using DWORD = unsigned int;
using SDWORD = int;
using WORD = unsigned short;
using SWORD = short;
using DOUBLE = double;
using FLOAT = float;

#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))

static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }

#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)

using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)

static void printMatrix(DWORD **p, DWORD dwSize)
{
    printf("---\n");
    for (DWORD i = 0; i < dwSize; i++) {
        for(DWORD j = 0; j < dwSize; j++) {
            printf("%5d", p[i*dwSize + j]);
        }
        cout << endl;
    }
    printf("---\n");
}

int main()
{
    DWORD dwInput_N, dwInput_M, dwInput_Q;
    char str[200];

    fgets(str, sizeof(str), stdin);
    dwInput_N = atoi(strtok(str, " "));
    dwInput_M = atoi(strtok(NULL, " "));
    dwInput_Q = atoi(strtok(NULL, " "));

    /* input train */
    DWORD aadwTrainMap[dwInput_N+1][dwInput_N+1];
    memset(aadwTrainMap, 0, sizeof(aadwTrainMap));
    for (DWORD dwIdx = 0; dwIdx < dwInput_M; dwIdx++) {
        fgets(str, sizeof(str), stdin);
        WORD wCity_L, wCity_R;

        wCity_L = atoi(strtok(str, " "));
        wCity_R = atoi(strtok(NULL, " "));
        aadwTrainMap[wCity_L][wCity_R]++;
    }

    /* calc camsum(Row, Col) */
    for (DWORD dwRow = 1; dwRow <= dwInput_N; dwRow++) {
        DWORD dwSum = 0;
        for (DWORD dwCol = 1; dwCol <= dwInput_N; dwCol++) {
            dwSum += aadwTrainMap[dwRow][dwCol];
            aadwTrainMap[dwRow][dwCol] = dwSum + aadwTrainMap[dwRow-1][dwCol];
        }
    }

    DWORD aadwAnswer[dwInput_N+1][dwInput_N+1];
    for (DWORD dwBegin = 1; dwBegin <= dwInput_N; dwBegin++) {
        for (DWORD dwEnd = 1; dwEnd <= dwInput_N; dwEnd++) {
            DWORD dwAnswer= (aadwTrainMap[dwEnd][dwEnd]
                        - aadwTrainMap[dwBegin-1][dwEnd]
                        - aadwTrainMap[dwEnd][dwBegin-1]
                        + aadwTrainMap[dwBegin-1][dwBegin-1]);
            aadwAnswer[dwBegin][dwEnd] = dwAnswer;
        }
    }


    /* input question */
    for (DWORD dwIdx = 0; dwIdx < dwInput_Q; dwIdx++) {
        DWORD dwAnswer;
        fgets(str, sizeof(str), stdin);
        WORD wBegin = atoi(strtok(str, " "));
        WORD wEnd   = atoi(strtok(NULL, " "));

        printf("%d\n", aadwAnswer[wBegin][wEnd]);
    }

    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;

    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n>>k;
        vi v(n+1);
        for(i=1;i<=n;i++)
            cin>>v[i];
        vi vv(n+3);
        vv[0]=1;
        vi vis(n+4,-1);
        ll x=1;
        vis[1]=0;
        for(i=1;i<n;i++)
        {
            vv[i]=v[x];
            if(k==i)
            {
                cout<<vv[i];return 0;
            }
            if(vis[v[x]]==-1)vis[v[x]]=i;
            else
            {
                // cout<<vv;
                l=vis[v[x]];
                j=i-vis[v[x]];
                k=k-l;
                // cout<<k<<endl;
                k%=j;
                // cout<<k<<endl;
                // cout<<l<<" "<<j<<endl;
                // cout<<j+l<<endl;
                cout<<vv[k+l];
                return 0;
            }
            x=v[x];
            if(x==1)
            {
                j=i;break;
            }
        }
        cout<<vv;
        k=k%j;
        cout<<vv[k];
    }
    return 0;
}

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

int main() {
  int n, ac=0, wa=0, tle=0, re=0; cin >>n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >>s;
    if(s=="AC") ac++;
    if(s=="WA") wa++;
    if(s=="TLE") tle++;
    if(s=="RE") re++;
  } 

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define FALSE 0
#define TRUE 1
int a[20];
int n;
int solve(int, int);
int main(){
  int i,j,q,m[200];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
      }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&m[j]);
  }
  for(j=0;j<q;j++){
    if(solve(0,m[j]))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  if(m==0)return TRUE;
  if(i>=n)return FALSE;
  if(solve(i+1,m)||solve(i+1,m-a[i]))return TRUE;
  else return FALSE;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
using namespace std;

int main()
{
	ll int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c=c-b;
		if (c<=0)
		{
			cout<<"Yes"<<endl;
			break;
		}
		a=a-d;
		if (a<=0)
		{
			cout<<"No"<<endl;
			break;
		}
		
	}
	
	
}



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

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

    vector<int> d(N);
    for (int i = 0; i < N; i++)
        cin >> d.at(i);

    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());

    int count = 1;
    for (int i = 0; i < N-1; i++) {
        if (d.at(i) != d.at(i+1)) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define zahyoutype double
typedef struct Point{zahyoutype x,y;}P;

double distPP(P p,P q){return hypot(p.x-q.x,p.y-q.y);}

void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}
void printpoint(P p){zahyoutype x=1;printf(x/2?"%.f %.f\n":"%ld %ld\n",p.x,p.y);}

int main(){
	P p1,p2;
	int r1;
	readpoint(&p2);
	readpoint(&p1);
	scanf("%d",&r1);
	double dist=distPP(p1,p2);
	double theta=acos(r1/dist);
	double arg=atan2(p2.y-p1.y,p2.x-p1.x);
	double x1,y1,x2,y2;
	x1=p1.x+r1*cos(arg+theta);
	y1=p1.y+r1*sin(arg+theta);
	x2=p1.x+r1*cos(arg-theta);
	y2=p1.y+r1*sin(arg-theta);
	if(x2<x1||(x2==x1&&y2<y1)){
		double t=x1;x1=x2;x2=t;
		t=y1;y1=y2;y2=t;
	}
	printf("%.9f %.9f\n%.9f %.9f\n",x1,y1,x2,y2);
}



Measured memory_bytes: 2172
// Aizu Vol-1 0141:   Spiral Pattern
// 2017.8.4

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

char *gets(char *);
char buf[100];

char a[105][105];
#define U 1
#define R 2
#define D 3
#define L 4

int main()
{
	int r, c, n, d, stop;
	int ci, cn;

	gets(buf);
	cn = atoi(buf);
	for (ci = 0; ci < cn; ci++) {
		gets(buf);
		n = atoi(buf);
		memset(a, ' ', sizeof(a));
		for (r = 0; r < n + 4; r += n + 3) {
			for (c = 0; c < n + 4; c++) a[r][c] = '#';
		}
		for (c = 0; c < n + 4; c += n + 3) {
			for (r = 0; r < n + 4; r++) a[r][c] = '#';
		}
		r = n + 1, c = 2, d = U, stop = 0, a[r][c] = '#';
		while (1) {
			if (stop >= 4) break;
			if (d == U) {
				if (a[r-2][c] == '#' || a[r-1][c] == '#' || a[r-1][c+1] == '#') d = R, stop++;
				else a[--r][c] = '#', stop = 0;
			}
			if (d == R) {
				if (a[r][c+2] == '#' || a[r][c+1] == '#' || a[r+1][c+1] == '#') d = D, stop++;
				else a[r][++c] = '#', stop = 0;
			}
			if (d == D) {
				if (a[r+2][c] == '#' || a[r+1][c] == '#' || a[r+1][c-1] == '#') d = L, stop++;
				else a[++r][c] = '#', stop = 0;
			}
			if (d == L){
				if (a[r][c-2] == '#' || a[r][c-1] == '#' || a[r-1][c-1] == '#') d = U, stop++;
				else a[r][--c] = '#', stop = 0;
			}
		}
		if (ci > 0) putchar('\n');
		for (r = 2; r < n + 2; r++) {
			a[r][n + 2] = 0;
			puts(a[r]+2);
		}
	}
	return 0;
}

Measured memory_bytes: 524
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Library.Knapsack
{
    class AOJ_dpl1c
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nw = ReadInts();
            var vws = new int[nw[0]][];
            for(int i = 0; i < nw[0]; i++)
            {
                vws[i] = ReadInts();
            }
            var dp = new int[nw[0], nw[1] + 1];
            for(int i = 0; i < nw[0]; i++)
            {
                for(int j = 1; j < nw[1] + 1; j++)
                {
                    if (i == 0)
                    {
                        if (j-vws[i][1] >= 0)
                        {
                            dp[i, j] = dp[i, j - vws[i][1]] + vws[i][0];
                        }
                    }
                    else
                    {
                        if (j - vws[i][1] >= 0)
                        {
                            dp[i, j] = Math.Max(dp[i - 1, j],
                                dp[i, j - vws[i][1]] + vws[i][0]);
                        }
                        else
                        {
                            dp[i, j] = dp[i - 1, j];
                        }
                    }
                }
            }
            Console.WriteLine(dp[nw[0] - 1, nw[1]]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 21416
import sys
input = sys.stdin.readline

N = int(input())
rating = [int(r) for r in input().split()]
rating.sort()

color = ['gray', 'brown', 'green', 'cyan', 'blue', 'yellow', 'orange', 'red']
c_count = {c: 0 for c in color}

count_over = 0
for r in rating:
    if r < 400:    c_count[color[0]] += 1
    elif r < 800:  c_count[color[1]] += 1
    elif r < 1200: c_count[color[2]] += 1
    elif r < 1600: c_count[color[3]] += 1
    elif r < 2000: c_count[color[4]] += 1
    elif r < 2400: c_count[color[5]] += 1
    elif r < 2800: c_count[color[6]] += 1
    elif r < 3200: c_count[color[7]] += 1
    else:          count_over += 1
     
dif_c_count = 0
for v in c_count.values():
    if v != 0: dif_c_count += 1 

mini, maxi = dif_c_count if dif_c_count != 0 else 1, dif_c_count + count_over
print(mini, maxi)

Measured memory_bytes: 3064
line_1= input().split(' ')
a= int(line_1[0])
b= int(line_1[1])
c= int(line_1[2])
k= int(line_1[3])

if k<=a:
  print(k)
elif k<=a+b:
  print(a)
else:
  print(a-(k-a-b))

Measured memory_bytes: 9120