akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int total = 0;
    
    for(int i = 1; i <= n; i++){
      int sum = 0;
      int j = 0;
      j = i;
      // 整数の桁の合計を求める
      while (j != 0) {
        sum += j % 10;
        j /= 10;
      }
      if(sum >= a && sum <= b){
        total += i;
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 23380
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		List<Long> list = new ArrayList<>();

		for(int i = 0; i < n; i++) {
			list.add(sc.nextLong());
		}

		Long total = 0L;
		for(long a : list) {
			total += a;
		}

		Long half = total / 2;

		Long left = 0L;
		for(Long a : list) {
			if(left == half) {
				break;
			}
			if(left + a > half) {
				if(left > total - left - a || left + a == total) {
					break;
				}
			}
			left += a;
		}

		Long right = total - left;

		Long diff = Math.abs(left - right);


		System.out.println(diff);

		sc.close();
	}


}


Measured memory_bytes: 98412
#include<algorithm>
#include <iostream>
#include<cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll INF=10000000000000000;
int n,m;
ll g[105][105];
int main(){
   cin>>n>>m;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j){
                    g[i][j]=0;
                }else{
                    g[i][j]=INF;
                }
            }
        }
        ll s,t,w;
        for(int i=0;i<m;i++){
            cin>>s>>t>>w;
            g[s][t]=min(g[s][t],w);
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(g[i][k]!=INF&&g[k][j]!=INF)
                    g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
                }
            }
        }
    int flag=0;
    for(int i=0;i<n;i++){
        if(g[i][i]<0){
            flag=1;
        }
    }
    if(flag){
        printf("NEGATIVE CYCLE\n");
    }else{
        for(int i=0;i< n;i++){
            for(int j=0;j<n;j++){
                if(j==0){
                     if(g[i][j]==INF){
                        printf("INF");
                    }else{
                        printf("%lld",g[i][j]);
                    }
                }else{
                    if(g[i][j]==INF){
                        printf(" INF");
                    }else{
                        printf(" %lld",g[i][j]);
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 3276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {
			var inputArray = retreiveStringArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var S = inputArray[0];

			//答えの出力
			var ans = getAns(S);
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string getAns(string S) {

			if(S[2] == S[3] && S[4] == S[5]) {
				return "Yes";
			}

			return "No";
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define INF 0x3f3f3f
#define PB push_back
#define F first
#define S second
#define FOR(i,k) for(int i=0; i<k; i++)
#define RFOR(i,k) for(int i=k; i>=0; i--)
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#define DEBUGV(x) cout<<#x<<": "; for(auto &d:x) cout<<d<<" "; cout<<endl
#define DEBUGM(x) for(auto &p:x) cout<<p.F<<":"<<p.S<<" "; cout<<endl;
#define OUT(x) cout<<(x)<<endl

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<char,int> MC;
typedef map<int,int> MI;
typedef map<string,int> MS;

template<typename T, typename U> void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if(x < y) x = y; }
VPII neighbors = {{0,1}, {1,0}, {0,-1}, {-1,0}};
PII operator+(PII &l, PII &r) { return {l.F+r.F, l.S+r.S}; }
bool IsValid(PII p, int Y, int X) { 
  return p.F >=0 && p.F < Y && p.S >=0 && p.S < X; }
bool IsPrime(int n) {
  if (n <= 1)  return false;
  if (n <= 3)  return true;
  if (n%2 == 0 || n%3 == 0) return false;
  for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
      return false;
  return true;
}

int main() {
  string s;
  cin>>s;
  MC m;
  for(auto c : s) {
    m[c]++;
  }
  if(m.size() == 3)
    OUT("Yes");
  else
    OUT("No");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int T = sc.nextInt();
		int max = sc.nextInt();
		for (int i=1; i<T; i++) {
			int a = sc.nextInt();
			if (a>max) max = a;
		}
		//
		int remain = K-max;
		if (max-remain>0) System.out.println(max-remain-1);
		else System.out.println(0);
		sc.close();
	}
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	ll t=(a+b-1)/2;
	if((b-a)%2==0) cout << (b-a)/2 << endl;
	else cout << min(t, n-t) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  
  cin >> a >> b;
  
  if(a>=13){
    cout << b << endl;
  }else if(a<6){
    cout << "0" << endl;
  }else{
    cout << b/2 << endl;}
  return 0;
    
}

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

int main() {
    int q, x;
    char com[20];
    list<int> v;
    scanf("%d", &q);
    for ( int i = 0; i< q; i++) {
        scanf("%s", com);
        if (com[0] == 'i') {
            scanf("%d", &x);
            v.push_front(x);
        } else if (com[6] == 'F') {
            v.pop_front();
        } else if (com[6] == 'L') {
            v.pop_back();
        } else {
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++ ) {
                if ( *it == x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i = 0;
    for ( list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if(i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");
}



Measured memory_bytes: 33916
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

int main(void){
        int r;
        double R;

        scanf("%d", &r);
        R = r;
        printf("%f\n", R * 2 * 3.14159265);

	return 0;

       
}



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

int main() {
  using LL = long long;
  const LL M = 1000000007;

  int N;
  cin >> N;
  vector<string> node(N);
  for(auto& n: node) cin >> n;
  vector<vector<int>> child(N);
  for(int i = 1; i < N; ++i) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    child[s].push_back(t);
  }

  auto A = [&node](int n){return node[n][0] == 'A';};
  auto E = [&node](int n){return node[n][0] == 'E';};
  auto R = [&node](int n){return node[n][0] == 'R';};
  auto option = [&node](int n){return node[n].size() == 2;};
  function<LL(const vector<LL>&,int)> combination = [&](const vector<LL>& list, int n){
    if(n == list.size()) return 1ll;
    return (combination(list, n+1) + ((list[n]*combination(list, n+1))%M)) % M;
  };
  function<LL(int)> dfs = [&](int cur){
    vector<LL> part;
    for(auto nex: child[cur]) part.push_back(dfs(nex) + (option(nex) ? 1 : 0));
    if(E(cur)) return accumulate(begin(part), end(part), 1ll, [&](LL lhs, LL rhs){return (lhs * rhs) % M;});
    if(A(cur)) return accumulate(begin(part), end(part), 0ll, [&](LL lhs, LL rhs){return (lhs + rhs) % M;});
    if(R(cur)) return (combination(part, 0) + M - 1) % M;
  };
  cout << dfs(0) << endl;
}

Measured memory_bytes: 3368
def resolve():
    K = int(input())
    a = [0] * (K + 1)
    a[1] = 7 % K
    for i in range(2, K + 1):
        a[i] = (a[i - 1] * 10 + 7) % K
    for i in range(1, K + 1):
        if a[i] == 0:
            print(i)
            return
    print(-1)


resolve()


Measured memory_bytes: 48320
while 1:
	arr = list(map(int, input().split()))
	H = arr[0]
	W = arr[1]
	
	if H == 0 and W == 0:
		break

	line = ''
	for i in range(W):
		line += '#'
	
	for i in range(H):
		print(line)

	print('')



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

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

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int R = in.nextInt();
            if (N >= 10)
            {
                out.print(R);
            } else
            {
                out.print((100 * (10 - N)) + R);
            }
        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n){
      cin>>a[i];
  }
  so(a);
  ll ans=MOD;
  for(int i=a[0];i<=a[n-1];i++){
      ll sum=0;
      rep(j,n){
          sum+=(i-a[j])*(i-a[j]);
      }
      ans=min(sum,ans);
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

#define MAXD 15

int d;
ll g;
int p[MAXD];
int c[MAXD];
int perm[MAXD];
int result=0x7fffffff;
int ct;

int main(){
		cin>>d>>g;
		REP1(i,d)
		cin>>p[i]>>c[i];
		REP1(i,d)
		perm[i]=i;
		do{
			ll sc=0;
		
			REP1(i,d){
				int id=perm[i];
				int scOfQ= p[id]*id*100;
				if(scOfQ+sc<=g){
					ct+=p[id];
					sc+=scOfQ;
					if(sc+c[id]>=g) break;
					sc+=c[id];
				}else{
					int dSc=g-sc;
					int curSc=id*100;
					//cout<<"cur "<<curSc<<endl;
					if(!(dSc%curSc)){
						ct+=dSc/curSc;
					}else{
						ct+=dSc/curSc+1;
					}
					break;
				}
			}
			//cout<<ct<<endl;
			result=min(result,ct);
			ct=0;
		}while(next_permutation(perm+1,perm+1+d));
    cout<<result<<endl;
    return 0;

}


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

ans = 0
flag = 0

for i in range(a+1):
    tmp = x - i * 500
    if tmp < 0:
        break
    for j in range(b+1):
        tmp = x - i * 500
        tmp -= j * 100
        if tmp < 0:
            break
        elif tmp//50 <= c and tmp%50 == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
int main(){
    int X = 0;
    cin >> X;
    if (X >= 30)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	ll x;
	cin >> n >> x;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];

	ll b[n][n];
	for(int i=0; i<n; i++){
		b[i][0]=a[i];
		for(int j=0; j<n-1; j++){
			b[i][j+1]=min(b[i][j], a[(i-j-1+n)%n]);
		}
	}

	ll ans=20000*(ll)(1e9);
	for(int k=0; k<=n-1; k++){
		ll tmp=k*x;
		for(int j=0; j<n; j++){
			tmp+=b[j][k];
		}
		ans=min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#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){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x = 0, y = 0, T = 0;
    rep(i, n) {
        int t, a, b;
        cin >> t >> a >> b;
        if(abs(x - a) + abs(y - b) > t - T) {
            No();
            return 0;
        }else if(((abs(x - a) + abs(y - b)) & 1) ^ ((t - T) & 1)) {
            No();
            return 0;
        }else {
            T = t;
            x = a;
            y = b;
        }
    }
    Yes();
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<climits>
#include<vector>
#include <sstream>
#include<algorithm>
#include<array>
#include<map>

using namespace std;

int main(void) {

	int n;
	string in;

	cin >> n;

	vector<long long> sum(n+1);
	long long buf=0;

	for (int i = 1; i <= n;++i) {
		cin >> in;
		buf += stoll(in);
		sum[i] = buf;
	}

	sort(sum.begin(),sum.end());

	long long score=0,now,combo=0;
	now = sum[0];
	for (int i = 1;i <= n;++i) {
		if(now==sum[i]){
			combo++;
			score += combo;
		}
		else {
			now = sum[i];
			combo = 0;
		}
	}

	cout << score;
	return 0;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

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

  if(b%a == 0)
    cout << a+b << endl;
  else cout << b-a << endl;;
  
}

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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    ll MOD = 1e9 + 7;
    CIN(int, N);

    vector<vector<ll>> cnt(64, vector<ll>(N + 1, 0));
    // 0-15 => AA-TT

    for (int i = 0; i < 64; i++) {
        cnt[i][3] = 1;
    }
    cnt[0 * 16 + 2 * 4 + 1][3] = 0;
    cnt[0 * 16 + 1 * 4 + 2][3] = 0;
    cnt[2 * 16 + 0 * 4 + 1][3] = 0;


    for (int i = 4; i <= N; i++) {
        for (int j = 0; j < 64; j++) {
            ll temp = cnt[j][i - 1] % MOD;

            ll index0, index1;

            index0 = j % 16;
            index1 = j / 4;
            if ( index0 == 0 * 4 + 1 ) { // XAC- G
                cnt[(index0)*4 + 0][i] += temp;
                cnt[(index0)*4 + 1][i] += temp;
                // cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;

            } else if ( index0 == 0 * 4 + 2 ) { // XAG -C
                cnt[(index0)*4 + 0][i] += temp;
                // cnt[(index0)*4 + 1][i] += temp;
                cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;

            } else if ( index0 == 2 * 4 + 0 ) { // XGA -C
                cnt[(index0)*4 + 0][i] += temp;
                // cnt[(index0)*4 + 1][i] += temp;
                cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;

            } else if ( index1 == 0 * 4 + 2 ) { // AGX -C
                cnt[(index0)*4 + 0][i] += temp;
                // cnt[(index0)*4 + 1][i] += temp;
                cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;

            } else if ( j / 16 == 0 && j % 4 == 2 ) { // AXG -C
                cnt[(index0)*4 + 0][i] += temp;
                // cnt[(index0)*4 + 1][i] += temp;
                cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;

            } else {
                cnt[(index0)*4 + 0][i] += temp;
                cnt[(index0)*4 + 1][i] += temp;
                cnt[(index0)*4 + 2][i] += temp;
                cnt[(index0)*4 + 3][i] += temp;
            }
        }
    }

    ll ans = 0;
    // SHOW2(cnt);

    for (int i = 0; i < 64; i++) {
        ans = (ans + cnt[i][N]) % MOD;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<array>
#include<utility>
#include<set>
#include<algorithm>

using namespace std;

typedef array<int,9> Board;

struct S{
  int c;
  Board b;
  bool operator<(S s)const{
    return c>s.c;
  }
};

Board move(Board b,int f,int t){
  swap(b[f],b[t]);
  return b;
}

int main(){
  for(int ch,cv;cin>>ch>>cv,ch|cv;){
    Board start,goal;
    for(int i=0;i<9;i++){
      cin>>start[i];
    }
    for(int i=0;i<9;i++){
      cin>>goal[i];
    }
    priority_queue<S> que;
    que.push({0,start});
    set<Board> u;
    for(;;){
      auto c=que.top();
      if(c.b==goal)break;
      que.pop();
      if(!u.insert(c.b).second)continue;
      int x=find(begin(c.b),end(c.b),0)-begin(c.b);
      que.push({c.c+ch,move(c.b,x,(x+1)%9)});
      que.push({c.c+ch,move(c.b,x,(x+8)%9)});
      que.push({c.c+cv,move(c.b,x,(x+3)%9)});
      que.push({c.c+cv,move(c.b,x,(x+6)%9)});
    }
    cout<<que.top().c<<endl;
  }
}

Measured memory_bytes: 45072
"""
def find(s,p,g,box,cost):
    for i in rooter[p]:
        if i==g:box.append(cost+1)
        elif i==s:continue
        else:find(s,i,g,box,cost+1)
    return box
rooter={}
for i in range(int(input())):
    N=list(map(int,input().split()))
    box=[]
    for j in N[2:]:box.append(j)
    rooter[N[0]]=box

for i in range(int(input())):
    s,g,v=map(int,input().split())
    cost=1
    box=[]
    ans=min(find(s,s,g,box,cost))
    if ans<=v:print(ans)
    else:print("NA")
"""
from collections import deque

n = int(input())
rlst = [None] * (n + 1)
for _ in range(n):
    lst = list(map(int, input().split()))
    r = lst[0]
    lst = lst[2:]
    rlst[r] = lst

p = int(input())

for _ in range(p):
    s, d, v = map(int, input().split())
    visited = [False] * (n + 1)
    visited[s] = True
    que = deque()
    que.append((s, 0))
    while que:
        node, dist = que.popleft()
        if node == d:
            if dist < v:
                print(dist + 1)
            else:
                print("NA")
            break
        for to in rlst[node]:
            if not visited[to]:
                que.append((to, dist + 1))
                visited[to] = True
    else:
        print("NA")


Measured memory_bytes: 6000
import math
def main():
    ans = 0
    K = int(input())
    for i in range(1,K+1,1):
        for j in range(1,K+1,1):
            p = math.gcd(i,j)
            for k in range(1,K+1,1):
                ans += math.gcd(p,k)
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
	int n;cin>>n;
	int cnt[9]={0};
	for(int i=0;i<n;i++){
		int a;cin>>a;
		if(a<400){
			cnt[1]++;
		}else if(a<800){
			cnt[2]++;
		}else if(a<1200){
			cnt[3]++;
		}else if(a<1600){
			cnt[4]++;
		}else if(a<2000){
			cnt[5]++;
		}else if(a<2400){
			cnt[6]++;
		}else if(a<2800){
			cnt[7]++;
		}else if(a<3200){
			cnt[8]++;
		}else{
			cnt[0]++;
		}
	}
	int how=0;
	for(int i=1;i<9;i++){
		if(cnt[i])how++;
	}
	cout<<max(how,1)<<' '<<how+cnt[0];
	return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    ll H,W,N;
    cin >> H >> W >> N;

    map<P_ii,ll> mp;

    REP(i,N){
        int a,b;
        cin >> a >> b;
        for(int j = a-1;j<=a+1;j++) for(int k = b-1;k<=b+1;k++) {
            if(j <= 1 || k <= 1 || j >= H || k >= W) continue;
            mp[{j,k}]++;
        }
    }

    ll ans[10]={};
    for(auto m:mp) ans[m.second]++;
    
    ans[0] = (H-2)*(W-2) - (ans[1]+ans[2]+ans[3]+ans[4]+ans[5]+ans[6]+ans[7]+ans[8]+ans[9]);

    REP(i,10) pl(ans[i])

    return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort(all(v))
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int m, d;
  cin >> m >> d;
  int ans = 0;
  REP(i, 1, m + 1) {
    REP(j, 1, d + 1) {
      int a = j / 10, b = j % 10;
      if(a >= 2 && b >= 2 && a * b == i) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int N, M, K, parent[MAXN + 3], sz[MAXN + 3];
vector<int> friends[MAXN + 3], blocks[MAXN + 3];

int findSet(int u) {
    return (u == parent[u] ? u : parent[u] = findSet(parent[u]));
}

bool isSameSet(int u, int v) {
    return findSet(u) == findSet(v);
}

void unionSet(int u, int v) {
    int pu = findSet(u), pv = findSet(v);

    if (pu == pv) return;

    parent[pu] = pv;
    sz[pv] += sz[pu];
}

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

    for (int i = 1; i <= N; i++) {
        parent[i] = i;
        sz[i] = 1;
    }

    for (int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;

        friends[a].push_back(b);
        friends[b].push_back(a);

        unionSet(a, b);
    }

    for (int i = 1; i <= K; i++) {
        int a, b;
        cin >> a >> b;

        blocks[a].push_back(b);
        blocks[b].push_back(a);
    }

    for (int i = 1; i <= N; i++) {
        int componentSize = sz[findSet(i)];
        int numBlocks = 0, numFriends = friends[i].size();

        for (auto b: blocks[i]) {
            if (isSameSet(i, b))
                numBlocks += 1;
        }

        cout << (componentSize - 1) - numFriends - numBlocks << " ";
    }
    cout << endl;
}


Measured memory_bytes: 13176
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 2) {
			System.out.println(-1);
		} else {
			int[][] a = new int[n][n - 1];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n - 1; j++) {
					a[i][j] = (i + 2 + j) % n;
					if (a[i][j] == 0) {
						a[i][j] = n;
					}
				}
			}
			if (n % 2 == 0) {
				for (int i = 0; i < n / 2; i++) {
					int tmp = a[i][n / 2];
					a[i][n / 2] = a[i][n / 2 - 1];
					a[i][n / 2 - 1] = tmp;
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n - 2; j++) {
					System.out.print(a[i][j] + " ");
				}
				System.out.println(a[i][n - 2]);
			}
		}
	}
}

Measured memory_bytes: 27860
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
const ll INF = 1 << 30;
typedef pair<ll, ll  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<ll,payar  > > vpp;
vector < payar >  vp;

ll n ;
int ara[200005];

ll dp[200005];

ll par[100005];

ll k ;
ll cal(int pos)
{
      if(pos>n)
    {
        return 10000000000000000;
    }
    if(dp[pos]!=-1)
    {
        return dp[pos];
    }
    if(pos==n )
    {
        return 0 ;
    }



    dp[pos]=abs(ara[pos+1]-ara[pos]) +cal(pos+1);

    for(int i  = 2 ; i<=k ; i++)
    {

            dp[pos]=min( abs(ara[pos]-ara[pos+i])+ cal(pos+i), dp[pos] );

    }
    return dp[pos];
}
int main()
{

    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(int i =  1 ; i<=n ; i++)
    {
        //  cin>>ara[i];
        scanf("%d",&ara[i]);
    }
      for(int i =  n+1 ; i<=n+k ; i++)
    {
        ara[i]=10000000000000000;
       // scanf("%d",&ara[i]);
    }
    cout<<cal(1);



    return  0 ;
}


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

using namespace std;

int main(){
    int N;

    cin >> N;
    
    long long ans = 0;

    for (int i = 1; i < N+1; i++){
        if ((i % 3 == 0) or (i % 5 == 0)){
            continue;
        }
        else{
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}



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

int fact(int n){
  return (n>1) ? n*fact(n-1) : 1;
}

int main(){
  int n; cin >> n;
  vector<int> p(n), q(n);
  for(int i=0; i<n; ++i) cin >> p[i];
  for(int i=0; i<n; ++i) cin >> q[i];
  int sump = 1, sumq = 1;
  for(int i=0; i<n-1; ++i){
    int sp = 1, sq = 1;
    for(int j=i+1; j<n; ++j){
      if(p[j] < p[i]) ++sp;
      if(q[j] < q[i]) ++sq;
    }
    sump += fact(n-i-1) * (sp-1);
    sumq += fact(n-i-1) * (sq-1);
  }
  cout << abs(sump - sumq) << endl;  
  return 0;
}

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

namespace CSharpSample01
{
    
    class Program
    {
        
        static void Main(string[] args)
        {
            int time = 0;

            int[] dish = new int[5];
            int lastdish = -1;
            int maxspan = 0;
            

            for(int i = 0; i < 5; i++)
            {
                int d = int.Parse(Console.ReadLine());
                dish[i] = d;
                if(10 - d % 10 >= maxspan && d % 10 != 0)
                {
                    maxspan = 10 - d % 10;
                    lastdish = i;
                }
            }

            if(lastdish == -1)
            {
                lastdish = 0;
            }

            
            for(int i = 0; i < 5; i++)
            {                
                
                if(i != lastdish)
                {
                    if(dish[i] % 10 == 0)
                    {
                        time += dish[i];
                    }
                    else
                    {
                        time += dish[i] + 10 - dish[i] % 10;
                    }
                    
                }
                else
                {
                    time += dish[i];
                }

            }

            Console.WriteLine(time);

        }
    }
}


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


bool dfs(string s){
//    cout << "dfs :" << s << endl;
    if(s=="") return true;

    vector<string> vs;
    string ss;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='(') a++;
        else if(s[i]==')') a--;
        else if(s[i]=='[') b++;
        else if(s[i]==']') b--;
        ss += s[i];
        if(i!=0 && a==0 && b==0){
            vs.push_back(ss);
            ss="";
        }
    }

    if(a!=0 || b!=0){
//        cout << "a or b is not 0" << endl;
        return false;
    }

//    cout << " vs " << endl;
//    for(auto v : vs){
//        cout << v << endl;
//    }

    for(int i=0;i<vs.size();i++){
        string t = vs[i];
        char s = t[0];
        char e = t[t.size()-1];
        if(!((s=='('&&e==')')||(s=='['&&e==']'))){
//            cout << " not match " << endl;
            return false;
        }
        if(!dfs(t.substr(1,t.size()-2))){
//            cout << "dfs is not true" << endl;
            return false;
        }
    }
    return true;
}

void solve(string s){
    string ss;
    for(char c : s) if(c=='[' || c==']' || c=='(' || c==')') ss += c;

//    cout << ss << endl;
    bool f = dfs(ss);
    if(f) cout << "yes" << endl;
    else cout << "no" << endl;
}

int main(){
    string s;
    while(getline(cin,s)){
        if(s==".") break;
        solve(s);
    }
}

Measured memory_bytes: 3256
package main

import "fmt"

func main() {
	var A, B, C, K int64
	fmt.Scan(&A, &B, &C, &K)

	if K <= A {
		fmt.Println(K)
		return
	}

	if K <= A+B {
		fmt.Println(A)
		return
	}

	fmt.Println(A - (K - A - B))
}


Measured memory_bytes: 1752
import java.io.*;
import java.util.*;
	
public class Main {
	private static int[] prep(String s) {
		int[] sPre = new int[s.length() + 1];
		for(int i = 1; i <= s.length(); i++) {
			char c = s.charAt(i - 1);
			if(c == 'A') {
				sPre[i] = sPre[i - 1] + 1;
			} else {
				sPre[i] = sPre[i - 1] + 2;
			}
		}
		return sPre;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		String s = f.readLine();
		String t = f.readLine();
		int[] sPre = prep(s);
		int[] tPre = prep(t);
		int q = Integer.parseInt(f.readLine());
		for(int i = 0; i < q; i++) {
			StringTokenizer st = new StringTokenizer(f.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			int d = Integer.parseInt(st.nextToken());
			if((sPre[b] - sPre[a - 1]) % 3 == (tPre[d] - tPre[c - 1]) % 3) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}


Measured memory_bytes: 47392
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
string s;
bool y(int x){
    return 1;
}
bool m(int x){
    return (1<=x&&x<=12);
}
int LiangJiaJun(){
    cin>>s;
    int a,b;
    a=0+(s[0]-'0')*10+(s[1]-'0');
    b=0+(s[2]-'0')*10+(s[3]-'0');
    if(y(a)&&m(b)&&y(b)&&m(a))cout<<"AMBIGUOUS"<<endl;
    else if(!m(a)&&!m(b))cout<<"NA"<<endl;
    else if(y(a)&&m(b))cout<<"YYMM"<<endl;
    else if(m(a)&&y(b))cout<<"MMYY"<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    mod = 10 ** 9 + 7

    n = int(input())
    *a, = map(int, input().split())

    ctr = [0] * n
    for x in a:
        ctr[x] += 1

    if n % 2 == 1:
        if ctr[0] != 1:
            print(0)
            return
        for i in range(1, n):
            if (i % 2 == 0 and ctr[i] != 2) or (i % 2 == 1 and ctr[i] != 0):
                print(0)
                return

    else:
        for i in range(n):
            if (i % 2 == 0 and ctr[i] != 0) or (i % 2 == 1 and ctr[i] != 2):
                print(0)
                return

    print(pow(2, n // 2, mod))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
S = input()

ans = []

for i in range(len(S)-1):
	s = S[i]
	if s == S[i+1]:
		continue
	else:
		ans.append(s)

print(len(ans))

Measured memory_bytes: 45040
import java.util.*;

public class Main {
    static boolean next_permutation(int[] p) {
      for (int a = p.length - 2; a >= 0; --a)
        if (p[a] < p[a + 1])
          for (int b = p.length - 1;; --b)
            if (p[b] > p[a]) {
              int t = p[a];
              p[a] = p[b];
              p[b] = t;
              for (++a, b = p.length - 1; a < b; ++a, --b) {
                t = p[a];
                p[a] = p[b];
                p[b] = t;
              }
              return true;
            }
      return false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] x = new int[N];
        int[] y = new int[N];
        int[] xx = new int[N-1];
        int[] yy = new int[N-1];
        int[] array = new int[N];
        for (int i=0;i<N;i++) {
            array[i]=i;
        }
        for (int i=0;i<N;i++) {
            x[i] = Integer.parseInt(sc.next());
            y[i] = Integer.parseInt(sc.next());
        }
        for (int i=0;i<N-1;i++) {
            xx[i]=x[i+1]-x[i];
            yy[i]=y[i+1]-y[i];
        }
        double sum = 0;
        int div = 0;
        do {
            double tmp = 0L;
            for (int i=0;i<N-1;i++) {
                tmp+=Math.sqrt(Math.pow(x[array[i+1]]-x[array[i]], 2)+Math.pow(y[array[i+1]]-y[array[i]], 2));
            // System.out.println(Math.sqrt(Math.pow(x[array[i+1]]-x[array[i]], 2)+Math.pow(y[array[i+1]]-x[array[i]], 2)));
            }
            div+=1;
            sum+=tmp;
            // System.out.println(Arrays.toString(array));
        } while(next_permutation(array));
        System.out.println(sum/div);
    }
}

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

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    s2.erase(s2.size()-1,1);
    if(s1 == s2){
        cout<<"Yes";
    }else cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  vector<int> P(n); rep(i, n) cin >> P[i];
  vector<int> cnt(3);
  rep(i, n) {
    if(P[i]<=a) cnt[0]++;
    else if(P[i]<=b) cnt[1]++;
    else cnt[2]++;
  }
  cout << *min_element(all(cnt)) << endk;
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pi pair<int,int>
#define pl pair<ll, ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const ll N = 2e5 + 5, mod = 1e9 + 7;
const ll inf = 1e18;

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b){
    if(a.F == b.F) return a.S < b.S;
    return a.F > b.F;
}
ll power(ll x, ll p){
    ll r = 1ll;
    x = x % mod;
    while(p > 0){
        if(p & 1) r = (r * x) % mod;
        p = p >> 1;
        x = (x * x) % mod;
    }
    return r;
}

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, w = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
        else w++;
    }
    int ans = min(r, w);
    int cnt = 0, l = 0;
    r = n - 1;
    while(l <= r){
        while(l < n && s[l] != 'W') l++;
        while(r >= 0 && s[r] != 'R') r--;
        if(l > r) break;
        cnt++;
        l++;
        r--;
    }
    ans = min(ans, cnt);
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif*/
    //freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
    int t = 1, p;
    //cin >> t;
    for(p = 1; p <= t; p++){
        //cout << "Case #" << p << ": ";
        solve();
    }
    return 0;
}



Measured memory_bytes: 3760
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL N;
    GLL(N);
    LL ans=LLMAX;
    for(LL A=1;A<N;A++){
        LL r = 0;
        LL AA = A, B = N - A;
        while(0<AA){
            r += AA%10;
            AA/=10;
        }
        while(0<B){
            r += B%10;
            B/=10;
        }
        ans = min(r,ans);
    }
    printf("%lld\n",ans);
    return 0;
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool f = abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d);
    cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <string.h>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005],b[2];
    int f=0;
    b[0]=0;
    b[1]=0;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    for(int i=n-1;i>=0;)
    {
        if(f<2)
        {
            if(a[i]==a[i-1])
            {
                b[f]=a[i];
                f++;
                i-=2;
            }
            else
                i--;
        }
        else
            break;
    }
    ll s;
    s=(ll)b[0]*b[1];
    printf("%lld",s);
    return 0;
}

Measured memory_bytes: 640
mod my {

    use std::io;
    use std::io::Read;
    use std::str::FromStr;

    pub fn read<T: FromStr>() -> Result<T, &'static str> {
        let mut s = String::new();
        let mut stdin = io::stdin();
        let mut buf = [0];
        while let Ok(1) = stdin.read(&mut buf) {
            match buf[0] as char {
                c if c.is_whitespace() => {
                    if s.is_empty() { continue; }
                    break;
                },
                c => s.push(c)
            }
        }
        if s.is_empty() {
            return Result::Err("no content");
        }
        return match s.parse() {
            Ok(v) => Ok(v),
            Err(_) => Result::Err("invalid"),
        }
    }
}

fn main() {
    let word = my::read::<String>().unwrap().to_uppercase();
    let mut text: Vec<String> = vec!();
    while let Ok(w) = my::read::<String>() {
        if w == "END_OF_TEXT" {
            break;
        }
        text.push(w.to_uppercase());
    }
    let count: u32 = text.iter().map(|w| if w == &word { 1 } else { 0 }).sum();
    println!("{}", count);
}


Measured memory_bytes: 5032
gets;C=(r=*0..9).map{gets.split.map &:to_i};r.product(r,r){|i,j,k|C[j][k]=[C[j][k],C[j][i]+C[i][k]].min};p eval gets(p).split.map{|n|n[?-]?0:C[n.hex][1]}*?+

Measured memory_bytes: 50044
#include <stdio.h>

int cnt = 0;

void Insert(int A[],int n,int g)
{
  int i,j,v;

  for(i = g;i < n;i++)
  {
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v)
    {
      A[j + g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void Shell(int A[],int n)
{
  int i,m,h,G[100];

  for(i = 0,h = 1;i < n;i++)
  {
    if(h > n) break;
    G[i] = h;
    h = 3 * h + 1;
  }
  m = i;

  printf("%d\n",m);
  for(i = m - 1;i >= 0;i--)
  {
    printf("%d",G[i]);
    if(i) printf(" ");
  }
  printf("\n");

  for(i = m - 1;i >= 0;i--) Insert(A,n,G[i]);
}

int main()
{
  int i,n,A[1000000];

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&A[i]);

  Shell(A,n);

  printf("%d\n",cnt);
  for(i = 0;i < n;i++)
  {
    printf("%d\n",A[i]);
  }

  return 0;
}



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

class DisjointSet {
public:
    vector<int> Parent;

    DisjointSet(int n) {
        Parent = vector<int> (n, -1);
    }

    int root(int a) {
        if (Parent[a] < 0) return a;
        return Parent[a] = root(Parent[a]);
    }

    int size(int a) {
        return -Parent[root(a)];
    }

    bool link(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return false;

        if (size(a) < size(b)) swap(a, b);
        Parent[a] += Parent[b];
        Parent[b] = a;
        return true;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    int c, x, y;
    for (int i = 0; i < q; i++) {
        cin >> c >> x >> y;
        if (c == 0) {
            ds.link(x, y);
        } else {
            if (ds.root(x) == ds.root(y)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3216
function Main(input) {
    input = input.trim();
    input = input.split("\n");

    n = input[0];

    let s = [];
    for (let i = 0; i < n; i++) {
        s[i] = input[i+1];
    }

    // 重複を削除したリスト
    const t = Array.from(new Set(s))

    console.log(t.length);
    
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int H, W;
	cin >> H >> W;
	int arr[H][W] = {0};
	bool mine[H][W];
	string row;
	
	REP(i, 0, H){
		REP(j, 0, W){
			mine[i][j] = false;
			arr[i][j] = 0;
		}
	}
	
	REP(i, 0, H){
		cin >> row;
		REP(j, 0, W){
			if(row[j] == '#'){
				mine[i][j] = true;
				for(int k=-1; k <= 1; k++){
					for(int z=-1; z <= 1; z++){
						if(i + k >= 0 && j + z >= 0 && i + k < H && j + z < W){
							 arr[i+k][j+z] += 1;
						 }
					}
				}
			}
		}
	}
	REP(i, 0, H){
		REP(j, 0, W){
			if(mine[i][j] == true) cout << "#";
			else cout << arr[i][j] ;
		}
		
		cout << endl;
	}
	
	
							

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def calc(N,i,j,k):
  if dp[i][j][k]>=0:
    return dp[i][j][k]
  ans = 1
  if k-1>=0 and j+1<=N:
    ans += calc(N,i,j+1,k-1)*k/N
  if j-1>=0 and i+1<=N:
    ans += calc(N,i+1,j-1,k)*j/N
  if i-1>=0:
    ans += calc(N,i-1,j,k)*i/N
  ans *= N/(i+j+k)
  dp[i][j][k] = ans
  return ans
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
dp = [[[-1]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 0
ans = calc(N,c[1],c[2],c[3])
print(ans)

Measured memory_bytes: 405228