akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]

def solve(a):
    s=set()
    for i in a:
        s.add(i)
    s=sorted(list(s))[::-1]
    L=1010
    k=[0]*(L)
    ak=[0]
    for i in a:
        k[i]+=1
    for i in range(L):
        ak.append(ak[-1]+k[i])
    ans,a1,a2,a3,a4=0,0,0,0,0
    un=len(s)
    for i in range(un):
        c=s[i]
        if k[c]>=3:
            a1+=k[c]*(k[c]-1)*(k[c]-2)//6
        if k[c]>=2:
            a2+=ak[c]*k[c]*(k[c]-1)//2
        for j in range(i+1,un):
            sc=s[j]
            a3+=(1 if 2*sc>c else 0)*k[c]*k[sc]*(k[sc]-1)//2
            mm=c-sc+1
            if mm<0:
                continue
            elif mm>sc:
                break
            else:
                a4+=k[c]*k[sc]*(ak[sc]-ak[mm])
            
    ans=a1+a2+a3+a4
    return ans,a1,a2,a3,a4

def naive(a):
    b=sorted(a)[::-1]
    n=len(b)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if b[j]+b[k]>b[i]:
                    ans+=1
    return ans

print(solve(a)[0])


Measured memory_bytes: 41072
using System;

class MyClass {
    public static void	Main()
    {
	string[] str = Console.ReadLine().Split();
	int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        Console.WriteLine("{0} {1} {2:f8}", a/b, a%b, (double)a/b);
    }   
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b) && (b == c) && (c ==a))
    cout << 1 << endl;
  else if ((a == b) || (b == c) || (c == a))
    cout << 2 << endl;
  else 
    cout << 3 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);
        String arr02[] = mylist.get(1).split(" ");

        int mysum = Integer.valueOf(arr02[0]) + Integer.valueOf(arr02[n - 1 - 1]);

        for (int i = 0; i < n - 1 - 1; i++) {
            mysum += Math.min(Integer.valueOf(arr02[i]), Integer.valueOf(arr02[i + 1]));
        }
        System.out.println(mysum);

    }

}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
  int n,a,b; cin >> n >> a >> b;
  //+e=a +a=b
  if((a+b)%2==0) cout << "Alice" << endl;
  else cout << "Borys" << endl;  
  return 0;
}

Measured memory_bytes: 3616
a = list(map(int, input().split()))

K = 0

# square
K += a[1] * 1


if a[0] >= 1 and a[3] >= 1 and a[4] >= 1:
	oddn = 0
	for e in [0, 3, 4]:
		if a[e] % 2 == 1:
			oddn += 1

	if oddn >= 2:
		K += 3
		for e in [0, 3, 4]:
			a[e] -= 1

for e in [0, 3, 4]:
	K += (a[e] // 2) * 2

print(K)


Measured memory_bytes: 3192
while(True):
    a,op,b = input().split()
    if op == '?':
        break
    ai,bi = int(a),int(b)
    
    if op == '+':
        print(ai+bi)
    elif op == '-':
        print(ai-bi)
    elif op == '*':
        print(ai*bi)
    elif op == '/':
        print(ai//bi)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    long long x=0;
    int a[n];
    priority_queue<int>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x+=a[i];
        q.push(a[i]);
    }
    for(int i=0;i<m;i++){
        x-=(q.top()+1)/2;
        q.push(q.top()/2);
        q.pop();
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],b[MAX],T[MAX],f[MAX];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)b[a[i]=read()]=i;
	for(int i=n-1;i;--i)
		if(!T[i+1])
		{
			if(b[i]>b[i+1])T[i]=1,f[i]=i+1;
			else T[i]=0;
		}
		else
		{
			if((b[f[i+1]]<b[i])+(b[i]<b[i+1])+(b[i+1]<b[f[i+1]])==2)T[i]=T[i+1],f[i]=f[i+1];
			else T[i]=T[i+1]+1,f[i]=i+1;
		}
	printf("%d\n",T[1]);
	return 0;
}


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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p); 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p); 
string to_string(const string& s) {
  return '"' + s + '"';
} 
string to_string(const char* s) {
  return to_string((string) s);
} 
string to_string(bool b) {
  return (b ? "true" : "false");
} 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
} 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef complex<ll> P;
#define real X
#define imag Y

