akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

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

    vector<int> t(n), x(n), y(n);
    for(int i=0; i<n; i++){
        cin >> t.at(i) >> x.at(i) >> y.at(i);
    }
    int xpre=0, ypre=0, tpre=0;
    string ans = "Yes\n";
    for(int i=0; i<n; i++){
        int m = abs(x.at(i) - xpre) + abs(y.at(i) - ypre);
        int time = t.at(i) - tpre;
        if(m <= time && m % 2 == time % 2){
            xpre = x.at(i);
            ypre = y.at(i);
            tpre = t.at(i);
        }
        else{
            ans = "No\n";
            break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	vector<vector<int>> ans(h);
	rep(i, h) {
		ans[i].resize(w, -1);
	}
	int group = 1;
	rep(i, h) {
		bool exist = false;
		rep(j, w) {
			if (s[i][j] == '#') exist = true;
		}
		if (!exist) continue;
		bool first = true;
		rep(j, w) {
			if (s[i][j] == '#') {
				if (first) first = false;
				else group++;
			}
			ans[i][j] = group;
		}
		group++;
	}
	int idx = 0;
	while (ans[idx][0] == -1) idx++;
	for (int i = idx; i < h; i++) {
		if (ans[i][0] != -1) continue;
		rep(j, w) ans[i][j] = ans[i - 1][j];

	}
	for (int i = idx; i >= 0; i--) {
		if (ans[i][0] != -1) continue;
		rep(j, w) ans[i][j] = ans[i + 1][j];

	}


	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}

}

Measured memory_bytes: 1280
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = 305;

using namespace std;

