akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int vacation(vector<vector<int>> v){
  int n=v.size();
  for(int i=1; i<n; i++){
    v[i][0] += max(v[i-1][1], v[i-1][2]);
    v[i][1] += max(v[i-1][0], v[i-1][2]);
    v[i][2] += max(v[i-1][0], v[i-1][1]);
  }
  return max({v[n-1][0], v[n-1][1], v[n-1][2]});
}

int main(){
  int n;
  cin>>n;
  vector<vector<int>> v(n,vector<int>(3));
  for(int i=0; i<n; i++) cin>>v[i][0]>>v[i][1]>>v[i][2];
  cout<<vacation(v);
  return 0;
}

Measured memory_bytes: 14036
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 20
#define int long long
#define MOD 998244353

int32_t main()
{
	IOS
	set<string> p;
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;cin>>s;
		p.insert(s);
	}
	cout<<p.size();
	return 0;
}

Measured memory_bytes: 19196
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
ans = 0
for i in range(61):
    one_cnt = [a >> i & 1 for a in A].count(1)
    zero_cnt = n - one_cnt
    ans = (ans + pow(2, i, mod) * one_cnt * zero_cnt) % mod


print(ans)

Measured memory_bytes: 138168
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static char[] cs = { '.', '#' };

	public static void main(String[] args) {
		int N = sc.nextInt();
		String upper = "";
		String lower = "";
		for (int i = 0; i < 4; ++i) {
			if (queryAppend(upper, lower, i)) {
				upper += cs[i >> 1];
				lower += cs[i & 1];
				break;
			}
		}
		while (true) {
			boolean ok = false;
			for (int i = 0; i < 4; ++i) {
				if (queryAppend(upper, lower, i)) {
					upper += cs[i >> 1];
					lower += cs[i & 1];
					ok = true;
					break;
				}
			}
			if (!ok) break;
		}
		while (true) {
			boolean ok = false;
			for (int i = 0; i < 4; ++i) {
				if (queryPretend(upper, lower, i)) {
					upper = cs[i >> 1] + upper;
					lower = cs[i & 1] + lower;
					ok = true;
					break;
				}
			}
			if (!ok) break;
		}
	}

	static boolean queryAppend(String u, String l, int idx) {
		return query(u + cs[idx >> 1], l + cs[idx & 1]);
	}

	static boolean queryPretend(String u, String l, int idx) {
		return query(cs[idx >> 1] + u, cs[idx & 1] + l);
	}

	static boolean query(String u, String l) {
		System.out.println(u);
		System.out.println(l);
		System.out.flush();
		String res = sc.next();
		if (res.equals("end")) System.exit(0);
		return res.equals("T");
	}
}


Measured memory_bytes: 13716
#include<stdio.h>
int main(){
	double a,b,c;
	scanf("%lf",&a);
	b=(double)a*(double)a*(double)3.14159265358979;
	c=(double)a*(double)2*(double)3.14159265358979;
	printf("%f %f\n",b,c);
	return 0;
}

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

int main()
{
  string s,ans;
  cin>>s;
  for(int i=0;i<3;i++)
  {
    if(s.at(i)=='7')
    {
      ans="Yes";
      break;
    }
  }
  if(ans!="Yes")
    ans="No";
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, k;
	cin >> n >> k;
	vector<double> p(n);
	forn(i, n) cin >> p[i];
	forn(i, n) p[i] = (p[i]+1)/2.0;
	double sum = 0;
	for(int i = 0; i < k; i++)
		sum += p[i];
	double mx = sum;
	for(int i = k; i < n; i++) {
		sum -= p[i-k];
		sum += p[i];
		mx = max(mx, sum);	
	}
	cout << fixed << setprecision(8) << mx << endl;
	return 0;
}



