akhauriyash/Code-Regression huggingface dataset:
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

n = int(input())
#b = int(input())
#n, m = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#dp = [MOD for _ in range(m)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
#dp = [[[0 for _ in range(11)] for _ in range(2)] for _ in range(11)]

#Combination = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

sum = 0
for i in range(1,n+1):
    if((1 <= i and i < 10) or (100 <= i and i < 1000) or (10000 <= i and i < 100000)):
        sum += 1

print(sum)

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

int main(void) {
	long long n, i, ans = 1;
	cin >> n;
	for (i = 1; i <= n; i++) {
		ans *= i;
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

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

int arr[10005];
int main()
{
    int n,k,sum=0;
    scanf("%d",&n);
    scanf("%d",&k);
    for(int i=0;i<k;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    int res;
    if(sum<=n)
    {
        res=n-sum;
    }
    else{
        res=-1;
    }
    printf("%d",res);

}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18;  
int n,k;
auto x = vector<ll>();

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

  int c1=0;
  for (ll i = 0;i<s.size(); i++)
  {
    if(s[i]!='1'){
      break;
    }else{
      c1++;
    }
  }
  
  if(c1==0 || c1<k){
  	cout << s[c1];
  }else{
  	cout << '1';
  }
  
}
  
  

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Resale
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

/* global variables */

int vs[MAX_N], cs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", vs + i);
  for (int i = 0; i < n; i++) scanf("%d", cs + i);

  int sum = 0;
  for (int i = 0; i < n; i++)
    if (vs[i] > cs[i]) sum += vs[i] - cs[i];
  printf("%d\n", sum);
  return 0;
}


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

namespace _0185
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] primes = new int[1000001];
            primes[2] = 1;
            for (int i = 3 ; i < 1000000 ; i += 2)
            {
                if (IsPrime(i)) primes[i] = 1;
            }

            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int cnt = 0;
                for (int i = 0 ; i < n / 2 + 1 ; i++)
                {
                    if (primes[i] == 1 &&  primes[n -i] == 1) cnt++;
                }
                Console.WriteLine(cnt);
            }
        }

        /// <summary>
        ///素数判定
        /// </summary>
        public static bool IsPrime(long number)
        {
            long boundary = (long)Math.Floor(Math.Sqrt(number));

            if (number == 1) return false;
            if (number == 2) return true;

            for (long i = 2 ; i <= boundary ; ++i)
            {
                if (number % i == 0) return false;
            }
            return true;
        }


        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 19300
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

