akhauriyash/Code-Regression huggingface dataset:
private class A {
    fun solve() {
        val c = nextToken()[0]
        if (c in 'a'..'z') {
            println('a')
        } else {
            println('A')
        }
    }

    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = A().solve()

}


Measured memory_bytes: 36504
"""
根付き木を構成する
"""
class Node:
    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.children = []

#空の木の構成
#node_idをインデックスに持たせる
n = int(input())
nodes = []
for _ in range(n):
    node = Node()
    nodes.append(node)

def getDepth(node_id):
    d = 0
    target = nodes[node_id]
    while target.parent != -1:
        d += 1
        tmp_num = target.parent
        target = nodes[tmp_num]
    return d

def getParent(node_id):
    target = nodes[node_id]
    return target.parent

def getChildren(node_id):
    target = nodes[node_id]
    return target.children

def getType(node_id):
    target = nodes[node_id]
    if target.parent == -1:
        return 'root'
    elif len(target.children) == 0:
        return 'leaf'
    else:
        return 'internal node'


#木の構成
for i in range(n):
    l = list(map(int, input().split()))
    node_id = l[0]
    num = l[1]

    for j in range(num):
        try:
            child = l[2+j] #l[2+j]というのは子供の番号
            nodes[node_id].children.append(child) 
            nodes[child].parent = node_id #子一人当たり親は必ず一人
        except:
            pass
    else:
        pass #子がいないとき


for i in range(n):
    ans = 'node '+str(i)+': parent = '+str(getParent(i))+', ' +\
    'depth = '+str(getDepth(i))+', '+getType(i)+', '+str(getChildren(i))
    print(ans)
    



Measured memory_bytes: 40008
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int maxlim = 1e18;
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        int ans = n % k;
        ans = min(ans, abs(k - ans));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <inttypes.h>

int32_t n;
uint32_t a[1000000];
uint32_t b[1000000];

int main(void) {
	int32_t i;
	int32_t bs, be;
	if (scanf("%"SCNd32, &n) != 1) return 1;
	for (i = 0; i < n; i++) {
		if (scanf("%"SCNu32, &a[i]) != 1) return 1;
	}
	bs = be = (sizeof(b) / sizeof(*b)) / 2;
	for (i = 0; i < n; i++) {
		if (i % 2 == 0) {
			b[be++] = a[i];
		} else {
			b[--bs] = a[i];
		}
	}
	if (n % 2 == 0) {
		for (i = bs; i < be - 1; i++) printf("%"PRIu32" ", b[i]);
		printf("%"PRIu32"\n", b[be - 1]);
	} else {
		for (i = be - 1; i > bs; i--) printf("%"PRIu32" ", b[i]);
		printf("%"PRIu32"\n", b[bs]);
	}
	return 0;
}


Measured memory_bytes: 6656
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-9;

int getNum(int num){
	int a = num * num;
	int res=0;
	a/=100;
	for(int i=0;i<4;i++){
		res += (a % 10) * pow(10.0,i);
		a/=10;
	}

	return res;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int num;
			scanf("%d",&num);
			printf("Case %d:\n",i+1);
			for(int j=0;j<10;j++){
				num = getNum(num);
				printf("%d\n",num);
			}
		}
	}
}

Measured memory_bytes: 0
def sieve(n):
    s = [True for _ in range(n + 1)]
    for i in range(2, int(n ** 0.5) + 1):
        if s[i]:
            for j in range(i * 2, len(s), i):
                s[j] = False
    return (i for i in range(n + 1) if s[i] and i > 1)


