akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  Nikkei09Qual
//
//  Created by 原大曜 on 2019/01/27.
//  Copyright © 2019年 原大曜. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

void probA()
{
    int N,A,B;
    cin >> N >> A >> B;
    cout << std::min(A,B) << " " << std::max(0,(A + B - N)) << endl;
}

void probB()
{
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    int sum = 0;
    for(int i=0;i<N;i++)
    {
        if(A[i]==B[i] && B[i]==C[i])
        {
            
        }
        else if(A[i] == B[i] && B[i] != C[i])
        {
            sum += 1;
        }
        else if(A[i] != B[i] && B[i] == C[i])
        {
            sum+=1;
        }
        else if(A[i] != B[i] && A[i] == C[i])
        {
            sum+=1;
        }
        else
        {
            sum+=2;
        }
    }
    cout << sum << endl;
    
}

int main(int argc, const char * argv[]) {
    probB();
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
#include <atcoder/fenwicktree>
using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a / gcd(a, b) * b;}
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    fenwick_tree<ll> d(n);
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        d.add(i, a);
    }
    while(q--){
        int t, a, b; cin >> t >> a >> b;
        if(t){
            cout << d.sum(a, b) << endl;
        }
        else{
            d.add(a, b);
        }
    }
} 


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int n;
vec<int> v;

bool bin(int key) {
   int left = 0, right = n;
   while (left <= right) {
      int mid = (left + right) / 2;
      // printf("(%d, %d, %d)\n", left, right, mid);
      if (key < v[mid]) {
         right = mid - 1;
      } else if (key > v[mid]) {
         left = mid + 1;
      } else {
         return true;
      }
   }
   return false;
}

int main() {
   cin >> n;
   rep (i, 0, n) {
      int x;
      cin >> x;
      v.push_back(x);
   }
   sort(all(v));

   int q;
   cin >> q;
   int cnt = 0;
   rep (i, 0, q) {
      int x;
      cin >> x;
      if (bin(x)) cnt++;
   }
   cout << cnt << endl;

   return 0;
}


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

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

    target_i = None
    for i in range(1, N):
        if P[i-1] > P[i]:
            target = P[i-1]
            target_i = i-1
            if i-2 >= 0:
                low = P[i-2]
            else:
                low = None
            high = P[i]
            break
    
    # low超え high未満で、入れ替え可能な数字を探す
    if target_i is not None:
        for i in range(target_i+2, N):
            if P[i] < high:
                if low is None:
                    P[target_i] = P[i]
                    P[i] = target
                    break
                else:
                    if low < P[i]:
                        P[target_i] = P[i]
                        P[i] = target
                        break
                    else:
                        continue
    
    # 昇順か確認
    for i in range(N):
        if P[i] != i+1:
            print("NO")
            return
    print("YES")




