akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M,vector<int>(2));
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    vec.at(i).at(0) = a;
    for(int j=0; j<b; j++){
      int x;
      cin >> x;
      vec.at(i).at(1) += pow(2,x-1);
    }
  }
  
  int INF = 1000000000;
  int P = pow(2,N);
  
  int dp[M+1][P];
  for(int i=0; i<M+1; i++){
    for(int j=0; j<P; j++){
      dp[i][j] = INF;
    }
  }
  
  for(int i=0; i<M; i++){
    int a = vec.at(i).at(0);
    int b = vec.at(i).at(1);
    dp[i+1][b] = a;
    for(int j=0; j<P; j++){
      if(dp[i][j] != INF){
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]); 
        dp[i+1][j|b] = min({dp[i][j|b], dp[i][j] + a, dp[i+1][j|b]});
      }
    }
  }
  
  /*for(int i=0; i<M+1; i++){
    for(int j=0; j<P; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  
  if(dp[M][P-1] == INF){
    cout << -1 << endl;
  }
  else{
    cout << dp[M][P-1] << endl;
  }
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    string S, S2;
    long long K; 
    cin >> S;
    cin >> K;
 
    long long count = 0;
    long long count2 = 0;
    // long long count_buff = 0;
    long long l = S.length();
    long long flag = 0;
    long long flag_same = 0;
 
    for(long long i=0; i < l-1; i++){
        if(S[i] != S[i+1]){
            flag_same = 1;
            break;
        }
    }

    if(flag_same == 0){
        cout << (long long) (l * K / 2) << endl;
        return 0; 
    }

    //check start-fin
    // cout << S[0] << S[l-1] << endl;
    for(long long i=0; i < l-1; i++){
        if(S[i] == S[i+1] && S[i+1] == S[i+2]){
            count++;
            i++;
        }else if(S[i] == S[i+1]){
            count++;
        }
    }

    S2 = S + S;
    for(long long i=0; i < 2*l-1; i++){
        if(S2[i] == S2[i+1] && S2[i+1] == S2[i+2]){
            count2++;
            i++;
        }else if(S2[i] == S2[i+1]){
            count2++;
        }
    }
    if(count2 == 2*count){
        cout << count*K << endl;
    }else{
        cout << count*K + (K-1) << endl;
    }
    // cout << count << endl;
    // cout << count2 << endl;
    
 
    // cout << l << endl;
    // cout << count*K << endl;
 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int i,j,ar[n],dp[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        if(i==0)
        {
            dp[i]=0;
            continue;
        }
        if(i==1)
        {
            dp[i]=abs(ar[i]-ar[i-1]);
            continue;
        }
        dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
    }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
  int N;
  long sum = 0;
    scanf("%d",&N);
    while(N > 0){
        if(N % 3 != 0 && N % 5 !=0 )
            sum = sum + N;
        N = N - 1;
    }
    printf("%ld\n",sum);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    int d,t,s;cin>>d>>t>>s;
    double tim = (double)d/(double)s;
    if(tim>t) cout<<"No"<<endl;
    else cout<<"Yes"<<'\n';
}


Measured memory_bytes: 3644
H = []
W = []

while True:
    h, w = map(int, input().split())
    if h == w and h == 0:
        break
    H.append(h)
    W.append(w)

for i in range(len(H)):
    for j in range(H[i]):
        print('#'*W[i])
    print('')



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

int main() {
    string s;
    cin >> s;
    if (s=="A") cout << "T" << endl;
    else if(s=="T") cout << "A" << endl;
    else if(s=="G") cout << "C" << endl;
    else  cout << "G" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

int const INF = 1e9;

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D), bestT(D);
  int ans = -INF;
  //std::set<int> last[26];
  //for(auto& li: last) li.insert(-1); // sentinel
  int ansa[27];
  for(int k = 0; k <= 26; ++k) {
    ansa[k] = 0;
    int las[26];
    std::fill_n(las, 26, -1);
    for(int d = 0; d < D; ++d) {
      int ma = -INF, tt = -1;
      for(int T = 0; T < 26; ++T) {
        int cur = s[d][T];
        int sv = las[T];
        las[T] = d;
        for(int cx = 0; cx < 26; ++cx) {
          cur -= c[cx]*(d+k - las[cx]);
        }
        las[T] = sv;
        if(cur > ma) { ma = cur; tt = T; }
      }
      ansa[k] += ma;
      las[tt] = d;
      t[d] = tt;
    }
    if(ansa[k] > ans) {
      ans = ansa[k];
      std::copy(t.begin(), t.end(), bestT.begin());
    }
  }
  std::copy(bestT.begin(), bestT.end(), t.begin());
  //for(auto& li: last) li.insert(D); // sentinel
#if 0  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  int range = 50;
  for(int rep = 0;; ++rep) {
    if((xor64()>>25)%2) {
      one_day(xor64()%365);
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-range || d2 < d1-range || t[d1] == t[d2]) {
          d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
      }
    }
    if(rep%100 == 0) {
      int x = get_time();
      if(x > 1950) break;
    }
  }
#endif
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int height[10];
	for(int i=0;i<10;i++){
		cin >> height[i];
	}
	sort(height,height+10,greater<int>());
	for(int i=0;i<3;i++){
		cout << height[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc061_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N, K;
  cin >> N >> K;

  vector<pl> c(N);
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    c[i] = {a, b};
  }
  sort(c.begin(), c.end());

  for (auto p : c) {
    if (p.second >= K) {
      cout << p.first << endl;
      return 0;
    }
    K -= p.second;
  }

  return 0;
}

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

int x1[10][3]={},x2[10][3]={},x3[10][3]={},x4[10][3]={};

int main(){
	int diu,a,x,y,num;
	string s="####################";
	cin>>diu;
	for (int i=0;i<diu;i++){
	cin>>a>>x>>y>>num;
		if (a==1)x1[y-1][x-1]+=num;
		if (a==2)x2[y-1][x-1]+=num;
		if (a==3)x3[y-1][x-1]+=num;
		if (a==4)x4[y-1][x-1]+=num;
	}
	for (int i=0;i<3;i++){
		for (int j=0;j<=9;j++)cout<<" "<<x1[j][i];
		cout<<endl;
	}
	cout<<s<<endl;
	for (int i=0;i<3;i++){
		for (int j=0;j<=9;j++)cout<<" "<<x2[j][i];
		cout<<endl;
	}
	cout<<s<<endl;
	for (int i=0;i<3;i++){
		for (int j=0;j<=9;j++)cout<<" "<<x3[j][i];
		cout<<endl;
	}
	cout<<s<<endl;
	for (int i=0;i<3;i++){
		for (int j=0;j<=9;j++)cout<<" "<<x4[j][i];
		cout<<endl;
	}
	
}


Measured memory_bytes: 3152
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
S = list(input())[:-1]
a = S[:3]
print("".join(a))


Measured memory_bytes: 10512
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  lint n,x;
  lint mi=100000000000;
  lint gc=0;
  vector<lint> l;
  cin>>n>>x;
  rep(i,n){
    lint j;
    cin>>j;
    mi=min(mi,j);
    l.pb(j);
    gc=gcd(gc,abs(x-j));
  }

  cout<<gc<<endl;

}

Measured memory_bytes: 1400
using System;
using System.Linq;

public class Solution
{
    public static bool CanKillAll(int[] enemies, long turn, int basicDamage, int exDamage)
    {
        long d = basicDamage * turn;
        var remain = enemies.Select(hp => hp - d).Where(hp => hp > 0);
        foreach (var hp in remain)
        {
            var t = (hp + exDamage - 1) / exDamage;
            turn -= t;
            if (turn < 0)
            {
                return false;
            }
        }
        return true;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var a = vals[1];
        var b = vals[2];
        var enemies = new int[n];
        for (int i = 0; i < n; i++)
        {
            enemies[i] = int.Parse(Console.ReadLine());
        }

        var basicDamage = b;
        var exDamage = a - b;

        var max = enemies.Max();
        long minRange = (max + a - 1) / a;
        long maxRange = (max + b - 1) / b;

        while (minRange != maxRange)
        {
            var turn = (minRange + maxRange) / 2;
            bool can = CanKillAll(enemies, turn, basicDamage, exDamage);
            if (can)
            {
                maxRange = turn;
            }
            else
            {
                minRange = turn + 1;
            }
        }

        Console.WriteLine(minRange);
    }
}

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

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

int main(){
    vector<int> imos(1010,0);
    int a,b,n;
    cin>>a>>b;
    cin>>n;
    //imos[a]++;
    //imos[b+1]--;

    rep(i,n){
        int x,y;
        cin>>x>>y;
        imos[x]++;
        imos[y]--;
    }

    rep(i,1010){
        imos[i+1]+=imos[i];
      //  cerr<<imos[i]<<" ";
    }
    //cerr<<endl;
    for (int i=a;i<b;i++){
        if (imos[i]!=0){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;


}


Measured memory_bytes: 3128
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define dbg(x) cerr<<"["<<#x<<" = "<<x<<"]"

int D;
vector<vector<int>> s;
vector<int> c;

int get_score(vector<int> &sc) {
    unordered_map<int, int> last;
    int S = 0;
    for (int i = 0; i < D; ++i) {
        S += s[i][sc[i] - 1];
        last[sc[i] - 1] = i + 1;
        for (int j = 0; j < 26; j++)S -= c[j] * (i + 1 - last[j]);
    }
    return S;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

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

    cin >> D;
    c = vector<int>(26);
    s = vector<vector<int>>(D, vector<int>(26));
    for (auto &i:c)cin >> i;
    for (auto &i:s) {
        for (auto &j:i)cin >> j;
    }

    vector<int> ans(D);
    for (int i = 0; i < D; ++i) {
        int cur = -1, pos = -1;
        for (int j = 0; j < 26; ++j) {
            if (cur < s[i][j]) {
                pos = j;
                cur = s[i][j];
            }
        }
        ans[i] = pos + 1;
    }
    for (auto i:ans)cout << i << endl;

//    int score = get_score(ans);
//    dbg(score) << endl;
}

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

int main() {

	int n, m; cin >> n >> m;
	vector<int> l(m), r(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
	}
	int left = l[0];
	int right = r[0];
	for (int i = 1; i < m; i++) {
		left = max(left, l[i]);
		right = min(right, r[i]);
	}
	cout << max(0, right - left + 1) << endl;
	return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, a = 0, ans;
    string S;
    cin >> N >> S;
    ans = N;
    vector<int> E(N);
    for (int i = 0; i < N; i++){
        if (S.at(i) == 'E') {
            a++;
        }
        E.at(i) = a;
    }
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            ans = min(ans, E.at(N - 1) - E.at(i));
            continue;
        }
        int left = i - E.at(i - 1);
        int right = E.at(N - 1) - E.at(i);
        ans = min(left + right, ans);
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 1796
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>
#include<bitset>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const double EPS = 0.000000000001;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


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


	ll sum = 0;
	int start = 0;
	for (int i = 1; i < N; i++) {
		if (t[i] - t[i - 1] > T) {
			sum += (t[i - 1] + T - start);
			start = t[i]; 
			
			if (i == N - 1) {
				sum += T;
			}
		}

		else if (i == N - 1) {
			sum += (t[i] + T - start);
		}
	}

	if (N != 1) {
		cout << sum;
	}
	else {
		cout << T;
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int,int> P;
int a,b;
P p[5];

int main(){
	while(cin>>a>>b){
		if(!a)return 0;
		p[0]=make_pair(a+b,0);
		for(int i=1;i<5;i++){
			cin>>a>>b;
			p[i]=make_pair(a+b,i);
		}
		sort(p,p+5);
		cout<<(char)('A'+p[4].second)<<" "<<p[4].first<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int n;
P x[100000];
ll c[100000];

int main(){
  cin >> n;
  rep(i, n){
    int a;
    cin >> a;
    x[i] = P(a, i);
  }
  sort(x, x + n);
  int p = n - 1;
  for(int i = n - 1; i >= 0; --i){
    if(!i || x[i].first > x[i - 1].first){
      p = min(x[i].second, p);
      c[p] += ll(x[i].first - (i ? x[i - 1].first : 0)) * (n - i);
    }
  }
  rep(i, n){
    cout << c[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string ans = "Draw";

            var line = Console.ReadLine().Split(' ');

            a = int.Parse(line[0]);
            b = int.Parse(line[1]);

            if (a > b)
                ans = (b == 1) ? "Bob" : "Alice";
            else if (a < b)
                ans = (a == 1) ? "Alice" : "Bob";

            Console.WriteLine(ans);


            return;
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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

int main(){
    int n;
    cin >> n;
    int GCD;
    int a;
    cin >> a;
    GCD = a;
    for(int i = 1; i < n; i++){
        cin >> a;
        GCD = gcd(a,GCD);
    }
    cout << GCD << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace 令和{
    class ABC{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            //bool[] isEven = new bool[n-1];
            List<int[]>[] tonari = new List<int[]>[n+1];
            int[] ans = new int[n+1];
            for(int i=0;i<n+1;i++){
                tonari[i] = new List<int[]>();
                tonari[i] = new List<int[]>();
                tonari[i] = new List<int[]>();
                tonari[i] = new List<int[]>();
                tonari[i] = new List<int[]>();
                tonari[i] = new List<int[]>();
                ans[i] = -1;
            }
            int u,v,w;
            for(int i=1;i<n;i++){
var rrrr =  Console.ReadLine();
                string[] uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                tonari[u].Add(new int[2]{v,w});
                tonari[v].Add(new int[2]{u,w});
            }
            Queue<int> q = new Queue<int>();
            q.Enqueue(1);
            ans[1] = 0;
            while(q.Count!=0){
                int p = q.Dequeue();
                foreach(int[] tnr in tonari[p]){
                    if(ans[tnr[0]]==-1){
                        ans[tnr[0]] = (tnr[1]+ans[p])%2;
                        q.Enqueue(tnr[0]);
                    }
                }
            }
            for(int i=0;i<n;i++){
                Console.WriteLine(ans[i+1]);
            }
 
 
        }
    }
}


Measured memory_bytes: 39072
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int units[] = {10, 50, 100, 500};

int m;
int num_coin;
int lim[4];

int mi;
int ans[4];

int change(int x) {
    int ret = 0;
    rrep(i, 4) {
        ret += x / units[i];
        x %= units[i];
    }
    return ret;
}

void dfs(vector<int> cand = {0, 0, 0, 0}, int k = 0, int payment = 0, int num_used = 0) {
    if (k == 4) {
        if (payment < m) return;
        int rest = num_coin - num_used + change(payment - m);
        if (mi > rest) {
            mi = rest;
            rep(i, 4) ans[i] = cand[i];
        }
        return;
    }

    rep(i, lim[k] + 1) {
        dfs(cand, k + 1, payment, num_used);
        cand[k]++;
        payment += units[k];
        num_used++;
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int flag = 0;
    while (cin >> m, m) {
        if (flag++ > 0) cout << endl;

        num_coin = 0;
        rep(i, 4) {
            cin >> lim[i];
            num_coin += lim[i];
        }

        mi = 1e9;
        dfs();

        rep(i, 4) {
            if (ans[i] > 0) cout << units[i] << " " << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); 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; }


int main() {
    ll x, n;
    cin >> x >> n;
    vector<ll> p(n, 0), l(200);
    rep1(i, n) cin >> p[i];
    ll num = 100000;
    ll ans = 0;
    sort(p.begin(), p.end(), greater<ll>());
    rep1(i,200) l[i] = i;
    rep1(i,p.size()){
        l.erase(l.begin() + p[i]);
    }
    rep1(i, l.size()){
        if (num > abs(x-l[i])){
            num = abs(x-l[i]);
            ans = l[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
n = int(input())
d = input().split()
d = sorted([int(d_) for d_ in d])

ind = 0
small = 0

if(n%2 != 0):
    print(0)
else:
    ind = int(n/2)
    d1 = d[ind-1]
    d2 = d[ind]
    
    if(d1 == d2):
        print(0)
    else:
        print(d2-d1)
        

Measured memory_bytes: 15196
#include <stdio.h>
#define max 500000  
int L[max/2+2];
int R[max/2+2];
int c=0;
int merge(int S[], int n, int left, int mid, int right){
int i, j, k;      
int n1 = mid-left;
int n2 = right-mid;
for (i = 0; i < n1; i++)
L[i] = S[left+i];
for (i = 0; i < n2; i++)
R[i] = S[mid+i];
L[n1] = R[n2] = 2000000000;
i = j = 0;
for ( k = left; k < right; k++){
c++;
if ( L[i] <= R[j]){
S[k] = L[i]; 
i++;
}
else{
S[k] = R[j];
j++;
}
}
}
void mergeSort(int S[], int n, int left, int right){
int mid;
if (left+1<right){
mid = (left+right) / 2;
mergeSort(S,n, left,mid);
mergeSort(S, n,mid,right);
merge(S,n, left,mid,right);
}
}
int main(){
int S[max], n, i;
 
scanf("%d", &n);
for (i = 0; i < n; i++) 
scanf("%d", &S[i]); 
mergeSort(S, n, 0, n);
for (i = 0; i < n; i++){
if(i==0)
printf("%d", S[i]);
else 
printf(" %d", S[i]);
}

printf("\n");
 
printf("%d\n", c);
 
return 0;
}

Measured memory_bytes: 5588
void main() {
  problem();
}

void problem() {
  const X = scan!int;
  const Y = scan!int;
  const A = scan!int;
  const B = scan!int;
  const C = scan!int;
  auto P = scan!long(A).sort!"a > b".array;
  auto Q = scan!long(B).sort!"a > b".array;
  auto R = scan!long(C);
  
  deb([X, Y, A, B, C]);
  deb(P);deb(Q);deb(R);

  long solve() {

    auto apples = (P[0..X] ~ Q[0..Y] ~ R).sort!"a > b".array;
    return apples[0..X+Y].sum;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 18928
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	x := nextInt()
	y := nextInt()
	for i := 0; i <= x; i++ {
		if i*2+(x-i)*4 == y {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1756
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0010
  * Circumscribed Circle of a Triangle
  */
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(n).map(_.split(" +").map(BigDecimal(_)))
      .map { case Array(x1, y1, x2, y2, x3, y3) => solve(x1, y1, x2, y2, x3, y3) }
      .foreach { case (px, py, r) =>
        println(s"${px.setScale(3, BigDecimal.RoundingMode.HALF_UP)} ${py.setScale(3, BigDecimal.RoundingMode.HALF_UP)} ${r.setScale(3, BigDecimal.RoundingMode.HALF_UP)}")
      }
  }

  def solve(x1: BigDecimal, y1: BigDecimal, x2: BigDecimal, y2: BigDecimal, x3: BigDecimal, y3: BigDecimal): (BigDecimal, BigDecimal, BigDecimal) = {
    val px = ((y1 - y2) * ((x1 + x3) * (x1 - x3) + (y1 + y3) * (y1 - y3)) - (y1 - y3) * ((x1 + x2) * (x1 - x2) + (y1 + y2) * (y1 - y2))) / (2 * ((x1 - x3) * (y1 - y2) - (x1 - x2) * (y1 - y3)))
    val py = ((x1 - x2) * ((y1 + y3) * (y1 - y3) + (x1 + x3) * (x1 - x3)) - (x1 - x3) * ((y1 + y2) * (y1 - y2) + (x1 + x2) * (x1 - x2))) / (2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3)))
    val r = BigDecimal(math.sqrt(math.pow((x1 - px).toDouble, 2) + math.pow((y1 - py).toDouble, 2)))
    (px, py, r)
  }
}