Measured memory_bytes: 4812
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
vector<string> v;
int main(){
  ll n; cin>>n;
  for(int i=0;i<n;i++){
    string s; cin>>s;
    sort(s.begin(),s.end());
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  string bef="#"; ll cnt=0,ans=0;
  for(int i=0;i<v.size();i++){
    if(v[i]!=bef){
      ans+=cnt*(cnt-1)/2;
      bef=v[i];
      cnt=0;
    }
    cnt++;
  }
  cout<<ans+cnt*(cnt-1)/2<<endl;
  return 0;
}


Measured memory_bytes: 5748
ans_list = []

while True:
    n,l,r = map(int,input().split())
    if (n,l,r) == (0,0,0):
        break
    A = [int(input()) for _ in range(n)]
    cnt = 0
    for x in range(l,r+1):
        for i,a in enumerate(A,1):
            if x % a == 0:
                if i % 2 == 1:
                    cnt += 1
                break
            if i == n:
                if n % 2 == 0:
                    cnt += 1
    ans_list.append(cnt)

for ans in ans_list:
    print(ans)


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

int main(){
  int n;
  scanf("%d",&n);
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int z=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)
        z++;
    }
    if(z==8)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int g[1001],s[1001],d[1001],f[1001];
	int j,i,k,a,h[1001];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			h[i]=0;
			g[i]=0;
		}
		for(i=0;i<a;i++){
			scanf("%lld %lld %lld",&s[i],&d[i],&f[i]);
			if(d[i]*f[i]>=1000000) h[i]=1;
			/*if(d[i]==1000000&&f[i]>=1) h[i]=1;
			if(f[i]==100000&&d[i]>=10) h[i]=1;*/
			if(h[i]==0) g[i]=d[i]*f[i];
			else g[i]=0;
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
				if(s[i]==s[j]){
					if(h[i]==0){
						g[i]+=g[j];
						g[j]=0;
					}
					else g[j]=0;
				}
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
			}
		}
		k=0;
		for(i=0;i<a;i++){
			if(h[i]==1){
				printf("%lld\n",s[i]);
				k=1;
			}
		}
		if(k==0) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 2716
n,a,b = [int(i) for i in input().split()]
s = 0
for i in range(n+1):
    num = map(int,str(i))
    sum_tmp = 0
    for n in num:
        sum_tmp = sum_tmp + n
    if( a<= sum_tmp and sum_tmp <= b ):
        s = s + i
print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int arr[n];
	int moder[4]={0};
	for(int i=0; i<n; i++){
		cin>>arr[i];
		arr[i]%=4;
		moder[arr[i]]++;
	}
	int pos = moder[0];
	int impos = moder[1]+moder[3]+(moder[2]?1:0);
	if(pos>=impos-1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3980
import heapq
def main():
    N, M, S = map(int, input().split())
    maxS = 50 * (N-1)
    cost = [[] for _ in range(N)]
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U = U - 1
        V = V - 1
        cost[U].append((A,B,V))
        cost[V].append((A,B,U))
    for i in range(N):
        cost[i].sort()
    r = []
    for _ in range(N):
        C, D = map(int, input().split())
        r.append((C,D))
    time = [-1] * N
    money = [-1] * N
    used = set()
    cities = N
    q = [(0, S, 0)] # time, silver, city
    count = 0
    while cities:
        count += 1
        t, s, ci = heapq.heappop(q)
        if (s, ci) in used or money[ci] >= s:
            continue
        used.add((s, ci))
        if time[ci] == -1:
            time[ci] = t
            money[ci] = s
            cities -= 1
        for a, b, v in cost[ci]:
            if s < a:
                break
            if (s-a, v) not in used and money[v] < s-a:
                heapq.heappush(q, (t+b, s-a, v))
        if s != maxS:
            c, d = r[ci]
            m = cost[ci][0][0]
            k = max(1, (m-s+c-1)//c)
            if (s+c, ci) not in used:
                heapq.heappush(q, (t+d*k, min(s+c*k, maxS), ci))
    for i in time[1:]:
        print(i)
main()


Measured memory_bytes: 43968
import java.util.*;
public class Main {
  
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i=0; i<n; i++) {
			a[i] = Integer.parseInt(sc.next());
			// 1個でも条件を満たさなければDENIED
			if(!check(a[i])) {
				System.out.println("DENIED");
				return;
			}
		}
		System.out.println("APPROVED\n");
		
	}

	// 奇数なら判定しなくていいのでtrue扱い
	// 偶数ならさらに判定する
	private static boolean check(int num) {
		if(num%2 != 0 ) {
			return true;
		}
		if(num%3 == 0 || num%5 == 0) {
			return true;
		}else {
			return false;
		}
	}
}

Measured memory_bytes: 23764
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
hash = {}
a.each do |num|
  hash[num] ? hash[num] += 1 : hash[num] = 1
end

memo = [0]
hoge = 0
for i in 1..200000 do
  memo[i] = hoge + i
  hoge += i
end

sum = 0
hash.each do |k,v|
  sum += memo[v-1]
end

a.each do |num|
  puts sum - (hash[num] - 1)
end

Measured memory_bytes: 31568
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
deque<P> que;