def main():
    x = int(input())

    p = list(sieve(x * 2))
    for a in p:
        if a >= x:
            print(a)
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin >> n >> t;
  int ans=1001;
  vector<int> ti(n),co(n);
  for(int i=0;i<n;i++)
    cin >> co[i] >> ti[i];
  for(int i=0;i<n;i++){
    if(ti[i]<=t){
      ans=min(ans,co[i]);
    }
  }
  if(ans==1001)
    cout << "TLE" << endl;
  else
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, long long> pii;
const int maxn = 100005;
int n, m;
vector<pii> jobs;
set<int> f;

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

	int a;
	long long b;
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		if(a <= m){
			jobs.push_back({b, a});
		}
	}

	sort(jobs.begin(), jobs.end(), greater<pii>());

	for(int i = 1; i <= m; i++){
		f.insert(i);
	}

	int ans = 0;
	for(auto it : jobs){
		auto fit = f.upper_bound(it.second);
		if(f.find(it.second) != f.end()){
			ans += it.first;
			f.erase(it.second);
		}
		else if(fit != f.end()){
			ans += it.first;
			f.erase(fit);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6512
x = int(input())

if 400 <= x <= 599:
    print("8")
elif 600 <= x <= 799:
    print("7")
elif 800 <= x <= 999:
    print("6")
elif 1000 <= x <= 1199:
    print("5")
elif 1200 <= x <= 1399:
    print("4")
elif 1400 <= x <= 1599:
    print("3")
elif 1600 <= x <= 1799:
    print("2")
elif 1800 <= x <= 1999:
    print("1")

Measured memory_bytes: 9168
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := readInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = readInt()
	}

	sort.Ints(L)
	result := 0
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			result += sort.SearchInts(L[j+1:], L[i]+L[j])
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 998244353

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> D;
    inputVector(D, N);

    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    map<int, int> m;
    for (int d : D) {
        m[d]++;
    }

    if (m[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    int ret = 1;
    for (auto &pr : m) {
        int num = pr.first;
        int cnt = pr.second;
        if (num == 0) continue;
        if (m.find(num - 1) == m.end()) {
            cout << 0 << endl;
            return 0;
        }
        int prevCnt = m[num - 1];
        rep(i, cnt) {
            ret *= prevCnt;
            ret %= MOD;
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
const int maxn=200007;
char a[maxn];
char b[maxn];
int main(){
	int n,m;
	scanf("%d%d%s%s",&n,&m,a,b);
	int g=__gcd(n,m);
	bool ok=true;
	for(int i=0;i<g;i++){
		if(a[n/g*i]!=b[m/g*i])ok=false;
	}
	if(ok)printf("%lld\n",1ll*n*m/g);
	else printf("-1\n");
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  string s, p;
  cin >> s >> p;
  string ss = s + s;
  cout << (ss.find(p) == string::npos ? "No" : "Yes") << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3232
// 1_5_B

#include <iostream>
using namespace std;

int main(){
  int H, W;

  while(true){
    cin >> H >> W;
    if(H == 0 && W == 0) return 0;
    for(int i = 0; i < H; i++){
      if(i == 0 || i == H - 1){
        for(int j = 0; j < W; j++){
          cout << '#';
        }
        cout << endl;
      } else{
        cout << '#';
        for(int j = 1; j < W-1; j++){
          cout << '.';
        }
        cout << '#' << endl;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int m1, d1, m2, d2;

void input() {
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  ;
  ;
}
void solve() {
  if (m1 != m2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
n = int(input())
b = [int(input()) for i in range(n)]

chk = [[False for i in range(3)] for j in range(3)]

for i in range(n):
	x = b[i]
	for j in range(3):
		for k in range(3):
			if a[j][k] == x:
				chk[j][k] = True

flg = False
if chk[0][0] and chk[0][1] and chk[0][2]:
	flg = True
if chk[1][0] and chk[1][1] and chk[1][2]:
	flg = True
if chk[2][0] and chk[2][1] and chk[2][2]:
	flg = True
if chk[0][0] and chk[1][0] and chk[2][0]:
	flg = True
if chk[0][1] and chk[1][1] and chk[2][2]:
	flg = True
if chk[0][2] and chk[1][2] and chk[2][2]:
	flg = True
if chk[0][0] and chk[1][1] and chk[2][2]:
	flg = True
if chk[0][2] and chk[1][1] and chk[2][0]:
	flg = True

if flg:
	print ("Yes")
else:
	print ("No")

Measured memory_bytes: 3188
k, n = map(int, input().split())
a = list(map(int, input().split()))

diff = (k - a[-1]) + a[0]
dmax = diff
for i in range(1, n):
   diff = a[i] - a[i-1]
   dmax = max(dmax, min(diff, k - diff))

print(k - dmax)


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin >> S;
  lint N = S.size();
  vector<lint> SA(N+1);
  REP(i, N) SA[i+1] = SA[i] + (S[i]=='A' ? 1 : 0);
  vector<lint> SC(N+1);
  REP(i, N) SC[i+1] = SC[i] + (S[i]=='C' ? 1 : 0);
  vector<lint> SQ(N+1);
  REP(i, N) SQ[i+1] = SQ[i] + (S[i]=='?' ? 1 : 0);
  lint Q = 0;
  REP(i, N) if(S[i] == '?') Q++;
  lint ans = 0;
  FOR(i, 1, N-1) {
    if(S[i] == 'B') {
      ans = (ans + SA[i] * (SC[N]-SC[i+1]) % MOD * power(3, Q, MOD) % MOD) % MOD;
      ans = (ans + SQ[i] * (SC[N]-SC[i+1]) % MOD * power(3, Q-1, MOD) % MOD) % MOD;
      ans = (ans + SA[i] * (SQ[N]-SQ[i+1]) % MOD * power(3, Q-1, MOD) % MOD) % MOD;
      ans = (ans + SQ[i] * (SQ[N]-SQ[i+1]) % MOD * power(3, Q-2, MOD) % MOD) % MOD;
    } else if(S[i] == '?') {
      ans = (ans + SA[i] * (SC[N]-SC[i+1]) % MOD * power(3, Q-1, MOD) % MOD) % MOD;
      ans = (ans + SQ[i] * (SC[N]-SC[i+1]) % MOD * power(3, Q-2, MOD) % MOD) % MOD;
      ans = (ans + SA[i] * (SQ[N]-SQ[i+1]) % MOD * power(3, Q-2, MOD) % MOD) % MOD;
      ans = (ans + SQ[i] * (SQ[N]-SQ[i+1]) % MOD * power(3, Q-3, MOD) % MOD) % MOD;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3024
#include <cstdio>
#include <cstring>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;

int main(){
	int n, m, k;
	cin >>n;
	m = n;
	int sum = 0;
	while (n){
		sum = sum + n % 10;
		n = n / 10;
	}
	if (m % sum == 0) 
		cout <<"Yes\n";
	else cout <<"No\n";

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n;
int ans=0;
string s[100010];
map<string,int>mp;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>s[i];
		sort(all(s[i]));
		mp[s[i]]++;
	}
	for(pair<string,int> i:mp){
		ans+=i.se*(i.se-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 18176
import numpy as np
n, ma, mb = map(int, input().split())
r = 10 * n + 6
inf = 10**5
dp = np.full((n+1, r, r), inf)
dp[0][0][0] = 0
for i in range(n):
    a, b, c = map(int, input().split())
    dp[i+1][a:, b:] = np.minimum(
        dp[i][:r-a, :r-b] + c, dp[i][a:, b:]
    )
    dp[i+1] = np.minimum(dp[i+1], dp[i])

ans = inf
x, y = 0, 0
while True:
    x += ma
    y += mb
    if x < r and y < r:
        ans = min(ans, dp[n][x][y])
    else:
        break
if ans == inf:
    print(-1)
else:
    print(int(ans))

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

int main() {
  ll a,b,ab,na,nb;
  cin >> a >> b >> ab >> na >> nb;
  if(a+b<ab*2) {
    cout << a*na+b*nb << endl;
  }
  else {
    ll ans=0;
    ll temp=min(na,nb);
    ans+=temp*ab*2;
    na-=temp;
    nb-=temp;
    if(a<2*ab) {
      ans+=na*a;
    }
    else {
      ans+=na*ab*2;
    }
    if(b<2*ab) {
      ans+=nb*b;
    }
    else {
      ans+=nb*ab*2;
    }
    cout << ans << endl;
  }
}

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

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

	int a[n+5][3];

	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}

	int dp[3][n+1];

	memset(dp,0,sizeof(dp));

	for(int i=0;i<3;i++){
		dp[i][0]=a[0][i];
	}

	for(int i=1;i<n;i++){
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i][0];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+a[i][1];
		dp[2][i]=max(dp[1][i-1],dp[0][i-1])+a[i][2];
	}


	int res=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
	cout<<res<<endl;
	return 0;
}
		


Measured memory_bytes: 5968
#include <iostream>
#include <set>
using namespace std;
int main( void) {
	int n; cin >> n;
	set <int> s;
	for (int i = 0;i < n; i++) {
		int a; cin >> a;
		s.insert(a);
	}
	cout << (int)s.size() << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAX_V 1000
#define INF 1e16
#define cost first
#define to second
typedef long long ll;
typedef pair<ll,int> edge;
vector<edge> g[MAX_V];
ll dp[MAX_V];
bool usedV[MAX_V];
map<pair<int,int>,bool> usedE;

int main(void){
    int N,M;
    cin>>N>>M;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        g[a].push_back({c,b});
    }

    priority_queue<edge,vector<edge>> pq;
    pq.push({dp[0]=0,0});
    while(pq.size()){
        edge pr=pq.top(); pq.pop();
        int v=pr.second;
        if(usedV[v] && pr.first < dp[v]) continue;
        for(edge e : g[v]){
            if(dp[e.to] >= INF) continue;
            if(!usedV[e.to] || dp[e.to] < dp[v]+e.cost){
                dp[e.to] = (usedE[{v,e.to}] ? INF : dp[v]+e.cost);
                pq.push({dp[e.to],e.to});
                usedV[e.to] = true;
                usedE[{v,e.to}] = true;
            }
        }
    }
    if(dp[N-1] >= INF) cout<<"inf"<<endl;
    else cout<<dp[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 384
a,b=map(int,input().split())
a-=1
la,lb=[a%2**i for i in range(41)],[b%2**i for i in range(41)]
ans=0
for i in range(2,41):
    na,nb=max(la[i]-2**(i-1)+1,0),max(lb[i]-2**(i-1)+1,0)
    if (max(na,nb)-min(na,nb))%2==1:
        ans+=2**(i-1)
c=lb[2]-la[2] if lb[2]-la[2]>=0 else lb[2]-la[2]+4
if la[1]==0 and (c==1 or c==2):
    ans+=1
elif la[1]==1 and (c==2 or c==3):
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
int a[114514], cnt[114514];
signed main() {
	int n, ans = 0, inf = -1e9;
	cin >> n;
	rep(i, n)cin >> a[i];
	for (int i = 0; i < 114514; i++)cnt[i] = 0;
	for (int i = 0; i < n; i++)cnt[a[i] - 1]++;
	sort(a, a + n);
	for (int i = a[0]; i <= a[n - 1]; i++) {
		if (inf < cnt[i - 1] + cnt[i] + cnt[i + 1])inf = cnt[i - 1] + cnt[i] + cnt[i + 1];
	}
	cout << inf << endl;
	getchar(); getchar(); return 0;
}

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

int main(){
    long long n,ans = 1;
    map<int,long long> prime;
    cin >> n;
    for(int num = n;2 <= num;num--){
        int buf = num;
        for(int i = 2;i * i<= n;i++){
            int count = 0;
            while(buf % i == 0)buf /= i,count++;
            prime[i] += count;
        }
        if(buf != 1)prime[buf]++;
    }
    for(auto pri : prime){
        ans = ans * (pri.second + 1) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
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 K = sc.nextInt();
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        int maxDeffrence = 0;
        int[] reverseIndex = new int[2];

        for (int i = 0; i < N; i++) {
            list.add(sc.nextInt());
            if (i > 0) {
                int oldMaxDeffrence = maxDeffrence;
                maxDeffrence = Math.max(maxDeffrence, list.get(i) - list.get(i - 1));
                if (maxDeffrence > oldMaxDeffrence) {
                    reverseIndex[0] = i - 1;
                    reverseIndex[1] = i;
                }
            }
        }
        
        if(maxDeffrence <= list.get(0) + K - list.get(list.size()-1)){
            System.out.println(list.get(list.size()-1) - list.get(0));
        } else {
            int lap = list.get(reverseIndex[0]) + K - list.get(reverseIndex[1]);
            System.out.println(lap);
        }
    }
}

Measured memory_bytes: 84416
N,W = map(int, input().split())
L = []
for i in range(N):
    L.append([int(a) for a in input().split()])
    
dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    for j in range(1, W+1):
        if j < L[i][1]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-L[i][1]]+L[i][0])
            
print(dp[N][W])


Measured memory_bytes: 25956
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
} 
signed main(){
    fast();
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i=0,x, y; i<n; i++){
        cin >> x >> y;
        if(x*x + y*y <= d*d)    ans++;
    }
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

double abso(double n){
	if(n<0) return n*=-1;
	return n;
}

int main(){
	int q;
	double x;
	while(cin>>q,q!=-1){
		x = (double)q/2.0;
		while(abso(x*x*x-q)>=0.00001*q){
			x = x-((x*x*x-q)/(3*x*x));
		}
		printf("%.6lf\n",x);
	}
	return 0;
}

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


int main(){

  string s;
  cin >> s;

  int ans = s.size();
  for(int i = 1; i < s.size(); i++){
    if(s[i] != s[i - 1])
      ans = min(ans, max(i, (int)s.size() - i));
  }

  cout << ans << '\n';


}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int fie[152][1002][78];
int main(){
    while(1){
        int M,N;
        cin>>M>>N;
        if(M==0&&N==0)break;
        int lis[154][1002];
        for(int i=0;i<154;i++){
            for(int j=0;j<1002;j++){
                if(i!=0&&i!=M+1)lis[i][j]=-1;
                else lis[i][j]=0;
            }
        }
        for(int i=0;i<152;i++){
            for(int j=0;j<1002;j++){
                for(int k=0;k<78;k++){
                    if(i!=0||k!=0)fie[i][j][k]=2000000000;
                    else fie[i][j][k]=0;
                }
            }
        }
        for(int i=0;i<M;i++){
            int a;
            cin>>a;
            for(int j=1;j<=a;j++){
                int b,c;
                cin>>b>>c;
                lis[i+1][b]=c;
            }
        }
        for(int i=0;i<=M;i++){
            for(int j=0;j<1002;j++){
                for(int k=0;k<76;k++){
                    if(fie[i][j][k]<2000000000){
                        for(int l=0;l<1002;l++){
                            if(lis[i+1][l]!=-1)
                                fie[i+1][l][k]=min(fie[i+1][l][k],fie[i][j][k]+(lis[i][j]+lis[i+1][l])*(int)fabs(j-l));
                            if(lis[i+2][l]!=-1)fie[i+2][l][k+1]=min(fie[i+2][l][k+1],fie[i][j][k]+(lis[i][j]+lis[i+2][l])*(int)fabs(j-l));
                        }
                    }
                }
            }
        }
        int ans=2000000000;
        for(int j=0;j<1002;j++){
            for(int k=0;k<76;k++){
                if(k<=N)ans=min(ans,fie[M+1][j][k]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 48164
import math

k = int(input())
k_range = range(1, k + 1)

sum_gcd = 0
for l in k_range:
    temp = 0
    for m in k_range:
        temp = math.gcd(l, m)
        for n in k_range:
            sum_gcd += math.gcd(n, temp)

print(sum_gcd)

Measured memory_bytes: 9068
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*約数*/vector<ll>div(ll a){vector<ll>b;ll i;rep(i,1,a){if(!a%i)push(b,a);}return b;}
/*円周率*/ double pi=acos(-1);
llfor;///////////////////////////////////////////////////////////
int main(){
 double a,b,x;
 sc(a);sc(b);sc(x);
 ll v=a*a*b;
 double ans;
 if(v<=2*x){
  ans=atan(2*(v-x)/a/a/a)*180/pi;
 }
 else{
  ans=atan(a*b*b/(2.00000*x))/pi*180;
 }
 printf("%.10lf\n",ans);
return 0;}



Measured memory_bytes: 3968
#include<stdio.h>
int main(void)
{
    int i,A,B,C,D,a,b,c,d,e,f,g,h,a1;
	while(1){
	scanf("%d",&a1);
	if(a1==0) break;
	for(i=0;i<a1;i++){
	A=0; B=0;
	C=0; D=0;
	scanf("%d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
	A=a*e-(b*f)-(c*g)-(d*h);
	B=a*f+b*e+c*h-(d*g);
	C=a*g+c*e+d*f-(b*h);
	D=a*h+b*g+d*e-(c*f);
	printf("%d %d %d %d\n",A,B,C,D);
	}
	}
	return 0;
	}

Measured memory_bytes: 600
def rainyseason(S):
    days = 0
    max_days = 0
    flag = 0
    for i in range(len(S)):
        if S[i] == 'R':
            days += 1
            flag = 1
        elif S[i] == 'S' and flag == 1:
            if days > max_days:
                max_days = days
                days = 0
                flag = 0
    if days > max_days:
        max_days = days
    return max_days

if __name__ == '__main__':
    S =str(input())
    print(rainyseason(S))

Measured memory_bytes: 9128
N=int(input())
X=[]
for i in range(N):
	x, L = map(int, input().split())
	X.append([x-L, x+L])
from operator import itemgetter

W=sorted(X, key=itemgetter(1))

ans=0
last=-float("inf")

for s, e in W:
	if s>=last:
		last=e
		ans+=1
print(ans)

Measured memory_bytes: 26412
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int n = 0,w = 0,s = 0,e = 0;
    for(auto c:S){
        if(c == 'N')n++;
        if(c == 'W')w++;
        if(c == 'S')s++;
        if(c == 'E')e++;
    }
    if(((n == 0 && s == 0) || (n >= 1 && s >= 1 )) && 
    ((w == 0 && e == 0) || (w >= 1 && e >= 1)))cout << "Yes" << endl;
    else    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		int l = str.length();
		int l1=0;
		for(int i=0;i<l;i++) {
			l1 += str.charAt(i) =='1' ? 1 : 0;
		}
		System.out.println(l-Math.abs(l-2*l1));
	}

}


Measured memory_bytes: 28228
#include<bits/stdc++.h>
#define For(i,l,r) for(int i=(l),i##end=(r);i<=i##end;i++)
#define Fordown(i,r,l) for(int i=(r),i##end=(l);i>=i##end;i--)
using namespace std;
typedef long long ll;
const int INF=1e9;
const int N=1e5+10;
ll x[N],v[N],sum[N],Max[N][20],Log[N];
inline ll read(){
	ll _=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))_=(_<<3)+(_<<1)+ch-'0',ch=getchar();
	return _*flag;
}
inline ll Query(ll l,ll r){
	ll val=Log[r-l+1];
	return max(Max[l][val],Max[r-(1<<val)+1][val]);
}
int main(){
	ll n=read(),c=read();
	For(i,2,n+2)Log[i]=Log[i>>1]+1;
	For(i,1,n)x[i]=read(),v[i]=read();
	x[n+1]=c,v[n+1]=0;
	For(i,1,n)sum[i]=sum[i-1]+v[i],Max[i][0]=sum[i]-x[i];
	For(i,1,18)For(j,0,n-(1<<i)+2)Max[j][i]=max(Max[j][i-1],Max[j+(1<<(i-1))][i-1]);
	ll ans=0;
	For(i,1,n+1){
		ll val=Query(0,i-1);
		if(val==0)ans=max(ans,sum[n]-sum[i-1]-(c-x[i]));
		else ans=max(ans,sum[n]-sum[i-1]-(c-x[i])*2+val);
	}
	memset(sum,0,sizeof(sum));
	Fordown(i,n,1)sum[i]=sum[i+1]+v[i],Max[i][0]=sum[i]-(c-x[i]);
	For(i,1,18)For(j,0,n-(1<<i)+2)Max[j][i]=max(Max[j][i-1],Max[j+(1<<(i-1))][i-1]);
	For(i,0,n){
		ll val=Query(i+1,n+1);
		if(val==0)ans=max(ans,sum[1]-sum[i+1]-x[i]);
		else ans=max(ans,sum[1]-sum[i+1]-x[i]*2+val);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 18944
#include <stdio.h>

int main(void)
{
	int a[5];
	int memo[13];
	int i, j;
	int flag;
	
	while (scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4]) != EOF){
		flag = 0;
		for (i = 0; i < 13; i++){
			memo[i] = -1;
		}
		
		for (i = 0; i < 5; i++){
			if (memo[a[i] - 1] == -1){
				memo[a[i] - 1] += 2;
			}
			else {
				memo[a[i] - 1]++;
			}
		}
		
		for (i = 0; i < 13; i++){
			if (memo[i] == 4){
				printf("four card\n");
				flag = 1;
			}
		}
		
		if (flag == 1){
			continue;
		}
		
		for (i = 0; i < 13; i++){
			if (memo[i] == 3){
				for (j = 0; j < 13; j++){
					if (memo[j] == 2){
						printf("full house\n");
						flag = 1;
					}
				}
				if (flag == 0){
					printf("three card\n");
					flag = 1;
				}
				else {
					break;
				}
			}
		}
		
		if (flag == 1){
			continue;
		}
		
		for (i = 0; i < 10; i++){
			if (memo[i % 13] + memo[(i + 1) % 13]+ memo[(i + 2) % 13] + memo[(i + 3) % 13] + memo[(i + 4) % 13] == 5){
				printf("straight\n");
				flag = 1;
			}
		}
		
		if (flag == 1){
			continue;
		}
		
		for (i = 0; i < 13; i++){
			if (memo[i] == 2){
				for (j = 0; j < 13; j++){
					if (i != j && memo[j] == 2){
						printf("two pair\n");
						flag = 1;
					}
				}
				if (flag == 0){
					printf("one pair\n");
					flag = 1;
				}
				else {
					break;
				}
			}
		}
		
		if (flag == 0){
			printf("null\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int n,x;
	while(cin >> n >> x)
	{
		if(n == 0 && x == 0) break;

		int count = 0;
		REP(i,1,n-1)
		{
			REP(j,i+1,n)
			{
				REP(k,j+1,n+1)
				{
					if(i+j+k == x) count++;
				}
			}
		}

		cout << count << endl;
	}
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int h, w;
    cin >> h >> w;
    vstr a(h);
    rep(i, h) cin >> a[i];

    qpint q;
    int dist[1005][1005];
    arrayFill(dist, -1);
    rep(i, h) rep(j, w)
    {
        if (a[i][j] == '#')
        {
            dist[i][j] = 0;
            q.emplace(i, j);
        }
    }

    vint dx{1, 0, -1, 0};
    vint dy{0, 1, 0, -1};

    while (!q.empty())
    {
        int x = q.front().second;
        int y = q.front().first;
        q.pop();

        rep(i, 4)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (nx >= 0 && ny >= 0 && nx < w && ny < h && dist[ny][nx] == -1)
            {
                dist[ny][nx] = dist[y][x] + 1;
                q.emplace(ny, nx);
            }
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w)
    {
        ans = max(ans, dist[i][j]);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
    int n;
    cin >> n;
    bool cea = true;
    for(int i=1;i<=n;i++){
      double che = i*1.08;
      int ans = che;
      if(ans==n){
        cout <<i<<endl;
        cea = false; 
      }
    }
    if(cea)cout <<":("<<endl;
 }


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

int main() {
  int h, w;
  cin >> h >> w;
  string board[50];
  for (int i = 0; i < h; i++) cin >> board[i];

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

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (board[i][j] == '#') continue;
      
      int num = 0;
      for (int d = 0; d < 8; d++){
	int ni = i + dx[d];
	int nj = j + dy[d];
	if (ni < 0 or h <= ni) continue;
	if (nj < 0 or w <= nj) continue;
	if (board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < h; i++) cout << board[i] << endl;

  return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop i arr g =
        if i = n then (
            let s = Array.fold_left (fun acc v -> if v > 0 then acc + 1 else acc) 0 arr in
            let mi = if s = 0 then 1 else s in
            let mx = s + g in
            Printf.printf "%d %d\n" mi mx
        ) else (
            if a.(i) < 3200 then (
                let () = arr.(a.(i) / 400) <- arr.(a.(i) / 400) + 1 in
                loop (i + 1) arr g 
            ) else loop (i + 1) arr (g + 1)
        )
    in
    loop 0 (Array.make 8 0) 0
)

Measured memory_bytes: 3784
using System;
using System.Linq;
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] l = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(l);
        Array.Reverse(l);
        long ans = 0;
        for (int i = 1 ; ;i += 2){
            try{ans += l[i];}
            catch{Console.WriteLine(ans); break;}
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>


int main()
{
    long N;
    std::cin >> N;
    std::vector<long> X;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        X.push_back(temp);
    }
    std::sort(X.begin(),X.end());

    long temp;
    long min;
    long P;
    for(long i=1; i<=100;i++){
        P=i;
        temp=0;
        for(long j=0; j<N; j++){
            temp+=(X[j]-P)*(X[j]-P);
        }
        if(i==1){
            min=temp;
        }else{
            if(temp<min){
                min=temp;
            }
        }
    }

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String input2 = sc.nextLine();
        int len = input2.length();
        int input = Integer.parseInt(input2);
        int judge [] = new int[len];
        for(int i = 0 ; i<len; i++){
            judge[i]=input%10;
            input = input/10;
        }
        for(int i = len-1 ; i>=0 ; i--){
            System.out.print(10-judge[i]);
        }
    //    System.out.print("1");
    //    System.out.print("2");
    }
}

Measured memory_bytes: 21844
import numpy as np
import time
import random
import collections
import bisect  

start = time.time()

def insert(list, n): 
    bisect.insort(list, n)  
    return list

def read_input():
  D = int(input())
  c = list(map(int, input().split()))
  s = [list(map(int, input().split())) for _ in range(D)]
  return D, c, s
D, c, s = read_input()

tests = [int(input()) - 1 for _ in range(D)]
M = int(input())
d = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]

c = np.array(c)
s = np.array(s)
#tests = np.argmax(s, axis=1)

def get_dates_for_tests(tests):
  dates_for_tests = [list([-1]) for _ in range(26)]
  for i, t in enumerate(tests):
    dates_for_tests[t].append(i)
  for t in range(26):
    dates_for_tests[t].append(D)
  return dates_for_tests

dates_for_tests = get_dates_for_tests(tests)

def get_score(tests):
  dates_for_tests = get_dates_for_tests(tests)
  score = 0
  d = np.zeros(26, dtype=np.int64)
  for selected, S in zip(tests, s):
    d += 1
    d[selected] = 0
    score += S[selected] - (c * d).sum()
  return score

def score_diff(date, test):
  #print(date, test)
  before = tests[date]
  if test == before:
    return 0, None, None
  pos_diff = s[date, test] - s[date, before]
  new_index = bisect.bisect_left(dates_for_tests[test], date, 1)
  new_diff = c[test] * (dates_for_tests[test][new_index] - date) * (date - dates_for_tests[test][new_index-1])

  old_index = bisect.bisect_left(dates_for_tests[before], date, 1)
  #print(c[test], dates_for_tests[test])
  #print(c[before], dates_for_tests[before])
  old_diff = c[before] * (dates_for_tests[before][old_index+1] - date) * (date - dates_for_tests[before][old_index-1])
  
  total_diff = pos_diff + new_diff - old_diff
  #print(test, total_diff, pos_diff, new_diff, -old_diff)
  return total_diff, new_index, old_index

current_score = get_score(tests)
#print(d)
for date, test in d:
  total_diff, new_index, old_index= score_diff(date, test)
  current_score += total_diff
  del dates_for_tests[tests[date]][old_index]
  insert(dates_for_tests[test], date)
  tests[date] = test
  
  print(current_score)

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

long long n;
vector<long long> a, ans;

void solve();

int main() {
  cin >> n;
  a.resize(n);
  ans.assign(n, 0);
  for(int i = 0; i < n; ++i) cin >> a[i];
  solve();
  for(int i = 0; i < n; ++i) {
    if(i != 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

void solve() {
  long long sum = 0;
  for(int i = 0; i < n; ++i)
    if(i % 2)
      sum -= a[i];
    else
      sum += a[i];
  ans[0] = sum;
  for(int i = 0; i < n; ++i) {
    ans[(i + 1) % n] = (a[i] - ans[i] / 2) * 2;
  }
}


Measured memory_bytes: 2944
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 14:09:17 2019

@author: Yamazaki Kenichi
"""
import sys
sys.setrecursionlimit(10**6)

n,m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]
q = int(input())
Q = [list(map(int,input().split())) for i in range(q)]

class UnionFind(object):
    def __init__(self,size):
        self.table = [-1 for i in range(size)]
    def find(self,x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        else:
            return False
    def check(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            return False
        else:
            return True

uf = UnionFind(n)
for c in A:
    uf.union(c[0],c[1])
for c in Q:
    if uf.check(c[0],c[1]):
        print('yes')
    else:
        print('no')


Measured memory_bytes: 26108
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, K, i, j, sum = 0;
	scanf("%d%d", &N, &K);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
		B[i] = 0;
	}
	sort(A, N);
	for(i = 1, B[0] = 1, j = 0; i < N; i++){
		if(A[i] != A[i - 1]){
			j++;
		}
		B[j]++;
	}
	j++;
	sort(B, j);
	if(j <= K){
		printf("0\n");
	}
	else{
		for(i = 0; i < j - K; i++){
			sum += B[i];
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 2560
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 11/20/2018, 11:09:14 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  string S[3];
  for (auto i = 0; i < 3; i++)
  {
    cin >> S[i];
  }
  for (auto i = 0; i < 3; i++)
  {
    cout << (char)(S[i][0] - 'a' + 'A');
  }
  cout << endl;
}

Measured memory_bytes: 256