Measured memory_bytes: 44564
n, m=map(int, input().split())
results=[0]*m

for i in range(n):
    check=list(map(int, input().split()))
    num=check[0]
    for j in range(1, num+1):
        results[check[j]-1]+=1

ans=0  
for result in results:
    if result==n:
        ans+=1

print(ans)

Measured memory_bytes: 3060
use proconio::input;
use std::collections::HashMap;

#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        As: [i64; N],
    }

    let hm: HashMap<i64, i64> = {
        let mut hm: HashMap<i64, i64> = HashMap::new();

        for a_ref in As.iter() {
            let a = *a_ref;
            match hm.get(a_ref) {
                Some(cnt_ref) => {
                    let cnt: i64 = *cnt_ref + 1;
                    hm.insert(a, cnt);
                }
                None => {
                    hm.insert(a, 1);
                }
            }
        }

        hm
    };

    // ループする前にbanする前のカウントをキャッシュしておく
    let sum = {
        let mut sum = 0;
        for (_key, val) in hm.iter() {
            sum += val * (val - 1) / 2;
        }

        sum
    };

    for a_ref in &As {
        let cnt: i64 = *hm.get(a_ref).unwrap();
        let ans = sum - cnt * (cnt - 1) / 2 + (cnt - 1) * (cnt - 2) / 2;
        println!("{}", ans);
    }
}