int main(void){
	scanf("%d%d",&n,&k);
	string str;
	cin >> str;
	for(int i=0;i<n;i++){
		if(str[i]=='A')que.push_back(P(0,0));
		else que.push_back(P(1,0));
	}
	int flip=0;
	for(int i=0;i<min(n*2,k);i++){
		int g=que[0].first;
		if((flip-que[0].second)%2==1)g=1-g;
		if(g==0){
			que.pop_front();
			que.push_front(P(1,flip));
		}else{
			flip++;
			que.pop_front();
			que.push_back(P(0,flip));
		}
	}
	for(int i=0;i<n;i++){
		if((flip-que[i].second)%2==1){
			que[i].first=1-que[i].first;
		}
	}
	if(n*2<k){
		int rest=k-n*2;
		if(n%2==1 && rest%2==1){
			que[0].first=1-que[0].first;
		}
	}
	for(int i=0;i<n;i++){
		printf("%c",que[i].first==0?'A':'B');
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2308
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
deque<char> d;
string S;
int T[200010],F[200010];
char C[200010];
int num[200010];


signed main(){
	cin>>S>>N;
	REP(i,S.size()){
		d.push_back(S[i]);
	}
	int cnt2=0;
	REP(i,N){
		cin>>T[i];
		if(T[i]==2){
			cin>>F[i]>>C[i];
			F[i]%=2;
		}
		else{
			cnt2++;
		}
	}
	if(cnt2%2==1){
		reverse(d.begin(),d.end());
	}
	int cnt=0;
	for(int i=N-1;0<=i;i--){
		if(T[i]==1){
			cnt++;
		}
		else{
			num[i]=cnt;
		}
	}
	REP(i,N){
		if(T[i]==2){
			int b=num[i]%2;
			if((b^F[i])==1){
				d.push_front(C[i]);
			}
			else{
				d.push_back(C[i]);
			}
		}
	}
	REP(i,d.size()){
		cout<<d[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 ll dp[2000][2000];

ll n ,m,q,z[1010]={};
ll a[101],b[101],c[101],d[101];

ll co(ll cn,ll sum,vector<ll>v){

    if(v.size()>=n){
        ll ans=0;
        rep(j,q){
            if(v[b[j]-1]-v[a[j]-1]==c[j]){
                ans+=d[j];
            }
        }
        return ans;
    }
    REP(i,cn,m+1){
        ll sum2=sum;
        vector<ll> v2=v;
        v2.pb(i);
        
        sum=max(sum,co(i,sum2,v2));
    }
    return sum;
}

int main(){
   
   string s ;
   cin>>n>>m>>q;

   rep(i,q){
       cin>>a[i]>>b[i]>>c[i]>>d[i];
   }
   cout<<co(1,0,{})<<endl;;

}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> p;
  vector<int> q;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    p.push_back(a);
    q.push_back(a);
  }
  sort(q.begin(),q.end());
  int count = 0;
  for(int i = 0;i < n;i++){
    if(p[i] == q[i]) count++;
  }
  if(count == n)
  {
    cout << "YES" << endl;
    return 0;
  }
  int flag = 0;
  int num1,num2;
  for(int i = 0;i < n;i++){
    if(flag == 1 && p[i] != q[i])
    {
      num2 = i;
      break;
    }
    if(p[i] != q[i])
    {
      num1 = i;
      flag = 1;
    }
  }
  int tmp = p[num1];
  p[num1] = p[num2];
  p[num2] = tmp;
  // for(int i = 0;i < n;i++){
  //   cout << p[i] << " ";
  // }
  // cout << endl;
  for(int i = 0;i < n;i++){
    if(p[i] != q[i])
    {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x = 0; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		x ^= a[i];
	}
	for(int i = 0; i < n; i++) cout << (x ^ a[i]) << ' ';

	return 0;
}

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

int main() {
    string s1, s2, ans = "";
    cin >> s1 >> s2;
    int l1 = s1.size(), l2 = s2.size();
    int dp[l2+1][l1+1];
    for (int i = 0; i < l2+1; ++i)
        for (int j = 0; j < l1+1; ++j)
            dp[i][j] = 0;
    for (int i = 1; i < l2+1; ++i)
        for (int j = 1; j < l1+1; ++j)
            if (s2[i-1] == s1[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    int ci = l2, cj = l1;
    while (dp[ci][cj] > 0) {
        if (dp[ci][cj] == dp[ci][cj-1]) --cj;
        else if (dp[ci][cj] == dp[ci-1][cj]) --ci;
        else {
            ans = s1[cj-1] + ans;
            --ci;
            --cj;
        }
    }
    cout << ans;
}


Measured memory_bytes: 38820
#include <bits/stdc++.h>
using namespace std;
int main() {
 int N;
 long long sum = 0;
 cin >> N;
 vector<int> A(N + 1), B(N);
 // A monster 
 for (int i = 0; i < N + 1; i++) {
   cin >> A.at(i);
 }
 for (int i = 0; i < N; i++) {
   cin >> B.at(i);
 }

 for (int i = 0; i < N; i++) {
   if(A.at(i) >= B.at(i)) {
     sum += B.at(i);
   }
   else if (A.at(i) + A.at(i + 1) <= B.at(i)) {
     sum += A.at(i) + A.at(i + 1);
     A.at(i + 1) = 0;
   }
   else if (A.at(i) + A.at(i + 1) > B.at(i)) {
     A.at(i + 1) -= B.at(i) - A.at(i);
     sum += B.at(i);
   }
 }
 cout << sum << endl;
}


Measured memory_bytes: 1024
def f(header, n, max)
    puts header + n.to_s if n <= max
    [max, n-1].min.downto(1){|i|
        f(header + "#{i} ", n - i, i)
    }
end

loop {
    n = gets.to_i
    break if n == 0
    f("", n, n)
}

Measured memory_bytes: 6104
input = $stdin.read.split("\n")
a = []
input.each_with_index do |b, i|
  next if i == 0
  a << b.split('')
end
a1 = []
a.each do |aa|
  aa_uniq = aa.uniq
  if aa_uniq.size > 1 || (aa_uniq.size == 1 && aa_uniq[0] == '#')
    a1 << aa
  end
end
a2 = []
a1.transpose.each do |aa|
  aa_uniq = aa.uniq
  if aa_uniq.size > 1 || (aa_uniq.size == 1 && aa_uniq[0] == '#')
    a2 << aa
  end
end
a2.transpose.each do |aa|
  puts aa.join
end

Measured memory_bytes: 2428
let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k
let (a, b) = Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (a, b)

let () =
  for i = a to b do
    if i mod k = 0 then begin 
      print_endline "OK";
      exit 0
    end
  done;
  print_endline "NG"


Measured memory_bytes: 3676
import std;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
  int l = scan!int;
  E[] ans;
  int i = 0;
  while(l > 1){
    if(l % 2) ans ~= E(i, -1, l - 1);
    ans ~= E(i, i + 1, l / 2);
    if(l > 1) ans ~= E(i, i + 1, 0);
    l /= 2;
    i += 1;
  }
  print(i + 1, ans.length);
  foreach(an; ans){
    print(an.u + 1, (an.v < 0)? (i + 1): (an.v + 1), an.w);
  }
}
struct E{
  int u, v, w;
}

Measured memory_bytes: 3660
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
    let (n,m) = read!(usize,usize);
    let h = read!([i64]);
    let ab = read!(usize,usize;m);
    let mut seen = vec![true;n];
    for (a,b) in ab {
        if h[a-1]<=h[b-1] {
            seen[a-1] = false;
        }
        if h[a-1]>=h[b-1] {
            seen[b-1] = false;
        }
    }
    println!("{}", seen.into_iter().filter(|&x| x).count());
}

fn run() {
    solve();
}


Measured memory_bytes: 3956
n=int(input())
I={"AC":0,"WA":0,"TLE":0,"RE":0}
for i in range(n):
  I[input()]+=1
print("AC x {}".format(I["AC"]))
print("WA x {}".format(I["WA"]))
print("TLE x {}".format(I["TLE"]))
print("RE x {}".format(I["RE"]))

Measured memory_bytes: 69900
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int count = 1;
  cin >> N;
  unsigned long long s;
  for (int i=0; i<N; i++) {
    cin >> s;
    if (count == s) {
      count++;
    }
  }
  if (count == 1){
    cout << "-1";
  } else {
    cout << N - count + 1;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int s, m, n, i=1, a[1000001], j=0;
    a[0]=0;

    scanf("%d", &s);

    while(1){
        if(i==1) a[1]=s;
      else if(i>1){
            if(a[i-1] % 2 ==0){
                a[i]=a[i-1]/2;
            }
            else{
                a[i]=3*a[i-1]+1;
            }
        }
        
        for(n=1;n<i;n++){
            if(a[i]==a[n]){
                m=i;
                j=1;
            }
        }
        if(j==1)
            break;
        
            i++;
    }
    printf("%d\n", m);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,ans=0;
    cin>>n;
    for(ll i=1;i*i<n;i++){
        m=(n-i)/i;
        if(m&&n%m==i)ans+=m;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    int n;
    cin >> n;


    vector<int> v(n);
    vector<int> cnt(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        if(v[i] % 2 == 0) cnt[i] = 2;
        else cnt[i] = 1;
    }

    ll ans = 1;
    ll no_ans = 1;
    for(int i = 0; i < n; i++){
        ans = ans * 3;
        no_ans = no_ans * cnt[i];
    }

    cout << ans - no_ans << endl;


}

Measured memory_bytes: 256
def cross(x, y):
    return (x.conjugate() * y).imag

def inside_triangle(p, x, y, z):
    a = cross(y-x, p-y)
    b = cross(z-y, p-z)
    c = cross(x-z, p-x)
    if a*b > 0 and b*c > 0:
        return True
    return False

import sys

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    x = complex(x1, y1)
    y = complex(x2, y2)
    z = complex(x3, y3)
    p = complex(xp, yp)
    if inside_triangle(p, x, y, z):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7416
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    int a[110];
    int b[10];
    int t=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<10;i++){
        b[i]=0;
    }
    for(int i=0;i<n;i++){
        if(a[i]>=3200) {
                t++;
        }
        else{
            if(1<=a[i] && a[i]<=399){
                b[0]++;
            }
        for(int j=1;j<8;j++){
            if(400*j<=a[i] && a[i]<=400*(j+1)-1){
                b[j]++;
                break;
            }        
        }
        }
    }
    int cnt=0;
    for(int i=0;i<10;i++){
        if(b[i]!=0){
            cnt++;
        }
    }
    if(cnt!=0)cout<<cnt<<' '<<cnt+t<<endl;
    else cout<<1<<' '<<t<<endl;;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include<chrono>
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define mt make_tuple
#define tc  ll t; cin>>t; while(t--)
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define vi vector<ll>
#define pii pair<ll,ll>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define vii vector<pair<ll,ll>>
ll gcd(ll n,ll m)
{
    if(n==0)
            return m;
    return gcd(m%n,n);
}
bool ifprime(ll n)
{
if(n==1)
return false;
    ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
 
}
return true;
}
void disp(vi v)
{
    for(auto u:v)
    cout<<u<<" ";
    cout<<"\n";
}
void remleadzero(vector<int> &v)
{
    vector<int> u;
    int i=0;
    while(v[i]==0)
        i++;
    while(i<v.size())
    {
        u.push_back(v[i]);
        i++;
    }
    v=u;
}
#define mod 1000000007LL
/*
void myscanf(long long *n)
{
    register long long c=getchar_unlocked();
    *n=0;
    for(;(c<48 ||c>57);c=getchar_unlocked())
        ;
    for(;(c>47 && c<58);c=getchar_unlocked())
    {
        *n=(*n<<1)+(*n<<3)+(c&15);
    }
 
}
void fastscan(long long &number)
{
    bool negative = false;
    register long long c;
 
    number = 0;
 
    c = getchar_unlocked();
    if (c=='-')
    {
 
        negative = true;
 
        c = getchar_unlocked();
    }
 
 
    for (; (c>47 && c<58); c=getchar_unlocked())
        number = number *10 + c - 48;
 
 
    if (negative)
        number *= -1;
}
*/
ll fast_expo(ll n,ll m, ll md)
{
    ll a=1;
    while(m>0)
    {
        if(m&1) a=(a*n)%md;
        n=(n*n)%md;
        m/=2;
    }
    return a%md;
}
// checks if a number is a perfect square in almost O(1) time
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,0LL);
    while(sq*sq<n){
        sq++;
    } 
    if((sq*sq)==n)
        return sq;
    return -1;
}
int dig_sum(ll n){
    int ret=0;
    while(n>0){
        ret+=(n%10);
        n/=10;
    }
    return ret;
}


int main()
{
    io;
    int n,x,y;
    cin>>n>>x>>y;
    int ans[n]{};
    int ct=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i<y and j<y){
                    ans[min(j-i,abs(x-i) + 1 + abs(y-j))]++;
                
                ct++;
                // cout<<i<<' '<<j<<' '<<min(j-i,x-i + 1 + y-j)<<'\n';
            }
            else if(j>=y){
                if(i>x)
                    ans[min(j-i,i-x + 1 + j-y)]++;
                else{
                    ans[x-i + 1 + j-y]++;
                }
                ct++;
            }
        }
    }
    // cout<<ct<<'\n';
    for(int i=1;i<=n-1;i++)
        cout<<ans[i]<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
