akhauriyash/Code-Regression huggingface dataset:
object Main {
    import scala.annotation.tailrec

    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)

        output(sc)
    }

    @tailrec
    def output(scanner: java.util.Scanner): Unit = {
        val x, y = scanner.nextInt

        if( x != 0 || y != 0 ) {
            println(if( x < y ) x + " " + y else y + " " + x)
            output(scanner)
        }
    }

}



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

int n, t = 0;
int A[101][101];
int d[101], f[101];

void dfs(int r) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) dfs(i);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		d[i] = f[i] = 0;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		if (d[i] == 0) dfs(i);
	}

	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << d[i] << ' ' << f[i] << endl;
	}

	return 0;
}

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

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define deb(x) cout << #x << "= " << x << endl
#define pb push_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(x) for(auto it = x.begin(); x != x.end(); it++)
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
    fast;
    int t=1;
    while(t--){
        //begin code here
        int n;
        cin>>n;
        int arr[n];
        for0(i,n){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout << arr[n-1]-arr[0];
    }
}

Measured memory_bytes: 3524
#include <stdio.h>

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

	 int flag = 7;

	 flag = flag -( 1 << (a-1)) - (1 << (b-1));

	 for (int i = 0; i < 3;i++) {
		 if ((flag >> i) & 1) {
			 printf("%d", i + 1);
		 }
	 }
}

Measured memory_bytes: 128
import math

P = []
# 素数一覧リスト
Max = 1000000

def Era(P, Max) :
    D = list(range(2, Max))
    limit = math.sqrt(Max)
    while True :
        p = D[0]
        
        if limit <= p :
            P += D
            return P
        
        P.append(p)
        D = [d for d in D if d % p != 0]
        
def Sub(x) :
    return abs(x - n)

def Sub2(x) :
    return abs(x - n // 2)

def Near(List, num):
# Listからnumに最も近い値を返す

    Ind = list(map(Sub, List))
    ind = min(Ind)
    # list要素とnumの差分を計算し最小値のインデックスを取得
    return Ind.index(ind)

def Near2(List, num):

    Ind = list(map(Sub2, List))
    ind = min(Ind)
    return Ind.index(ind)

Era(P, Max)

while True :
    n = int(input())
    
    if n == 0 :
        break
    else :
        l = Near2(P, n // 2) + 1
        N = Near(P, n) + 1
        cnt = 0
        s = 0
        I = []
        
        for i in range(N + 1, l - 2, -1) :
            for j in range(s, l + 1) :
                if n == P[i] + P[j] :
                    if P[j] not in I :
                        cnt += 1
                        s = j
                        I.append(P[i])
                        
                elif n < P[i] + P[j] :
                    break
                    
        print(cnt)
        



Measured memory_bytes: 49004
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll l, r, d;
  cin >> l >> r >> d;
  cout << r / d - (l - 1) / d << endl;

  return 0;
}


Measured memory_bytes: 3624
n,x = map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
for i in range(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
print(ans)


Measured memory_bytes: 14548
from collections import deque

def main():
  n=int(input())
  a=[0]*n
  for i in range(n):
    a[i]=deque(list(map(lambda x:int(x)-1,input().split())))
  q=deque([])
  tmp=set()
  for idx,i in enumerate(a):
    x=idx
    y=i[0]
    if x == a[y][0]:
      tmp.add(x)
      tmp.add(y)
  q=deque(tmp)
  for i in tmp:
    a[i].popleft()
  
  
  day=0
  while True:
    day+=1
    t=q.copy()
    q=deque()
    tmp=set()
    while t:
      x=t.popleft()
      if len(a[x])==0: continue;
      y=a[x][0]
      if x == a[y][0]:
        tmp.add(x)
        tmp.add(y)
    q=deque(tmp)
    for i in tmp:
      a[i].popleft()
    if len(q)==0: break;

  for i in range(n):
    if len(a[i])!=0:
      print(-1)
      exit()
  print(day)


if __name__=='__main__':
  main()

Measured memory_bytes: 41612
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n,k=getints()
s=input()
n=len(s)

rl = []
now, cnt = '0', 0

for i in range(n):
    if now != s[i]:
        rl.append(cnt)
        now = s[i]
        cnt = 1
    else:
        cnt += 1
if cnt > 0:
    rl.append(cnt)
acc=[0]*len(rl)
acc[0]=rl[0]
for i in range(1, len(rl)):
    acc[i] = acc[i-1]+rl[i]

# print(rl)
# print(acc)

res = 0
for i in range(len(acc)):
    if i % 2 == 0:
        i0 = i - 2
        j  = min(i + 2 * k - 1, len(acc) - 1)
    else:
        i0 = i - 1
        j  = min(i + 2 * k, len(acc) - 1)
    #print(i,i0,j)
    tmp1 = acc[i0] if i0 >= 0      else 0
    tmp2 = acc[j]  if j < len(acc) else 0
    res = max(res, tmp2-tmp1)


print(res)


Measured memory_bytes: 8052
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int n;
  cin>>n;

  vi a(n);
  cin>>a;

  REP(i,1,n) a[i]=__gcd(a[i],a[i-1]);

  cout<<a[n-1]<<endl;

  return 0;

}


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

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
*/

int checkpoint_num=0;
void pcheck(){
    cout << "----------------" << endl << checkpoint_num << endl << "----------------" << endl;
    checkpoint_num +=1;
}

template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
}

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
}