int dp[5000];
signed main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int ansS, ansW;
    double node = -1.0;

    rep(a, 31) {
        rep(b, 31) {
            rep(c, 3000) {
                if (F - a * 100 * A - b * 100 * B - c*C < 0) {
                    continue;
                }

                int d1 = (F - a * 100 * A - b * 100 * B - c*C) / D;
                int d2 = ((a*A + b*B)*E - c*C) / D;
                chmax(d1, 0);
                chmax(d2, 0);
                int d = min(d1, d2);

                if ((a*A + b*B)*E < c*C + d*D) {
                    continue;
                }

                double calc = (double)(c*C + d*D) / (double)(c*C + d*D + a*A * 100 + b*B * 100);
                if (calc > node) {
                    ansW = c*C + d*D + a*A * 100 + b*B * 100;
                    ansS = c*C + d*D;
                    node = calc;
                }

            }
        }
    }



    cout << ansW << " " << ansS << "\n";
    return 0;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  for (int i = 0; i <= A; ++i) {
    for (int j = 0; j <= B; ++j) {
      for (int k = 0; k <= C; ++k) {
        int total = 500*i + 100*j + 50*k; // 合計金額
        if (total == X) ++count; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import itertools
import math
L=0
M=0
N=int(input())
p=[list(map(int,input().split())) for i in range(N)]
for seq in itertools.permutations(range(N),N):
    tmp=0
    for i in range(N-1):
        x1,y1=p[seq[i]]
        x2,y2=p[seq[i+1]]
        tmp+=math.sqrt((x1-x2)**2+(y1-y2)**2)
    L+=tmp
    M+=1
print(L/M)


Measured memory_bytes: 42476
// D - Harlequin

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans = "second";

	for (int i=0; i<N; i++) {
		int a;
		cin >> a;
		if (a % 2 == 1) ans = "first";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

constexpr ll V = 1000000;

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret * x % MOD;
        x = x * x % MOD;
        y /= 2;
    }
    return ret;
}

ll N;
ll A[200000];
ll C[V+1];
ll C1[V+1];
ll C2[V+1];
ll w[V+1];
ll inv[V+1];

void init() {
    for (ll i = 1; i <= V; i++) inv[i] = mod_pow(i, MOD-2);
    for (ll i = 1; i <= V; i++) {
        w[i] = (inv[i] - w[i]%MOD + MOD) % MOD;
        for (ll j = i*2; j <= V; j += i) {
            w[j] += w[i];
        }
    }
}

int main() {
    init();
    cin >> N;
    rep(i,N) cin >> A[i];
    rep(i,N) C[A[i]]++;
    for (ll i = 1; i <= V; i++) {
        C1[i] = C[i] * i % MOD;
        C2[i] = C1[i] * i % MOD;
    }
    ll ans = 0;
    for (ll i = 1; i <= V; i++) {
        ll add = 0;
        ll sum1 = 0, sum2 = 0;
        for (ll j = i; j <= V; j += i) {
            sum1 += C1[j];
            sum2 += C2[j];
        }
        sum1 %= MOD;
        sum2 %= MOD;
        add = (sum1*sum1-sum2+MOD)%MOD;
        add = add * inv[2] % MOD;

        ans = (ans + add*w[i]) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

ll p[1000001], pos[1000001], po[1000001];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    ll n;
    cin>>n;

    p[0] = 1, po[0] =1, pos[0] = 1;
    for(ll i=1;i<=n;i++){
        p[i] = (p[i-1]*10)%mod;
    }
    for(ll i=1;i<=n;i++){
        po[i] = (po[i-1]*9)%mod;
    }
    for(ll i=1;i<=n;i++){
        pos[i] = (pos[i-1]*8)%mod;
    }
    ll y = (2*po[n])%mod;
    y = (y - pos[n])%mod;
    ll an = (p[n] - y + mod)%mod;
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 27012
#include<iostream>
#include <stdio.h>
using namespace std;
 
int main(){
	int a,b;
	    int c=0;
	cin>>a>>b;
	char clouds[100][100];
	for(int i=0;i<a;i++){
	for(int i0=0;i0<b;i0++){
	cin>>clouds[i][i0];}}
	for(int i2=0;i2<a;i2++){
	for(int i3=0;i3<b;i3++){
		while(1){
			if(clouds[i2][i3]=='c'){
			cout<<0;c=0;
		if(b==1+i3){
			cout<<endl;}else{
			cout<<" ";}
		break;}
		if(clouds[i2][i3-c]=='c'){
		cout<<c;
		c=0;
		if(b==1+i3){
			cout<<endl;}else{
			cout<<" ";}
		break;}else{if(c>=i3){
		cout<<-1;
		if(b==1+i3){
			cout<<endl;}else{
			cout<<" ";}
		break;}
		c++;
		}}}}
	return 0;}


Measured memory_bytes: 1168
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse4")
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long  ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
mt19937 rnd(random_device{}());
#define all(a) a.begin(), a.end()
#define fr(i, n) for (ll i = 0; i < n; ++i)
#define fr1(i, n) for (ll i = 1; i <= n; ++i)
const int N = 1000001;
void solve() {
    ll x, k, d; cin >> x >> k >> d;
    if (x < 0) x = -x;
    if (k <= x / d) {
        cout << x - k * d;
        return;
    }
    ll k2 = x / d;
    x -= k2 * d;
    k -= k2;
    cout << (k & 1ll ? d - x : x);
}
void pre_calc() {
}
int main() {
    pre_calc();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    int tst = 1;
    if (tst != 1) cin >> tst;
    while (tst--)
        solve();
}

Measured memory_bytes: 3664
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=1; i<(int)n+1; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main(){
 int K;cin>>K;
  ll ans=0;
  rep(i,K){
    rep(j,K){
         rep(k,K){
           ans+=__gcd(i,__gcd(j,k));
         }
    }
  }
cout<<ans<<endl;
}

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

int x, y, a, b, c;
int q[100004], p[100004], r[100004];
priority_queue<int, vector<int>, greater<int>> red, green;

int main() {
	cin>>x>>y>>a>>b>>c;
	for(int i = 0; i < a; i++)
		cin>>q[i];
	for(int i = 0; i < b; i++)
		cin>>p[i];
	for(int i = 0; i < c; i++)
		cin>>r[i];
	sort(q, q+a);
	sort(p, p+b);
	sort(r, r+c);
	long long sum = 0;
	for(int i = a-1; i >= a-x; i--){
		red.push(q[i]);
		sum += q[i];
	}
	for(int i = b-1; i >= b-y; i--){
		green.push(p[i]);
		sum += p[i];
	}
	for(int i = c-1; i >= 0; i--){
		if(red.top() > green.top()){
			if(green.top() < r[i]){
				sum -= green.top();
				green.pop();
				green.push(r[i]);
				sum += r[i];
			}
		}
		else{
			if(red.top() < r[i]){
				sum -= red.top();
				red.pop();
				red.push(r[i]);
				sum += r[i];
			}
		}
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 2552
#include <stdio.h>

int main () {
     int x[3000], y[3000], n;
     for (n = 0; n < 3000; n++) {
          scanf ("%d %d\n", &x[n], &y[n]);

          if (x[n] == 0 && y[n] == 0)
               break;
     }

     for (n = 0; n < 3000; n++) {
          if (x[n] == 0 && y[n] == 0)
               break;
          if (x[n] < y[n]) {
                printf ("%d %d\n", x[n], y[n]);
          } else {
                printf ("%d %d\n", y[n], x[n]);
          }
      }

     return 0;

}

Measured memory_bytes: 2712
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    cin >> n;
    vl a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    ll pos = 2020202020ll * 200000ll + 1ll;
    vl sum(n, a[0]);
    for(int i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i];
    rep(i, n - 1){
        ll left = sum[i];
        ll right = sum[n - 1] - sum[i];
        ll temp = abs(left - right);
        pos = min(temp, pos);
    }
    cout << pos << endl;
}

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

int main() {
  int n;
  cin >> n;
  if(n%10 == 3) {
    cout << "bon" << endl;
  } else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


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

typedef complex<double> P;
typedef pair<double,int> Pa;
vector<Pa> v;

int W,H;
char fie[605][605];

double getAngle(P a, P b ){
  return atan2(b.real()-a.real(),b.imag()-a.imag());
}

int main(){
  cin >> H >> W;
  for(int i=0;i<=H+1;i++)
    for(int j=0;j<=W+1;j++)
      fie[j][i] = '.';

  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)
      cin >> fie[j][i];

  P o = P(1,H+1);
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if( fie[j][i] == '#' ){
        if( fie[j-1][i] == '.' &&
            fie[j-1][i-1] == '.' &&
            fie[j][i-1] == '.' ) {
          v.push_back( Pa(getAngle(o,P(j,i)),1) );
        }
        if( fie[j+1][i] == '#' &&
            fie[j+1][i+1] == '.' &&
            fie[j][i+1] == '#' ) {
          v.push_back( Pa(getAngle(o,P(j+1,i+1)),1) );
        }

        if( fie[j+1][i] == '.' &&
            fie[j+1][i+1] == '.' &&
            fie[j][i+1] == '.' ) {
          v.push_back( Pa(getAngle(o,P(j+1,i+1)), -1) );
        }
        if( fie[j-1][i] == '#' &&
            fie[j-1][i-1] == '.' &&
            fie[j][i-1] == '#' ) {
          v.push_back( Pa(getAngle(o,P(j,i)),-1) );
        } 
      }
    }
  }
  sort(v.rbegin(),v.rend());
  int res = 1;
  int cnt = 1;
  for(int i=0;i<(int)v.size();i++){
    //  cout << v[i].first / 2.0 / M_PI * 360.0 << " " << v[i].second << endl;
    cnt += v[i].second;
    if( i == (int)v.size()-1 ||  abs(v[i+1].first - v[i].first) > 1e-8 )
      res = max( res, cnt );
  } 
  cout << res << endl;
      
}

Measured memory_bytes: 3536
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

ll n;
ll a[2 * 100010];

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

	ll res = 0, t = 0;
	ll sum = 0;
	for (int s = 0; s < n; s++) {
		while (t < n && (sum ^ a[t]) == (sum + a[t])) sum += a[t++];

		res += t - s;

		if (s == t) t++;
		else sum -= a[s];
	}

	printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
        if(flagb) return true;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
        if(flagc) return true;
    }
    return false;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

namespace CSharpSample01
{

	class Program
	{
		static void Main(string[] args)
		{
			var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			var K = inputNum[0];
			var N = inputNum[1];

			var inputNum2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var dp = new long[N];

			long max = 0;
			for(int i = 0; i < N - 1; i++)
			{
				long value = inputNum2[i + 1] - inputNum2[i];
				if(max < value)
				{
					max = value;
				}
//				dp[i] = inputNum2[i + 1] - inputNum[i];
			}

			if(max < K + inputNum2[0] - inputNum2[N - 1])
			{
				max = K + inputNum2[0] - inputNum2[N - 1];
			}

			Console.WriteLine(K - max);

/*			long migiMawari = inputNum2[N - 1] - inputNum2[0];
			long hidariMawari = (inputNum2[N - 2] + K - inputNum2[N - 1]);

			if(migiMawari > hidariMawari)
			{
				Console.WriteLine(hidariMawari);
			}
			else
			{
				Console.WriteLine(migiMawari);
			}
*/		}

	}
}

Measured memory_bytes: 36452
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line = br.readLine()) != null){
            if(line.equals("0")) break;

            char[] a = line.toCharArray();
            int result = 0;

            for(char c : a){
                result += c - '0';
            }

            System.out.println(result);
        }
    }
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll pts = 0;
  for (ll i = 0; i < N; i++) pts += (i + 1) * (N - i);
  ll edges = 0;
  for (ll i = 0; i < N-1; i++) {
    ll u, v; cin >> u >> v; u--; v--;
    if (u > v) swap(u, v);
    edges += (u + 1) * (N - v);
  }
  cout << pts - edges << endl;


  return 0;
}



Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
	int a, b, c, d, e;
	int i;
	
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	for(i=0; i<4; i++) {
		if(a<b) {
			int t=0;
			t=a; a=b; b=t;
		}
		if(b<c) {
			int t=0;
			t=b; b=c; c=t;
		}
		if(c<d) {
			int t=0;
			t=c; c=d; d=t;
		}
		if(d<e) {
			int t=0;
			t=d; d=e; e=t;
		}
	}
	
	printf("%d %d %d %d %d\n", a, b, c, d, e);
	
	return 0;
}


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