int n, m, k;
int ans[N][N];

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	cin >> n >> m >> k;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		int cur = 0;
		for (int j = 0; j < m; j++)
		{
			cur += bool(s[j] == '#');			
		}
		if (cur)
		{
			cnt++;
			for (int j = 0; j < m; j++)
			{
				ans[i][j] = cnt;
				if (s[j] == '#' && cur > 1)
					cnt++, cur--;
			}
		}
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < m; j++)	
			if (!ans[i][j])
				ans[i][j] = ans[i - 1][j];
	}
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = 0; j < m; j++)
			if (!ans[i][j])
				ans[i][j] = ans[i + 1][j]; 
	}
	for (int i = 0; i< n; i++)
	{
		for (int j = 0; j < m; j++)
			cout << ans[i][j] << ' ';
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 1152
import math
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
else:
  a=(x+y)//3
  b=2*a-x
  c=2*a-y
  if b<0 or c<0:
    print(0)
  else:
    print(cmb(a,b)%(10**9+7))
    

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

int main(){
  ll N,A[200000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  ll B[200000]={0};
  for (int i(0);i<N;i++) {
    if (i==0) B[i]=A[i];
    else B[i]=B[i-1]+A[i];
  }
  map<ll,ll> C;
  for (int i(0);i<N;i++){
    C[B[i]]++;
  }
  C[0]++;
  ll cnt(0);
  for (auto e: C) {
    cnt+=(e.second-1)*e.second/2;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  string a,b; cin >> a >> b;
  string ab = a+b;
  int now = 0;
  for(int i = 0; i < ab.size(); i++){
    now *= 10;
    now += ab[i] - '0';
  }
  bool flg = false;
  for(int i = 1; i <= 1000; i++){
    if(i * i == now) flg = true;
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
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<ll>>;

int main(){
  int N,M,Q;cin >> N >> M >> Q;
  vector<int> L(M),R(M),LQ(Q),RQ(Q);
  vector<vector<int>> sum(N+1,vector<int>(N+1,0));
  for(int i = 0;i < M;i++){
    cin >> L[i] >> R[i];
    L[i];R[i];
    sum[L[i]][R[i]]++;
  }
  for(int i = 0;i < Q;i++){
    cin >> LQ[i] >> RQ[i];
  }
  sum[0][0] = 0;
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
      sum[i+1][j+1] += sum[i][j+1];
      sum[i+1][j+1] += sum[i+1][j];
      sum[i+1][j+1] -= sum[i][j];
    }
  }
  for(int i = 0;i < Q;i++){
    cout << sum[RQ[i]][RQ[i]] - sum[RQ[i]][LQ[i]-1] - sum[LQ[i]-1][RQ[i]] + sum[LQ[i]-1][LQ[i]-1] << endl;
  }
}


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

#define int int64_t
#define MAX_N 105
#define MAX_VAL 100005

#define INF LONG_LONG_MAX/2

using namespace std;

int N,W;
int dp[MAX_N][MAX_VAL];

pair<int,int> input[MAX_N];

int f(int index, int value){
    if(index == 0 && value > 0) return INF;
    if(index <= 0 && value == 0) return 0;
    if(dp[index][value] != -1)return dp[index][value];

    dp[index][value] = f(index-1, value);
    if(value-input[index].second >= 0)
        dp[index][value] = min(dp[index][value], input[index].first + f(index-1, value-input[index].second));

    return dp[index][value];
}

signed main() {
    scanf("%lld %lld", &N, &W);

    int w,v;
    for(int i = 1; i<=N; i++) {
        scanf("%lld %lld", &w, &v);
        input[i] = make_pair(w,v);
    }

    for(int y = 0; y<=N+1; y++) {
        for(int x= 0; x<=MAX_VAL-3; x++){
            dp[y][x] = -1;
        }
    }

    //printf("%lld\n", f(1, W));

    //f(MAX_N,0);
    for(int i = 0; i<= MAX_VAL-3; i++) f(N, i);

    for(int value = MAX_VAL-3; value >= 0; value--){
        if(dp[N][value] <= W){
            printf("%lld\n",value);
            break;
        }
    }
}

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

int d, N;
set<int> d_set;
vector<int> d_vec;

int main() {
    cin >> N;

    for (int i = 1; i <= N; ++i) {
        cin >> d;
        d_set.insert(d);
    }

    copy(d_set.begin(), d_set.end(), back_inserter(d_vec));
    sort(d_vec.begin(), d_vec.end());
    cout << d_vec.size() << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    int ans = (N-1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll R;
    cin >> R;
    if (R < 1200) cout << "ABC\n";
    else if (R < 2800) cout << "ARC\n";
    else cout << "AGC\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[10000];
        int j=0;
       while (true) {
        int x = sc.nextInt();
        if (x == 0 ) {
            break; 
        }
        a[j++] = x;
    }
    for (int i = 0; i<j; i++) {
            System.out.printf("Case %d: %d\n", i+1, a[i]);

} 
}
}


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

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

    int n;
    cin >> n;

    int even_buc[100001] = {0};
    int odd_buc[100001] = {0};

    rep(i, n){
        int v;
        cin >> v;

        if(i%2) ++even_buc[v];
        else ++odd_buc[v];
    }

    int max_even = -1;
    int max_e_num = -1;
    int max_odd = -1;
    int max_o_num = -1;

    rep(i, 100001){
        if(even_buc[i] > max_even){
            max_even = even_buc[i];
            max_e_num = i;
        }
        if(odd_buc[i] > max_odd){
            max_odd = odd_buc[i];
            max_o_num = i;
        }
    }

    sort(even_buc, even_buc+100001, greater<int>());
    sort(odd_buc, odd_buc+100001, greater<int>());

    if(max_e_num == max_o_num){
        if(max_even == max_odd){
            int e_res = max_even;
            int o_res = max_odd;

            for (int i = 2; i < 100001; ++i){
                if(even_buc[i] == 0) break;
                e_res += even_buc[i];
            }
            for (int i = 1; i < 100001; ++i){
                if(odd_buc[i] == 0) break;
                e_res += odd_buc[i];
            }
            
            for (int i = 2; i < 100001; ++i){
                if(odd_buc[i] == 0) break;
                o_res += odd_buc[i];
            }
            for (int i = 1; i < 100001; ++i){
                if(even_buc[i] == 0) break;
                o_res += even_buc[i];
            }
            
            cout << min(e_res, o_res) << endl;
            return 0;

        }
        else{
            if(max_even>max_odd) odd_buc[1] = odd_buc[0];
            else even_buc[1] = even_buc[0];
        }
    }

    if(even_buc[1] == 0 && odd_buc[1] == 0) cout << 0 << endl;
    else {
        int res = 0;
        if(even_buc[1]){
            for (int i = 1; i < 100001; ++i) {
                if(even_buc[i] == 0) break;
                res += even_buc[i];
            }
        }
        if(odd_buc[1]){
            for (int i = 1; i < 100001; ++i) {
                if(odd_buc[i] == 0) break;
                res += odd_buc[i];
            }
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<bits/stdc++.h>
using namespace std;


int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];

    long long dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
n = int(input())
w = []
for i in range(n):
    w.append(str(input()))

count = n
for i in range(n - 1):
    for j in range(i + 1, n):
        if w[i] == w[j]:
            count = 0

for i in range(n - 1):
    s1 = list(w[i])
    s2 = list(w[i + 1])
    #print(s1)
    #print(s2)
    if s1[len(s1) - 1] != s2[0]:
        #print(i)
        count = 0

if count == n:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i=0;
int tmp=0;
String rtn;
int[] nums=new int[3];
for(i=0;i<3;i++){nums[i]=sc.nextInt();}
while((tmp=nums[0]%nums[1])!=0){
nums[0]=nums[1];
nums[1]=tmp;
}
if(nums[2]%nums[1]==0)rtn="YES"; else rtn="NO";
System.out.println(rtn);
}
}

Measured memory_bytes: 21716
<?php
list($N,$M) = explode(" ",trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));
$l=lcm($N,$M);
if($s[0]!=$t[0]){
  echo -1;
}else{
  $i=0;
  while($i<$N){
    $ans[($l/$N)*$i+1]=$s[$i];
    ++$i;
  }
  $i=0;
  while($i<$M){
    if(!isset($ans[($l/$M)*$i+1])){
      $ans[($l/$M)*$i+1]=$t[$i];
    }else{
      if($ans[($l/$M)*$i+1]!=$t[$i]){
        echo -1;
        exit;
      }
    }
    ++$i;
  }
  echo $l;
}
  
function gcd($a,$b){
    return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function lcm($a,$b){
    return ($a*$b/gcd($a,$b));
}
  

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;
const int INF = 10000000;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int minimum = INF;
	rep(i, n) {
		cin >> a[i];
		minimum = min(minimum, a[i]);
	}
	int count = 0;
	rep(i, n) {
		if (minimum != a[i]) count++;
	}
	int ans = (count + k - 2) / (k-1);
	cout << ans << endl;
	return 0;
}



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

typedef struct{
  int num;
  int mmm;
  char mark;
}Card;


int n,x;

int pertition(Card *A,int p,int r){
  int i,j;
  Card tmp;
  x=A[r].num;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].num<=x){
      i++; 
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
      tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    return i+1;
}