if __name__ == "__main__":
    solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int num; cin>>num;
  if(num>81){
    cout<<"No"<<endl;
  }
  else {
    for(int i=1;i<=9;i++){
      if(num%i==0){
        if(num/i<=9) {
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
    cout<<"No";
  }
  return 0;
}

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

using namespace std;

struct node{

	long long int a,b;

};

bool cmp(node e,node f)

{

	if(e.a!=f.a)

	return e.a<f.a;

	else

	return e.b>f.b;

}

int main(){

long long int n,m,y=0;

cin>>n>>m;

node d[n+1];

for(int i=1;i<=n;i++)

cin>>d[i].a>>d[i].b;

sort(d+1,d+n+1,cmp);

for(int i=1;i<=n;i++){

	if(d[i].b<m)

	{

		y+=d[i].a*d[i].b;

		m-=d[i].b;

	}

	else

	{

		y+=d[i].a*m;

		break;

	}

}

cout<<y;

}



Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc116/submissions/14852322 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] t = new int[n];
			long[] d = new long[n];
			IntStream.range(0, n).forEach(i -> {
				t[i] = scanner.nextInt();
				d[i] = scanner.nextLong();
			});
			// indexをd[i]でソートする
			int[] sortedIndexes = IntStream.range(0, n).boxed().sorted((i1, i2) -> Long.compare(d[i2], d[i1]))
					.mapToInt(Integer::intValue).toArray();
			// 選択されたtを保存するセット
			Set<Integer> tSet = new HashSet<>();
			Stack<Long> extraDs = new Stack<>();
			long sum = IntStream.range(0, k).map(i -> sortedIndexes[i]).mapToLong(index -> {
				if (tSet.contains(t[index])) {
					extraDs.add(d[index]);
				} else {
					tSet.add(t[index]);
				}
				return d[index];
			}).sum();
			long max = sum + tSet.size() * (long) tSet.size();
			for (int i = k; i < n; i++) {
				int index = sortedIndexes[i];
				if (!extraDs.isEmpty() && !tSet.contains(t[index])) {
					sum += d[index] - extraDs.pop();
					tSet.add(t[index]);
					max = Math.max(max, sum + tSet.size() * (long) tSet.size());
				}
			}
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 63728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  map<ll,ll> mp;
  ll count = 0;
  for(int i = 0;i < n;i++){
    ll k = 0;
    cin >> k;
    for(int j = 0;j < k;j++){
      ll in = 0;
      cin >> in;
      mp[in]++;
    }
  }
  for(auto i:mp){
    if(i.second == n)count++;
  }
  cout << count << endl;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n],b[n],c[n], maximum[n][3] = {0};
    for(int i=0; i<n; ++i)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    maximum[0][0] = a[0];
    maximum[0][1] = b[0];
    maximum[0][2] = c[0];
    for(int i=1; i<n; ++i)
    {
        maximum[i][0] = max(maximum[i-1][1] + a[i], a[i] + maximum[i-1][2]);
        maximum[i][1] = max(maximum[i-1][0] + b[i], b[i] + maximum[i-1][2]);
        maximum[i][2] = max(maximum[i-1][1] + c[i], c[i] + maximum[i-1][0]);
    }
    cout<<max({maximum[n-1][0], maximum[n-1][1], maximum[n-1][2]});
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    private static final int NINE＿VAL = 9;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final String indexStr = sc.next();
        String[] Array = indexStr.split("");
        int iTotalVal = 0;
        for (String i : Array) {
            iTotalVal += Integer.parseInt(i);
        }

        String outputVal = "";
        // 入力された文字の総数が9の倍数か？
        if (0 == (iTotalVal % NINE＿VAL)) {
            outputVal = "Yes";
        } else {
            outputVal = "No";
        }
        System.out.print(outputVal);
    }
}


Measured memory_bytes: 54540
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
r, c, dr, dc = 0, 0, 0, 1
ret = []
for i in range(h * w - 1):
    if not (0 <= r + dr < h and 0 <= c + dc < w and a[r + dr][c + dc] >= 0):
        dr, dc = dc, -dr
    if a[r][c] % 2 != 0:
        ret.append((r, c, r + dr, c + dc))
        a[r + dr][c + dc] += 1
    a[r][c] = -1
    r, c = r + dr, c + dc
print(len(ret))
for r1, c1, r2, c2 in ret:
    print(r1 + 1, c1 + 1, r2 + 1, c2 + 1)

Measured memory_bytes: 75228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n;
cin >> n;

vi b(n);
rep(i,n) cin >> b[i];

int sum = 0;
rep(i,n) {
    sum ^=b[i];
}
sum ^= 0;


rep(i,n) {
    int a = sum ^ b[i];
    cout << a << endl;
}

return 0;
}

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

#define N 2000000
#define MAX 10000