int main(void){
    int n,q;
    cin >> n >> q;
    // cout << n << q << endl;
    map<long long ,vector<long long>> path;
    set<long long> visited;
    vector <long long> ques(n,0);
    vector<long long> tosearch(1,0);
    vector<long long> ans(n,0);
    int loop = n-1;
    for (int i = 0; i < loop; ++ i){
        int a,b;
        cin >> a >> b;
        a-=1;
        b-=1;
        if (path.count(a) > 0){
            path[a].push_back(b);
        }else{
            path[a] = vector<long long>(1,b);
        }
        if (path.count(b) > 0){
            path[b].push_back(a);
        }else{
            path[b] = vector<long long>(1,a);
        }
    }
    for (int j = 0 ; j < q; ++ j){
        long long p,x;
        cin >> p >> x;
        p-=1;
        ques[p] += x;
    }
    visited.insert(0);
    while (true){
        vector<long long> temp;
        for (auto key:tosearch){
            for (auto ns:path[key]){
                if (visited.count(ns) == 0){
                    visited.insert(ns);
                    ans[ns] += ques[key] + ans[key];
                    temp.push_back(ns);
                }
            }
            ans[key] += ques[key];
        }
        if (temp.empty()){
            break;
        }else{
            tosearch = temp;
        }
    }
    for (int i = 0; i < n-1; ++i){
        cout << ans[i] << " ";
    }
    cout << ans[n-1] << endl;
    return 0;
};


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