int main() {
  int num; cin >> num;
  
  int a = num / 1000;
  int b = num % 1000 / 100;
  int c = num % 100 / 10;
  int d = num % 10;
  
  if (a-b-c-d==7) cout << a << '-' << b << '-' << c << '-' << d << "=7";
  else if (a-b-c+d==7) cout << a << '-' << b << '-' << c << '+' << d << "=7";
  else if (a-b+c-d==7) cout << a << '-' << b << '+' << c << '-' << d << "=7";
  else if (a-b+c+d==7) cout << a << '-' << b << '+' << c << '+' << d << "=7";
  else if (a+b-c-d==7) cout << a << '+' << b << '-' << c << '-' << d << "=7";
  else if (a+b-c+d==7) cout << a << '+' << b << '-' << c << '+' << d << "=7";
  else if (a+b+c-d==7) cout << a << '+' << b << '+' << c << '-' << d << "=7";
  else if (a+b+c+d==7) cout << a << '+' << b << '+' << c << '+' << d << "=7";
}

Measured memory_bytes: 256
r, c, n = gets.split.map(&:to_i)
bd = [0, r, c]
xy = n.times.map { |i|
  gets.split.map(&:to_i) + [i]
}.select{ |x1, y1, x2, y2, id|
  (bd.include?(x1) || bd.include?(y1)) &&
    (bd.include?(x2) || bd.include?(y2))
}

