akhauriyash/Code-Regression huggingface dataset:
import core.stdc.stdio;
import std.typecons;
import std.conv;
import std.container;
import std.algorithm;

void main(){
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	int[] hs = new int[n];
	for(int i=0;i<n;i++)
		scanf("%d",&hs[i]);
	alias Tuple!(long,"cost",int,"idx") ci;
	ci[][] graph = new ci[][n];
	for(int i=0;i<m;i++){
		int a,b;
		long t;
		scanf("%d%d%lld",&a,&b,&t);
		--a;
		--b;
		if(hs[a]>=t)
			graph[a] ~= ci(t,b);
		if(hs[b]>=t)
			graph[b] ~= ci(t,a);
	}

	alias Tuple!(long,"cost",long,"down",int,"idx") cdi;
	alias BinaryHeap!(cdi[],"a>b") pq;
	pq q = pq(new cdi[400000],0);
	q.insert(cdi(max(0,hs[n-1]-x),0,0));
	long ans=-1;
	bool[] visited = new bool[n];
	
	while(!q.empty){
		cdi t = q.front;
		q.removeFront;
		with(t){
			if(idx==n-1){
				ans=cost;
				break;
			}
			if(visited[idx])
				continue;
			visited[idx] = true;
			foreach(cs;graph[idx]){
				if(!visited[cs.idx]){
					cdi nx;
					nx.idx = cs.idx;
					nx.down = down+cs.cost;
					if(x-nx.down>hs[cs.idx])
						nx.down = x-hs[cs.idx];
					if(x-nx.down<hs[n-1])
						nx.cost = hs[n-1]-(x-nx.down);
					nx.cost += nx.down;
					q.insert(nx);
				}
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 35500
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            var Rectangle = 0;
            var rhombus = 0;

            while ((input = ReadLine()) != null)
            {
                var abc = input.Split(',');
                var a = int.Parse(abc[0]);
                var b = int.Parse(abc[1]);
                var c = int.Parse(abc[2]);

                if (Pow(a, 2) + Pow(b, 2) == Pow(c, 2))
                {
                    Rectangle++;
                }
                else if (a == b)
                {
                    rhombus++;
                }
            }
            WriteLine(Rectangle);
            WriteLine(rhombus);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 15996
n , m = map(int, input().split())
count = 0
low = 0
high  = n
for _ in range(m):
    l,r=map(int, input().split())
    low = max(l, low)
    high = min(high, r)
    #print(low, high)

print(max(high-low+1, 0))

Measured memory_bytes: 9128
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

arr = list(range(n + 1))

for i in arr:
    for j in a:
        if i == j:
            arr[i] = 1
            break
        else:
            arr[i] = 0

low = arr[:x]
high = arr[x:]
c = 0
d = 0
for i in low:
    c += i
for i in high:
    d += i
print(min(c, d))

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

using namespace std;
typedef long long LL;

int main(){
  int N, L;
  cin >> N >> L;
  int ans=0;
  rep(i,N) ans+=L+i;
  if(L>0) cout << ans-L << endl;
  else if(L+N-1<0) cout << ans-(L+N-1) << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int x,y;
    scanf("%d%d", &x, &y);
    int i,j;
    int ans=INF;
    for(i=0; i<2; i++) {
        for(j=0; j<2; j++) {
            int x0=(i==0? x: -x);
            int y0=(j==0? y: -y);
            if(y0>=x0) ans=MIN(ans, y0-x0+i+j);
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	vector<int> t(N), x(N), y(N);
	for(int i=0; i<N; i++)
		cin >> t[i] >> x[i] >> y[i];

	string ret = "Yes";
	int prevT, prevX, prevY;
	prevT = prevX = prevY = 0;
	for(int i=0; i<N; i++){
		int dt, dx, dy;
		dt = t[i] - prevT;
		dx = abs(x[i] - prevX);
		dy = abs(y[i] - prevY);

		if(dt < dx+dy || (dt-dx-dy)%2 != 0)
			ret = "No";

		if(ret == "No")
			break;

		prevT = t[i];
		prevX = x[i];
		prevY = y[i];
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1408
<?php

fscanf(STDIN, "%d", $n);
$D = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($D);

$x = $D[$n / 2];
$y = $D[$n / 2 - 1];

if ($x === $y) {
    echo 0;
} else {
    echo $x - $y;
}


Measured memory_bytes: 16884
from collections import Counter, deque, defaultdict
from functools import lru_cache

n=input()
a =list(map(lambda x:int(x), input().split()))

f=True
for i in a:
	if i&1:
		continue
	if i%3 and i%5:
		f=False
		break

if f:
	print("APPROVED")
else:
	print("DENIED")

Measured memory_bytes: 3572
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int all = 1, odd = 1;
    for(int i = 0; i < n; i++){
        all *= 3;
        if(a[i]%2 == 0) odd *= 2; //すべてのiについてbiが奇数になる個数
    }
    cout << all-odd << endl;
    return 0;
}


Measured memory_bytes: 256
S,T = input(),input()
x,y = len(S),len(T)

dp = [[0]*(y+1) for _ in range(x+1)]

for i,s in enumerate(S):
  for j,t in enumerate(T):
    dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j], dp[i][j] + int(s==t))
    
a = ""
while x > 0 and y > 0:
  if dp[x][y] == dp[x-1][y]:
    x -= 1
  elif dp[x][y] == dp[x][y-1]:
    y -= 1
  else:
    x -= 1
    y -= 1
    a += S[x]

print(a[::-1])

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

using namespace std;

int main()
{
	int A, B, C, D;
	int ans = 0;
	cin >> A >> B >> C >> D;

	if (A > B)
	{
		ans += B;
	}
	else
	{
		ans += A;
	}

	if (C > D)
	{
		ans += D;
	}
	else
	{
		ans += C;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import numpy as np
import math

def fuctrization(n):
    arr = []
    tmp = n
    for i in range(2,math.ceil(n**(1/2))+1):
        if tmp%i==0:
            j = 0
            while tmp%i==0:
                j += 1
                tmp //= i
            arr.append([i,j])
    if tmp != 1:
        arr.append([tmp,1])
    if arr:
        pass
    else:
        arr.append([n,1])
            
    return arr
            
        
        
n = int(input())
if n == 1:
    print(0)
else:
    arr = fuctrization(n)
    nn = 0
    for i in range(len(arr)):
        k = arr[i][1]
        nnn = 1
        while k-nnn>=0:
            k -= nnn
            nnn += 1
            nn +=1
    print(nn)


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int n;
    cin >> n;

    cout << n * n * n << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        fi = [pow(f[-1], mod - 2, mod)]
        for idx in range(max_fact, 0, -1):
            fi += [fi[-1] * idx % mod]
        fi = fi[::-1]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 5*10**5
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation

N, M = [int(_) for _ in input().split()]
ans = 0
for p in range(N + 1):
    ans += (-1)**p * comb(N, p) * perm(M - p, N - p)
    ans %= mod
ans *= perm(M, N)
ans %= mod
print(ans)


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

int main(void){
    ll a, b, c;
    cin >> a >> b >> c;

    if(c < a){
        cout << "NO" << endl;
    }else if(a + b < c){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const s: string = input[0];

if(s === 'Sunny'){
    console.log('Cloudy');
}else if(s === 'Cloudy'){
    console.log('Rainy');
}else{
    console.log('Sunny');
}

Measured memory_bytes: 7372
'''
5
1 3 4 5 7
'''
lens = int(input())
vals = [0] + [int(x) for x in input().split()]
odds = 0
for i in range(1, lens + 1):
    if i % 2 == 1 and vals[i] % 2 == 1:
        odds += 1
print(odds)

Measured memory_bytes: 9176
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

#define int long long

typedef long long ll;

const int MAXN = 3e5 + 7;
const ll HA = 1e9 + 7;

int n;
ll a[MAXN], ans;

signed main() {
	scanf("%lld", &n);
	rep(i, 1ll, n) scanf("%lld", a + i);
	rep(tt, 0ll, 60ll) {
		ll bast = (1ll << tt);
		bast %= HA;
		ll c[2] = {0ll, 0ll};
		rep(i, 1, n) {
			ans = (ans + bast * c[1ll ^ ((a[i] >> tt) &1ll)] % HA) % HA;
			c[(a[i] >> tt) & 1ll]++;
		}
		// printf("tt = %d, ans = %lld\n", tt, ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

ll f(ll a, ll b) {
	if(a > b) swap(a, b);
	if(b % a == 0) return 2 * b - a;
	return a * (b / a * 2) + f(b % a, a);
}

int main() {
	ll n, X;
	cin >> n >> X;
	printf("%lld\n", n + f(X, n - X));
}


Measured memory_bytes: 256
from itertools import product

MOD = 10**9 + 7
S = input()
N = len(S)
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
for d in range(N):
    if S[d] == '?':
        for i, j in product(range(13), range(10)): # '?' = j
            rem = ((10 * i) % 13 + j) % 13
            dp[d + 1][rem] += dp[d][i]
            dp[d + 1][rem] %= MOD
    else:
        for i in range(13):
            rem = ((10 * i) % 13 + int(S[d])) % 13
            dp[d + 1][rem] += dp[d][i]
            dp[d + 1][rem] %= MOD
print(dp[N][5])

Measured memory_bytes: 61916
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    final int N = scan.nextInt();
    final int A = scan.nextInt();
    final int B = scan.nextInt();
    int point1 = 0;
    int point2 = 0;
    int point3 = 0;

    for (int i = 0; i < N; i++) {
      int p = scan.nextInt();
      if (1 <= p && p <= A)
        point1++;
      else if (A < p && p <= B)
        point2++;
      else
        point3++;
    }
    System.out.println(Math.min(Math.min(point1, point2), point3));
  }
}


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

int main(int argc, char const *argv[])
{
	long long a, b;
	cin >> a >> b;
	int ans=0;
	long long a1=a, a2=a, b1=b, b2=b, t1=0, t2=0, l1=a, l2=b;
	while(1)
	{
		//a1 save b1 die
		b1-=a1/2;
		if(t1==1&&a1%2==1) --b1, t1=0;
		else if(a1%2==1) t1=1;
		if(b1<=0) break;		

		//a2 die b2 save
		if(l2>0)
		{
			if(l2>a2) l2-=a2;
			else b2-=a2-l2;
		} 
		else b2-=a2;
		++ans;

		if(l1>0)
		{
			if(l1>b1) l1-=b1;
			else a1-=b1-l1;
		} 
		else a1-=b1;

		a2-=b2/2;
		if(t2==1&&b2%2==1) --a2, t2=0;
		else if(b2%2==1) t2=1;
		if(a2<=0) break;
		++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3096
# import sys
# sys.setrecursionlimit(10 ** 6)
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, ps):
    ev = [0] *  (N + 1)       # Expected value
    cs = [0] * (N + 1)        # Cumulative sum
    for i, p in enumerate(ps, 1):
        ev[i] = (p + 1) / 2
        cs[i] = cs[i - 1] + ev[i]

    ans = 0
    for i in range(K, N + 1):
        ans = max(ans, cs[i] - cs[i - K])

    print(ans)


if __name__ == '__main__':
    N, K = map(int, input().split())
    ps = [int(i) for i in input().split()]

    # N, K = 200000, 2
    # ps = [i for i in range(1, 200000 + 1)]

    solve(N, K, ps)


Measured memory_bytes: 25188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>

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

int main() {
    string s, t;
    cin >> s >> t;

    long long count = 0;

    for(int i = 0; i < s.length(); i++) {
        if(s[i] != t[i])
            count++;
    }

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

Measured memory_bytes: 3580
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};
 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                   > pq;*/
  /*   #define MAXN 1000001
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        // marking smallest prime factor for every
        // number to be itself.
        spf[i] = i;

    // separately marking spf for every even
    // number as 2
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        // checking if i is prime
        if (spf[i] == i)
        {
            // marking SPF for all numbers divisible by i
            for (int j=i*i; j<MAXN; j+=i)

                // marking spf[j] if it is not
                // previously marked
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<ll> getFactorization(ll x)
{
    vector<ll> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
*/
// take multiset of all edges
// meanwhile for all cc keep record of all edges in multiset too which can be used to digest
// one line or two lines
//

int main()
{   ll n;cin>>n;
    string s;cin>>s;
     ll r=0;
      for(auto x:s)if(x=='R')r++;
      ll ans=0;
       for(ll i=0;i<r;i++)if(s[i]=='W')ans++;
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner in = new Scanner(System.in);
	    while(true){
	        int n = in.nextInt();
//	        System.out.println("n="+n);
	        if(n==0) break;
	        int arr[] = new int[n];
	        for(int i=0;i<n;i++) arr[i] = in.nextInt();
	        int res = 0;
	        while(!isFinish(arr) && res < 10000){
	            res++;
	            arr = doit(arr);
	            arr = remove(arr);           
	        }
	        if(res == 10000) res = -1;
	        System.out.println("" + res);
	    }
	}

	static boolean isFinish(int[] arr){
	    for(int i=0;i<arr.length; i++){
	        if(arr[i] != i+1) return false;
	    }
	    return true;
	}

	static int[] remove(int[] arr){
	    int c = 0;
	    for(int i : arr) if(i!=0)c++;
	    int[] res = new int[c];
	    int t = 0;
	    for(int i : arr) if(i!=0) res[t++] = i;
	    return res;
	}

	static int[] doit(int[] arr){
	    int[] res = new int[arr.length+1];
	    for(int i=0;i<arr.length; i++){
	        res[i] = arr[i]-1;
	    }
	    res[arr.length] = arr.length;
	    return res;
	}
}

Measured memory_bytes: 151748
#include <stdio.h>

int main(){
  int i,j,k,m,n;
  int o[100],omx;
  while(scanf("%d %d\n",&n,&m)){
    if(m==0 && n==0) break;
    for(i=0;i<m;i++) o[i]=0; omx=0; k=0;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        o[j]+=getchar()-'0';
        getchar();
        if(o[j]>omx) omx=o[j];
      }
    }
    for(i=omx,k=m;i>=0;i--)
      for(j=0;j<m;j++)
        if(o[j]==i)
          printf("%d%c",j+1,--k==0?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

int main(void) {

  int a, b, d, r;
  double f;

  scanf("%d %d", &a, &b);

  d = a / b;
  r = a % b;
  f = (double)a / (double)b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef rsd511
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    #ifndef rsd511
    #define trace(...) {}
    #define cotra(...) {}
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    ll n, m, q; cin >> n >> m >> q;
    map <ll,ll> row, col;
    vector < pair<ll,ll> > bomb;
    f(_,1,q) {
    	ll x, y; cin >> x >> y;
    	bomb.pb(mp(x,y));
    	row[x]++; col[y]++;
    }
    ll max_r = 0, max_c = 0;
    fa(x,row) max_r = max(max_r, x.ss);
    fa(x,col) max_c = max(max_c, x.ss);
    ll nr = 0, nc = 0;
    fa(x,row) if(max_r == x.ss) nr++;
    fa(x,col) if(max_c == x.ss) nc++;
    ll total = nr * nc;
    ll ans = max_r + max_c - 1;
    fa(x,bomb) if(row[x.ff] + col[x.ss] - 1 == ans) total--;
    if(total > 0) ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 45472
from collections import defaultdict
from copy import deepcopy


def dfs(graph, v, visited):
    visited.add(v)
    for nv in graph[v]:
        if nv not in visited:
            dfs(graph, nv, visited)
    return visited


def is_connected(graph, nodes_cnt):
    visited = dfs(graph, 1, set())
    if len(visited) == nodes_cnt:
        return True
    else:
        return False


N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]
G = defaultdict(set)
for u, v in edges:
    G[u].add(v)
    G[v].add(u)
ans = 0
for u, v in edges:
    H = deepcopy(G)
    H[u] -= {v}
    H[v] -= {u}
    if not is_connected(H, N):
        ans += 1
print(ans)


Measured memory_bytes: 9680
def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().split(" ")]
    a_list.sort(reverse=True)
        
    from heapq import heappush, heappop

    hq = []
    joined = set()
    joined.add(0)
    heappush(hq, (-a_list[0], 0, 0))
    result = 0
            
    for i in range(1, n):

        comfort, left, right = heappop(hq)
        comfort = -comfort

        result += comfort

        heappush(hq, (-(a_list[left] if a_list[left] < a_list[i] else a_list[i]),left, i))
        heappush(hq, (-(a_list[right] if a_list[right] < a_list[i] else a_list[i]),i,right))
    
    print(result)


if __name__ == "__main__":
    resolve()


# を理解する。そうすると、明らかに制限時間内に実行が終わらないソースコードを出さなくなる。ちなみに、競プロでは 108108 ～ 109109 回程度のループが回せるといわれている。

Measured memory_bytes: 44288
n = gets.to_i
numbers = gets.split.map(&:to_i)
q = gets.to_i
replacing = []
q.times do
  replacing << gets.split.map(&:to_i)
end

tally = numbers.tally
tally.default = 0
sum = numbers.sum

replacing.each do |before, after|
  sum = sum + tally[before] * (after - before)
  tally[after] += tally[before]
  tally[before] = 0
  puts sum
end


Measured memory_bytes: 32840
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s;
  cin >> s;

  int N = s.size();

  // dp[i][j]: i文字目まで見た時の個数
  // j = 1: 未満
  vector<vector<int>> dp(N+1, vector<int>(2));
  dp[0][0] = 1;
  REP(i, N){
    if(s[i] == '0'){
      (dp[i+1][0] += dp[i][0]) %= MOD;
      (dp[i+1][1] += 3*dp[i][1]) %= MOD;
    }else{
      (dp[i+1][1] += dp[i][0]) %= MOD;
      (dp[i+1][1] += 3*dp[i][1]) %= MOD;
      (dp[i+1][0] += 2*dp[i][0]) %= MOD;
    }
  }

  cout << (dp[N][1]+dp[N][0])%MOD << endl;

  return 0;
}

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

ans = 0
if N%2 == 0:
    num2 = 0
    d = 2
    while d <= N:
        num2 += N//d
        d *= 2

    num5 = 0
    d = 10
    while d <= N:
        num5 += N//d
        d *= 5

    ans = min(num2, num5)

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string S;
    cin >> S;
    
    ll ans = 0;
    ll tmp = 1;
    ll a = 0;
    bool allgt = true;
    if(S[0] == '<') allgt = false;
    if(S.size() == 1){
        cout << 1 << "\n";
        return 0;
    }
    
    for(int i = 1; i < S.size(); i++){
        if(S[i] == '<') allgt = false;
        if(S[i-1] == S[i])
            tmp++;
        else{
            ans += tmp*(tmp+1)/2;
            if(S[i-1] == '<'){
                a = tmp;
            }else{
                ans -= min(a, tmp);
                a = 0;
            }
            tmp = 1;
        }
        //cout << ans << "\n";
    }
    ans += tmp*(tmp+1)/2;
    if(S[S.size()-1] == '>')
        ans -= min(a, tmp);
    if(allgt)
        ans += a;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 900
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
#include <random>
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { d, r, u, l , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D array to 1D array. (Zero-indexed)
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) {
	int r = n / nCol, c = n % nCol;
	return ii(r, c);
}

ll poww(ll num, ll p, ll md = MOD) {
	num %= md;
	ll ret = 1;
	while (p > 0) {
		if (p & 1) ret = (ret * num) % md;
		num = (num * num) % md;
		p >>= 1;
	}
	return ret;
}

void inter(string s) {
	cout << s << endl;
	fflush(stdout);
}


int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vll v(n), pre(n+1, 0);
	lop(i, n) cin >> v[i], pre[i+1] = pre[i] ^ v[i];
	lop(i, n) {
		cout << (pre[n] ^ pre[i+1] ^ pre[i]) << ' ';
	}
	cout << endl;




	return 0;
}


Measured memory_bytes: 6280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int i, j;
    int n;
    int ans;

    cin >> n;
    ans = n % 2 ? n/2+1 : n/2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bitset>

#define MAX 1440 /* max duration */

using namespace std;

int main(void){
	while(true){
		int sub_max_duration = 0;
		int answer = 0;
		int n,p,q;
		bitset<MAX> result;

		cin >> n >> p >> q;

		if( n == 0 && p == 0 && q == 0 ) break;

		for(int i = 0; i < n; ++i){
			int k;
			bitset<MAX> b;

			cin >> k;
			for(int j = 0; j < k; ++j){
				int s,e;
				int cm_duration;

				cin >> s >> e;
				cm_duration = 60*(e/100-s/100)+(e%100-s%100);
				// cout << cm_duration << endl;
				for(int m = 0; m < cm_duration; ++m){
					b[60*(s/100)+(s%100)+m] = true;
				}
			}
			if( i == 0 ){
				result = b;
			}else{
				result &= b;
			}
		}

		for(int i = 60*(p/100)+(p%100); i < 60*(q/100)+(q%100); ++i){
			if( !result[i] ){
				++sub_max_duration;
			}else{
				answer = max( answer, sub_max_duration );
				sub_max_duration = 0;
			}
		}
		answer = max( answer, sub_max_duration );

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main (void){

    int N, A, B, train;
    scanf("%d%d%d",&N,&A,&B);

    train = A * N;

    if(train > B){
        printf("%d\n",B);
    }else{
        printf("%d\n",train);
    }
    

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
vector<int> edge[200001];
int cnt[200001] = {};
void solve(int num, int p){
  for(int v: edge[num]){
    if(v==p)continue;
    cnt[v] += cnt[num];
  	solve(v, num);
  }
}

int main(){
  int n, q;cin>>n>>q;
  for(int i=0;i<n-1;i++){
  	int a, b;cin>>a>>b;a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i=0;i<q;i++){
  	int p, x;cin>>p>>x;p--;
    cnt[p] += x;
  }
  solve(0, -1);
  for(int i=0;i<n;i++){
  	if(i!=n-1)cout<<cnt[i]<<" ";
    else cout<<cnt[i]<<endl;
  }
}

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

using namespace std;
using ll = long long;

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

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

  ll sum = 0;
  rep(i, n) {
    if (i % 2)
      sum -= a[i];
    else
      sum += a[i];
  }

  ll x[n];
  x[0] = sum;
  rep(i, n - 1) { x[i + 1] = (ll)2 * a[i] - x[i]; }

  rep(i, n) printf("%lld%c", x[i], (i == n - 1) ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 4860
#include<iostream>
using namespace std;
int main() {
	int N,a,b,c;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a >> b >> c;
		if (a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];
ll pos[N];
int main()
{
   ll n,l,mn=10000,sum=0,ans=0,k;

   cin>>n>>l;

   ll ara[n+1];

   for(ll i=1;i<=n;i++)
   {
       ara[i]=l+i-1;
       sum+=ara[i];
       k=abs(ara[i]-0);
       if(k<mn)
       {
           mn=k;
           ans=ara[i];
       }
   }

   cout<<sum-ans<<endl;


}





Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] X = new int[N];
            for (int i = 0; i < N; i++) {
                X[i] = sc.nextInt();
            }

            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += X[i];
            }
            int mean = sum / N;

            int min = (int) 1e9;
            min = Math.min(min, calculateCost(N, X, mean));
            min = Math.min(min, calculateCost(N, X, mean + 1));

            System.out.println(min);
        }
    }

    private static int calculateCost(int N, int[] X, int mean) {
        int cost = 0;
        for (int i = 0; i < N; i++) {
            cost += (X[i] - mean) * (X[i] - mean);
        }
        return cost;
    }
}

Measured memory_bytes: 27264
#include<cmath>
#include<cstdio>
#define int long long
#define x1 xxx1
#define x2 xxx2
#define y1 xxx3
#define y2 xxx4
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
template<typename T>inline void rd(T&x){int fl=0,ch;while(ch=getchar(),ch<48||57<ch)fl^=!(ch^45);x=(ch&15);while(ch=getchar(),47<ch&&ch<58)x=x*10+(ch&15);if(fl)x=-x;}
template<typename T>inline void pt(T x){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);}
template<typename T>inline void pt(T x,int ch){pt(x),putchar(ch);}
template<typename T>inline T max(const T&x,const T&y){return x<y?y:x;}
template<typename T>inline T min(const T&x,const T&y){return x<y?x:y;}
int S,sq,x1,y1,x2,y2;
signed main(){
	rd(S),sq=(int)sqrt(S);
	if(sq*sq!=S)++sq;
	S=sq*sq-S,x1=y2=sq;
	if(S<=1000000000)y1=1,x2=S;
	else{
		for(int i=2;i*i<=S;++i)
			if(S%i==0){y1=i,x2=S/i;break;}
	}
	printf("%lld %lld %lld %lld %lld %lld\n",0ll,0ll,x1,y1,x2,y2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n,k;cin >> n >> k;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	auto ok = [&](int x){
		//最大値xをk階以内でできるか
		int ret = 0;
		rep(i,n){
			if(a[i] > x){
				ret += a[i]/x;
			}
		}

		return ret <= k;
	};
	int bot = 0,top = 1e9;
	while(top - bot > 1){
		int mid = (top+bot)/2;
		if(ok(mid)){
			top = mid;
		}
		else bot = mid;

	}
	
	cout << top << endl;

	return 0;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

using Graph = vector<vector<int>>;
Graph G;
int dist = 0;
int dp[100010];
int dfs(int v)
{
    if(G[v].size() == 0){
        return 0;
    }
    vector<int> ans;
    for (auto &u : G[v])
    {
        ans.push_back(dfs(u));
    }
    sort(ALL(ans));
    int k = ans.size();
    for (int i = 0; i < k; i++)
    {
        ans[i] += k - i;
    }
    return *max_element(ALL(ans));
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    G.assign(n, vector<int>());
    for (int i = 1; i < n; i++)
    {
        int x;
        cin >> x;
        x--;
        G[x].push_back(i);
    }
    cout<<dfs(0)<<endl;
    return 0;
}

Measured memory_bytes: 13568
#pragma gcc target("avx,avx2")
#pragma gcc optimize("ofast,fast-math")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <immintrin.h>
#define mid (s+e>>1)
#define sca(aa) scanf("%d",&aa)
#define to e[i].t
#define ls(x) x<<1
#define rs(x) x<<1|1
#define lson(x) ls(x),s,mid
#define rson(x) rs(x),mid + 1,e
#define p(x) x*x
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int inf = INT_MAX;
const int N = 3000003;
const LL p = 1e9 + 7;
const double eps = 1e-10;
const ull strmod = 212370440130137957ll;
const int strp = 233;
inline LL read() {
	char ch = getchar(); LL x = 0, f = 1;
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	} while ('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
LL kpow(LL a, LL b)
{
	LL r = 1;
	while (b)
	{
		if (b & 1)
			r = r * a % p;
		a = a * a % p, b >>= 1;
	}
	return r % p;
}
LL h[N] = { 1 };
int main()
{
	int n, m;
	int x, y, d, k;
	LL ans;
	for (LL i = 1; i < N; i++)
		h[i] = h[i - 1] * i % p;
	while (cin >> n >> m)
	{
		if ((n + m) % 3) { printf("0\n"); continue; }
		d = (n + m) / 3, x = (2 * m - n) / 3, y = d - x;
		if (x < 0 || y < 0) { printf("0\n"); continue; }
		ans = h[d] * kpow(h[x] * h[y] % p, p - 2) % p;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 23680
import java.io.*;
import java.util.Arrays;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int maxValue;
int minValue;
int dif;
int[] num=new int[8];
int n=Integer.parseInt(br.readLine());
for(int p=0;p<n;p++){
line=br.readLine();
maxValue=0;
minValue=0;
dif=0;
for(int i=0;i<num.length;i++){
num[i]=(int)(line.charAt(i)-'0');
}
Arrays.sort(num);
for(int i=0;i<num.length;i++){
maxValue+=num[i]*Math.pow(10,i);
minValue+=num[i]*Math.pow(10,7-i);
}
dif=maxValue-minValue;
System.out.println(dif);
}
}
}

Measured memory_bytes: 16868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int min(int A,int B){
    return A<B?A:B;
}

int main(void){
    int a,b,k;
    scanf("%d%d%d",&a,&b,&k);
    for (int i=min(a,b); i>=1; i--){
        if (a%i==0 && b%i==0){
            k--;
        }
        if (k==0){
            printf("%d\n",i);
            break;
        }
    }
    return 0 ;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

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); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vi d(n); rep(i, n) cin >> d[i];
	ll all = 0;
	rep(i, n) {
		for(int j = i+ 1; j < n; ++j) {
			all += d[i] * d[j];
		}
	}
	cout << all << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b;
  cin>>a>>b;
  cout<<max(0,a-b-b)<<endl;
}


Measured memory_bytes: 888
#include<cstdio>
#define ll long long
using namespace std;
int main() {
	ll a, b, c, k;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
	if (k%2==0)
		printf("%lld", a - b);
	else
		printf("%lld", b - a);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> r(n);
    rep(i, n) {
        cin >> a[i];
        if (i % 2 == 0) r[0] += a[i];
        else r[0] -= a[i];
    }
    rep(i, n-1) {
        r[i+1] = 2 * a[i] - r[i];
    }
    rep(i, n-1) cout << r[i] << " ";
    cout << r[n-1] << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N; cin >> N;
    vector<int> X(N); rep(i,N) cin >> X[i];

    auto y(X);
    sort(all(y));

    int m1 = (N-1)/2;
    int m2 = m1 + 1;

    rep(i,N){
        if(X[i] <= y[m1]) cout << y[m2] << endl;
        else cout << y[m1] << endl;
    }
}


Measured memory_bytes: 3712