akhauriyash/Code-Regression huggingface dataset:
N,C=map(int,input().split())
D=[list(map(int,input().split())) for _ in range(C)]
G=[list(map(int,input().split())) for _ in range(N)]
C0=[0]*(C+1)
C1=[0]*(C+1)
C2=[0]*(C+1)

for x in range(N):
    for y in range(N):
        if (x+y+2)%3==0: C0[G[x][y]]+=1
        elif (x+y+2)%3==1: C1[G[x][y]]+=1
        elif (x+y+2)%3==2: C2[G[x][y]]+=1

miniwa=250000000
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if (c1-c0)*(c2-c1)*(c0-c2)==0: continue
            iwa=0
            for i in range(1,C+1):
                iwa+=(D[i-1][c0-1]*C0[i]+D[i-1][c1-1]*C1[i]+D[i-1][c2-1]*C2[i])
            miniwa=min(miniwa,iwa)
print(miniwa)

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

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> d(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    cout << d[N / 2] - d[(N / 2) - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    ll a, ans;
    int tmp;
    char b[5];
    scanf("%lld %s", &a, b);
    char bd[3];
    rep(i, 3) bd[i] = '\0'; 
    bd[0] = b[0];
    tmp = atoi(bd);
    bd[0] = b[2];
    bd[1] = b[3];
    ans = a * atoi(bd);
    ans /= 100;
    ans += a * tmp;
    printll(ans);
}

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

int main() {
        int N; cin >> N;
        int C[N], V[N];
        for (int i = 0; i < N; ++i) {
                cin >> V[i];
        }
        for (int i = 0; i < N; ++i) {
                cin >> C[i];
        }

        int sum = 0;
        for (int i = 0; i < N; ++i) {
                int sub = V[i] - C[i];
                if (sub > 0) {
                        sum += sub;
                }
        }
        cout << sum<<"\n";
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>

int main(){
    using namespace std;
    using bigint = boost::multiprecision::cpp_int;
    bigint S, W;
    cin >> S >> W;
    puts(S <= W ? "unsafe" : "safe");
    return 0;
}

Measured memory_bytes: 3580
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

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

    static class Ki {
        List<List<Integer>> graph;
        long[] cost;

        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int q = in.nextInt();

            graph = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                graph.add(new ArrayList<>());
            }

            cost = new long[n + 1];

            for (int i = 1; i <= n - 1; i++) {
                int a = Integer.parseInt(in.next());
                int b = Integer.parseInt(in.next());
                graph.get(a).add(b);
                graph.get(b).add(a);
            }

            for (int i = 0; i < q; i++) {
                int p = Integer.parseInt(in.next());
                long x = Long.parseLong(in.next());
                cost[p] = cost[p] + x;
            }

            dfs(1, -1);
            for (int i = 1; i <= n; i++) {
                out.print(cost[i] + " ");
            }
        }

        public void dfs(int dst, int parent) {
            for (Integer num : graph.get(dst)) {
                if (num != parent) {
                    cost[num] += cost[dst];
                    dfs(num, dst);
                }
            }
        }

    }
}



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

using namespace std;

int N,L;
string dispo;
priority_queue <string,vector<string>,greater<string> > pq;

int main(){
    cin>>N>>L;
    for(int i=0;i<N;i++){
        cin>>dispo;
        pq.push(dispo);
    }
    while(!pq.empty()){
        cout<<pq.top();
        pq.pop();
    }
    cout<<endl;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine()); //1行目：個数
            string[] arr = Console.ReadLine().Split(' ');   //2行目：数値（文字列）の羅列
            ulong sum = 1;  //羅列を全てかけた値
           
            //文字列変換して入れる
            for (int i = 0; i < num; i++)
            {               
                if(ulong.Parse(arr[i]) == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
            }


            for (int i = 0; i < num; i++)
            {
                try
                {
                    checked
                    {
                        sum *= ulong.Parse(arr[i]);
                    }
                }
                catch (OverflowException)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            if (sum > (ulong)Math.Pow(10, 18))
            {
                Console.WriteLine(-1);
                return;
            }
            else
            {
                Console.WriteLine(sum);
            }


        }

    }
}

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

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

    for(int i=a;i<min(a+k,b+1);i++)cout << i << endl;
    for(int i=max(a+k,b-k+1);i<=b;i++)cout << i << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve()
{
    double N, K; cin >> N >> K;
    int coin_ptns = min(K-1, N);
    double ans = (N - coin_ptns) / N;
    
    if (coin_ptns)
    {
        double coins = 0;
        for (int i = 1; i <= coin_ptns; i++) coins += pow(1.0 / 2.0, ceil( log2(K/i) ) );
        
        ans += coins / N;
    }
    
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s;
  cin>>s;
  ll k;
  cin>>k;
  vector<string> vs;
  rep(i,0,s.sz){
    string s1;
    rep(j,0,k){
      if(i+j<s.sz){
        s1+=s[i+j];
        vs.pb(s1);
      }
    }
  }
  set<string> se(all(vs));
  vector<string> vs1(all(se));
  cout << vs1[k-1] << endl;
  return 0;
}