ea, eb, ec, ed = [], [], [], []

xy.each{ |x1, y1, x2, y2, id|
  [[x1, y1], [x2, y2]].each{ |x, y|
    t = [x, y, id]
    if x == 0
      ea << t
    elsif y == c
      eb << t
    elsif x == r
      ec << t
    else
      ed << t
    end
  }
}

ea.sort_by!{ |x| x[1] }
eb.sort_by!{ |x| x[0] }
ec.sort_by!{ |x| -x[1] }
ed.sort_by!{ |x| -x[0] }

st = ea + eb + ec + ed
q = []
st.each{ |x, y, id| q[-1] == id ? q.pop : q << id }
puts q.size.zero? ? :YES : :NO



Measured memory_bytes: 33428
from collections import Counter
from itertools import accumulate
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
C = Counter([0] + [a % M for a in accumulate(A)])
cnt = 0
for c in C.values():
  cnt += c * (c - 1) // 2
print(cnt)

Measured memory_bytes: 17368
import sys

N=input()
if N.isdecimal() == 0 or int(N)<1 or int(N)>20 :
    print("error")
    sys.exit()

N=int(N)

V=list(map(int,input().strip().split()))
C=list(map(int,input().strip().split()))
# print(V[0],V[1],V[2])                                                                              

for i in range(N):
    if C[i]<1 or C[i]>50 or V[i]<1 or V[i]>50:
        print("error")
        sys.exit()

diff=0
max_profit=0



for i in range(N):
    # print(V[i],type(V[i]),C[i],type(C[i]))                                                         
    diff=V[i]-C[i]
    if diff >=0 :
        max_profit=max_profit+diff

print(max_profit)



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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
ll l;
map<int,int> mp;
int cnt = 0;
ll m = 1;
graph t;
ll ans = 0;

//t[n][m] nはノード番号,mは子供のノード番号
void trietree(string &s, ll node, ll level){
  if(level == s.size()) return;
  for(auto &x:t[node]){//すでにそのノードが埋まっている場合
    if(x.second == s[level]) return trietree(s,x.first,level+1);
  }
  t[node][m] = s[level];
  m++;
  trietree(s,m-1,level+1);
  return;
}