using namespace std;


int main(){
	int n;
    int a[5]={0};
    char tmp[50];
    long long count=0;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmp;
        if(tmp[0]=='M') a[0]++;
        if(tmp[0]=='A') a[1]++;
        if(tmp[0]=='R') a[2]++;
        if(tmp[0]=='C') a[3]++;
        if(tmp[0]=='H') a[4]++;
    }

    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                count += (long)a[i]*a[j]*a[k];
            }
        }
    }

    printf("%lld\n", count);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int gcd(int a, int b) {
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

int main() {
    int X;
    cin >> X;
    if(360%X == 0) cout << 360/X << endl;
    else {
        cout << lcm(360,X)/X << endl;
    }
}

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

int main(){
    double R;
    cin >> R;

    double ans = 2.0 * 3.141592 * R;
    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}


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

int main() {
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    string ans="";
    int x=sx,y=sy;
    while(y<ty){ans+="U";y++;}
    while(x<tx){ans+="R";x++;}
    while(y>sy){ans+="D";y--;}
    while(x>=sx){ans+="L";x--;}
    while(y<=ty){ans+="U";y++;}
    while(x<tx){ans+="R";x++;}
    ans+="D";y--;
    ans+="R";x++;
    while(y>=sy){ans+="D";y--;}
    while(x>sx){ans+="L";x--;}
    ans+="U";
    cout<<ans;
}

Measured memory_bytes: 3528
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, Y;
    std::cin >> N >> Y;

    for (int64_t m = 0; m <= N; ++m) {
        for (int64_t g = 0; g <= N - m; ++g) {
            auto s = N - m - g;
            if (m*10000 + g*5000 + s * 1000 == Y) {
                std::cout << m << " " << g << " " << s << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
if abs(k-n)>n:
  print(n)
elif k==1 or k==n or n==0:
  print(0)
elif n<k:
  print(k%n)
else:
  n = k+ n%k
  n1 = n%k
  while n1<n:
    n=n1
    n1 = abs(k-n1)
  print(n)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cctype>

int main(void){

  std::string str,command,opstr;

  int num,op1,op2;
  std::cin>>str>>num;
  //std::cout<<str<<std::endl;

  for(int i=0;i<num;i++){
    std::cin>>command;
    if(command=="replace"){
      std::cin>>op1>>op2>>opstr;
      str.replace(op1,op2-op1+1,opstr);
    }
    else if(command=="reverse"){
      std::cin>>op1>>op2;
      for(int j=0;j<=(op2-op1)/2;j++){
        char temp=str[op1+j];
        str[op1+j]=str[op2-j];
        str[op2-j]=temp;
      }
    }
      else if(command=="print"){
          std::cin>>op1>>op2;
        for(int j=op1;j<op2+1;j++) std::cout<<str[j];
        std::cout<<std::endl;
      }
    }
    return 0;
  }



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<int> longest;
std::vector<std::vector<std::pair<int, int> > > hen;
std::vector<std::vector<std::pair<int, int> > > res;
void dfs1(int i, int prev) {
	for (auto j : hen[i]) {
		if (j.first == prev) continue;
		dfs1(j.first, i);
		longest[i] = std::max(longest[i], longest[j.first] + j.second);
	}
}
void dfs2(int i, int prev) {
	for (auto j : hen[i]) {
		if (j.first != prev) res[i].push_back({longest[j.first] + j.second, j.first});
		else {
			if (res[prev][0].second == i) {
				if (res[prev].size() > 1) res[i].push_back({res[prev][1].first + j.second, prev});
				else res[i].push_back({j.second, prev});
			} else res[i].push_back({res[prev][0].first + j.second, prev});
		}
	}
	std::sort(res[i].begin(), res[i].end(), std::greater<>());
	for (auto j : hen[i]) if (j.first != prev) dfs2(j.first, i);
}

int main() {
	int n = ri();
	if (n == 1) {
		std::cout << 0 << std::endl;
		return 0;
	}
	hen.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int x = ri(), y = ri(), z = ri();
		hen[x].push_back({y, z});
		hen[y].push_back({x, z});
	}
	res.resize(n);
	longest.resize(n);
	dfs1(0, -1);
	dfs2(0, -1);
	int ans = 0;
	for (int i = 0; i < n; i++) ans = std::max(ans, res[i][0].first);
	std::cout << ans << std::endl;
	return 0;
}



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

void solve() {
    string s;
    int k;
    cin >> s >> k;
   set<string> sub;
   int n = (int) s.size();
   for (int i = 0; i < n; i++) {
       for (int j = i; j < i + k && j < n; j++) {
           string x;
           for (int l = i; l <= j; l++) {
               x += s[l];
           }
           sub.insert(x);
       }
   }

   auto t = sub.begin();
   for (int i = 0; i < k - 1; i++) {
       t++;
   }
   cout << *t;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 4764
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;
bool prime[10000000];



int main() {
  ll s;
  cin >> s;

  const ll v = 1e9;

  ll x = (v - s % v) % v;
  ll y = (s + x) / v;

  if(x == v) cout << "iji"<<endl;

  cout << "0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
// 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
// 3つの文字の固まりをそれぞれ整数値と想定して読み込む
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (a < c) { // ... 以降を書き足そう！
                System.out.printf("%d %d %d\n", a, c, b);
            } else {
                System.out.printf("%d %d %d\n", c, a, b);
            }
        } else { // ... 以降を書き足そう！
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else if (b < c) {
                System.out.printf("%d %d %d\n", b, c, a);
            } else {
                System.out.printf("%d %d %d\n", c, b, a);
            }
        }
    }
}


Measured memory_bytes: 26244
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main()
{
  int N,W;
  int h,w;
  cin >>N>>W>>h>>w;
  cout <<W*N-(W*h+N*w-w*h) << endl;
}

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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B;
	cin>>A>>B;
	if(A < 10 && B < 10) cout<<A*B<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	long long sum = 0;
	for (int i = 0; i <= n; i++) {
		if (!((i % 3 == 0) || (i % 5 == 0) || (i%3 == 0 && i%5 == 0))) sum += i;
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
using namespace std;
int n,a[100001],ans1,ans2;
void swap(int &a,int &b)
{
	int t=a;a=b;b=t;
}
int px(int l,int r)
{
	int i=l,j=r,mid=a[(l+r)/2];
	do
	{
		while(a[i]>mid)	i++;
		while(a[j]<mid)	j--;
		if(i<=j)
		{
			swap(a[i],a[j]);
			i++,j--;
		}
	}while(i<=j);
	if(i<r)	px(i,r);
	if(j>l)	px(l,j);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	px(1,n);
	for(int i=1;i<=n;i++)
		if(i%2==1)
			ans1+=a[i];
		else
			ans2+=a[i];
	cout<<ans1-ans2<<endl;
}

Measured memory_bytes: 256
import math
N, D = map(int, input().split())
v = []
for i in range(N):
  temp =  list(map(int, input().split()))
  v.append(temp)
res = 0
for i in range(N-1):
  for j in range(i+1, N):
    temp = 0
    for k in range(D):
      temp += (v[i][k] - v[j][k]) ** 2
    temp = math.sqrt(temp)
    if temp.is_integer():
      res += 1
print(res)

Measured memory_bytes: 62488
D, G = [int(i) for i in input().split()]

p = []
c = []
for i in range(D):
    tmp = [int(i) for i in input().split()]
    p.append(int(tmp[0]))
    c.append(int(tmp[1]))

def AccuracyQestionNum(acc_list, count):
    counter = count
    for i in range(len(acc_list)):
        if acc_list[i] == 1:
            counter += p[i]
    return counter

def MaxScoreIndex(acc_list):
    for i in reversed(range(len(acc_list))):
        if acc_list[i] == 0:
            return i
        
def FinalQestionNum(acc_list, score):
    remain_point = G - score
    counter = 0
    max_score_index = MaxScoreIndex(acc_list)
    for i in range(p[max_score_index]):
        remain_point -= (max_score_index+1) * 100
        counter += 1
        if remain_point <= 0:
            break

    if counter == p[max_score_index]:
        return None
    else:
        return counter
        
def ScoreCalculation(acc_list):
    score = 0
    for i in range(len(acc_list)):
        if acc_list[i] == 1:
            score += (i+1) * 100 * p[i]
            score += c[i]
    return score

def DFSQestion(acc_list):
    """先に全探索で得たスコアを計算して, 正解数もカウントしておく"""
    if len(acc_list) == D:
        score = ScoreCalculation(acc_list)
        if score >= G:
            question_num = AccuracyQestionNum(acc_list, 0)
        else:
            count = FinalQestionNum(acc_list, score)
            if count == None:
                return None
            else:
                question_num = AccuracyQestionNum(acc_list, count)
        return question_num
    else:
        question_num1 = DFSQestion(acc_list + [0])
        question_num2 = DFSQestion(acc_list + [1])
        if question_num1 == None:
            return question_num2
        if question_num2 == None:
            return question_num1
        if question_num1 >= question_num2:
            return question_num2
        else:
            return question_num1
        
question_num = DFSQestion([])

print(question_num)



"""
全ての問題に対する全探索(おバカな探索)
sum_question  = 0
for i in range(D):
    sum_question += p[i]

def ScoreCalculation(question_list):
    pre_i = 0
    count = 0
    score = 0
    for p_i in range(len(p)):
        count = sum(question_list[pre_i : pre_i + p[p_i]])
        pre_i += p[p_i]
        score += (p_i+1) * 100 * count
        if count == p[p_i]:
            score += c[p_i]
        
    return score

def DFSAccuracy(question_list):
    if len(question_list) == sum_question:
        score = ScoreCalculation(question_list)
        if score >= G:
            return question_list
        else:
            return None
    else:
        result1 = DFSAccuracy(question_list + [1])
        result2 = DFSAccuracy(question_list + [0])

        if result1 == None:
            return result2
        elif result2 == None:
            return result1
        else:
            que_num1 = sum(result1)
            que_num2 = sum(result2)
            if  que_num1< que_num2:
                return result1
            else:
                return result2

ans_list = DFSAccuracy([])
accuracy_num = sum(ans_list)
print(accuracy_num)
"""

Measured memory_bytes: 3188
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] line = in.nextLine().split(" ");

		int sum = (Integer.parseInt(line[0]) - 1) * (Integer.parseInt(line[1]) - 1);
		System.out.println(sum);
	}
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main()
{
    int n,a,temp;
    cin>>n>>a;
    temp=n%500;
    if(temp-a<=0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(M*2);
  
  for(int i=0;i<M*2; i++)
    cin >> vec.at(i); 
  
  for(int j=0;j<N; j++){
    int sum = 0;
    for(int k=0; k<vec.size(); k++){
      if(vec.at(k) == j+1)
        sum = sum + 1;
    }
    cout << sum << endl;  
  }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (100000L)
#define SIZE_BUF (30L)
#define NUM_MOD (1000000007L)

int main(int argc, char *argv[]) {
  // read inputs
  long N;
  char cs[MAX_N + 1], buf[SIZE_BUF];
  scanf("%ld", &N);
  fgets(buf, SIZE_BUF, stdin);
  scanf("%s", cs);
  // printf("%s\n", cs);

  // count number of each letter
  long cnts[26] = {};
  for (long i = 0; i < N; i++) {
    cnts[cs[i] - 'a']++;
  }

  // solve
  long ans = 1;
  for (long i = 0; i < 26; i++) {
    ans = ans * (cnts[i] + 1) % NUM_MOD;
  }
  printf("%ld\n", ans - 1);

  return 0;
}


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

using namespace std;

int main(){
	int n;
	int ans = 0;
	cin >> n;
	
	vector<int> v(n);
	
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	
	sort(v.begin(),v.end());
	
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			ans += (lower_bound(v.begin()+j+1,v.end(),v[i]+v[j]) - (v.begin()+j+1));
		}
	}
	
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		double M=1000000;
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			double x[]=new double[n];
			double y[]=new double[n];
			double z[]=new double[n];
			double r[]=new double[n];
			double cost[][]=new double[n][n];
			double mincost[]=new double[n];//頂点iへの辺の最小コスト
			boolean use[]=new boolean[n];//頂点iが部分全域木に含まれているか
			double total=0;//answer
			for(int i=0;i<n;i++)
				Arrays.fill(cost[i], M);
			Arrays.fill(mincost, M);
			Arrays.fill(use, false);
			for(int i=0;i<n;i++)
				cost[i][i]=0;
			for(int i=0;i<n;i++)
			{
				x[i]=in.nextDouble();
				y[i]=in.nextDouble();
				z[i]=in.nextDouble();
				r[i]=in.nextDouble();
			}
			for(int i=0;i<n;i++)
				for(int j=i+1;j<n;j++)
				{
					if(i==j)
						continue;
					double dif=Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]));
					if(dif<=r[i]+r[j])
						cost[i][j]=cost[j][i]=0;
					else
						cost[i][j]=cost[j][i]=dif-(r[i]+r[j]);
				}
			mincost[0]=0;
			for(;;)
			{
				int v=-1;//追加する頂点				
				for(int j=0;j<n;j++)//追加する頂点を探す
					if(!use[j]&&(v==-1||mincost[v]>mincost[j]))
						v=j;
				if(v==-1) //全ての頂点を選んだ
					break;
				if(mincost[v]!=0)
					total+=mincost[v];
				use[v]=true;
				for(int j=0;j<n;j++)//追加した頂点と繋がっている辺を調べ最小コストを更新
				{
					if(!use[j]&&mincost[j]>cost[v][j])
						mincost[j]=cost[v][j];
				}
			}
			System.out.printf("%.3f\n",total);
		}
	}
}

Measured memory_bytes: 13000