int main(){
  int k,i,j,C[MAX+1];
  unsigned short  *A,*B;
  
  scanf("%d",&k);

  A = malloc(sizeof(short)*k+1);
  B = malloc(sizeof(short)*k+1);

  for(i = 0; i <= MAX; i++){
    C[i] = 0;
  }

  for(i = 1; i <= k; i++){
    scanf("%d",&A[i]);
    C[A[i]]++;
  }
  
  
  for(i = 1; i <= MAX; i++){
    C[i] += C[i-1];
  }

  for(j = k; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i = 1; i <= k; i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 8460
def main():
    s = input()
    n = len(s)

    if n == 2:
        if s[0] == s[1]:
            print(1, 2)
        else:
            print(-1, -1)
        exit()

    for i in range(n - 2):
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            exit()
        elif s[i] == s[i + 2]:
            print(i + 1, i + 3)
            exit()
    print(-1, -1)

main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define vinn(n,v) int n;cin>>n;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define vinm(n,m,v) int n,m;cin>>n>>m;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define debug(x) cerr<<#x<<" : "<<x<<endl;
mt19937 rd(time(0)); // i = rd%n
struct compare 
{
  bool operator()(const int& l, const int& r) 
  {
      return l > r; //min: > ; max: <
  }
};
 
signed main() 
{
    fastio();
    int n,m;
    cin>>n;
    m = n-1;
    int ans= 1;
    map<int,int>mp;
    for(int i = 2;i*i<=m;i++)
    {
        if(m%i==0)
        {
            while(m%i==0)
                mp[i]++,m/=i;
        }
    }
    if(m>1)
        mp[m]++;
    for(auto i:mp)
    {
        ans*=(i.second+1);
    }
    // cout<<ans<<endl;
    for(int i = 2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            int temp = n;
            while(temp%i==0 )
                temp/=i;
            if(temp%i==1)
                ans++;
            if(i*i!=n)
            {
                int temp = n;
                while(temp%(n/i)==0)
                    temp/=(n/i);
                if(temp%(n/i)==1)
                    ans++;

            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
//---Vaidik Patel"---//-------------------Proud to be Indian--------------------------------//
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set,multi multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define pii pair<int,int>
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order()
#define deb1(x) cout<<#x<<" : "<<x<<"\n";
#define deb2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<"\n";
#define deb4(x,y,z,w) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<"\t"<<#w<<" : "<<w<<endl;
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rFOR(i,a,b) for(int i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vvi vector<vector<int>>
#define M 1000000007
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int powermodm(int x,int n,int m)
{int ans=1;   while(n){if(n&1){ans=(ans*x)%m;}x=(x*x)%m;n=n>>1;}return ans;}
void solve()
{
    int n;
    cin>>n;
    vi arr(10005);
    int temp;
    FOR(i,1,101)
    {
        FOR(j,1,101)
        {
            FOR(k,1,101)
            {
                temp=i*i+j*j+k*k+i*j+j*k+k*i;
                if(temp<=10000)
                {
                    arr[temp]++;
                }

            }
        }
    }
    FOR(i,1,n+1)
    {
        cout<<arr[i]<<"\n";
    }



}
signed main()
{
    #ifndef ONLINE_JUDGE
   
    #endif
    FIO
    int t;
    t=1;
    //cin>>t;
    FOR(i,0,t)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}


Measured memory_bytes: 3684
#include<iostream>
#include<string>

using namespace std;

int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H') {
		if (b == 'H') {
			cout << "H" << endl;
		}
		else {
			cout << "D" << endl;
		}
	}
	else {
		if (b == 'H') {
			cout << "D" << endl;
		}
		else {
			cout << "H" << endl;
		}
	}

	return 0;
}

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

typedef long long ll;

int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    rep(i, N) cin >> T[i];
    sort(T.begin(), T.end());
    int l = 0, ans = 0;
    rep(r, N) {
        if (T[r] > T[l] + K) {
            l = r;
            ans++;
            //cout << "(1)" << r << endl;
        } else if (r - l == C - 1) {
            l = r + 1;
            ans++;
            //cout << "(2)" << r << endl;
            continue;
        }
        if (r == N - 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
	int k, x, s, e;
	int min = -1000000, max = 1000000;
	
	cin >> k >> x;
	
	s = x - k + 1;
	if(s < min) s = min;
	
	e = x + k - 1;
	if(e > max) e = max;
	
	for(int i = s; i < e; i++){
		cout << i << " ";
	}
	cout << e << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;

namespace A___Changing_a_Character
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var k = int.Parse (input[1]);
            var s = Console.ReadLine ();
            var a = "";
            for (var i = 0; i < s.Length; i++)
            {
                if (i == k - 1)
                {
                    a += Char.ToLower (s[i]);
                }
                else
                {
                    a += s[i];
                }
            }
            Console.WriteLine (a);
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){
  int a,b,C;

  double S,L,h;

  cin >> a >> b >> C;

  double d = C * M_PI /180.0;

  h = b * sin(d);

  double c;
  c = sqrt(a*a+b*b-2*a*b*cos(d));
  L=a+b+c;

  S=a*h/2.0;

  cout << fixed << setprecision(5) << S << endl << fixed << setprecision(5) << L << endl << fixed << setprecision(5) << h << endl;
}

Measured memory_bytes: 3516
X,K,D = map(int,input().split())
ans = 0
if X<0:
  X = (-1)*X
  
if X-K*D >=0:
  ans = X-K*D
else:
  Y = int(X/D)
  Z = X%D
  if (K-Y)%2==0:
    ans = Z
  if (K-Y)%2==1:
    ans = D-Z
print(ans)

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

const int MOD = 998244353;

const int LIMIT_SQ = 1000 * 1000 * 1000;
const LL LIMIT = (LL) LIMIT_SQ * LIMIT_SQ;

void solve_test() {
	int n;
	cin >> n;
	vector<LL> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	bool has_zero = false;
	for (int i = 0; i < n; i++) if (a[i] == 0) has_zero = true;
	if (has_zero) {
		cout << "0\n";
		return;
	}

	LL prod = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] > LIMIT / prod) {
			cout << "-1\n";
			return;
		}
		prod *= a[i];
	}
	cout << prod << '\n';
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


Measured memory_bytes: 4028
#include <string>
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
// ll mod=1000000007;
 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,k,temp,temp2,n,m,x,y,sum=0;
    cin >> t;
    string s = to_string(t);
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout << "Yes";
    else cout << "No";
}

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

int main() {
  int n,k;cin>>n>>k;
  vector<int> A(200009,0); //A[i]はiが書かれたボールの数
  for(int i=0;i<n;++i){
    int a;cin>>a;
    A[a]++;
  }
  
  vector<int> B(200009,0); //B[i]はi個のボールをもつ整数の種類数
  int num=0; //numはすべてのボールに書かれた整数の種類数
  for(int i=0;i<200009;++i){
    if(A[i]==0) continue;
    num++;
    B[A[i]]++;
  }
  
  int ans=0;
  if(num>k){
    int hoge=1;
    for(int i=0;i<num-k;++i){
      while(B[hoge]==0) hoge++;
      ans+=hoge;
      B[hoge]--;
    }
  }
  
  cout<<ans<<endl;      
}

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

using namespace std;

int digitsSum(int n){//99999までの数値nの各位の和
    int k = n/100000;
    n = n % 100000;
    int a = n/10000;
    n = n % 10000;
    int b = n/1000;
    n = n % 1000;
    int c = n / 100;
    n = n % 100;
    int d = n / 10;
    n = n % 10;
    return(k + a + b + c + d + n);
}

int main(){
    int N;
    scanf("%d", &N);
    int res = digitsSum(1) + digitsSum(N - 1);
    for(int i = 2; i < N; i++){
        int a = digitsSum(i) + digitsSum(N - i);
        if(a < res){
            res = a;
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
P=[int(i)-1 for i in input().split()]
a=[0 for i in range(M)]
b=[0 for i in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1;b[i]-=1
par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
def init(n):
    for i in range(N):
        par[i]=i
        rnk[i]=0
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:
        return
    if (rnk[x]<rnk[y]):
        par[x]=y
    else:
        par[y]=x
        if(rnk[x]==rnk[y]):
            rnk[x]+=1
def same(x,y):
    return find(x)==find(y)
init(N)
for i in range(M):
    unite(a[i],b[i])
ans=0
for i in range(N):
    if same(i,P[i]):
        ans+=1
print(ans)


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

int main() {
	string s;
    cin >> s;
    int a=0;
    for(int i=0;i<s.size();i++){
      for(int j=i+1;j<s.size();j++){
      	if(s.at(i)==s.at(j)){
        	a++;
        	break;
      	}
      }
    }
    if(a==0){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
long long b[200001];
int main(void){
	int N;
	scanf("%d",&N);
	long long a[N+1];
	int i;
	b[0]=0;
	for(i=1;i<=N;i++){
		scanf("%lld",&a[i]);
		b[i] = b[i-1]+a[i];
	}
	long long x = b[1];
	long long y = b[N]-b[1];
	long long min = labs(x-y);
	for(i=1;i<N;i++){
		 x = b[i];
		 y = b[N]-b[i];
		if(min>labs(x-y)){
			min = labs(x-y);
		}
	}
	printf("%lld",min);
	return 0;
}

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

template <typename Func, typename Num>
Num integral(Func f, Num begin, Num end, Num d) {
	Num ret = 0;
	for (Num n = begin; n < end; n += d) {
		ret += f(n) * d;
	}
	return ret;
}

int main() {
	int n;
	std::vector<int> ans;
	
	while (std::cin >> n) {
		const int a = integral([](int x){return x*x;}, 0, 600, n);
		ans.push_back(a);
	}
	
	for (auto a : ans) {
		std::cout << a << std::endl;
	}
}

Measured memory_bytes: 1212
x, y = list(map(int, input().split(" ")))

group_list = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]

finished = False
for gl in group_list:
    if (x in gl) and (y in gl):
        print("Yes")
        finished = True
if finished != True:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int D[100001] = {};
	rep(i, N) (*(D + getint()))++;
	int S = 0;
	int kotae = 0;
	for (int i = 100000; i > 0; i--) {
		S += *(D + i);
		if (S >= N / 2) {
			if (S == N / 2) {
				i--;
				kotae++;
				while (!D[i]) {
					kotae++;
					i--;
				}
			}
			break;
		}
	}
	co(kotae);

	Would you please return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int i = N / 111;
  if (N % 111 != 0) ++i;
  
  cout << i * 111 << endl;
   
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a,b;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	if(n==1&&a!=b){
		cout<<0;
	}
	else if(a>b){
		cout<<0;
	}
	else
		cout<<(n-1)*b+a-((n-1)*a+b)+1;
	return 0;
}

Measured memory_bytes: 3572
N = int(input())
Ts = input().split()
Ts = [int(i) for i in Ts]
Tsum = sum(Ts)
M = int(input())
res_list = []
for i in range(M):
    P,X = map(int,input().split())
    res = Tsum - Ts[P-1] + X
    print(res)

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

using namespace std;
typedef long long ll;

int N,K;

int main(){
    cin >> N >> K;
    if(K > (N-1)*(N-2)/2){
        cout << -1 << endl;
        return 0;
    }
    ll c = (N-1)*(N-2)/2 - K;
    cout << N-1 + c << endl;
    for(int i=2;i<=N;i++) cout << 1 << " " << i << endl;
    for(int i=2;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            if(c == 0) break;
            cout << i << " " << j << endl;
            c--;
        }
        if(c == 0) break;
    }
    return 0;
}

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-19.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int H, W;
vector <string> S;

int main() {
    cin >> H >> W;
    S.resize(H);
    for (int i = 0; i < H; ++i) cin >> S[i];

    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (S[i][j] == '#') continue;
            vector <vector<int>> distance(H, vector<int>(W, INF));
            vector <vector<int>> used(H, vector<int>(W, 0));
            queue <i_i> que;
            distance[i][j] = 0;
            used[i][j] = 1;
            que.push(make_pair(i, j));
            while (!que.empty()) {
                auto p = que.front();
                que.pop();
                int x = p.first, y = p.second;
                //cout << "(x,y): " << x << " " << y << endl;
                if (0 <= x - 1 && !used[x - 1][y] && S[x - 1][y] == '.') {
                    chmin(distance[x-1][y], distance[x][y] + 1);
                    que.push(make_pair(x - 1, y));
                    used[x - 1][y] = 1;
                }
                if (0 <= y - 1 && !used[x][y - 1] && S[x][y - 1] == '.') {
                    chmin(distance[x][y-1], distance[x][y] + 1);
                    que.push(make_pair(x, y - 1));
                    used[x][y-1] = 1;
                }
                if (x + 1 < H && !used[x + 1][y] && S[x + 1][y] == '.') {
                    chmin(distance[x+1][y], distance[x][y] + 1);
                    que.push(make_pair(x + 1, y));
                    used[x+1][y] = 1;
                }
                if (y + 1 < W && !used[x][y + 1] && S[x][y + 1] == '.') {
                    chmin(distance[x][y+1], distance[x][y] + 1);
                    que.push(make_pair(x, y + 1));
                    used[x][y+1] = 1;
                }
            }
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    //cout << distance[i][j] << " ";
                    if (used[i][j]) chmax(ans, distance[i][j]);
                }
                //cout << endl;
            }
            //cout << "--------------------" << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)



bool isPrime(int n) {
	if(n == 1) {
		return 0;
	}
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) {
			return 0;
		}
	}
	return 1;
}

void solve() {

	int n;
	cin >> n;
	while(!isPrime(n)) {
		n++;
	}
	cout << n << "\n";
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int x;
	cin >> x;
	cout << 10 - x / 200 << endl;
}


Measured memory_bytes: 3624
def solve():
    N, K = map(int,input().split())
    ans = 0
    for b in range(1,N+1):
        ans += max(0,(N//b) * (b-K)) 
        ans += max(0, N%b - K+1)
    
    if K == 0:
        ans -= N
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 39280
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int cnt = 0;
        int x = 0;
        for(int i = 2;i*i < n; i++){
            if(n % i == 0){
                cnt += i;
                x = n/i;
                cnt += x;
            }
        }
        cnt++;
        if(n == 1)printf("deficient number\n");
        else if(n == cnt)printf("perfect number\n");
        else if(n > cnt)printf("deficient number\n");
        else printf("abundant number\n");
    }
    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	ll ans = 0;
	// cを何枚食えるか。
	ans += min(c, a+b+1);
	ans += b ;
	cout << ans << endl;
}


Measured memory_bytes: 3652
import numpy as np
import itertools as it

N,M,X = map(int,input().split())

CA = []

for i in range(N):
    CA.append( list(map(int, input().split())))

CA = np.array(CA)

def choice(N):
    ch = []
    for k in range(1,N+1):
        ch.append(list(it.combinations(range(N),k)))
    return list(it.chain.from_iterable( ch ))

ch = choice(N)
ans = 10**10

for c in ch:
    und = np.array( list(map( lambda i : sum(CA[c,i]), range(1,M+1))) )
    cost = sum(CA[c,0])
    if set( und >= X) == {True} and cost < ans:
        ans = cost

if ans == 10**10:
    ans = -1
    
print(ans)

Measured memory_bytes: 27752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,x;
    cin >> n >> x;
    int num[n],cum[n+1]={0};
    rep(i,n){
        cin >> num[i];
    }
    sort(num,num+n);
    rep1(i,n){
        cum[i] = cum[i-1] + num[i-1];
    }
    int ans = n;
    rep(i,n+1){
        if(i == n){
            if(x != cum[n]){ ans--;}
            break;
        }
        if(cum[i] <= x && x < cum[i+1]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>

const int group[13] = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

int main(void) {
	int x, y;

	scanf("%d %d", &x, &y);

	puts(group[x] == group[y] ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
ll a[100005];
int n;
int check(ll x)
{
	ll now=x;
	for(int i=1;i<=n;i++)
	{
		now=(now/a[i])*a[i];
	}
	if(now==2) return 1;
	else if(now>2) return 2;
	return 0;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	ll l=1,r=9000000000000000000LL,ans=-1;
	//cout<<r<<endl;
	while(l<=r)
	{
		//cout<<l<<" "<<r;
		ll mid=(l+r)/2LL;
		//cout<<mid<<" "; 
		if(check(mid))
		{
			if(check(mid)==1)
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	if(ans==-1)
	{
		puts("-1");
		return 0;
	}
	else cout<<ans<<" ";
	l=1,r=9000000000000000000LL;
	while(l<=r)
	{
		ll mid=(l+r)/2LL;
		if(check(mid)==2) r=mid-1;
		else if(check(mid)==1)
		{
			ans=mid;
			l=mid+1;
		}
		else l=mid+1;
	}
	cout<<ans;
}


Measured memory_bytes: 1024
import sys
import copy

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    n = ni()
    ws = sall()
    ws = [w.rstrip() for w in ws]

    o = ws[0]
    s = set()
    s.add(o)
    for w in ws[1:]:
        if o[-1] != w[0] or w in s:
            print('No')
            return

        s.add(copy.copy(w))
        o = copy.copy(w)

    print('Yes')

main()


Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e7+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }
  


int n,spf[N];

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<N; i++)       
        spf[i] = i; 
 
    for (int i=4; i<N; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<N; i++)
     {        
        if (spf[i] == i) 
        {           
            for (int j=i*i; j<N; j+=i)  
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

int  get(int x) 
{ 
   int ct=1,p=1;
    while (x != 1) 
    {   int nx=spf[x],c=0;
		while(x%nx==0) {
			  x/=nx;
			  c++;
			}
		if(c>0) p*=(c+1); 
         
    }
     
    return p; 
} 
 

//~ int cal(int x) {
	   //~ int ct=0;
	   //~ for(int i=1;i*i<=x;i++) {
		     //~ if(x%i==0) {
				   //~ ct++;
				   //~ if(i != (x/i)) ct++;				   
				 //~ }
		   //~ }
	    //~ return ct;
	    
	//~ }

void solve() {
     cin>>n;
     
     int sm=0,ct=0;
    
    
     rep1(i,1,n) {
		    int x=get(i);
		    //~ cout<<i<<" "<<x+1<<endl;
		    ct+=x;
		    sm+=x*i;
		 } 
		 //~ cout<<sm<<endl;
		 //~ cout<<ct<<endl;
		 cout<<sm<<endl;  
   					   
 }

    
int32_t main() {
	cool;
	int t=1;
	sieve();

	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<pii> ab(n);
  REP(i,n)cin >> ab[i].first >> ab[i].second;
  sort(ALL(ab));
  int64 ans = 0;
  REP(i,n){
    int64 x = min(ab[i].second, m);
    ans += x * ab[i].first;
    m -= x;
    if(m == 0)break;
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  atcoder
//
//  Created by Jonathan Bramley on 6/2/19.
//  Copyright © 2019 Jonathan Bramley. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    string s; cin >>s;
    int n = s.size();
    long long a = 0, cnt=0;
    for(int i = 0; i < n-1;i++) {
        if(s[i] == 'A') a++;
        else if(s[i] == 'B') {
            if(s[i+1]== 'C') {
                cnt+=a;
                i++;
            } else {
                a=0;
            }
        } else {
            a=0;
        }
    }
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
#define mod 1000000007
using namespace std;
int main()
{ 
   ll  int n,x,t;
   cin>>n>>x>>t;
   ll int d=n/x;
   if (n%x!=0)
   d++;
   ll int ans=0;
   ans+=d*t;
   cout<<ans<<endl;
   
}
   



	
		
	
	
	
	



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const int MAXN = 1e5 + 10;
vi svakiDan[MAXN];

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

    for(int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        if(m - a >= 0)
        {
            svakiDan[m-a].pb(b);
        }
    }

    int resenje = 0;

    priority_queue<int> pq;

    for(int i = m; i >= 0; --i)
    {
        for(int j = 0; j < (int)svakiDan[i].size(); ++j)
        {
            pq.push(svakiDan[i][j]);
        }

        if(!pq.empty())
        {
            resenje += pq.top();
            pq.pop();
        }
    }

    cout << resenje << '\n';

    return 0;
}


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

int main() {
    int n,Alice=0,Bob=0;
    bool AB = true;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    for(int i = 0; i < n; i++){
        int max = 0;
        int max_i = 0;
        for(int i = 0; i < n; i++){
            if(max < a.at(i)){
                max = a.at(i);
                max_i = i;
            }
        }
        a.at(max_i) = 0;
        if(AB){
            Alice += max;
            AB = false;
        }else{
            Bob += max;
            AB = true;
        }
    }
    cout << abs(Alice - Bob) << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<char, ll>map;

	string m = "MARCH";
	int n;
	cin >> n;
	rep(i, 0, n) {
		string c;
		cin >> c;
		map[c[0]]++;
	}
	ll ans = 0;

	rep(i, 0, 5) {
		rep(j, i + 1, 5) {
			rep(q, j + 1, 5) {
				ans += map[m[i]] * map[m[j]] * map[m[q]];
			}
		}
	}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        String ans = "YES";
        for (int i = 1; i <= N; i++) {
            int a = in.nextInt();
            if (i != a) {
                count++;
            }
            if (count > 2) {
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 25172
//itp1_topic9_B
#include <iostream>
#include <string>
using namespace std;

int main(){
  string r;
  int i,m,h;
  cin>>r;
  while(r!="-"){
    cin>>m;

    for(i=0;i<m;i++){
         cin>>h;
	 string t1=r.substr(h,(int)r.size());
	 string t2=r.substr(0,h);
	 t1+=t2;
	 r=t1;
	 /* cout<<r<<endl;*/
    }
    cout<<r<<endl;
    cin>>r;
  }

  return 0;
}



Measured memory_bytes: 3180
import random

b = input()


def ans_1():
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    else:
        print("C")


def ans_2():
    Dic = {"A": "T", "T": "A", "C": "G", "G": "C"}
    print(Dic[b])


def ans_3():
    keys = ["A", "T", "C", "G"]
    values = keys[:]
    values[0], values[1] = values[1], values[0]
    values[2], values[3] = values[3], values[2]

    Dic = dict(zip(keys, values))
    print(Dic[b])


def get_key_from_value(d, val):
    keys = [k for k, v in d.items() if v == val]
    if keys:
        return keys[0]
    return None


def ans_4():
    Dic = {"A": "T", "C": "G"}
    if get_key_from_value(Dic, b):
        print(get_key_from_value(Dic, b))
    else:
        print(Dic[b])


method = random.randrange(4)
if method == 0:
    ans_1()
elif method == 1:
    ans_2()
elif method == 2:
    ans_3()
else:
    ans_4()

Measured memory_bytes: 4464
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


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

	if (A > B) {
		if (A > C && B < C) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (A < C && B > C) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (106)
ll n,m,grid[MAXN][MAXN],A[MAXN][MAXN],B[MAXN][MAXN];
vector<pi> v[MAXN];
int match[MAXN];//match[i]=index of edge from i
ll paired[MAXN];
bitset<MAXN>vis;
void bp() {
	mmst(match,-1);mmst(paired,-1);
	function<ll(ll)>dfs=[&](ll x){
		if(vis[x])return 0;
		vis[x]=1;
		ll co=0;
		for(auto i:v[x]){
			if(paired[i.f]==-1 || dfs(paired[i.f])){
				paired[i.f]=x;
				match[x]=co;
				return 1;
			}
			++ co;
		}
		return 0;
	};
	FOR(i,0,n-1)if(match[i]==-1)vis.reset(),dfs(i);
}
int main(){
	FAST
	cin>>n>>m;
	auto which_row=[&](ll x){
		return x/m;
	};
	FOR(i,0,n-1)FOR(j,0,m-1)cin>>grid[i][j],--grid[i][j];
	FOR(i,0,n-1)FOR(j,0,m-1){ll k=which_row(grid[i][j]);v[i].eb(k,grid[i][j]);}
	FOR(j,0,m-1){
		bp();
		FOR(i,0,n-1){
			assert(match[i]!=-1&&siz(v[i])>match[i]);
			A[i][j]=v[i][match[i]].s;
			v[i].erase(v[i].begin()+match[i]);
		}
	}
	FOR(i,0,n-1)assert(v[i].empty());
	FOR(i,0,n-1)FOR(j,0,m-1)cout<<A[i][j]+1<<" \n"[j==m-1];
	FOR(j,0,m-1){
		set<int>s;
		FOR(i,0,n-1)s.ins(which_row(A[i][j]));
		assert(s.size()==n);
	}
	FOR(j,0,m-1){
		FOR(i,0,n-1){
			B[which_row(A[i][j])][j]=A[i][j];
		}
	}
	FOR(i,0,n-1)FOR(j,0,m-1)cout<<B[i][j]+1<<" \n"[j==m-1];
}


Measured memory_bytes: 816
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
const ll MOD = 1000000007;

int main() {
   int n; scanf("%d", &n);
   char s[n]; scanf("%s", &s);
   int ans = 1;
   for (int i = 0; i < n - 1; ++i)
      if (s[i] != s[i + 1]) ++ans;
   printf("%d", ans);
   return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = l[0], B = l[1];

        for (var i = 1; i < 10000; i++)
        {
            if (Math.Floor(i * 0.08) == A && Math.Floor(i * 0.1) == B)
            {
                Console.WriteLine(i);
                return;
            }
        }

        Console.WriteLine(-1);
    }
}


Measured memory_bytes: 13396