void dfs(ll node, ll d){
  if(t[node].size()==1){
    ll x = 1;
    while((l-d)%x==0) x <<= 1;//約数2の指数を数えている。
    x >>= 1;
    ans ^= x;
  }
  for(auto &x: t[node]){
    dfs(x.first,d+1);
  }
}

int main(){
  cin >> n >> l;
  REP(i,n){
    string x;
    cin >> x;
    trietree(x,0,0);
  }
  dfs(0,0);
  if(ans==0){
    cout << "Bob" << endl;
  }else{
    cout << "Alice" <<endl;
  }
}


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

using namespace std;


int main()
{

	string a = "", b = "", c = "";
	int a_last = 0, b_last = 0;

	cin >> a >> b >> c;

	a_last = a.length() - 1;
	b_last = b.length() - 1;

	if (a.at(a_last) == b.at(0) && b.at(b_last) == c.at(0)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

    return 0;
}

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

int main(void) {
	int A = 0;
	long B;
	scanf("%ld", &B);
	long temp = B;
	for(int i = 10; i >= 0; i--){
		A += temp / (long)(powl(10,i));
		temp -= (long)powl(10,i) * (temp / (long)powl(10,i));
	}
	if(B % A == 0){
		printf("Yes");
	}else{
		printf("No");
	}
	

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
constexpr long long INF = 1e18;

void pr(bool f){
	if(f)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
};

signed main(){
	int N;
	cin>>N;
	int digitSum = 0;
	vector<int>d(N),c(N);
	int sum = 0;
	REP(i,N){
		cin>>d[i]>>c[i];
		digitSum += c[i];
		sum += d[i]*c[i];
	}
	int ans = digitSum+(sum-1)/9;
	cout<<ans-1<<endl;
}

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, L, Q, ans=0, tmp=0;
vector<ll> A;
vector<vector<ll>> C;
string S;

signed main(){
    cin >> N;
    C.resize(20, vector<ll>(N, 0));
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    cin >> L >> Q;
    for(int i=1;i<N;i++) {
        ll id = lower_bound(A.begin(), A.end(), A[i]-L)-A.begin();
        C[0][i] = id;
    }
    for(int i=1;i<20;i++) {
        for(int j=1;j<N;j++) {
            C[i][j] = C[i-1][C[i-1][j]];
        }
    }
    for(int i=0;i<Q;i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        ans = 0;
        if(a>b) swap(a, b);
        for(int j=19;j>=0;j--) {
            if(C[j][b]>a) {
                b = C[j][b];
                ans += pow(2, j);
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int N, Q;
ll K;

int main(){
    cin >> N >> K >> Q;
    vector<ll> A(N,0);
    REP(i,Q)
    {
        int a;
        cin >> a;
        A[a-1]++;
    }
    REP(i,N)
    {
        if(K-(Q-A[i])>0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
import sys
import numpy as np


def main():
    n = int(input())
    balls = [[int(e) for e in input().split()] for _ in range(n)]
    if n == 1:
        print(n)
        sys.exit()
    diff = {}
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if ((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1])) in diff:
                diff[((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1]))] += 1
            else:
                diff[((balls[i][0] - balls[j][0]), (balls[i][1] - balls[j][1]))] = 1
    print(n - max(diff.values()))


main()


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

int main() {
  int A,B,C,D;
  cin >>A >>B >>C >>D;
  if((A+B)>(C+D))
    cout <<"Left" <<endl;
  else if((A+B)==(C+D))
    cout <<"Balanced" <<endl;
  else
    cout <<"Right" <<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    lli n;
    cin >> n;
    double t = log(n) / log(3);
    int ans = 0;
    ans = ceil(t);
    lli aa = 1LL;
    REP (i, 0, 22) {
        aa *= 3;
        if (aa == n) ans = i + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3392
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include <sstream>
#include <cctype>
#include<algorithm>

using namespace std;
typedef string::const_iterator State;

bool fg;

int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    if(ret>=10000)fg=true;
    return ret;
}

int term(State &begin) {
    int ret = number(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= number(begin);
	    if(ret>=10000)fg=true;
        } else if (*begin == '/') {
            begin++;
            ret /= number(begin);
        } else {
            break;
        }
    }

    return ret;
}

int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);	    
	    if(ret>=10000)fg=true;
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
	    if(ret<0)fg=true;
        } else {
            break;
        }
    }

    return ret;
}

int main(void){
  
  string s;
  while(cin>>s){
    fg=false;
    State begin = s.begin();
    int ans = expression(begin);
  
    fg=false;
    begin = s.begin();
    ans=number(begin);
    while(*begin!='='){
      if(*begin=='+')begin++,ans+=number(begin);
      else if(*begin=='*')begin++,ans*=number(begin);
      else begin++,ans-=number(begin);
      if(ans<0 || ans>=10000)fg=true;
    }
    if(fg)cout << "E" << endl;
    else cout << ans << endl;
  }
  return 0;
}

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

int main(void){
    int n = 0, m = 0; 

    scanf("%d%d", &n, &m);

    if(n == m){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;

} 


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			long sum = 0;
			for(int i = 0; i < n;i++){
				data[i] = sc.nextInt();
				sum += data[i];
			}
			
			long [] add = new long[n];
			add[0] = data[0];
			for(int i = 1; i < n; i++){
				add[i] = data[i] + add[i-1];
			}
			
			
			long min = Long.MAX_VALUE;
			for(int i = 0; i < n-1; i++){
				long a = add[i];
				long b = sum - a;
				min = Math.min(min, Math.abs(a - b));
				
			}
			System.out.println(min);
		}
	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 63832
#include <iostream>
#include <cstdio>

using namespace std;

int nums[10];

bool check_recursion(int i, int left, int right){
	if(i == 10) return true;
	if(nums[i] > left and check_recursion(i+1, nums[i], right)) return true;
	if(nums[i] > right and check_recursion(i+1, left, nums[i])) return true;
	
	return false;
}

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

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);
		 ans ? cout<<"YES"<<endl : cout<<"NO"<<endl;

	}
	return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 100000;

int N, a[MAXN+5], uni[MAXN+5];
LL cnt;

struct BIT {
    int S, c[2*MAXN+5];
    void init(int N) {
        fill(c, c + N, 0);
        S = N;
    }
    int query(int p) {
        int res = 0;
        while (p) {
            res += c[p];
            p -= p & -p;
        }
        return res;
    }
    void add(int p) {
        while (p <= S) {
            c[p] ++;
            p += p & -p;
        }
    }
} tree;

bool check(int x) {
    int zero = N + 1;
    LL res = 0;
    tree.init(2 * N + 2);
    for (int i = 0; i < N; i++) {
        tree.add(zero);
        if (a[i] <= x) zero++;
        else zero--;
        res += tree.query(zero - 1);
    }
    return res >= cnt / 2 + 1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    cin >> N;
    cnt = (LL)N * (N - 1) / 2 + N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        uni[i] = a[i];
    }

    sort(uni, uni + N);
    int M = unique(uni, uni + N) - uni, l = 0, r = M - 1, ans = -1;
    while (l <= r) {
        int m = (l + r) >> 1;
        if (check(uni[m])) {
            ans = m;
            r = m - 1;
        }
        else {
            l = m + 1;
        }
    }

    cout << uni[ans] << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
 
ll solve(ll a, ll b) {
	if (a == b) {
		return 2 * a - 2;
	} else if (a + 1 == b) {
		return 2 * a - 2;
	} else {
		ll c = (ll)sqrt(a * b);
		if (c * c == a * b) c--;
		if (c * (c + 1) >= a * b) {
			return 2 * c - 2;
		} else {
			return 2 * c - 1;
		}
	}
}

void solve() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		cout << solve(a, b) << endl;
	}
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	char ab[10][9]={"* = ****","* =* ***","* =** **","* =*** *",
					"* =**** "," *= ****"," *=* ***"," *=** **",
					" *=*** *"," *=**** "};
	char buf[9][6];
	int base[5]={10000,1000,100,10,1};
	int i,j,wk,x,n,flg;
	flg=1;
	while(scanf("%d",&x)!=EOF)	{
		for(i=0;i<5;i++)	{
			n=x/base[i];
			x=x%base[i];
			for(j=0;j<8;j++)	{
				buf[j][i]=ab[n][j];
			}
		}
		if(flg==0)	printf("\n");
		if(flg==1)	flg=0;
		for(i=0;i<8;i++)	{
			for(j=0;j<5;j++)	{
				printf("%c",buf[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}


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

#define mod 1000000007
int n;
long long int res[105][105];
long long int mat[105][105];

void multiply(long long int a[][105],long long int b[][105],long long int c[][105]){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            c[i][j] = 0;
            for(int k=0;k<n;k++){
                c[i][j] = (c[i][j] + ((a[i][k]*b[k][j])%mod))%mod; 
            }
        }
    }
}

void copymat(long long int c[][105],long long int a[][105]){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            c[i][j] = a[i][j];
        }
    }
}