Measured memory_bytes: 2428
#define ASIZE 200005
#include <bits/stdc++.h>
using namespace std;
long long ft[ASIZE],n=ASIZE+1;
typedef pair<long long,long long> pii;

void increment(long long p){
  for(;p<=n;p+=(p & -p))ft[p]++;
}

long long query(long long p){
  long long sum=0;
  for(;p>0;p-=(p & -p))sum+=ft[p];
  return sum;
}

int main() {
  long long n,k,a[ASIZE]={0},ps[ASIZE],x,sum=0;
  priority_queue<pii,vector<pii>,greater<pii> >pq;
  cin>>n>>k;
  for(long long i=1;i<=n;i++){
    cin>>a[i];
    a[i]-=k;
    ps[i]=ps[i-1]+a[i];
    pq.emplace(ps[i],i);
  }
  while(!pq.empty()){
    x=pq.top().second;
 //   cout<<"x= "<<x<<"\n";
    sum+=query(x);
    increment(x);
    if(pq.top().first>=0)sum++;
    pq.pop();
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 8940
#include<bits/stdc++.h>
using namespace std;
long long l,sum,sum1;
string s;
int main()
{
	cin>>s;
	l=s.size();
	for(int i=0;i<l;i++)
	{
		sum1+=s[i]-'0';
		if(s[i]=='1'&&i==0) continue;
		  else if(i==0) {sum+=(s[i]-'0'-1);continue;}
		sum+=9;
	}
	cout<<max(sum1,sum)<<"\n";
	return 0;
 } 

Measured memory_bytes: 256
import math
import sys

def isBetween(i1, i2, res1, res2):
    return (i1 % 2 == i2 % 2) != (res1 == res2)

def search(s_range, isLeft, result):
    half = s_range[0] + math.floor((s_range[1] - s_range[0])/2)
    print(half)
    res = input()

    if res == 'Vacant':
        return

    if isLeft:
        if isBetween(s_range[0]-1, half, result, res):
            search((s_range[0], half-1), False, res)
        else:
            search((half+1, s_range[1]), True, res)
    else:
        if isBetween(half, s_range[1]+1, res, result):
            search((half+1, s_range[1]), True, res)
        else:
            search((s_range[0], half-1), False, res)


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

    print(0)
    res = input()

    s_range = (1, N-1)
    search(s_range, True, res)

main()


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
typedef pair<long long, long long> pll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//arc080D
int main() {

    ll H,W;
    cin >> H >> W;

    ll N,tmp;
    cin >> N;
    vector <pll> a(N);

    REP(i,N)
    {
        cin >> tmp;
        a[i] = make_pair(i+1, tmp);
    }

    //基本的には、左上から横に貼り付けでよい?
    //折返しに気をつける
    //↑ ジグザグに出力する?

    vector <vector<ll>> c(H,vector<ll>(W));

    ll cnt = 0;
    ll tar = 0;
    REP(i,H)
    {
        REP(j,W)
        {
            if(i % 2 ==0)
            {
                c[i][j] = a[tar].first;
            }
            else
            {
                c[i][W - 1- j] = a[tar].first;
            }
            
            ++cnt;
            if(a[tar].second <= cnt)
            {
                ++tar;
                cnt = 0;
            }
        }
    }

    REP(i,H)
    {
        REP(j,W)
        {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
    
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
int main(void) {
    Int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
    return 0;
}



Measured memory_bytes: 3596
#include <iostream>

using namespace std;

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

    int ac = 0, wa = 0, tle = 0, re = 0;
    string str;
    for(int i = 0; i < n; i++) {
        cin >> str;
        if(str == "AC") {
            ac++;
        }else if(str == "WA") {
            wa++;
        }else if(str == "TLE") {
            tle++;
        }else {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);	
	int arr[3];
	for(int i = 0; i < 3; i++){
		cin >> arr[i];
	}
	sort(arr, arr + 3);
	int ans = arr[0] * arr[1];
	cout << ans / 2;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
cnt = [0]*(10**5+1)
sumA = sum(A)
for a in A:
  cnt[a] += 1
        
for query in range(Q):
  b,c = map(int,input().split())
  sumA += cnt[b]*(c-b)
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(sumA)
       

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

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

using namespace std;

int multi_max(int n)
{
	int k = 10;
	int maxi=0;
	while(n/k > 0){
		maxi = max(maxi, (n/k)*(n-n/k*k));
		k *= 10;
	}
	return maxi;
}

int main(void)
{
	int q;
	cin >> q;
	while(q--){
		int n, ans=0;
		cin >> n;
		while(n >= 10){
			n = multi_max(n);
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    i32 a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k <= a) {
        cout << k << '\n';
    }
    else {
        k -= a;
        if(k <= b) {
            cout << a << '\n';
        }
        else {
            k -= b;
            cout << a - k << '\n';
        }
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main(){
  int n,sum=1; cin >>n;
  vector<string>a(n);
  for(int i=0; i<n; i++) cin >>a[i];
  sort(a.begin(),a.end());
  for(int i=0; i<n-1; i++)
  {if(a[i]!=a[i+1]) sum++;}
  cout <<sum;
return 0;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
 
int main(){
  int l;
  cin >> l;
  long long dp[200005][5];
  for(int i=0;i<5;i++)dp[0][i]=0;
  for(int i=1;i<=l;i++){
    long long a;
    cin >> a;
    dp[i][0]=dp[i-1][0]+a;
    dp[i][4]=min(dp[i-1][0],min(dp[i-1][1],min(dp[i-1][2],min(dp[i-1][3],dp[i-1][4]))))+a;
    dp[i][1]=min(dp[i-1][0],dp[i-1][1]);
    dp[i][2]=min(dp[i][1],dp[i-1][2]);
    dp[i][3]=min(dp[i][2],dp[i-1][3]);
    if(a==0){dp[i][1]+=2;  dp[i][2]+=1;  dp[i][3]+=2;}
    else if(a%2==0){dp[i][1]+=0;  dp[i][2]+=1;  dp[i][3]+=0;}
    else{dp[i][1]+=1;  dp[i][2]+=0;  dp[i][3]+=1;}
  }
  cout << min(dp[l][0],min(dp[l][1],min(dp[l][2],min(dp[l][3],dp[l][4])))) << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<string> s(n);
    rep(i,n) cin>>s[i];

    map<string,int> mp;
    rep(i,n) mp[s[i]]++;

    int m = 0;
    for (auto &&e: mp) {
        chmax(m,e.second);
    }
    for (auto &&e: mp) {
        if (e.second == m) cout << e.first << '\n';
    }
    return 0;
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
 using namespace std;
 
 typedef unsigned long long ull;
 typedef long long ll;
 typedef pair<int, int> pii;
 typedef pair<ll, ll> pll;
 typedef pair<double, double> pdd;
 const ull mod = 1e9 + 7;
 #define REP(i,n) for(int i=0;i<(int)n;++i)
 
const int MAX_N = 1e6;

struct UnionFind{
    int N;
    int par[MAX_N];

    UnionFind(int N): N(N){
        for (int i=0;i<N;i++){
            par[i] = i;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        int rx = root(par[x]);
        par[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }

    bool find(int x, int y){
        return root(x) == root(y);
    }
};

 int main(){
 	int N, M;
 	cin >> N >> M;
 	vector<int> p(N);
 	REP(i, N){
 		cin >> p[i];
 	}
 	UnionFind uf(N+1);

 	int x, y;
 	REP(i, M){
 		cin >> x >> y;
 		uf.unite(x, y);
 	}

 	int res = 0;
 	REP(i, N){
 		res += uf.find(i+1, p[i]);
 	}
 	cout << res << endl;

     return 0;
 }

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+')
		cout << a + b << endl;
	else
		cout << a - b << endl;

}


Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        Arrays.sort(A);
        boolean found = true;
        while (found) {
            long target = 0;
            found = false;
            for (int i = 0; i < N; i++) {
                if (target == 0) {
                    if (0 < A[i]) {
                        target = A[i];
                    }
                    continue;
                }
                A[i] = A[i] % target;
                found = true;
            }
            Arrays.sort(A);
        }
        long answer = 0;
        for (int i = 0; i < N; i++) {
            if (0 < A[i]) {
                answer = A[i];
                break;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 50876
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, m;
pair<int, int> a[200010];

signed main() {
	cin >> n >> m;
	rep(i, m)cin >> a[i].first >> a[i].second;
	vector<bool> ta(n + 10);
	sort(a, a + m);
	rep(i, m) {
		if (a[i].first == 1)ta[a[i].second] = true;
		else if (a[i].second == n && ta[a[i].first] == true) {
			cout << "POSSIBLE" << endl;
			ggr
		}
	}
	cout << "IMPOSSIBLE" << endl;
	ggr
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<climits>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define asc(a,n) sort(a,a+n);
#define dsc(a,n) sort(a,a+n,comp);
#define fo(i,x,y) for(int i=x;i<y;i++)
#define inarr(x) int n; cin>>n; int x[n]; fo(i,0,n){cin>>x[i];}
#define test int t; cin>>t; while(t--)
using namespace std;

int basic(){freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);return 0;}
bool comp(int a,int b){return a>b;}



int32_t main()
{ //basic(); 
  fast;
  int n,k; cin>>n>>k; int d,x,cnt=0;
  int a[n+1]={};
  fo(i,0,k)
  {
    cin>>d;
    fo(j,0,d){cin>>x; a[x]=1;}
  }
  fo(i,1,n+1)
  {
    if(a[i]==0){cnt++;}
  }
  cout<<cnt;


  
  return 0;
}






Measured memory_bytes: 3648
#n=int(input())
n,x,y=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

adjl=[[0 for i in range(n)] for j in range(n)]

dic={}

for i in range(n):
    for j in range(i,n):
        #if i>=j:
        #    continue
        dis=j-i
        maybe=abs(x-(i+1))+1+abs(y-(j+1))
        dis=min(dis,maybe)
        adjl[i][j]=dis

for i in range(n):
    for j in range(i,n):
        #if i>=j:
        #    continue
        dis=adjl[i][j]
        dic[dis]=dic.get(dis,0)+1
for k in range(1,n):
    print(dic.get(k,0))


Measured memory_bytes: 82396
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 998244353;
const ll mod1 = 2e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
const int inf = 0x3f3f3f3f;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 1e4 + 5;
int t;
int a[N], b[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	string s, ss;
	cin >> s >> ss;
	int a, b;
	cin >> a >> b;
	string tmp;cin >> tmp;
	if (tmp == s)cout << a - 1 << " " << b << endl;
	else cout << a << " " << b - 1 << endl;
	return 0;
}

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

struct Node{
  int key;
  Node *parent, *left, *right;
};

Node *NIL, *root;

void init(void){
  root=(Node*)malloc(sizeof(Node));
  
  root->key=INT_MAX;
  root->left=NIL;
  root->right=NIL;
}

void insert(int key){
  Node *in=(Node*)malloc(sizeof(Node));
  Node *tmp=root;
  Node *par;
  
  in->key=key;
  in->left=NIL;
  in->right=NIL;

  if(root->key == INT_MAX) root=in;
  else{
    while(tmp != NIL){
      par=tmp;
      if(tmp->key > in->key) tmp=tmp->left;
      else tmp=tmp->right;
    }
    in->parent=par;
    if(in->parent->key > in->key) in->parent->left=in;
    else in->parent->right=in;
  }
}

void preorder(Node *point){
  if(point == NIL) return;

  printf(" %d", point->key);
  preorder(point->left);
  preorder(point->right);
}

void inorder(Node *point){
  if(point == NIL) return;

  inorder(point->left);
  printf(" %d", point->key);
  inorder(point->right);
}

void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

int main(){
  int  i, n, key;
  char com[7];

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

  for(i=0; i<n; i++){
    scanf("%s %d", com, &key);
    if(com[0] == 'i') insert(key);
    else print();
  }
  
}



Measured memory_bytes: 26508
#include <stdio.h>

int main(void){
  int a, b;

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

  if (a < b) {
    printf("a < b\n");
  }
  else if (a > b) {
    printf("a > b\n");
  }
  else if (a == b) {
    printf("a == b\n");
  }

  return 0;
}


Measured memory_bytes: 2136
import java.util.*;

class Main{

    boolean debug=false;
    int INF=1<<28;
    int N;
    int[][] t;
    int[] dp;

    void solve(){
	Scanner sc=new Scanner(System.in);
	while(true){
	    N=sc.nextInt();
	    if(N==0)break;

	    t=new int[N][N+1];
	    for(int i=0;i<N;i++){
		for(int j=0;j<N+1;j++){
		    t[i][j]=sc.nextInt();
		}}

	    dp=new int[(1<<N)];
	    Arrays.fill(dp,INF);
	    dp[0]=0;

	    for(int S=0;S<(1<<N);S++){
		for(int i=0;i<N;i++){
		    if(((S>>i)&1)==0){
		    int mintime=t[i][0];
		    for(int j=0;j<N;j++){
			if(((S>>j)&1)==1){
			    mintime=Math.min(mintime,t[i][j+1]);
			}
		    }
		    dp[S+(1<<i)]=Math.min(dp[S+(1<<i)],dp[S]+mintime);
		    }
		}
	    }

	    System.out.println(dp[(1<<N)-1]);
	}
    }
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 35672
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  if(s.size()<4) cout<<"No"<<endl;
  else if(s.at(0)=='Y'&&s.at(1)=='A'&&s.at(2)=='K'&&s.at(3)=='I')
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
// Minesweeper

#include <iostream>

using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	char S[H][W];
	int res[H][W];

	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			cin >> S[i][j];
			res[i][j] = 0;
		}
	}

	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			if (S[i][j] == '#'){
				if (i-1 >= 0)
					res[i-1][j]++;
				if (i+1 < H)
					res[i+1][j]++;
				if (j-1 >= 0)
					res[i][j-1]++;
				if (j+1 < W)
					res[i][j+1]++;
				if (i-1 >= 0 && j-1 >= 0)
					res[i-1][j-1]++;
				if (i-1 >= 0 && j+1 < W)
					res[i-1][j+1]++;
				if (i+1 < H && j-1 >= 0)
					res[i+1][j-1]++;
				if (i+1 < H && j+1 < W)
					res[i+1][j+1]++;
				res[i][j] -= 9;
			}
		}
	}

	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			if (res[i][j] >= 0)
				cout << res[i][j];
			else
				cout << '#';
		}
		cout << endl;
	}

	return 0;
}


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

int main() {
  int A, B, a, b, f=1;
  cin >> A >> B;
  for (int i=1; i<1010; i++) {
    a=i*0.08;
    b=i*0.1;
    if (a==A && b==B) {
      cout << i << endl;
      f=0;
      break;
    }
  }
  
  if (f==1) {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)

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

ans = [0] * (n - 1)


def col(now, color):
    c = 1
    for (b, j) in A[now]:
        if c == color:
            c += 1
        ans[j] = c
        col(b, c)
        c += 1


col(0, 0)
print(max(ans))
for a in ans:
    print(a)


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

int main() {
    int n, r;
    cin >> n >> r;
    cout << (n < 10 ? r + 100 * (10 - n) : r) << endl;
}

Measured memory_bytes: 256
type
  arr=array[1..200000]of longint;
var
  n,i,m,j,x:longint;
  d,t:arr;

  procedure sort(l,r:longint;var a:arr);
  var
    i,j,x,y:longint;
  begin
    i:=l; j:=r;
    x:=a[(l+r) div 2];
    while i<=j do
      begin
        while a[i]<x do inc(i);
        while x<a[j] do dec(j);
        if i<=j then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; inc(i); dec(j); end;
      end;
    if l<j then sort(l,j,a);
    if i<r then sort(i,r,a);
  end;

begin
  readln(n);
  for i:=1 to n do read(d[i]);
  sort(1,n,d);
  readln(m);
  for i:=1 to m do read(t[i]);
  sort(1,m,t);
  i:=1; j:=1;
  while (i<=n)and(j<=m) do
    begin
      x:=d[i];
      while (d[i]=t[j])and(d[i]=x)and(i<=n)and(j<=m) do begin inc(i); inc(j); end;
      while (d[i]<t[j])and(i<=n) do inc(i);
      if j=m+1 then begin writeln('YES'); halt; end;
      if d[i]<>t[j] then begin writeln('NO'); halt; end;
    end;
  writeln('NO');
end.

Measured memory_bytes: 1792
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	std::string S;
	std::cin >> S;

	auto iseven = [](auto first, auto last)->bool {
		int n = (last - first) / 2;
		for (int i = 0; i < n; ++i) {
			if (*(first + i) != *(first + n + i))
				return false;
		}
		return true;
	};

	auto first = S.begin();
	for (auto last = S.end() - 2; last != first; last -= 2) {
		if (iseven(first, last)) {
			std::cout << (last - first) << "\n";
			return 0;
		}
	}
	std::cout << "0\n";
}


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

using namespace std;

int main(){

  int k;
  string str;
  cin>>k;
  cin.ignore();
  getline(cin,str);
  int len = str.length();
  if(len>k){
   str[k]='.';
    k++;
   str[k] ='.';
    k++;
    str[k]='.';
    for(int i=0;i<k+1;i++)
      cout<<str[i];
  }
  else 
    cout<<str;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/
 
const int dx[]={0,1,1,-1,-1,0};
const int dy[]={1,1,0,0,-1,-1};
set<char>vowel={'a','i','u','e','o'};


 
signed main(){
	IOS();
	int N;
	vector<int>ans;
	while(cin>>N,N){
		string s[N];
		rep(i,0,N)cin>>s[i];
		int num = -1;
		string code[N];
		rep(i,0,N){
			code[i]+=s[i][0];
			rep(j,1,s[i].size()){
				if(vowel.find(s[i][j-1])!=vowel.end()||j==0)code[i]+=s[i][j];
			}
		}
		rep(i,1,51){
			set<string>st;
			rep(j,0,N){
				st.insert(code[j].substr(0,i));
			}
			if(st.size()==N){
				ans.push_back(i);
				break;
			}
			if(i==50){
				ans.push_back(-1);
			}
		}
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3172
import collections

int_n = int(input())
ar_int_a = list(map(int, input().split()))

c = collections.defaultdict(int)
result = []

for a in ar_int_a:
    c[a] += 1

for k in sorted(c.keys(), key=lambda x: x, reverse=True):
    if len(result) == 0 and c[k] >= 4:
        print(k ** 2)
        exit(0)
    elif len(result) < 2 and c[k] >= 2:
        result.append(k)

    if len(result) == 2:
        print(result[0] * result[1])
        exit(0)
else:
    print(0)





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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 501


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    map <string , int> mp;
    string str , p;
    for (int i = 0; i < n; i++) {
        cin >> str;
        mp[str]++;
        if (i) {
            if (str[0] != p[p.size() - 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
        p = str;
    }
    for (auto it : mp) {
        if (it.second > 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

typedef long long int LLI;

int N;
LLI C;
LLI xs[114514];
LLI vs[114514];
LLI lsum[114514];
LLI rsum[114514];
LLI lmax[114514];
LLI rmax[114514];
LLI ans;

int main() {
  scanf("%d%lld", &N, &C);
  for (int i=1; i<=N; i++) {
    scanf("%lld%lld", &xs[i], &vs[i]);
    lsum[i] = lsum[i-1] + vs[i] - (xs[i]-xs[i-1]);
    lmax[i] = max(lmax[i-1], lsum[i]);
    ans = max(ans, lsum[i]);
  }

  xs[N+1] = C;
  for (int i=1; i<=N; i++) {
    rsum[i] = rsum[i-1] + vs[N+1-i] - (xs[N+2-i]-xs[N+1-i]);
    rmax[i] = max(rmax[i-1], rsum[i]);
    ans = max(ans, rsum[i]);
  }

  for (int i=1; i<=N; i++) {
    LLI t = lsum[i] - xs[i] + rmax[N-i];
    //printf("%d: lsum[i]:%lld - xs[i]:%lld + rmax[N-i]:%lld\n", i, lsum[i], xs[i], rmax[N-i]);
    ans = max(ans, t);
  }

  for (int i=1; i<=N; i++) {
    LLI t = rsum[i] - (C-xs[N+1-i]) + lmax[N-i];
    //printf("%d: rsum[i]:%lld - (C-xs[N+1-i]):%lld + lmax[N-i]:%lld\n", i, rsum[i], C-xs[N+1-i], lmax[N-i]);
    ans = max(ans, t);
  }

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



Measured memory_bytes: 5120
const MOD = 10**9+7
// factors[f].e+n-1、において max(n)=10**5, max(factors[f].e)=log(M)=log(10**9)=29.89..=30
const N = 10**5+30

let fac = [...new Array(N)].fill(0)
let ifac = [...new Array(N)].fill(0)
const mul = (a,b) => ((a>>16)*b%MOD*65536+(a&65535)*b)%MOD;

const factorization = (n) => {
    let primes= []
    for(let i=2; i*i<=n; i++) {
        let exponent = 0
        while(n%i===0) {
            n /= i
            exponent++
        }
        if(exponent) {
            primes.push({p:i, e:exponent})
        }
    }
    
    if(n!==1) {
        primes.push({p:n, e:1})
    }
    return primes
}

const mpow = (x, n) => {
    ans = 1;
    let _x = x
    while(n != 0){
        if(n & 1) ans = mul(ans,_x);
        _x = mul(_x,_x);
        n = n >> 1;
    }
    return ans;
}

const comb = (n, r) => {
    if(n == 0 && r == 0) return 1;
    if(n < r || n < 0) return 0;
    return mul(fac[n], mul(ifac[r], ifac[n-r]))
}

const init = () => {
    fac[0] = 1;
    ifac[0] = 1;
    for(let i=0; i<N; i++){
        fac[i+1] = mul(fac[i],(i+1));
        ifac[i+1] = mpow(fac[i+1], MOD - 2)
    }
}

const main = (arg) => {
    let [n, m] = arg.split(" ").map(Number)
    let factors = factorization(m)
    let ans = 1
    init()
    Object.keys(factors).forEach(f=>{
        let a = factors[f].e+n-1
        let b = factors[f].e
        ans = mul(ans,comb(a, b))
    })
    console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    char ch;
    cin>>ch;
    if(ch >=65 and ch<= 95)
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"a"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n;

int main() {
	cin >> n;
	
	vector<pair<int, int>> v;
	inc1(i, n) {
	inc1(j, n) {
		if(! (i < j)) { continue; }
		
		if(i + j == (n % 2 == 0 ? n + 1 : n)) { continue; }
		
		v.EB(i, j);
	}
	}
	
	cout << SI(v) << endl;
	RF(e, v) { cout << e.FI << " " << e.SE << "\n"; }
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

map<int, int>mp;
int n, a[214514], sum[214514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sum[0] = a[0];
	REP(i, n)sum[i] = sum[i - 1] + a[i];
	mp[0] = 1;
	int ans = 0;
	rep(i, n) {
		mp[sum[i]]++;
		ans += mp[sum[i]] - 1;
	}
	cout << ans << endl;
	endre;
}

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

const int MAX_N = 100000;
typedef long long ll;

int main() {
		int N, K;
		ll h[MAX_N];

		std::cin >> N >> K;
		for(int i = 0; i < N; ++i) {
			std::cin >> h[i];
		}
		std::sort(h, h + N);

		ll ans = h[N - 1];
		for(int i = 0; i + K - 1 < N; ++i) {
			ans = std::min(ans, h[i + K - 1] - h[i]);
		}

		std::cout << ans << std::endl;
}


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

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

    if (a * n < b)
        cout << a * n << endl;
    else
        cout << b << endl;
    return 0;
}


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

void main_()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> As;
    As.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));

    auto As_sorted(As);
    sort(begin(As_sorted), end(As_sorted));

    ll ans = 0;
    for (ll i = 0; i < N; ++i) {
        const ll mod = 1e9 + 7;
        auto num = As[i];
        // A内での転倒数
        ans += count_if(begin(As), begin(As) + i, [num](auto a) { return a > num; }) * K;
        ans %= mod;

        // 全体での転倒数
        auto it = upper_bound(begin(As_sorted), end(As_sorted), num);
        auto mult = (K * (K - 1) / 2) % mod;
        ans += distance(it, end(As_sorted)) * mult;
        ans %= mod;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  R = [tuple(map(int, input().split())) for _ in range(N)]
  B = [tuple(map(int, input().split())) for _ in range(N)]

  num_friends = 0
  B.sort(key=lambda x: x[0])

  for ib, b in enumerate(B):
    bx, by = b[0], b[1]

    tmp_r = (-1, -1)

    for ir, r in enumerate(R):
      rx, ry = r[0], r[1]

      if rx < bx and \
         ry < by and \
         tmp_r[1] < ry:
         # b[0] - r[0] < tmp_b[0] - r[0] and \
         # b[1] - r[1] < tmp_b[1] - r[1]:
        tmp_r = r

    if tmp_r == (-1, -1):
      continue
    num_friends += 1
    R.remove(tmp_r)

  print(num_friends)


if(__name__ == '__main__'):
  main()

Measured memory_bytes: 9044
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			String[] s=sc.nextLine().split(",");
			double[] x=new double[4];
			double[] y=new double[4];
			for(int i=0; i<4; i++){
				x[i]=Double.parseDouble(s[i*2]);
				y[i]=Double.parseDouble(s[i*2+1]);
			}
			int[] signs=new int[4];
			for(int k=0; k<4; k++){
				int i=(k+1)%4;
				int j=(k+3)%4;
				double vx1=x[i]-x[k];
				double vy1=y[i]-y[k];
				double vx2=x[j]-x[k];
				double vy2=y[j]-y[k];
				double det=vx1*vy2-vy1*vx2;
				if(det<-EPS)
					signs[i]=-1;
				else
					signs[i]=1;
			}
			boolean f=true;
			for(int i=0; i<3; i++)
				if(signs[i]!=signs[i+1])
					f=false;
			println(f?"YES":"NO");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

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

using namespace std;

int n, nr, Max, x, cmmdc;
int main()
{
    cin.sync_with_stdio(false);
    cin >> n >> nr;
    cin >> Max;
    cmmdc = Max;
    while(--n)
    {
        cin >> x;
        Max = max(x, Max);
        cmmdc = __gcd(x, cmmdc);
    }

    cout << (nr % cmmdc == 0 && nr <= Max ? "POSSIBLE" : "IMPOSSIBLE") << '\n';

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

struct St{
	int x;
	int y;
	int hp;
	int c;
};

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {1, 0, -1, 0};

int bfs(int a[10][10], int w, int h, int s, int t){
	St st;
	queue<St> que;
	int r = -1;
	st.x = t;
	st.y = s;
	st.hp = 6;
	st.c = 0;
	que.push(st);
	while(!que.empty()){
		st = que.front();
		que.pop();
		
		if(st.c > 100){
			break;
		}
		if(st.hp == 0){
			continue;
		}
		if(a[st.y][st.x] == 4){
			st.hp = 6;
			a[st.y][st.x] = 1;
		}

		if(a[st.y][st.x] == 3){
			r = st.c;
			break;
		}
		
		for(int i = 0; i < 4; i++){
			int dx = st.x+xdir[i];
			int dy = st.y+ydir[i];
			
			if(0 <= dx && dx < w && 0 <= dy && dy < h && a[dy][dx] != 0){
				St u;
				u.hp = st.hp - 1;
				u.x = dx;
				u.y = dy;
				u.c = st.c+1;
				
				que.push(u);
			}
		}
	}
	
	return r;
}

int main()
{
	int w, h, a[10][10], s, t;
	
	while(cin >> w >> h && w && h){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> a[i][j];
				if(a[i][j] == 2){
					s = i;
					t = j;
				}
			}
		}
		
		cout << bfs(a, w, h, s, t) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0