int main(){
  int N;
  char A[4];
  cin>>N;
  for(int i=0;i<4;i++){
    A[i]=N%10;
    N=N/10;
  }  
  if(A[1]==A[2]&&(A[0]==A[1]||A[2]==A[3])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
  long N,i,wa,wa0;
  scanf("%ld",&N);
  wa=0;
  wa0=0;
  for(i=1;i<=N;i++)
  {
    if(i%3==0||i%5==0)
    {
      wa0=wa0+i;
    }
    else if(i%3==0&&i%5==0)
    {
      wa0=wa0+i;
    }
    wa=wa+i;
  }
    printf("%ld",wa-wa0);
}

Measured memory_bytes: 1736
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<vector<int>>lst;
unordered_map<long long,pair<int,int>>m;

pair<int,int> dfs(int d,int cur){
	long long key=(long long)d<<32|cur;
	if(m.find(key)!=m.end())return m[key];
	pair<int,int> r={cur,cur};
	if(cur>0){
		auto it=upper_bound(lst[cur].begin(),lst[cur].end(),d);
		if(it!=lst[cur].end()){
			r.first=dfs(*it,cur-1).first;
		}
	}
	if(cur<lst.size()-1){
		auto it=upper_bound(lst[cur+1].begin(),lst[cur+1].end(),d);
		if(it!=lst[cur+1].end()){
			r.second=dfs(*it,cur+1).second;
		}
	}
	return m[key]=r;
}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector<pair<int,int>>v(k);
	for(int i=0;i<k;i++){
		scanf("%d%d",&v[i].first,&v[i].second);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	lst.resize(n);
	for(int i=0;i<k;i++){
		lst[v[i].second].push_back(i);
	}
	for(int i=0;i<n;i++){
		auto p=dfs(-1,i);
		printf(i<n-1 ? "%d " : "%d\n",p.second-p.first+1);
	}
}

Measured memory_bytes: 28924
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
*/
/*
*/
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010];
vector<int> vis(100010,0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    int n,l;
    cin>>n>>l;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        sum=sum+l+i-1;
    }
    ll sum2=sum;
    int mini=1<<30,val=1<<30;
    for(int i=1;i<=n;i++)
    {
        if(mini>abs(l+i-1))
        {
            mini=abs(l+i-1);
            val=l+i-1;
        }
    }
    sum=sum-val;
    cout<<sum<<endl;
}



Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,e,t=0,x;
	cin>>a>>b>>c>>d>>e;
	if(a<0){
		t=t+d;
		x=a*-1;}
	else x=a;
	
	if(a<0)t=t+(c*x)+(e*b);
	else if(a>0)t=e*(b-a);
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 3084
#include "stdio.h"
int main(void)
{
	int a,b,c,i,count=0;
	scanf("%d",&a);	
	scanf("%d",&b);
	scanf("%d",&c);
	for(i=a;i<=b;i++){
	if (c%i==0)
		count++;
	}
		printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class modMCalc
        {
            private const int M = 1000000007;       // 素数(int範囲)

            // 乗算結果 % Mを求める
            static public int Mul(int a, int b)
            {
                return (int)(Math.BigMul(a, b) % M);
            }

            // 冪乗(mod M)
            static public int Pow(int a, int m)
            {
                if (0 == m)
                {
                    return 1;
                }
                if (1 == m)
                {
                    return a;
                }

                int result = 1;
                int param = a;
                for (; m > 0; m >>= 1)
                {
                    if ((m & 0x01) == 1)
                    {
                        result = Mul(result, param);
                    }

                    param = Mul(param, param);
                }

                return result;
            }

            // 除算(mod M)
            static public int Div(int a, int b)
            {
                return Mul(a, Pow(b, M - 2));
            }
        }

        class CombinationPermutation
        {
            private readonly int[] fac;

            // コンストラクタ
            // (mod Mの)階乗テーブル作成する
            public CombinationPermutation(int n)
            {
                fac = new int[n + 1];
                fac[0] = 1;
                for (int i = 1; i <= n; ++i)
                {
                    fac[i] = modMCalc.Mul(fac[i - 1], i);
                }
            }

            // 階乗求める
            public int Factorial(int n)
            {
                return fac[n];
            }

            // nPr
            public int nPr(int n, int r)
            {
                if (n < r)
                {
                    return 0;
                }

                if (n == r)
                {
                    return 1;
                }

                int result = Factorial(n);
                result = modMCalc.Div(result, Factorial(n - r));

                return result;
            }

            // nCr
            public int nCr(int n, int r)
            {
                return modMCalc.Div(nPr(n, r), Factorial(r));
            }
        }

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            if ( Math.Abs(N-M) >= 2)
            {
                Console.WriteLine(0);
                return;
            }

            CombinationPermutation perm = new CombinationPermutation(Math.Max(N, M));

            int ans = perm.Factorial(N);
            ans = modMCalc.Mul(ans, perm.Factorial(M));

            if (N == M)
            {
                ans = modMCalc.Mul(ans, 2);
            }

            Console.WriteLine(ans);
        }
    }
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 2e4 + 1;

bool cmp(const pair<pair<int, int>, int>& one, const pair<pair<int, int>, int>& two) {
	return one.first.first + one.first.second < two.first.first + two.first.second;
}

void solve() {
	int n; 
	cin >> n;
	vector<pair<pair<int, int>, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first.first >> a[i].first.second >> a[i].second;
	}
	sort(all(a), cmp);

	vector<int> dp(maxN);
	for (int i = 0; i < n; i++) {
		int w = a[i].first.first;
		int s = a[i].first.second;
		int v = a[i].second;
		for (int j = maxN - 1;j>=0; j--) {
			if (0 <= j - w && j - w <= s) dp[j] = max(dp[j], dp[j - w] + v);
		}
	}
	cout << *max_element(all(dp));
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