int main(){
    long long int m,k;
    cin >> n >> k;
    long long int c[105][105];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin >> mat[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(i==j)
                res[i][j] = 1;
            else
                res[i][j] = 0;
        }
    while(k>0){
        if(k%2==1){
            multiply(res,mat,c);
            copymat(res,c);
        }
        multiply(mat,mat,c);
        copymat(mat,c);
        k=k/2;
    }
    long long int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            ans = (ans + res[i][j])%mod;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3728
import bisect

abq = input().split()
a = int(abq[0])
b = int(abq[1])
q = int(abq[2])
slist = [int(input()) for i in range(a)]
slist.sort()
tlist = [int(input()) for i in range(b)]
tlist.sort()
xlist = [int(input()) for i in range(q)]


def get_nears(list_search, idx, val):
    if idx == 0:
        return (None, list_search[idx])

    try:
        list_search[idx]
    except IndexError:
        return (list_search[idx - 1], None)

    return (list_search[idx - 1], list_search[idx])


def get_min_distance(x, anear, bnear, mindis):
    if anear is None or bnear is None:
        return mindis

    dis = abs(x - anear)
    dis += abs(anear - bnear)

    if mindis is None:
        return dis
    return min(dis, mindis)


for x in xlist:
    sidx = bisect.bisect_left(slist, x)
    tidx = bisect.bisect_left(tlist, x)

    snear1, snear2 = get_nears(slist, sidx, x)
    tnear1, tnear2 = get_nears(tlist, tidx, x)

    mindis = None
    mindis = get_min_distance(x, snear1, tnear1, mindis)
    mindis = get_min_distance(x, snear1, tnear2, mindis)
    mindis = get_min_distance(x, snear2, tnear1, mindis)
    mindis = get_min_distance(x, snear2, tnear2, mindis)
    mindis = get_min_distance(x, tnear1, snear1, mindis)
    mindis = get_min_distance(x, tnear1, snear2, mindis)
    mindis = get_min_distance(x, tnear2, snear1, mindis)
    mindis = get_min_distance(x, tnear2, snear2, mindis)

    print(mindis)


Measured memory_bytes: 16168
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}
int dp(VII& dist,int i,int a,int b)
{
    if(i==dist.size()-1)
        return 0;

    return min((dist[i+1]-dist[i])*a,b)+dp(dist,i+1,a,b);
}
int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll> dist(n);
	for(auto &x:dist)cin>>x;
	ll ans=0;
	for(int i=0;i<n-1;++i)
	    ans+=min(a*(dist[i+1]-dist[i]),b);
	cout<<ans;
	return 0;
} 

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