void quickSort(Card *A,int p,int r){
  int q;
  if(p<r){
    q = pertition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int main(void){
  int i,q,flag=0;
  Card *A;
  char spe;
  scanf("%d%c",&n,&spe);
  A=malloc(n*sizeof(Card));
  for(i=0;i<n;i++){
    scanf("%c%d%c",&A[i].mark,&A[i].num,&spe);
    A[i].mmm=i;
  }
  quickSort(A,0,n-1);
  for(i=0;i<n-1;i++){
    if(A[i].num==A[i+1].num && A[i].mmm>A[i+1].mmm){
      flag++;
      break;
    }
  }
  if(flag==0) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].mark,A[i].num);
  }
  free(A);
  return 0;
}

Measured memory_bytes: 1680
use proconio::input;

const MAX: i64 = 150;

fn main() {
    input! {
        x: i64,
    }

    for i in 0..MAX {
        for j in 0..MAX {
            if i.pow(5) - j.pow(5) == x {
                println!("{} {}", i, j);
                return;
            }

            if i.pow(5) + j.pow(5) == x {
                println!("{} {}", i, -j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2132
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n,d,ans=0;
    scanf("%lld%lld",&d,&n);
    // ll [n];
    ans = POW(100,d);
    ans*=n;
    // if(d==0 && n==100){
    //     ans=101;
    // }
    // if(d==1 && n==100)
    if(n==100){
        if(d==0) ans=101;
        if(d==1) ans=10100;
        if(d==2) ans=1010000;
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int H,W,i,j;
	for(;;){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0) break;
		if(H>=1&&H<=300&&W>=1&&W<=300){
			for(i=0;i<H;i++){
				for(j=0;j<W;j++){
					if(i==0||i==H-1||j==0||j==W-1) printf("#");
					else printf(".");
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
long long  n,a[MAX],b[MAX];
long long ans;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i]>>b[i];
	for (int i=n-1;i>=0;i--)
	{
		a[i]+=ans;
		ans+=(b[i]-a[i]%b[i])%b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#define ll long long
#define pi acos(-1.0)
#define Go "\n"
#define Afor(i,a,b) for( i=a;i<b;i++)
#define GCD __gcd
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll N,i,X=0,Y=0;
   cin>>N;
   ll V[N];
   ll C[N];
   Afor(i,0,N)
   {
       cin>>V[i];
   }
   Afor(i,0,N)
   {
       cin>>C[i];
       if(V[i]<=C[i])
       {
           V[i]=0;
           C[i]=0;
       }
   }
  ll p= accumulate(V,V+N,X);
   ll q= accumulate(C,C+N,Y);
    ll g=p-q;
    if(g<=0)
    {
        cout<<"0"<<"\n";
    }
    else
    {
        cout<<g<<"\n";
    }




}


Measured memory_bytes: 3592
N = int(input())
A = list(map(lambda x:int(x)-1,input().split()))
ans = 0
paired = []
flag = [0]*N
for i in range(N):
    if flag[i]:
        continue
    else:
        if A[A[i]] == i:
            ans += 1
            flag[A[i]] = 1
print(ans)

Measured memory_bytes: 83740
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string ans;
    REP(i, 3) {
        string s;
        cin >> s;
        ans += toupper(s[0]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void) {
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if (((a % 2 == 0) && (b % 2 == 0) && (c % 2 == 0)) && (a == b && b == c)) {
        cout << -1 << endl;
        return 0;
    }
    
    int counter = 0;
    int temp_a;
    int temp_b;
    int temp_c;
    
     while ((a % 2 == 0) && (b % 2 == 0) && (c % 2 == 0)) {
           temp_a = a;
           temp_b = b;
           temp_c = c;
           a = (temp_b + temp_c) / 2;
           b = (temp_a + temp_c) / 2;
           c = (temp_a + temp_b) / 2;
           counter++;
       }
    cout << counter << endl;
    
    return 0;
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
X = [int(_) for _ in input().split()]
X.sort()


def solve():
    if N >= M:
        print(0)
        return

    diff = []
    for i in range(1, M):
        diff.append(X[i] - X[i - 1])

    diff.sort(reverse=True)

    sum_ = sum(diff)
    r = sum(diff[:N - 1])
    print(sum_ - r)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 13840
#include<bits/stdc++.h>
using namespace std;
queue <pair<int ,int> > po;
int memo[1005][1005],ans,h,w,n, miti[1005][1005];
char c;
bool flag=false;


int main(){

    cin >> h >> w >> n;
    fill(miti[0],miti[1004],100);

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> c;
            if(c=='S'){
                po.push(make_pair(j,i));
                miti[j][i]=0;
            }else if(c=='X')miti[j][i]=100;
            else if(c=='.')miti[j][i]=0;
            else miti[j][i]=(c-'0')+10;
        }
    }

    for(int hp=1;hp<=n;hp++){
            flag=false;
           // printf("hp=%d\n",hp);

        while(!po.empty()){
        int px,py;
        px=po.front().first;
        py=po.front().second;
        po.pop();
        // printf("%d %d\n",px,py);

    int xx[4]={0,1,0,-1};
    int yy[4]={1,0,-1,0};

    if(px<1||py<1||px>w||py>h);
    else{
    for(int i=0;i<4;i++){
            if(miti[px+xx[i]][py+yy[i]]==hp+10){

                ans+=memo[px][py]+1;
               // printf("memo=%d\n",memo[px][py]);
               //   printf("%d=(%d %d)\nans=%d\n\n",hp,px+xx[i],py+yy[i],ans);
                flag=true;
                while(!po.empty())po.pop();
                po.push(make_pair(px+xx[i],py+yy[i]));
                fill(memo[0],memo[1004],0);
                break;
        }else if((miti[px+xx[i]][py+yy[i]]<hp||miti[px+xx[i]][py+yy[i]]>10)&&miti[px+xx[i]][py+yy[i]]!=100){
            po.push(make_pair(px+xx[i],py+yy[i]));
            memo[px+xx[i]][py+yy[i]]=memo[px][py]+1;
            if(miti[px+xx[i]][py+yy[i]]>10);
            else miti[px+xx[i]][py+yy[i]]=hp;
                }
            }
            if(flag==true)break;
    }
        }
    }


    cout << ans << endl;


return 0;
}

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string a, b; cin >> a >> b;
    int x, y; cin >> x >> y;

    string c; cin >> c;
    if (c == a) {
        x--;
    } else if (c == b) {
        y--;
    }
    cout << x << " " << y << endl;
    return 0;
}

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

int main() {
  long long K;
  cin >> K;
  queue<long long> Que;
  for (long long i = 1; i <= 9; i++) Que.push(i);
  long long res = 0;
  for (long long i = 0; i < K; i++){
    long long a = Que.front();
    Que.pop();
    if (i == K - 1) res = a;
    if (a % 10 == 0) {
      Que.push(a * 10);
      Que.push(a * 10 + 1);
    }
    else if (a % 10 == 9) {
      Que.push(a * 10 + 8);
      Que.push(a * 10 + 9);
    }
    else {
      Que.push(a * 10 + (a % 10) - 1);
      Que.push(a * 10 + (a % 10));
      Que.push(a * 10 + (a % 10) + 1);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 5168
from heapq import heappop, heapify, heappush
N, K = map(int, input().split())
H = list(map(int, input().split()))

heap = []
for h in H:
  heappush(heap, -h)

cnt = 0
while heap:
  if K > 0:
    heappop(heap)
    K -= 1
    continue

  h = -heappop(heap)
  if h > 0:
    cnt += h

print(cnt)

Measured memory_bytes: 25896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    long long c=n/(a+b);
    long long ans=c*a;
    n%=(a+b);
    ans+=min(a,n);
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3568
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(1, N+2):
    total += abs(A[i] - A[i-1])

ans = [0]*(N+1)
for i in range(1, N+1):
    bet = abs(A[i-1] - A[i]) + abs(A[i+1] - A[i])
    ans[i] = total - bet + abs(A[i+1] - A[i-1])
for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 14048
x,y = map(int, input().split())
ans='No'
if x in [2]:
  if y in [2]:
    ans='Yes'
if x in [4,6,9,11]:
  if y in [4,6,9,11]:
    ans='Yes'
if x in [1,3,5,7,8,10,12]:
  if y in [1,3,5,7,8,10,12]:
    ans='Yes'
print(ans)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

void change(const string& s, set<string>& dest){
  dest.insert(s);
  for(int i=0;i<SZ(s);++i){
	string tmp = s;
	tmp.erase(i, 1);
	dest.insert(tmp);
  }
  for(int i=0;i<=SZ(s);++i){
	string tmp = s;
	tmp.insert(i, ".");
	REP(c,26){
	  tmp[i] = c + 'a';
	  dest.insert(tmp);
	}
  }
  
  for(int i=0;i<SZ(s);++i){
	string tmp = s;
	REP(c,26){
	  tmp[i] = c + 'a';
	  dest.insert(tmp);
	}
  }
  for(int i=0;i+1<SZ(s);++i){
	string tmp = s;
	swap(tmp[i], tmp[i+1]);
	dest.insert(tmp);
  }
}

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

  int N, D;
  while(cin >> N, N){
	cin >> D;
	VS vs(N);
	REP(i,N){
	  cin >> vs[i];
	}

	vector<set<string>> memo(N);
	map<string,VI> ids;
	REP(i,N){
	  change(vs[i], memo[i]);
	  for(auto& s: memo[i])
		ids[s].PB(i);
	}

	vector<pair<string,string>> ans;
	for(auto& p: ids){
	  if(SZ(p.SS) == 1) continue;
	  if(D == 2){
		REP(ii,SZ(p.SS)) REP(jj,ii){
		  int i = p.SS[ii], j = p.SS[jj];
		  if(vs[i] < vs[j])
			ans.EB(vs[i], vs[j]);
		  else
			ans.EB(vs[j], vs[i]);
		}
	  }
	  REP(ii,SZ(p.SS)) REP(jj,SZ(p.SS)){
		if(ii == jj) continue;
		int i = p.SS[ii], j = p.SS[jj];
		if(p.FF != vs[i] && p.FF != vs[j]) continue;
		
		if(vs[i] < vs[j])
		  ans.EB(vs[i], vs[j]);
		else
		  ans.EB(vs[j], vs[i]);
	  }
	}

	SORT(ans);
	UNIQ(ans);
	for(auto& p: ans)
	  cout << p.FF << "," << p.SS << endl;
	cout << SZ(ans) << endl;
  }

  return 0;
}

Measured memory_bytes: 33220
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        ans=n/500*1000 +(n%500)/5*5;
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;

int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for(auto &e : a) cin >> e;
	sort(all(a));
	auto calc = [&](int x) {
		int r = 0;
		for(auto &e : a) r += (e - x) * (e - x);
		return r;
	};
	int l = a[0], r = a[n - 1];
	while(l + 2 < r) {
		int lm = l + (r - l) / 3;
		int rm = r - (r - l) / 3;
		if(calc(lm) < calc(rm)) {
			r = rm - 1;
		} else {
			l = lm;
		}
	}
	int res = INT_MAX;
	for (int i = l; i <= r; i++) res = min(res, calc(i));
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	ll X;

	cin >> X;


	for (ll i = -500; ;i++) {
		ll a = pow(i, 5);
		//cout << "a->" << a <<" i->" << i << endl;

		for (ll j = -300; j<300; j++ ) {
			ll b = pow(j, 5);
			//cout << "b->" << b << " j->" << j << endl;

			if (a - b == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		
		}
	}




	return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll h , w , m;
    cin>>h>>w>>m;
    set<pair<ll,ll>> s;
    map<ll,ll> mp1, mp2;
    for(int i = 0; i < m; i++){
        int x , y;
        cin>>x>>y;
        s.insert({x , y});
        mp1[x]++;
        mp2[y]++;
    }
    ll nx = -1, ny = -1;
    ll mx = -1;
    for(int i = 1; i <= h; i++){
        if(mx < mp1[i]){
            mx = mp1[i];
            nx = i;
        }
    }
    ll ans = 0;
    vector<int> rows;
    for(int i = 1; i <= h; i++){
        if(mx == mp1[i]){
            rows.pb(i);
        }
    }
    mx = -1;
    for(int i = 1; i <= w; i++){
        if(mx < mp2[i]){
            mx = mp2[i];
            ny = i;
        }
    }
    vector<int> cols;
    for(int i = 1; i <= w; i++){
        if(mx == mp2[i]){
            cols.pb(i);
        }
    }
    ans = mp1[nx] + mp2[ny] - 1;
    bool flag = 0;
    for(auto e : rows){
        for(auto f : cols){
            if(s.find({e , f}) == s.end()){
                ans = mp1[e] + mp2[f];
                flag = 1;
                break;
            }  
        }
        if(flag){
            break;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 63656
#include <stdio.h>

int main(void){
  int i, k = 0, n, a, v[20];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a);
    scanf("%d", &v[a-1]);
  }
  for(i = 1; i < n; i++){
    if(v[k] < v[i]){
      k = i;
    }
  }
  printf("%d %d\n", k+1, v[k]);
  return 0;
}

Measured memory_bytes: 600
from itertools import permutations
from math import factorial as fact
N = int(input())
towns = [list(map(int, input().split())) for _ in range(N)]
acc = 0
for p in permutations(range(N), N):
    for i in range(N - 1):
        t1, t2 = towns[p[i]], towns[p[i + 1]]
        acc += ((t1[0] - t2[0]) ** 2 + (t1[1] - t2[1]) ** 2) ** .5
print(acc / fact(N))


Measured memory_bytes: 9440
fun main(args: Array<String>) {
    val n = readLine()
    val valueList = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val costList = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val maxValueDelta = 0
    var gain = 0
    valueList.forEachIndexed { index, value ->
        if (value > costList[index]){
            gain += value - costList[index]
        }
    }
    println(gain)
}

Measured memory_bytes: 37720
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}

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

int main(){
  int i,a,b;
  string array[101];
  cin>>a>>b;
  for(i=0;i<a;i++){
    cin>>array[i];
    cout<<array[i]<<endl;
    cout<<array[i]<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;


void solve() {
	int K;
	cin >> K;
	vector<lli> runrun = { 1,2,3,4,5,6,7,8,9 };
	if (K <= 9) { cout << runrun[K - 1] << endl; return; }

	int now_runrun = 9;
	while (true) {
		vector<lli> nx_runrun;
		for (auto x : runrun) {
			lli lx = x % 10;
			lli base = x * 10;
			if (lx != 0)nx_runrun.push_back(base + (lx - 1));
			if (lx != 9)nx_runrun.push_back(base + (lx + 1));
			nx_runrun.push_back(base + lx);
		}
		if (K < now_runrun + nx_runrun.size()) {
			sort(nx_runrun.begin(), nx_runrun.end());
			cout << nx_runrun[K - now_runrun - 1] << endl;
			return;
		}
		now_runrun += nx_runrun.size();
		runrun = nx_runrun;
	}
}

int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
    }
    int ans=0;
    int fB=0,lA=0,fl=0;
    rep(i,n){
        for(int j=0;j<s[i].size()-1;j++){
            if(s[i].substr(j,2)=="AB"){
                ans++;
            }
        }
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A'){
            fl++;
        }
        else if(s[i][0]=='B'){
            fB++;

        }
        else if(s[i][s[i].size()-1]=='A'){
            lA++;
        }
    }
    if(fl==0){
        ans += min(fB,lA);
    }
    else if(fB==0 && lA==0){
        ans += fl-1;
    }
    else if(fB+lA>0){
        ans += fl+min(fB,lA);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int P=998244353;
const int inv=P-P/2;
void FWT(int* a,const int n){
	for(int d = 1; d != 1 << n; d <<= 1)
    	for(int i = 0; i != 1 << n; i += d << 1)
        	for(int j = 0; j != d; ++j){
	        	int l=a[i+j],r=a[i+j+d];
	            a[i+j]=l+r>=P?l+r-P:l+r;
				a[i+j+d]=l-r<0?l-r+P:l-r;
			}
}
void UFWT(int* a,const int n){
	for(int d = 1; d != 1 << n; d <<= 1)
    	for(int i = 0; i != 1 << n; i += d << 1)
        	for(int j = 0; j != d; ++j){
	        	int l=a[i+j],r=a[i+j+d];
	            a[i+j]=l+r>=P?l+r-P:l+r;
				a[i+j+d]=l-r<0?l-r+P:l-r;
				a[i+j]=1ll*inv*a[i+j]%P;
				a[i+j+d]=1ll*inv*a[i+j+d]%P;
			}
}
const int N=1<<18;
int a[N],b[N];
int qpow(int a,int b=P-2){
	int res=1;
	for(;b;b>>=1){
		if(b&1){
			res=1ll*res*a%P;
		}
		a=1ll*a*a%P;
	}
	return res;
}
int main(){
	int n;
	cin>>n;
	int sum=0;
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		sum=(sum+a[i])%P;
	}
	sum=qpow(sum);
	for(int i=0;i<(1<<n);i++){
		a[i]=1ll*sum*a[i]%P;
		b[i]=1;
	}
	b[0]=-(1<<n)+1;
	FWT(a,n);
	FWT(b,n);
	a[0]=0;
	for(int i=1;i<(1<<n);i++){
		a[i]=1ll*qpow((P+1-a[i])%P)*b[i]%P;
	}
	UFWT(a,n);
	for(int i=0;i<(1<<n);i++){
		cout<<(P+a[i]-a[0])%P<<'\n';
	}
}

Measured memory_bytes: 5540
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////


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

    vector<ll> L(2 * N + 1);
    repn(i, 2 * N) cin >> L[i];

    sort(++L.begin(), L.end());

    ll ans = 0;

    repn(i, N) { ans += L[2 * i - 1]; }
    cout << ans;
	
	system("PAUSE");
}


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

int main() {
  int n;
  cin >> n;
  vector<int> c(n), s(n), f(n);

  for (int i = 0; i < n - 1; i++) cin >> c[i] >> s[i] >> f[i];

  int count = 0;
  for (int i = 0; i < n-1; i++) {
    count = 0;
    for (int j = i; j < n-1; j++)
    {
      while (count % f[j] != 0 || count < s[j]) count++;
      count += c[j];
    }
    cout << count << endl;
  }
  cout << 0;

  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    int dp[n];
    dp[0] = 0;
    for (int i = 1;i < n;i++) {
        dp[i] = 1e18;
        for (int j = 1;j <= k;j++) {
            if (i - j >= 0) {
                chkmin(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
            }
        }
    }
    cout << dp[n  -1];
    return 0;
}


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

int main()
{
	string s,k="";
  int minn=INT_MAX;
  cin>>s;

  for(int i= 0;i<s.size()-2;i++)
  {
    for(int j=i;j<i+3;j++)
    {
      k+=s[j];
    }

    int n=stoi(k);
    int num=abs(753-n);
    minn=min(minn,num);
    k="";
  }

  cout<<minn<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{

        int a,b,d=0;
        int i;

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

        if(a>b)       d = a + (a-1);
        else if(a<b)  d = b + (b-1);
        else if(a==b) d = a + b;

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

return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
		if (s.equals(u)) {
			a--;
		} else {
			b--;
		}
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 22612
import math

n = int(input())
S = [list(input()) for i in range(n)]
ans = 0
for s in S:
  s.sort()
  "".join(s)
S.sort()
S.append(0)
cnt = 0
for i in range(n):
  if S[i]==S[i+1] :
    cnt += 1
  else:
    cnt += 1
    ans += math.factorial(cnt)/(math.factorial(cnt-2)*2) if cnt >= 2 else 0
    cnt = 0
print(int(ans))
    
  






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

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

  vi h(n);
  rep(i,n) cin >> h.at(i);

  int pre = -999;
  rep(i,n){
    if (pre <= h.at(i) - 1) pre = h.at(i) - 1;
    else if (pre <= h.at(i)) pre = h.at(i);
    else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 3756
n, h, w = map(int, input().split())
c = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])

ans = 0
for i in range(n):
    if c[i][0] >= h and c[i][1] >= w:
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl
using namespace std;
int main()
{
    int n;
    cin >> n;
    yorn (n % 10 == 9 || n / 10 == 9);
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const ll INF = 1e9 + 7;

int main() {

	ll n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	bool flag = true;

	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	ll md = n * (n + 1) / 2;
	if ((sum%md) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	sum /= md;//操作回数

	for (ll i = 0; i < n; i++)
	{
		ll tmp = a[(i + 1) % n] - a[i];
		tmp -= sum;
		flag &= (tmp <= 0LL && (tmp % n == 0));
		
	}

	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

#define PI 3.14159265359
#define MODULO 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x, n;
  int index;
  int diff = 102;
  cin >> x >> n; 
  vi v(102);
  for(int i =0; i<n;i++){
    int k;
    cin >> k;
    v[k] = !!k;
  }
  for(int i =0; i<102;i++){
    if(v[i] == 0){
      if( abs(i-x) <diff){
        diff = abs(i-x);
        index = i;
      }
    }
  }
  cout << index;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main(){
	while(1){
		int w;
		scanf("%d",&w);
		if(w==-1)return 0;
		int ans=0;
		if(w<=10)ans=1150;
		else if(w<=20)ans=1150+(w-10)*125;
		else if(w<=30)ans=2400+(w-20)*140;
		else ans=3800+(w-30)*160;
		printf("%d\n",4280-ans);
	}
}

		

Measured memory_bytes: 1028
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

n, q = map(int, input().split())

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

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    counter[p] += x

ans = [0] * n


def f(par, node, count):
    count += counter[node]
    ans[node] = count
    for n in edges[node]:
        if n == par:
            continue
        f(node, n, count)


f(-1, 0, 0)
print(*ans)


Measured memory_bytes: 237000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;



int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <=n; i+=2) {
		int cou = 0;
		for (int j = 1; j < n + 1; j += 2) {
			if (i % j == 0)cou++;
		}
		if (cou == 8)ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long[5] ary;
    foreach (i; 0 .. 3)
    {
        auto ab = aryread();
        ary[ab[0]]++;
        ary[ab[1]]++;
    }
    long[2] x;
    foreach (i; 1 .. 5)
    {
        x[ary[i] & 1]++;
    }
    bool b = x[0] == 2 && x[1] == 2;
    writeln(b ? "YES" : "NO");
}


Measured memory_bytes: 256