int sign(ll x) {
  return (x >= 0 ? 1 : -1);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  const ll inf = 1e18;
  ll x, k, d;
  cin >> x >> k >> d;
  /*
    x - k * d = 0
    k <= x / d => x - k * d >= 0
   */
  ll ths = x / d, oth = ths + sign(x);
  ll thsv = x - ths * d, othv = x - oth * d;
  ll ans = inf;
  debug(ths, oth, thsv, othv);
  ans = min(ans, abs(x - sign(x) * k * d));
  if (k >= abs(ths) && (k - abs(ths)) % 2 == 0) {
    ans = min(ans, abs(thsv));
  }
  if (k >= abs(oth) && (k - abs(oth)) % 2 == 0) {
    ans = min(ans, abs(othv));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=200000+5;

int a[N];
int b[N];
vector<int> ans;

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        scanf("%d",a+i);

    for(int i=n;i;--i)
    {
        int sum=0;
        for(int j=i;j<=n;j+=i)
            sum+=b[j];
        if(sum%2!=a[i])
        {
            b[i]=1;
            ans.push_back(i);
        }
    }
    cout<<ans.size()<<endl;
    for(int i:ans)
    {
        printf("%d ",i);
    }
    return 0;
}
/*

*/


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, k, arr[200005];

int ft[2][200005];              // 1-index
int ls(int x){
	return (x & (-x));
}
// N means the largest possible index you need for the fenwick!! Refer to flowering for more.
void update(int x, int l, int r, int v){ // Updates from l to r inclusive
	r++;           // Update the difference at r+1 not r
	for(; l <= n; l += ls(l)) ft[x][l] += v;// Add v to the diff at l
	for(; r <= n; r += ls(r)) ft[x][r] -= v;// Minus v from diff at r+1
}
int query(int x, int p){                     // Returns the element at p
	int sum = 0;
	for(; p; p -= ls(p)) sum += ft[x][p];
	return sum; 
}

int main() {
	fastio; cin >> n >> k;
	FOR(i, 1, n) {
		cin >> arr[i];
		update(0, max(1, i-arr[i]), min(n, i+arr[i]), 1);
	}
	FOR(ii, 1, k) {
		int i = ii % 2;
		bool ok = true;
		FOR(j, 1, n) {
			arr[j] = query(!i, j);
			if (arr[j] != n) ok = false;
			update(i, max(1, j-arr[j]), min(n, j+arr[j]), 1);
		}
		if (ok) break;
		memset(ft[!i], 0, sizeof ft[!i]); 
	}
	FOR(i, 1, n) cout << arr[i] << " ";
}


Measured memory_bytes: 5992
W, H, N = map(int, input().split())
graph = [[1] * W for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(H):
            for j in range(x):
                graph[i][j] = 0
    if a == 2:
        for i in range(H):
            for j in range(x, W):
                graph[i][j] = 0
    if a == 3:
        for i in range(y):
            for j in range(W):
                graph[i][j] = 0
    if a == 4:
        for i in range(y, H):
            for j in range(W):
                graph[i][j] = 0
ans = sum([sum(line) for line in graph])
print(ans)


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

n, m = map(int, input().split())
lis = []
for i in range(m):
    a, b = map(int, input().split())
    lis.append([a, b])

liss = sorted(lis)
dic = {}
cnt = [0] * n

for i in range(m):
    x, y = liss[i]
    cnt[x - 1] += 1
    xx, yy, cc = str(x), str(y), str(cnt[x - 1])
    id = "0" * (6-len(xx)) + xx + "0" * (6-len(cc)) + cc
    dic[xx + "_" + yy] = id

for x, y in lis:
    xx, yy = str(x), str(y)
    print(dic[xx + "_" + yy])


Measured memory_bytes: 42104
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr double EPS = 1e-2;

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

    string a, b;
    cin >> a >> b;

    const int x = stoi(a + b);
    const double sqrtx = sqrt(x);
    const int roundsqrtx = round(sqrtx);

    const bool ans = abs(sqrtx - roundsqrtx) < EPS;
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int nDigits( int );

int main( void ) {
	int i, a[ 200 ], b[ 200 ], nData = 0;

	while ( scanf( "%d %d", a + nData, b + nData ) == 2 )
		nData++;

	for ( i = 0; i < nData; i++ )
		printf( "%d\n", nDigits( a[ i ] + b[ i ] ) );

	return 0;
}

int nDigits( int x ) {
	int d = 1;

	while ( ( x /= 10 ) > 0 )
		d++;

	return d;
}

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

int main()
{
	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;
		int a, b, A, B;
		A = 0;
		B = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			if (a > b)
				A += a + b;
			if (a < b)
				B += a + b;
			if (a == b) {
				A += a;
				B += b;
			}
		}
		cout << A << " " << B << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#if 0
2019.12.17

对于两个可以交换的点连边，那么一个联通块的点是可以任意排布顺序的。
直接连边的复杂度是 O(n^2) ，但是由于只需要关注图的连通性，可以优化建图。

首先对于颜色 C 内的点只需要对于每个点 u 考虑是否能连 k 即可，
其中 k 是颜色 C 中重量最小的点。

对于颜色不同的点，首先找到全局重量最小的点 k ，其颜色为 c[k] ，
那么对于点 u 如果 c[u] != c[k] ，只需考虑 u, k 是否能连边即可。
但这样不够，还需找到除去 c[k] 外的重量最小的点 k2 ，
对于 c[u] != c[k2] 的点 u 再考虑 u, k2 之间的连边。
#endif
#include <cstdio>
#include <vector>
#include <map>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005, mod = 1000000007;
int color[maxn], weight[maxn];
std::vector<int> con[maxn];
int min[maxn];
int fa[maxn];
std::map<int, int> map[maxn];
ll fac[maxn], ifac[maxn];

inline ll power(ll x, int k) {
	if(k < 0) k += mod - 1;
	ll res = 1;
	while(k) {
		if(k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

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

inline void merge(int x, int y) {
	/* debug("%d - %d\n", x, y); */
	x = find(x);
	y = find(y);
	fa[x] = y;
}

int main() {
	int n = read, x = read, y = read;
	weight[0] = 2000000000;

	for(int i = 1; i <= n; i ++) {
		read(color[i], weight[i]);
		con[color[i]].push_back(i);
		if(weight[i] < weight[min[color[i]]])
			min[color[i]] = i;
	}

	for(int i = 1; i <= n; i ++)
		fa[i] = i;

	int minc = 0, minc2 = 0;
	for(int c = 1; c <= n; c ++)
		if(weight[min[c]] < weight[min[minc]]) {
			minc2 = minc;
			minc = c;
		} else if(weight[min[c]] < weight[min[minc2]])
			minc2 = c;

	/* debug("%d %d\n", minc, minc2); */

	for(int c = 1; c <= n; c ++)
		for(int p : con[c])
			if(weight[p] + weight[min[c]] <= x)
				merge(p, min[c]);

	for(int c = 1; c <= n; c ++)
		for(int p : con[c]) {
			if(c != minc and weight[p] + weight[min[minc]] <= y)
				merge(p, min[minc]);
			if(c != minc2 and weight[p] + weight[min[minc2]] <= y)
				merge(p, min[minc2]);
		}

	for(int i = 1; i <= n; i ++)
		++ map[find(i)][color[i]];

	ll ans = 1;

	fac[0] = 1;
	for(int i = 1; i <= n; i ++)
		fac[i] = fac[i - 1] * i % mod;
	ifac[n] = power(fac[n], -1);
	for(int i = n; i; i --)
		ifac[i - 1] = ifac[i] * i % mod;

	for(int i = 1; i <= n; i ++)
		if(fa[i] == i) {
			int tot = 0;
			for(auto pr : map[i]) {
				tot += pr.second;
				(ans *= ifac[pr.second]) %= mod;
				/* debug("%d in %d\n", pr.second, i); */
			}
			(ans *= fac[tot]) %= mod;
		}

	printf("%lld\n", ans);
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w){
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
object Main extends App {
  import scala.io.StdIn._
  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  if ((n - 1) * (n - 2) / 2 < k) {
    println("-1")
  }else {
    var rest = (n - 1) * (n - 2) / 2 - k
    println(n - 1 + rest)
    for (i <- 1 until n) {
      println(s"$i $n")
    }
    for (i <- 1 until n; j <- 1 until i) {
      if (rest > 0) {
        println(s"$i $j")
        rest -= 1
      }
    }
  }
}


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

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

    int t = b-a;
    int res = 0;
    for(int i=1; i<t; i++) {
        res += i;
    }
    res -= a;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = map(int, input().split())

count = {}

for a in A:
    count[a] = count.get(a, 0) + 1

tmp = []
for k, v in count.items():
    tmp.append(v)

tmp = sorted(tmp)

total = 0
for i in range(len(tmp) - K):
    total += tmp[i]

print(total)

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n;
    cin >> n;

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += (n - 1) / i;
    }
    cout << ans << newl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
ll a[N],b[N],c[N];
ll ans[3010];
priority_queue<ll>q;
bool cmp(ll a,ll b){return a>b;}
int main()
{
    int x,y,z,k;
    scanf("%d%d%d%d",&x,&y,&z,&k);
    for(int i=1;i<=x;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=y;i++)scanf("%lld",&b[i]);
    for(int i=1;i<=z;i++)scanf("%lld",&c[i]);
    sort(a+1,a+1+x,cmp);
    sort(b+1,b+1+y,cmp);
    sort(c+1,c+1+z,cmp);

   for(int i=1;i<=x;i++)
    for(int j=1;j<=y;j++)
    for(int u=1;u<=z;u++)
        if(i*j*u<=k)
            q.push(a[i]+b[j]+c[u]);
        else
            break;
    while(k--)
    {
        printf("%lld\n",q.top());
        q.pop();
    }
    return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
int main(void){
    int n, k, h[1000000], i, a=0;
    
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++) scanf("%d",&h[i]);
    
    for(i=0;i<n;i++){
        if(h[i]>=k) a++;
    }
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 2052
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input()) + 1
cache = []

for i in range(1, K):
    for j in range(i, K):
        if (i == j):
            continue
        else:
            cache.append(gcd(i, j))


sum = 0
for j in range(1, K):
    for i in range(len(cache)):
        if (cache[i] == 1 or j == 1):
            sum += 1 * 2
        else:
            sum += gcd(cache[i], j) * 2
    for k in range(1, K):
        sum += gcd(j, k)

print(sum)

Measured memory_bytes: 9648
/**
*    author:  boutarou
*    created: 05.07.2020 20:43:42
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    if (n % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - n % 1000 << endl;
    
    return 0;
}

Measured memory_bytes: 3684
object Main extends App {
  override def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine.toInt

    val seq = (1 to n).map(_ => io.StdIn.readLine.split(' ').toList)

    val (taro, hanako) = solve(seq)

    println(taro + " " + hanako)

  }

  def solve(seq: Seq[List[String]]): (Int, Int) = {
    seq.map(l => (l(0) compareTo l(1)) match {
      case 0          => (1, 1)
      case n if n < 0 => (0, 3)
      case n if n > 0 => (3, 0)
    }).reduce((z, n) => (z._1 + n._1, z._2 + n._2))
  }
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c || b == c && c != a || c == a && a != b) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 998244353;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector <ll> a(n);
  for (int i = 0; i < n; i++)
   cin >> a[i];
  sort(a.begin(),a.end());
  vector <ll> b;
  for (int i = 0; i < n - 1; i++)   
    b.push_back(a[i]), b.push_back(a[i]);
  b.push_back(a[n-1]);
  ll count = 1, hap = 0;
  for (int i = b.size() - 1; i >= 0 && count < n; i--)
   count++, hap += b[i];
  cout << hap;
}

Measured memory_bytes: 9056
N=int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans=num2alpha(N)
print(ans.lower())


Measured memory_bytes: 61724
package main

import (
	"fmt"
)

func main() {
	var k int
	var s string
	fmt.Scanf("%d", &k)
	fmt.Scanf("%s", &s)

	if len(s) > k {
		fmt.Printf("%s...\n", s[:k])
	} else {
		fmt.Printf("%s\n", s)
	}
}


Measured memory_bytes: 1816
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, K;
    cin >> N >> K;

    vector<ll> A(N + 100);
    FOR(i, 1, N)
    {
        cin >> A[i];
    }

    FOR(i, K + 1, N)
    {
        ll start = A[i - K], end = A[i];
        cout << (start < end ? "Yes" : "No") << "\n";
    }

    return 0;
}


Measured memory_bytes: 4504
/*
author : seryu
title : ABC172B_"Minor Change"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
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; }

void solve()
{
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, sz(s))
	{
		if(s[i] != t[i])ans++;
	}
	cout << ans << endl;
	return;	
}

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


Measured memory_bytes: 3808
// This code Write By chtholly_micromaker(MicroMaker)
#include <cstdio>
#include <cctype>
#include <algorithm>
#define reg register
using namespace std;
const int MaxN=100001;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
int a[MaxN],f[MaxN],prayforkyoani[MaxN];
signed main(void)
{
	int n;
	reg int ans=1,chtholly=0;
	rd(n);
	for(int i=1;i<=n;++i)
		rd(a[i]);
    for(int i=1;i<=n;++i) 
    {
        f[i]=1;
        for(int j=chtholly;j;--j)
            if(a[i]<=a[prayforkyoani[j]]) 
            {
                f[i]=f[prayforkyoani[j]]+1;
                break;
            }
        chtholly=max(chtholly,f[i]);
        prayforkyoani[f[i]]=i;
        ans=max(ans,f[i]);
    }
    printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstring>

constexpr int MAX = 100;

int n, m;
double board[MAX][MAX];
double dp[MAX][MAX];

int main() {
	while (1) {
		std::cin >> m >> n;
		if (m + n == 0)
			break;
		std::memset(dp, 0, sizeof(dp));
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < m; ++j)
				std::cin >> board[i][j];
		}
		for (int i = 0; i < m; ++i)
			dp[0][i] = 1.0;

		for (int i = 1; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < m; ++k)
					dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * board[k][j]);
			}
		}
		double ans = 0;
		for (int i = 0; i < m; ++i)
			ans = std::max(ans, dp[n - 1][i]);
		std::cout << std::fixed << std::setprecision(2) << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3404
#include<iostream>
#include<map>
#include<vector>
#include<math.h>
#define ll long long
using namespace std;

int dp[100001];
void fillarray()
{
	int i;
	for(i=0;i<=100000;i++)
	dp[i] = -1;
}

int dfs(vector<int> g[] , int i)
{
	if(dp[i] >= 0)
	return dp[i];
	
	//cout<<"Current vertex = "<<i<<endl;
	if(g[i].size() == 0)
	{
		dp[i] = 0;
		return 0;
	}
	
	int size = g[i].size();
	int j,k,len,maxm = 0;
	for(j=0;j<size;j++)
	{
		
		k = g[i][j];
		//cout<<"Child = "<<k<<endl;
		len = 1 + dfs(g , k);
		maxm = max(len , maxm);
	}
	
	dp[i] = maxm;
	return maxm;
	
}


main()
{
	int n,m;
	cin>>n>>m;
	int i,j;
	
	vector<int> g[n+1];
	for(i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
	}
	
	fillarray();
	
	for(i=1;i<=n;i++)
	{
		if(g[i].size() > 0)
		dfs(g , i);
	}
	
	int maxm = 0;
	int index;
	for(i=1;i<=n;i++)
	{
		//cout<<"node = "<<i<<" :: "<<dp[i]<<endl;
		if(maxm < dp[i])
		{
			maxm = dp[i];
			index = i;
		}
	}
	//cout<<endl<<maxm<<"is maximum d : node = "<<index;
	cout<<maxm;
	
	
}

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							     \
			cout.tie(0);
#define sz(arr) ll(arr.size())

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b, const ll MOD) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
ll div_floor(ll a, ll b) { return a / b - (((a ^ b) < 0) and a % b); }
ll div_ceil(ll a, ll b) { return a / b + (((a ^ b) >= 0) and a % b); }
ll kCn(ll k, ll n, ll f[]) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }



int main() {
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	fastio;
	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		b[i] = -a[i] - i;
		a[i] = a[i] - i;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		auto up = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
		auto low = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
		ans += up - low;
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>v(n);
  rep(i,n)cin >> v[i];
  sort(all(v));
  ll tmp = 0;
  rep(i,n - k)tmp += v[i];
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <numeric>
#include<limits.h>
using namespace std;

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

int main(void) {
	int n;
	cin >> n;
	long long x, p=0, m=0, min = LLONG_MAX, sum = 0;
	bool haszero = false;
	rep(i, n) {
		cin >> x;
		sum += abs(x);
		if (x == 0)haszero = true;

		if (!haszero) {
			if (min > abs(x))min = abs(x);
			if (x > 0)p++;
			else m++;
		}

	}
	if (haszero || m%2==0)cout << sum;
	else cout << sum - 2 * min;

	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> t(n),x(n),y(n); rep(i,n) cin >> t[i] >> x[i] >> y[i];

  bool ok = true;
  if(n==1){
    int dx = x[0];
    int dy = y[0];
    int sum = dx+dy;
    if(sum!=t[0]) ok = false;
  }
  
  rep(i,n-1){
    int dx = abs(x[i+1]-x[i]);
    int dy = abs(y[i+1]-y[i]);
    int sum = dx+dy;
    int dif = t[i+1]-t[i];
    
    if(sum>dif) ok = false;
    else if((sum-dif)%2!=0) ok = false;
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 4572
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    unordered_map<int,int>m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        m[x]++;
    }
    for(auto k:m){
        if(k.second>1)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

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

const int N = 200010;
using ll = long long;

int a[N];

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
    }
    int left = 1, right = int(1e9) + 10;
    while (left < right){
        int mid = (left + right) / 2;
        ll sum = 0;
        for (int i = 0; i < n; ++ i){
            sum += (a[i] - 1) / mid;
        }
        if (sum > k){
            left = mid + 1;
        }
        else{
            right = mid;
        }
    }
    printf("%d\n", left);
    return 0;
}

Measured memory_bytes: 4600
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 21:07:57 2019

@author: iwata
"""

N,M,C = map(int, input().split())
listb = list(map(int, input().split()))
count = 0

for i in range(N):
    num = 0
    lista = list(map(int, input().split()))
    for j in range(M):
         num = num + lista[j]*listb[j]
    num = num + C
    if num >0:
        count = count + 1     
print(count)

Measured memory_bytes: 3060
from itertools import combinations

N,K = map(int, input().split())

MAX_K = (N-1)*(N-2)//2
if K > MAX_K:
    print(-1)
    exit()

M = N-1 + (MAX_K - K)
print(M)
edges = list(combinations(range(1, N+1), 2))[:M]
# print(edges)
for e in edges:
    print(*e)


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

int main() {
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d), c(d);
  for(int i = 0; i < d; i++) {
    int a,b;
    cin >> a >> b;
    p.at(i) = a;
    c.at(i) = b / 100;
  }
  
  int ans = 0;
  for (int tmp = 0; tmp < (1 << d); tmp++) {
    bitset<10> s(tmp);
    
    int score = 0;
    int number = 0;
    for (int i = 0; i < d; i++) {
      if (s.test(i)) {
        score += (i + 1) * p.at(i) + c.at(i);
        number += p.at(i);
      }
    }
    for (int i = d - 1; i > -1; i--) {
      if (!s.test(i)) {
        int l = (g - score) - ((g - score) * i)/(i + 1);
        if(score > g) break;
        else if(g - score <= (i + 1) * (p.at(i) - 1)) {
          number += l;
          score += l * (i + 1);
          break;
        }else {
          score += (i + 1) * p.at(i) + c.at(i);
          number += p.at(i);
        }
      }
    }
    if(ans) ans = min(ans,number);
    else ans = number;
//    cout << s << ":" << score << "," << number << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    long M;
    cin >> N >> M;
    map<long, long> sum_mod_M;
    long sum = 0;
    sum_mod_M[0]++;
    for(int i = 0; i < N; i++){
        long A;
        cin >> A;
        sum += A;
        sum %= M;
        sum_mod_M[sum]++;
    }
    long ans = 0;
    for(auto i: sum_mod_M){
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
}


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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

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

    int a[n];
    rep(i,n) {
        cin >> a[i];
    }

    int count = 0;
    int k = 1;

    rep(i,n) {
        if(k==a[i]) {
            count++;
            k++;
        }
    }

    if(count == 0) {
        cout << -1 << endl;
        return 0;
    }

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

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

  string S;
  cin >> S;

  vector<int> acs;

  for (int n=0; n<N-1; ++n) {
    if (S[n]=='A'&&S[n+1]=='C')
      acs.push_back(n+1);
  }

  for (int q=0; q<Q; ++q) {
    int l,r;
    cin >> l >> r;
    auto l_itr = lower_bound(acs.begin(), acs.end(), l);
    auto r_itr = lower_bound(acs.begin(), acs.end(), r);

    cout << r_itr - l_itr << endl;
  }

  return 0;
}


Measured memory_bytes: 1276
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;

int N;
V<LL> v;

int main(){
    INIT;
    cin >> N;
    REP(i,N) {
        LL x; cin >> x;
        v.push_back(x);
    }
    LL sum = v[0];
    FOR(i,1,N) sum ^= v[i];

    for(int i = 0; i < N; i++) {
        if(0 == sum) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 1400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int side = 0;
		int[] sides = new int[3];

		while ((line = br.readLine()) != null) {
			if (line.contains(" ")) {
				side = Integer.parseInt(line.split(" ")[0]);
				sides[0] = side * side;
				side = Integer.parseInt(line.split(" ")[1]);
				sides[1] = side * side;
				side = Integer.parseInt(line.split(" ")[2]);
				sides[2] = side * side;
				Arrays.sort(sides);
				if (sides[2] == sides[0] + sides[1]) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			}
		}
	}
}

Measured memory_bytes: 23816
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
  ll x;
  mint(ll x = 0) : x((x + MOD) % MOD) {}
  mint& operator+= (const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+ (const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-= (const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator- (const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*= (const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator* (const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) { return 1; }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/= (const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/ (const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  vector<mint> inv(N + 1);
  for (int i = 1; i <= N; ++i) {
    inv[i] = mint(i).inv();
  }
  vector<mint> suminv(N + 1); // suminv[n] = 1/1 + 1/2 + ... + 1/n.
  suminv[0] = 1; // dummy
  suminv[1] = 1;
  for (int i = 2; i <= N; ++i) {
    suminv[i] = suminv[i-1] + inv[i];
  }

  // we want to calculate the w[j]. w[j] = sum_i p(i,j). p(i,j) = 1/(abs(j-i) + 1)
  vector<mint> w(N);
  rep(j, N) {
    // If j is 2, the left is (1/3 + 1/2). right is (1/2 + 1/3 + ... 1/(N - 1 - j + 1)) = (1/2 + 1/3 + ... + 1/(N-j)). self is 1.
    if (j > 0) {
      w[j] += suminv[j+1] - 1;
    }
    if (j < N-1) {
      w[j] += suminv[N-j] - 1;
    }
    w[j] += 1;
  }

  mint ans(0);
  rep(i, N) {
    ans += w[i] * A[i];
  }
  // ans * N!
  rep(i, N) {
    ans *= i + 1;
  }

  cout << ans.x << endl;
}


Measured memory_bytes: 3328
function compareNumbers2(a, b) { //for sort
    return b.charCodeAt()-a.charCodeAt();
}


function Main(arg) {
  var s = arg.split("\n")[0].split("");
  var t = arg.split("\n")[1].split("");

  s.sort();
  t.sort(compareNumbers2);

  if (s < t) {
    console.log("Yes");
  }
  else {
    console.log("No");
  }

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import math
nums=[]
round_nums=[]
for i in range(5):
    k=int(input())
    nums.append(k)
    round_nums.append(math.ceil(k/10.0)*10)

dist=0
for i in range(5):
    if round_nums[i]-nums[i]>dist:
        dist=round_nums[i]-nums[i]

#print(nums)
print(int(sum(round_nums)-dist))







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

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int m;
int k;
char a[N];
char b[N];

bool f(int g, int gg, char x, char y)
{
        for(int i = 1; i <= k; i++){
                g -= a[i] == x;
                if(g <= 0){
                        return true;
                }
                g += b[i] == y;
                g = min(g, gg);
        }
        return false;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> m >> k;
        int x, y;
        cin >> x >> y;
        for(int i = 1; i <= k; i++){
                cin >> a[i];
        }
        for(int i = 1; i <= k; i++){
                cin >> b[i];
        }
        if(f(y, m, 'L', 'R') || f(x, n, 'U', 'D') || f(m - y + 1, m, 'R', 'L') || f(n - x + 1, n, 'D', 'U')){
                cout << "NO" << "\n";
        } else{
                cout << "YES" << "\n";
        }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  int sum = 0;
  for (int i; i < 3; i++) {
    if (a.at(i) == '1') {
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n;
string s;
map <string, int> p;

int main()
{
	//File("");
	n = gi <int> ();
	for (int i = 1; i <= n; i+=1)
	{
		cin >> s;
		sort(s.begin(), s.end());
		++p[s];
	}
	LL ans = 0;
	for (auto x : p)
		ans += 1ll * x.second * (x.second - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;
const int N = 100100;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll total = 0, s = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        total += a[i];
    }
    ll ans = abs(a[0] * 2 - total);
    for (int i = 0; i + 1 < n; ++i) {
        s += a[i];
        ans = min(ans, abs(s * 2 - total));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(100000)

def insert(k, node):
    if k < node:
        if tree[node]["left"] == None:
            tree[node]["left"] = k
            tree[k] = {"parent": node, "left": None, "right": None}
            return
        else:
            insert(k, tree[node]["left"])
    else:
        if tree[node]["right"] == None:
            tree[node]["right"] = k
            tree[k] = {"parent": node, "left": None, "right": None}
            return
        else:
            insert(k, tree[node]["right"])


def pre_order(n):
    result = []
    if n == None:
        return []
    result.append(str(n))
    result.extend(pre_order(tree[n]["left"]))
    result.extend(pre_order(tree[n]["right"]))
    
    return result


def in_order(n):
    result = []
    
    if n == None:
        return []

    result.extend(in_order(tree[n]["left"]))
    result.append(str(n))
    result.extend(in_order(tree[n]["right"]))
    
    return result

def find(k, node):
    while node != None and node != k:
        if k < node:
            node = tree[node]["left"]
        else:
            node = tree[node]["right"]

    return node


M = int(input())
root = None
while root == None:
    inp = [n for n in input().split()]
    if inp[0] == "print":
        print()
        print()
    else:
        root = int(inp[1])

tree = {root:{"parent": None, "left": None, "right": None}}

for i, _ in enumerate(range(M-1)):
    inp = [n for n in input().split()]
    if inp[0] == "print":
        in_text = ""
        pre_text = ""
        print(" " + " ".join(in_order(root)))
        print(" " + " ".join(pre_order(root)))
        
    elif inp[0] == "find":
        res = find(int(inp[1]), root)
        if res == None:
            print("no")
        else:
            print("yes")
    else:
        insert(int(inp[1]), root)
        #if i%1000 == 0:
        #    print("done {}/{}".format(i, M))

Measured memory_bytes: 197380