int main(){
        int k; cin>>k;
        string s; cin>>s;
        int sz=s.size();
        if(sz<=k)
        {
                cout<<s;
        }
        if(sz>k){
                string sub=s.substr(0,k);
                cout<<sub<<"...";
        }
}

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

int main(){
int a;
cin>>a;
int b=a,c=a;
for(;b!=-1;b--){
	string d=to_string(b);
	if(d.length()==1)break;
	for(int e=0;e<d.length()/2;e++){
		if(d[e]!=d[d.length()-1-e])break;
		if(d.length()/2-1==e)goto p;
	}
}
p:;
for(;;c++){
	string d=to_string(c);
	if(d.length()==1)break;
	for(int e=0;e<d.length()/2;e++){
		if(d[e]!=d[d.length()-1-e])break;
		if(d.length()/2-1==e)goto q;
	}
}
q:;
if(c-a<a-b)printf("%d\n",c);
else printf("%d\n",b);
}

Measured memory_bytes: 3308
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    cout<<(s.size()%2==(s[0]==s.back()) ? "Second" : "First")<<endl;
}

Measured memory_bytes: 512
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int a=0,k,n,d;
    long long int x,y;
    double z;
    cin>>n>>d;
    int i;
    for( i=0; i<n; i++)
    {
        cin>>x>>y;
        if(x==0&&y==0)
        {
            k=0;
            goto m;
        }

        z=sqrt(((x+y)*(x+y))-2*x*y);
        k=ceil(z);
m:
        if(k<=d)
            a++;
    }
    cout<<a;
}


Measured memory_bytes: 3644
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

int main(){
   int N, M;
   std::cin >> N >> M;
   std::vector<std::pair<int, int>> ab(N);
   std::vector<std::pair<int, int>> cd(M);
   for (int i=0; i<N; i++){
      int a, b;
      std::cin >> a >> b;
      ab.at(i) = {a, b};
   }
   for (int i=0; i<M; i++){
      int c, d;
      std::cin >> c >> d;
      cd.at(i) = {c, d};
   }
   for (int i=0; i<N; i++){
      int min = abs(ab.at(i).first - cd.at(0).first) + abs(ab.at(i).second - cd.at(0).second);
      int ans = 1;
      for (int j=0; j<M; j++){
         int temp = abs(ab.at(i).first - cd.at(j).first) + abs(ab.at(i).second - cd.at(j).second);
         if (temp < min){
            min = std::min(min, temp);
            ans = j+1;
         }
      }
      std::cout << ans << std::endl;
   }
}



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