int main() {
  int N;
  double a;
  cin >> N;
  a = N / 1.08;
  if ((N - 13) % 27 == 0 or (N - 13) % 27 == 13) {
    cout << ":(" << endl;
    return 0;
  }
  if (int(a) == a) {
    cout << a;
  } else {
    cout << int(a) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// * template

#include <bits/stdc++.h>
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

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

template<class T, class U> inline void fill_array(T &e, const U &v) { e = v; }
template<class T, class U, size_t s> inline void fill_array(T (&a)[s], const U &v) {for(auto&e:a)fill_array(e,v);}
template<class T, class U, size_t s> inline void fill_array(array<T, s> &a, const U &v) {for(auto&e:a)fill_array(e,v);}
template<class T, class U> inline void fill_array(vector<T> &a, const U &v) {for(auto&e:a)fill_array(e,v);}

// * solve

int main(int argc, const char *const argv[]) {
#ifdef LOCAL
	init_debug(argc, argv);
#endif

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	n = 2 * n;

	vector<int> l(n);
	for(auto &e : l) cin >> e;

	sort(begin(l), end(l));

	int ans = 0;
	for(int i = 0; i < l.size(); i += 2) {
		ans += l[i];
	}
	cout << ans << endl;

	return EXIT_SUCCESS;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 10000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
 ll N;
 string S,T;
 cin >> N >> S >> T;
 for(int i = 0;i < N;i++){
   cout << S[i] << T[i];
 }
 cout << endl;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
s = input()

stack = deque()
for i in range(n):
    if len(stack) > 0:
        stack_last = stack.pop()
        if stack_last == "(" and s[i] == ")":
            continue
        else:
            stack.append(stack_last)
            stack.append(s[i])
    else:
        stack.append(s[i])

# print(stack)
for i in range(len(stack)):
    if stack[i] == '(':
        s = s + ')'
    else:
        s = '(' + s

print(s)


Measured memory_bytes: 3316
import java.util.*;import java.math.*;class Main{public static void main(String[]g){Scanner S=new Scanner(System.in);for(BigInteger a,b,c;S.hasNext();System.out.println(c+" "+a.multiply(b).divide(c))){a=S.nextBigInteger();b=S.nextBigInteger();c=a.gcd(b);}}}


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

typedef pair<int, int> P;

int main(){
    int d; cin>>d;
    int x; cin>>x;
    vector<P> score;
    for(int i=0; i<x; i++){
        char a; cin>>a;
        int p; cin>>p;
        if(a == 'D'){
            score.emplace_back(p, 1);
        }
    }

    int y; cin>>y;
    for(int i=0; i<y; i++){
        string b; cin>>b;
        int q; cin>>q;
        if(b == "DD"){
            score.emplace_back(q, 2);
        }
    }

    int n = score.size();

    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        int sum = 0;
        int need = 0;
        for(int i=0; i<n; i++){
            if((1<<i) & bit){
                sum += score[i].first;
                need += score[i].second;
            }
        }

        if(need <= d){
            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3168
a, b, c = (int(i) for i in input().split())

if a < b:
    if b < c:
        print(a, b, c)
    else:
        if a < c:
            print(a, c, b)
        else:
            print(c, a, b)
else:
    if a < c:
        print(b, a, c)
    else:
        if b < c:
            print(b, c, a)
        else:
            print(c, b, a)


Measured memory_bytes: 5600
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

int solve() {
    // handle IO here
    size_t N, M;
    cin >> N >> M;
    if (N == 0) {
        cout << 0 << '\n';
        return 0;
    }
    vector<size_t> cnt(M + 1);
    for (size_t i = 0; i < N; ++i) {
        size_t K;
        cin >> K;
        for (size_t j = 0; j < K; ++j) {
            size_t food;
            cin >> food;
            cnt[food] += 1;
        }
    }
    int result = 0;
    for (size_t i = 1; i <= M; ++i) {
        if (cnt[i] == N) {
            ++result;
        }
    }
    cout << result << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 256
inputted = int(raw_input())
l = list(raw_input())
x = 0
record = []
record.append(x)
for i in range(len(l)):
    if l[i] == "I":
        x+=1

    elif l[i] == "D":
        x-=1
    record.append(x)
print max(record)


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    string s,t = "01";
    cin >> s;
    
    int sum = 0,sum2 = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] != t[i%2])sum++;
        if(s[i] != t[(i+1)%2])sum2++;
    }
    
    cout << min(sum,sum2) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
main(){
  char number[1001];
  int i,num,sum,m;
  while(1){
    sum=0;
    for(i=0;i<=1000;i++){
      number[i]=0;
    }
    scanf("%s",number);
    if(number[0]=='0') break;
    for(i=0;i<=1000;i++){
      if(number[i]){
      num=number[i]-'0';
     /* printf("%c ",number[i]); */
      sum+=num;
      number[i]=0;
      }
    }
    printf("%d\n",sum);
  }
return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

const int MAX_N = 505050;
vector<int>e[MAX_N], er[MAX_N];
int fin[MAX_N], li[MAX_N], state[MAX_N];
int cnt = 0;
int num = 0;
void dfs1(int now) {
	state[now] = 1;
	fore(x, e[now]) {
		if (state[x] == 0) {
			cnt++;
			dfs1(x);
		}
	}
	cnt++;
	fin[now] = cnt;
}
void dfs2(int now, int num) {
	state[now] = 1;
	li[now] = num;
	fore(x, er[now]) {
		if (state[x] == 0)dfs2(x, num);
	}
}
void scc(int N) {
	//各頂点について終了時間を計算
	for (int i = 0; i < N; i++) {
		if (state[i] == 0)dfs1(i);
	}
	//逆辺を計算
	for (int i = 0; i < N; i++) {
		fore(x, e[i])er[x].pb(i);
	}

	for (int i = 0; i < N; i++)state[i] = 0;

	//終了時間の降順でdfsをしていく
	vector<pair<int, int>>finli;
	for (int i = 0; i < N; i++) {
		finli.pb({ fin[i],i });
	}
	sort(all(finli));
	reverse(all(finli));
	for (int i = 0; i < N; i++) {
		int v = finli[i].second;
		if (state[v] == 0) {
			dfs2(v, num);
			num++;
		}
	}
}

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

	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		e[a].pb(b);
	}
	scc(N);

	vector<vector<int>>v(num);
	for (int i = 0; i < N; i++)v[li[i]].pb(i);

	puts(num);
	for (int i = 0; i < num; i++) {
		cout << v[i].size() << " ";
		fore(x, v[i])cout << x << " ";
		puts("");
	}

	return 0;
}

Measured memory_bytes: 82228
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N;
int H[20],W[20];
string S[5];
int can[5][5][5][5];
int bit[5][5][5][5][5];
int fil[5][5][5][5];
string ord = "RGB";
int dis[POW(16)+10];

int calc(int x) {
  if (IN(x,0,3)) return x;
  if (x < 0) return 0;
  return 3;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  REP(i,N) cin >> H[i] >> W[i];
  REP(i,4) cin >> S[i];
  REP(k,N) {
    for (int y = -3; y <= 3; y++) {
      for (int x = -3; x <= 3; x++) {
        int L = calc(x);
        int R = calc(x+W[k]-1);
        int U = calc(y);
        int D = calc(y+H[k]-1);
        can[U][L][D][R] = 1;
        REP(c,3) {
          int tmp = 0;
          REP(i,H[k]) REP(j,W[k]) {
            if (IN(y+i,0,3) && IN(x+j,0,3)) {
              if (S[y+i][x+j] == ord[c]) {
                tmp |= POW((y+i)*4+(x+j));
              }
            }
          }
          bit[U][L][D][R][c] = tmp;
        }
      }
    }
  }
  REP(i,4) REP(j,4) FOR(k,i,4) FOR(l,j,4) {
    REP(x,16) {
      int add = 0;
      if (x < i*4) add = 1;
      else if (x >= (k+1)*4) add = 1;
      else if (x%4 < j) add = 1;
      else if (x%4 > l) add = 1;
      if (add) fil[i][j][k][l] |= POW(x);
    }
  }
  MINF(dis);
  dis[0] = 0;
  queue<int> que;
  que.emplace(0);
  while (!que.empty()) {
    int mask = que.front(); que.pop();
    REP(i,4) REP(j,4) FOR(k,i,4) FOR(l,j,4) if (can[i][j][k][l]) {
      REP(c,3) {
        int nmask = (mask & fil[i][j][k][l]) | bit[i][j][k][l][c];
        if (dis[nmask] == INF) {
          dis[nmask] = dis[mask] + 1;
          que.emplace(nmask);
        }
      }
    }
  }
  cout << dis[POW(16)-1] << endl;

  return 0;
}


Measured memory_bytes: 3904
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;


int main(){
  int n;
  cin>>n;
  bool ans=false;
  for(int i=0;i<30;i++){
    for(int j=0;j<30;j++){
      if(4*i+7*j==n)ans=true;
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, v;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> v;
        if (v % 2 == 0) {
            if (!(v % 3 == 0 || v % 5 == 0)) {
               cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout <<"APPROVED" << endl;
            
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
int main() {
	int N;
  	cin >> N;
  	vi a(N);
  	rep(i,N) cin >> a[i];
  	map<int,int> sum;
	rep(i,N){
    	int x=a[i];
      	if(sum.count(x)) sum.at(x)++;
      	else sum[x] = 1;
    }
  	int ans=0;
  	for (auto p : sum) {
 	 	auto key = p.first;
 	 	auto value = p.second;
      	if(value < key) ans += value;
      	else ans += value - key;
	}
  	cout << ans << endl;
}

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

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m >> k >> x;
    if(abs(n - m) <= x and abs(m - k) <= x or abs(n - k) <= x)
    {
        cout <<"Yes";
        return 0;
    }
        cout << "No";
}


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

int main(void){
    ll k;
    string ans;
    cin >> k;
    queue<string> que;
    for(int i = 1; i <= 9; i++){
        que.push(to_string(i));
    }

    ll cnt = 1;
    while(true){
        if(cnt == k){
            ans = que.front();
            break;
        } else {
            if(que.front().back() != '0'){
                que.push(que.front() + to_string((que.front().back() - '0') - 1));
            }
            que.push(que.front() + to_string((que.front().back() - '0')));
            if(que.front().back() != '9'){
                que.push(que.front() + to_string((que.front().back() - '0') + 1));
            }
            que.pop();
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String A = sc.next();
		String s = sc.next();
		String C = sc.next();

		System.out.println( "A" + s.charAt(0) + "C" );
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
int main(){
  int n,a;
  scanf("%d",&n);
  for(int i=0; i<n; i++){
    scanf("%d", &a);
    if( a%2==0 ){
      if( a%3 && a%5 ){ printf("DENIED\n"); return 0; }
    }
  }
  printf("APPROVED\n");
  return 0;
}

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

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<"."
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<"."
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"."
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d<<"."
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
char c;

void solve(){
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')
		cout<<"vowel"<<endl;
	else
		cout<<"consonant"<<endl;
}

int main(){
	cin>>c;
	solve();
	return 0;
}


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

const int N_MAX=200000;

int main(){
    int N, T;
    int t[N_MAX];

    cin >> N >> T;
    for(int i=0; i<N; i++)  cin>>t[i];

    int ans=T;

    for(int i=1; i<N; i++){
        ans += min(T, t[i]-t[i-1]);
    }

    cout << ans << endl;
}


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

int main(){
	int n;
	long sum1 = 0;
	long sum2 = 0;
	long op1 = 0;
	long op2 = 0;
	cin >> n;
	for(int i = 0; i <n; i++){
		int tmp;
		cin >> tmp;
		sum1 += tmp;
		sum2 += tmp;
		if(i%2){
			if(sum1 >= 0) {
				op1 += sum1 + 1;
				sum1 = -1;
			}
			if(sum2 <= 0) {
				op2 += -sum2 + 1;
				sum2 = 1;
			}
		} else {
			if(sum1 <= 0) {
				op1 += -sum1 + 1;
				sum1 = 1;
			}
			if(sum2 >= 0) {
				op2 += sum2 + 1;
				sum2 = -1;
			}
		}
	}
	if(op1 < op2) cout << op1;
	else  cout << op2;
	return 0;
}



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

int main() {
	long long int n , k ;
	cin >> n >> k ;
	long long int cnt_n = 0 , cnt_even = 0;
	cnt_n = n/k;
	if(k%2==0){
		for( int i = 1 ; i <= n ; ++i )if(i%k==(k/2))++cnt_even;
	}
	cout<<cnt_n*cnt_n*cnt_n+cnt_even*cnt_even*cnt_even;
	return 0;
}

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


int main(){
    long long H, W;
    cin >> H >> W;
    
    if(W == 1 || H == 1){
        cout << (int)1 << endl;
        return 0;
    }

    long long line1, line2;

    line1 = (W + 1) / 2; // 切り上げ
    // cout << line1 << endl;
    line2 = W / 2;
    // cout << line2 << endl;
    
    long long buf;
    buf = line1 + line2;

    if(H % 2 == 0){
        cout << (long long)buf * (H / 2) << endl;
    }else{
        cout << (long long)buf * (H / 2) + line1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_Q = 100000;

using ll = long long;

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

ll n, m, q;
std::set<ll> a;
bool fld[2000000][7];

void dfs( ll v, ll h )
{
  ll i = v/7, j = v%7;

  fld[i][j] = true;

  rep( d, 4 )
  {
    ll ni = i+dy[d], nj = j+dx[d];

    if( ni >= 0 && ni < h && nj >= 0 && nj < 7 && !fld[ni][nj] )
      dfs( ni*7+nj, h );
  }

  return;
}

int main()
{
  scanf( "%lld%lld%lld", &n, &m, &q );
  rep( i, q )
  {
    ll x;
    scanf( "%lld", &x );

    a.insert( x );
  }

  ll k = m%7==0 ? 1 : 7;

  rep( i, k*m )
    fld[i/7][i%7] = a.find( i%m )!=a.end();

  ll cnt = 0;
  rep( i, k*m ) if( !fld[i/7][i%7] )
    dfs( i, k*m/7 ), ++cnt;

  rep( i, 2*k*m )
    fld[i/7][i%7] = a.find( i%m )!=a.end();

  ll cnt2 = 0;
  rep( i, 2*k*m ) if( !fld[i/7][i%7] )
    dfs( i, 2*k*m/7 ), ++cnt2;
  
  ll a, b;
  
  // cnt (7a)*1+b
  // cnt2 (7ia)*2+b
  a = cnt2-cnt, b = cnt-a;

  printf( "%lld\n", a*7*n/m/k+b );

  return 0;
}

Measured memory_bytes: 13440
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using ll = long long int;
using Graph = vector<vector<pair<int,int>>>;

int choose(int a,int b){
    int c[3] = {0,1,2};
    for(int i=0;i<3;i++){
        if(c[i]==a||c[i]==b){
            c[i] = -1;
        }
    }
    for(int i=0;i<3;i++){
        if(c[i]!=-1){
            return c[i];
        }
    }
}

int main(void){
    int N;cin>>N;
    string S;cin>>S;
    vector<int> color(N,0);
    int sum[3] = {0};
    for(int i=0;i<N;i++){
        if(S[i]=='R'){
            sum[0]++;
        }else if(S[i]=='G'){
            sum[1]++;
            color[i] = 1;
        }else{
            sum[2]++;
            color[i] = 2;
        }
    }
    ll ans = 0;
    ll minus = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(color[i]!=color[j]){
                ans += sum[choose(color[i],color[j])];            
                if(j+j-i<N){
                    if(color[j+j-i]!=color[j]&&color[j+j-i]!=color[i]){
                        minus++;
                    }
                }
            }
            
        }
    }
    cout << (ans/3)-minus << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;
ll N;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int n,m;
int ans=0;

vector<vector<int>> grid;
vector<ll> H, S;
vector<bool> seen;
vector<ll>sum;
vector<int> pl;

vector<int> uf;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(int argc, char **argv){
	int q; cin>>q;
	vector<int> sosu(100001,1);
	vector<int> sum(100001,0);

	sosu[0]=0;
	sosu[1]=0;

	for(int i=2;i<100001;i++){
		if(!IsPrime(i)) sosu[i]=0;
	}

	for(int i=2;i<100001;i++){
		if(sosu[i]==0) continue;
		if(sosu[(i+1)/2]==1) sum[i]=1;  
	}

	/*
	for(int i=1;i<11;i++){
		cout<<sosu[i]<<" ";
	}
	cout<<endl;
	for(int i=1;i<11;i++){
		cout<<sum[i]<<" ";
	}
	for(int i=1;i<100001;i++){
		sum[i]+=sum[i-1];
	}
	cout<<endl;
	for(int i=1;i<11;i++){
		cout<<sum[i]<<" ";
	}*/
	
	for(int i=1;i<100001;i++){
		sum[i]+=sum[i-1];
	}
	queue<int> res;

	for(int i=0;i<q;i++){
		int l,r;cin>>l>>r;
		res.push(sum[r]-sum[l-1]);
	}

	while(!res.empty()){
		int a=res.front();
		res.pop();
		cout<<a<<endl;
	}

}


Measured memory_bytes: 1792
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N,M;
LL A[100000];

LL ans = 0;

void solve(){
	sort(A,A+N,greater<LL>());//降順にソート
	LL left = 0;//ギリギリOKなやつ
	LL right = INF;//ギリギリダメなやつ
	while(left+1<right){
		LL x = (left+right)/2;//このxがOKなやつなのかを判定する

		bool ok = [&]{
			LL total = 0;//xより大きい数がいくつあるかを格納
			for(int i=0;i<N;i++){//Aを順に一個ずつ見ていく
				int l = -1;//条件を満たす数が一個もなければ-1、全部条件を満たすならN-1になる
				int r = N;
				//二部探索
				while(l+1<r){
					int c = (l+r)/2;
					if(A[c]+A[i]>x) l = c;
					else r = c;
				}
				total += r;//結局、考えられるペアはr通り
			}
			return total<M;
		}();

		if(ok) right = x;
		else left = x;
	}

	LL sum_A[100000];//A[0] ~ A[i]の和をsum_A[i]とおく
	int ind[100000];
	sum_A[0] = A[0];
	for(int i=1;i<N;i++){
		sum_A[i] = sum_A[i-1] + A[i];
	}

	LL okline = left+1;//okline未満の数は候補外 (M番目がleftに格納されている数と同じ値を持つ)
	for(int i=0;i<N;i++){//Aを順に一個ずつ見ていく
		int l = -1;//条件を満たす数が一個もなければ-1、全部条件を満たすならN-1になる
		int r = N;
		//二部探索
		while(l+1<r){
			int c = (l+r)/2;
			if(A[c]+A[i]>okline) l = c;
			else r = c;
		}
		//結局、考えられるペアはr通り
		ind[i] = r;
		if(r>0){
			ans += r*A[i]+sum_A[r-1];
		}
	}

	LL sum_of_ind = 0;
	for(int i=0;i<N;i++){
		sum_of_ind += ind[i];
	}
	for(LL i=0;i<(M-sum_of_ind);i++){
		ans += okline;
	}
}
 
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
abc = gets.split.map(&:to_i)
i = 0
results = []
def change_abc(abc)
  a = abc[0]
  b = abc[1]
  c = abc[2]
  result = []
  result[0] = (b + c) / 2
  result[1] = (a + c) / 2
  result[2] = (b + a) / 2
  return result
end
loop do
  break if abc.any? { |a| a % 2 == 1 }
  if results.include?(abc)
    i = -1
    break
  end
  results << abc
  i += 1
  abc = change_abc(abc)
  break if i == 30
end
print i


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

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

Measured memory_bytes: 0
def small(x, y, a):
    a[x][y] += 1
    a[x + 1][y] += 1
    a[x - 1][y] += 1
    a[x][y + 1] += 1
    a[x][y - 1] += 1


def medium(x, y, a):
    small(x, y, a)
    a[x + 1][y + 1] += 1
    a[x - 1][y + 1] += 1
    a[x - 1][y - 1] += 1
    a[x + 1][y - 1] += 1


def large(x, y, a):
    medium(x, y, a)
    a[x + 2][y] += 1
    a[x - 2][y] += 1
    a[x][y + 2] += 1
    a[x][y - 2] += 1


p = [[0] * 13 for i in range(13)]
while 1:
    try:
        x, y, s = map(int, input().split(','))
        if s == 1:
            small(x, y, p)
        elif s == 2:
            medium(x, y, p)
        elif s == 3:
            large(x, y, p)
    except:
        break

w, dens = 0, 0
for i in range(10):
    for j in range(10):
        if p[i][j] == 0:
            w += 1
        if p[i][j] >= dens:
            dens = p[i][j]

print(w)
print(dens)



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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int> > s(M);
    for (int i = 0; i < M; ++i) {
        int k; cin >> k;
        for (int j = 0; j < k; ++j) {
            int a; cin >> a; a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; ++i) cin >> p[i];
    
    long long res = 0;
    for (int bit = 0; bit < (1<<N); ++bit) {
        bool ok = true;
        for (int i = 0; i < M; ++i) {
            int con = 0;
            for (auto v : s[i]) {
                if (bit & (1<<v)) ++con;
            }
            if (con % 2 != p[i]) ok = false;
        }
        if (ok) ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
    string a,b,c;
    int n,sum=0;
    cin >> n;
    cin >> a>> b>>c;
    for(int i=0;i<n;i++){
        if(a[i]==b[i] && a[i]==c[i] && b[i]==c[i] ){
            sum+=0;
        }else if(a[i]!=b[i] && b[i]!=c[i] && a[i]!=c[i]){
            sum+=2;
        }else{
            sum+=1;
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll p, q, r;
    cin >> p >> q >> r;
    cout << p + q + r - max({p, q, r}) << endl;
}

Measured memory_bytes: 256