Measured memory_bytes: 11472
#include<stdio.h>

int main(void){
  char S[3];
  int ans=0;
  scanf("%s",S);
  
  if(S[0]==S[1])
    ans=1;
  else if(S[1]==S[2])
    ans=1;
  else if(S[0]==S[2])
    ans=1;
  
  if(ans==0)
    printf("Yes\n");
  else 
    printf("No\n");



  return 0;
}

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

int main() {
	string A, B;
	cin >> A >> B;
	if (A.length() != B.length()) cout << (A.length() > B.length() ? "GREATER" : "LESS") << endl;
	else {
		for (int i = 0; i < A.length(); i++) {
			if (A[i] != B[i]) {
				cout << (A[i] > B[i] ? "GREATER" : "LESS") << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
}

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

using namespace std;
using ll = long long;

const int MOD = 2019;
const int INF = 100100100;

int main() {
  ll l, r;
  cin >> l >> r;
  ll c = r - l;
  int m = INF;
  for (ll i = l; i <= l + c; i++) {
    for (ll j = i + 1; j <= l + c; j++) {
      if (i == j) {
        continue;
      }
      int mod = (i * j) % MOD;
      m = min(m, mod);
      if (m == 0) {
        cout << m << endl;
        return 0;
      }
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{

	int a,b;
	char str[100];
	scanf("%d",&a);
    scanf("%d",&b);
	getchar();
    scanf("%s",str);
    int i=0;
    for( i=0;i<a;i++){
     if(str[i]>='0' && str[i]<='9')
     {
     //putchar(str[i]);
    //continue;
     }
     else{
		printf("No\n");
		return 0;
		}
	}

    if(str[i]!='-') {
    //putchar(str[i]);
    printf("No\n");
    return 0;
    }
i++;
for( ;i<strlen(str);i++) if(str[i]>='0' && str[i]<='9') {

}
    else{
    printf("No\n");
    return 0;
    }
    printf("Yes\n");
    return 0;
}


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

bool judge(double x1, double x2, double x3, double y1, double y2, double y3, double xp, double yp)
{
    if (((x2 - x1) * (yp - y2)) - ((y2 - y1) * (xp - x2)) > 0)
    {
        if (((x3 - x2) * (yp - y3)) - ((y3 - y2) * (xp - x3)) > 0)
        {
            if (((x1 - x3) * (yp - y1)) - ((y1 - y3) * (xp - x1)) > 0)
            {
                return true;
            }
        }
    }
    if (((x2 - x1) * (yp - y2)) - ((y2 - y1) * (xp - x2)) < 0)
    {
        if (((x3 - x2) * (yp - y3)) - ((y3 - y2) * (xp - x3)) < 0)
        {
            if (((x1 - x3) * (yp - y1)) - ((y1 - y3) * (xp - x1)) < 0)
            {
                return true;
            }
        }
    }
    return false;
}

int main(void){
    double x1, x2, x3, y1, y2, y3;
    double xp, yp;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
        bool d;
        d = judge(x1, x2, x3, y1, y2, y3, xp, yp);
        if(d){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3136
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    C = [list(map(int, input().split())) for _ in range(10)]
    A = [list(map(int, input().split())) for _ in range(H)]
    
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if C[i][j] > C[i][k] + C[k][j]:
                    C[i][j] = C[i][k] + C[k][j]
                    
    ans = 0
    for row in A:
        for n in row:
            if n != -1:
                ans += C[n][1]
    
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 40156
#include<stdio.h>

int main()
{
    int x,y;
    scanf("%d %d",&x,&y);

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



Measured memory_bytes: 2132
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int N, C;
Int s[200000],t[200000],c[200000];
Int sm[200002],tt[200002];

int solve(int x){

    
}

int main(){
	cin >> N>> C;
	for(Int i=0;i<N;i++){
		cin>>s[i]>>t[i]>>c[i];
	}

	for(Int j=0;j<200002;j++) sm[j]=0;

	for(Int i=1;i<=C;i++){
		for(Int j=0;j<200002;j++) tt[j]=0;
		for(Int j=0;j<N;j++){
			if(c[j] == i){
				tt[s[j]*2-1]++;
				tt[t[j]*2]--;
			}
		}
		for(Int j=1;j<200002;j++) tt[j]+=tt[j-1];
		for(Int j=0;j<200002;j++) if(tt[j]>0) sm[j]++;
	}

	int ans=0;
	for(Int j=0;j<200002;j++) if(ans<sm[j]) ans=sm[j];
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

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

    ll N, M;
    cin >> N >> M;

    if(N >= M / 2LL) {
        cout << M / 2LL << endl;
        return 0;
    }

    ll ans = N;

    M -= N * 2LL;

    ans += M / 4LL;

    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 117：C - Streamline


def main():
    N, M = [int(i) for i in raw_input().strip().split(' ')]
    X = [int(i) for i in raw_input().strip().split(' ')]

    if N >= M:
        print 0
        exit()

    sortx = sorted(X)
    dist = []
    for i in range(len(sortx) - 1):
        dist.append(sortx[i+1] - sortx[i])
    sortd = sorted(dist, reverse=True)
    print sum(sortd[N-1:])


if __name__ == '__main__':
    main()


Measured memory_bytes: 11508
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    int ans = 0;
    for(int i = 0; i < N; ++i){
        int a, b; scanf("%d %d", &a, &b);
        ans += b - a + 1;
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
n, x, y = [int(i) for i in input().split()]
# 0 index is 1 distance
result = [0] * (n-1)

for i in range(n-1):
	for j in range(i+1, n):
		dist = min(j-i, abs(x-1-i) + 1 + abs(j-y+1))
		result[dist-1] += 1

for ans in result:
	print(ans)


# TLE

# import queue
	
# q = queue.Queue()
# n, x, y = [int(i) for i in input().split()]
# result = [0] * (n-1)

# for p in range(n):
# 	dist_list = [111111] * n
# 	dist = 0
# 	q.put(p)
# 	dist_list[p] = dist 
# 	while not q.empty():
# 		p = q.get()
# 		dist = dist_list[p]
# 		if p+1 < n: 
# 			if dist_list[p+1] > dist:
# 				dist_list[p+1] = dist
# 				q.put(p+1)
# 		if p-1 < n: 
# 			if dist_list[p-1] > dist:
# 				dist_list[p-1] = dist
# 				q.put(p-1)
# 		if p == (x-1): 
# 			if dist_list[y-1] > dist:
# 				dist_list[y-1] = dist
# 				q.put(y-1)
# 		if p == (y-1): 
# 			if dist_list[x-1] > dist:
# 				dist_list[x-1] = dist
# 				q.put(x-1)

# 	for i in dist_list:
# 		if i != 0:
# 			result[i-1] += 1

# for ans in result:
# 	print(ans//2)
		






Measured memory_bytes: 3444
s = str(input())
k = int(input())

n = len(s)

l = [0]*n
for i in range(n):
    l[i] = ord('z') -ord(s[i]) + 1
    l[i] %= 26
#print(l)

ans = list(s)
i = 0
while k > 0:
    if i > n-1:
        break
    if l[i] <= k:
        ans[i] = 'a'
        k -= l[i]
    i += 1
k %= 26
if k > 0:
    ans[-1] = chr((k + ord(ans[-1])-ord('a'))%26+97)
#print(ans)
print(''.join(ans))


Measured memory_bytes: 4980
N = int(input())
A = [int(_) for _ in input().split()]

mxs = sorted(x for x in A if x < 0)
pxs = sorted(x for x in A if x >= 0)

if len(mxs) == 0:
    mxs = [pxs[0]]
    pxs = pxs[1:]

if len(pxs) == 0:
    pxs = [mxs[-1]]
    mxs = mxs[:-1]

#print(mxs, pxs)

result = sum(pxs) - sum(mxs)
print(result)

if len(pxs) == 1:
    for y in mxs:
        print(pxs[0], y)
        pxs[0] -= y
else:
    for y in pxs[:-1]:
        print(mxs[0], y)
        mxs[0] -= y
    print(pxs[-1], mxs[0])
    pxs[-1] -= mxs[0]
    for y in mxs[1:]:
        print(pxs[-1], y)
        pxs[-1] -= y

#for i in range





Measured memory_bytes: 63516
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int n;
int vv[22][22];
int dp[22][1ll<<22];

int f(int i,int mask){
    if(i==n)return mask==((1<<n)-1);
    int &ans=dp[i][mask];
    if(ans!=-1)return ans;
    ans=0;
    for(int x=0;x<n;x++){
        if(vv[i][x] && !(mask&(1<<(n-1-x)))){
            ans+=f(i+1,(mask^(1<<(n-1-x))));
            if(ans>=MOD)ans-=MOD;
        }
    }
    return ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>vv[i][j];
        }
    }
    cout<<f(0,0);
}


Measured memory_bytes: 721280
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a>b&&c>d){
		cout<<b+d<<endl;
	}
	else if(a<=b&&c>=d){
		cout<<a+d<<endl;
	}
	else if(a>=b&&c<=d){
		cout<<b+c<<endl;
	}
	else{
		cout<<a+c<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"

	"github.com/emirpasic/gods/sets/hashset"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)

	set := hashset.New()
	for i := 0; i < n; i++ {
		var d int
		fmt.Fscan(r, &d)
		set.Add(d)
	}

	fmt.Fprintln(w, set.Size())
}


Measured memory_bytes: 1868
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N;
int L[100];

int main(){
    cin>>N;
    rep(i,N) cin>>L[i];

    int ans=0;
    rep(i,N-2){
        for(int j=i+1;j<N-1;j++){
            for(int k=j+1;k<N;k++){
                if(L[i]==L[j] || L[j]==L[k] || L[k]==L[i]) continue;
                if(L[i]<L[j]+L[k] && L[j]<L[k]+L[i] && L[k]<L[i]+L[j]) ans++;
            }
        }
    }

    cout<<ans<<endl;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> sum1(N + 1);
    sum1[0] = 0;
    rep(i, N) sum1[i + 1] = sum1[i] + A[i];

    vector<ll> sum2(N + 1);
    for (int i = N - 1; i >= 0; --i) sum2[i] = sum2[i + 1] + A[i];

    int i = 0;
    while (sum1[i] < sum2[0] / 2.0) i++;

    ll ans = min(sum2[i - 1] - sum1[i - 1], sum1[i] - sum2[i]);

    cout << ans << endl;
}

Measured memory_bytes: 4096
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        int n=sc.nextInt();
  		int max=0;

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		for(int d=0;d<n-1;d++){
        	if((a[d+1]-a[d])>max){
            	max=a[d+1]-a[d];
            }
        }
  
  		if((k-a[n-1]+a[0])>max){
        	max=k-a[n-1]+a[0];
        }
    
  int ans=k-max;
 	

    	System.out.println(ans);
    }
}


Measured memory_bytes: 74128
#include <iostream>
using namespace std;
int main(){
        long N, M, i, j;
        cin >> N >> M;
        long a[M];
        long f[N+1];
        
        if (M!=0){
                for (i=0; i<M; i++){
                        cin >> a[i];
                }
        }
        f[0]=1;
        if(a[0]==1){
                f[1]=0;
                j=1;
        }else{
                f[1]=1;
                j=0;
        }

        for (i=2; i<=N; i++){
                if (a[j]==i){
                        f[i]=0;
                        j = j +1;
                }else{
                        f[i] = f[i-1] + f[i-2];
                        f[i] = f[i]%1000000007;
                }
        }
        cout << f[N];
}


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

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

  int count = 0;
  int check;
  string str;

  for (size_t i = 1; i <= n; i++) {
    str = to_string(i);
    check = str.size();
    if(check % 2 != 0){
      count++;
    }
  }

  cout << count <<endl;

}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};




LL a[100002],mul[100002];

PLL solve(LL n,LL min_sum)
{
    LL cnt=0,sum=0,x=1;
    for(int i=n;i>0;i--)
    {
        while(x <= n  &&  a[i]+a[x] < min_sum)++x;
        cnt+=(n-x+1LL);
        sum+=(n-x+1LL)*a[i]+mul[x];
    }
    return {cnt,sum};
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    PLL check;
    LL i,m,n,low,mid,high,ans=0LL;
    cin >> n >> m;
    for(i=1;i<=n;i++)cin >> a[i];
    sort(a+1,a+n+1);
    for(i=n;i>0;i--)mul[i]=mul[i+1]+a[i];
    low=1,high=2*a[n];
    while(low <= high)
    {
        mid=(low+high) >> 1LL;
        check=solve(n,mid);
        if(check.FI >= m)
        {
            ans=check.SE-mid*(check.FI-m);
            low=mid+1LL;
        }
        else high=mid-1LL;
    }
    cout << ans;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  map<long long int, int>mp;
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    mp[temp] += 1;
  }
  int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      if(itr->first > itr->second){
        ans += itr->second;
      }else if(itr->first <= itr->second){
        ans += itr->second - itr->first;
      }
    }
  cout << ans << endl;
}


Measured memory_bytes: 6272
#include <iostream>
using namespace std;
typedef long long ll;

ll gcd(ll x,ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
}

int main(){
    ll A,B,MCD,tmp;
    cin >> A >> B;
    MCD=gcd(A,B);
    int cnt=1;
    for(ll i=2;i*i<=MCD;i++){
        if(MCD%i==0){
            cnt++;
            while(!(MCD%i))MCD/=i;
        }
    }
    if(MCD!=1)cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    int a=N/10,b=N%10;
    if(a==9 || b==9)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3588
# import sys
# sys.setrecursionlimit

# getarr = lambda _f: list(map(_f, input().split()))

s = input()

ok = True

for i, c in enumerate(s):
    if i & 1 == 0:
        if c == "L":
            ok = False
            break
    else:
        if c == "R":
            ok = False
            break

print('Yes' if ok else 'No')

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

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;


int main(){
    
    ll a, v, b, w;
    cin >> a >> v;
    cin >> b >> w;

   ll dist = abs(a - b);
   ll v1 = abs( v - w );

    ll t;
    cin >> t;
    if( w >= v){
        cout << "NO" << endl;
    }
    else if( v1 * t >= dist ){
       cout << "YES" << endl;
   } 
   else{
       cout << "NO" << endl;
   }

    return 0;
}

Measured memory_bytes: 3624