int main() 
{
  string S;
  int K;
  cin >> K;
  cin >> S;
  if(S.size() <= K)
  {
    cout << S;
  }
  else
  {
    for(int i = 0; i < K; i++)
    {
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define per(i,l,r) for (int i=l;i>=r;i--)
using namespace std;
typedef long long ll;
const int maxn=1050;
int x,y,n,aim,rt,s,t,ans1,dia,mxdep,nrt;
vector<int> g[maxn];
int son[maxn],d[maxn],sz[maxn],dep[maxn],vis[maxn],fa[maxn];
ll f[maxn],ans2;
void dfs(int u){
	for (auto v:g[u]){
		if (v==fa[u]) continue;
		fa[v]=u;
		d[v]=d[u]+1;
		dfs(v);
	}
}
void dfs2(int u,int fa){
	int szson=0;
	sz[dep[u]]++; mxdep=max(mxdep,dep[u]);
	for (auto v:g[u]){
		if (v==fa) continue;
		szson++;
		dep[v]=dep[u]+1;
		dfs2(v,u);
	}
	son[dep[u]]=max(son[dep[u]],szson);
//	if (!szson) f[dep[u]]++;
}
void go(){
	rep(i,0,2*n) dep[i]=sz[i]=f[i]=vis[i]=son[i]=0;
	mxdep=0;
	dep[rt]=1;
	dfs2(rt,0);
	f[mxdep]=1;
	per(i,mxdep-1,1) f[i]=f[i+1]*son[i];
//	printf("%d\n",rt);
//	rep(i,1,mxdep) printf("%lld %d\n",f[i],son[i]);
	ans2=min(ans2,f[1]);
}
int main(){
	ans2=1e18;
    scanf("%d",&n);
    rep(i,1,n-1){
    	scanf("%d%d",&x,&y);
    	g[x].push_back(n+i);
    	g[n+i].push_back(x);
    	g[y].push_back(n+i);
    	g[n+i].push_back(y);
	}
	d[1]=1; dfs(1);
	rep(i,1,2*n) if (d[i]>d[s]) s=i;
	rep(i,1,2*n) d[i]=fa[i]=0;
	d[s]=1; dfs(s);
	rep(i,1,2*n) if (d[i]>d[t]) t=i;
	dia=d[t];
//	printf("%d %d\n",s,t);
//	rep(i,1,2*n) printf("%d ",fa[i]); puts("");
	ans1=((dia+1)/2+1)/2;
	nrt=t;
	int cnt=(dia+1)/2;
	while (--cnt) nrt=fa[nrt];
	if (((dia+1)/2)&1){
		rt=nrt; go();	
		for (int j=0;j<(int)g[nrt].size();j++){
			rt=g[nrt][j];
			go();
		}
	}
	else rt=nrt,go();
	printf("%d %lld\n",ans1,ans2);
	
	

    return 0;
}

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

int main ()
{
  int w, n, a, b, c;
  int r[30];
  cin >> w >> n;
  
  for (int i = 0; i <= w; i++){
    r[i] = i + 1;
  }

  for (int i = 0; i < n; i++){
    scanf("%d,%d", &a, &b);
    c = r[a - 1];
    r[a - 1] = r[b - 1];
    r[b - 1] = c;
  }

  for (int i = 0; i < w; i++){
    cout << r[i] << endl;
  } 

  return 0;
}

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

int main() {
  int A, B, m, c = 0;
  cin >> A >> B;
  for (int n = A; n <= B; n++) {
    if (n >= 10000) {
      if ((n % 10 == n / 10000) && ((n / 10) % 10 == (n / 1000) % 10)) {
        c++;
      }
    } else if (n >= 1000) {
      if ((n % 10 == n / 1000) && ((n / 10) % 10 == (n / 100) % 10)) {
        c++;
      }
    } else if (n >= 100) {
      if (n % 10 == n / 100) {
        c++;
      }
    } else if (n >= 10) {
      if (n % 10 == n / 10) {
        c++;
      }
    } else {
      c++;
    }
  }
  cout << c << endl;
}

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

int cnt[30];

int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	for(int i=0;i<int(s.size());i++){
		cnt[s[i]-'A']++;
	}
	int sum=0;
	for(int i=0;i<30;i++){
		if(cnt[i]==2) sum++;
	}
	if(sum==2) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256