akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,p[1000009],pi,sac[1000009],i,j,pas;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>b;
    for(i=2; i<=1000000; i++){
        if(sac[i]==0){
            pi++;
            p[pi]=i;
            for(j=i*i; j<=1000000; j+=i) sac[j]=1;
        }
    }
    c=a;d=b;
    for(i=1; i<=pi; i++){
        while(c%p[i]==0) c/=p[i];
        while(d%p[i]==0) d/=p[i];
        if(a%p[i]==0&&b%p[i]==0) pas++;
    }
    if(c!=1&&d!=1&&c==d) pas++;
    pas++;
    cout<<pas;
    return 0;
}

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

int main() {
  long n,k,a_sum=0;
  cin >> n >> k;
  vector<long> a(n);
  vector<long> b;
  for(int i=0;i<n;i++) cin >> a[i];

  for(int i=0;i<n;i++) a_sum+=a[i];
  for(int i=1;i*i<=a_sum;i++) {
    if(a_sum%i==0) {
      b.push_back(i);
      if(i*i!=a_sum) b.push_back(a_sum/i);
    }
  }
  sort(b.begin(),b.end());
  for(long i=b.size()-1;true;i--) {
    vector<long> aa(n);
    for(long j=0;j<n;j++) aa[j]=a[j]%b[i];
    sort(aa.begin(),aa.end());
    long be=0,en=n-1,co=0;
    while(true) {
      if(be>en) break;
      if(aa[be]==0) be++;
      else break;
    }
    while(be<=en&&co<=k) {
      if(aa[be]==b[i]-aa[en]) {
        co+=aa[be];
        be++;
        en--;
      } else if(aa[be]>b[i]-aa[en]) {
        co+=b[i]-aa[en];
        aa[be]-=b[i]-aa[en];
        en--;
      } else {
        co+=aa[be];
        aa[en]+=aa[be];
        be++;
      }
    }
    if(co<=k) {
      cout << b[i] << endl;
      break;
    }
  }
}

Measured memory_bytes: 384
defmodule Main do
  def main() do
    [a, b] =
      IO.gets("")
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
    odd_or_even(a, b)
  end
 
  def odd_or_even(a, b) when rem(a * b, 2) == 0, do: IO.puts("Even")
  def odd_or_even(a, b) when rem(a * b, 2) != 0, do: IO.puts("Odd")
end

Measured memory_bytes: 30848
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=209999;
const ll INF=0x3f3f3f3f3f3f3f;
ll n,a[MAX],p,q,ans=INF;
int main()
{
    scanf("%lld",&n);
    for(ll i=0;i<n;i++) scanf("%lld",&a[i]),p+=a[i];
    q=a[0],p-=a[0];
    for(ll i=1;i<n;i++){
        ans=min(ans,abs(p-q));
        p-=a[i],q+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
//いろはちゃん

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A == 5 && B == 5 && C == 7){
			System.out.println("YES");
		}
		else if(A == 7 && B == 5 && C == 5){
			System.out.println("YES");
		}
		else if(A == 5 && B == 7 && C == 5){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}

	}

}

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

int main(){
  int N;
  cin >> N;
  vector<tuple<string,int,int>> t(N);
  
  for(int i=0;i<N;i++){
    string S;
    int P;
    cin>>S>>P;
    if(P!=0){
    P=-P;
    }
    t.at(i)=make_tuple(S,P,i+1);
  }
  
  sort(t.begin(),t.end());
  
  for(auto x:t){
    int a;
    tie(ignore,ignore,a)=x;
    cout<<a<<endl; 
  }

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n; cin >> n;
  for(int i=1;i<=9;i++){
    if(n%i==0 && n/i>=1 && n/i<=9){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<pair<int, int>> plus, minus;
  REP(z, N){
    string s;
    cin >> s;

    int MIN = 0;
    int now = 0;
    REP(i, s.size()){
      if(s[i] == '(') now++;
      else now--;
      chmin(MIN, now);
    }

    if(now >= 0){
      plus.emplace_back(now, MIN);
    }else{
      minus.emplace_back(-now, MIN-now);
    }
  }

  auto f = [&](vector<pair<int, int>> &v){
    sort(ALL(v), [&](pair<int, int> const & l, pair<int, int> const & r){
        return l.second > r.second;
        });

    int now = 0;
    REP(i, v.size()){
      if(now+v[i].second < 0) return -INF;
      now += v[i].first;
    }
    return now;
  };

  int a = f(plus);
  int b = f(minus);

  if((a != INF && b != INF) && a == b) Yes;
  else No;

  return 0;
}

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

int main(){
    int N;
    double OT, ans = 0;
    string w;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> OT >> w;
        if(w[0] == 'J')
            ans += OT;
        else
            ans += OT * 380000.0;     
    } 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
MOD = 998244353
a, b, c, d = gets.split.map(&:to_i)

# dp[タテ][ヨコ] の塗り方
dp = c.times.map { Array.new(d, 0) }
# 初期化
dp[a - 1][b - 1] = 1
dp_row = dp[a - 1]
(b...d).each do |i|
  dp_row[i] = dp_row[i - 1] * a % MOD
end
(a...c).each do |i|
  dp[i][b - 1] = dp[i - 1][b - 1] * b % MOD
end

a.upto(c - 1) do |current_row|
  dp_previous = dp[current_row - 1]
  dp_current = dp[current_row]
  b.upto(d - 1) do |current_column|
    dp_current[current_column] = (dp_current[current_column - 1] * (current_row + 1) + dp_previous[current_column] * (current_column + 1) - current_column * current_row * dp_previous[current_column - 1]) % MOD
  end
end

# dp.each { |r| p r }

puts dp.last.last


Measured memory_bytes: 84752
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    
    
    int main() {
     
     string s;
     
     while(true){
        cin >> s;
        if(s=="0") break;
        
        int sum = 0;
        for(int i = 0; i < s.size(); i++){
        	sum += s[i] -'0';
        }
        
           cout << sum << '\n';
        	
     }	
     	
     return 0;
    }


Measured memory_bytes: 3204
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int dist[N];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  int k;
  cin >> k;

  memset(dist,63,sizeof dist);
  priority_queue<ii,vector<ii>,greater<ii>> pq;pq.push(ii(0,0));

  while(pq.size()){
      auto cur = pq.top();
      pq.pop();

      f(j,cur.S==0,10){
          if(dist[(cur.S*10+j)%k] > cur.F+j){
            dist[(cur.S*10+j)%k]=cur.F+j;
            pq.push({cur.F+j,(cur.S*10+j)%k});
          }
      }

  }

  cout << dist[0] << '\n';


  return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];
        vll l(N+1), r(N+1);

        rep(i, 0, N) {
                ll x = (l[i] + A[i]) % mod;
                l[i+1] = (l[i+1] + x) % mod;
        }
        repreverse(i, N, 1) {
                r[i-1] += r[i] + A[i-1];
        }

        ll ans = 0;
        rep(i, 0, N) {
                ll diff = l[N] - l[i+1];
                if (diff < 0) diff += mod;
                // cout << diff << endl;
                ll pl = A[i] * diff % mod;
                ans = (ans + pl) % mod;
        }

        cout << ans << endl;
}


Measured memory_bytes: 7996
#include <string>
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  
  int ans = 0;
  if('1' == s[0]) ++ans;
  if('1' == s[1]) ++ans;
  if('1' == s[2]) ++ans;
  
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main() {
	const ll MOD = 1e9 + 7;
	string s;
	cin >> s;
	s = "x" + s;

	int sz = s.size();
	vector<vector<ll>> dp(sz, vector<ll>(2, 0));
	dp[0][1] = 1;
	for (int i = 1; i < sz; ++i) {
		if (s[i] == '1') {
			dp[i][0] = (dp[i-1][0]*3 + dp[i-1][1]) % MOD;
			dp[i][1] = (dp[i-1][1]*2) % MOD;
		} else {
			dp[i][0] = (dp[i-1][0]*3) % MOD;
			dp[i][1] = dp[i-1][1] % MOD;
		}
	}

	cout << (dp[sz-1][0] + dp[sz-1][1]) % MOD << endl;

	return 0;
}


Measured memory_bytes: 5756
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

long long n;
long long k;

bool asc(const pair<long long, long long> left, const pair<long long, long long> right) {
    return left.first < right.first;
}

int main()
{
    vector<pair<long long, long long> > ab;
    cin >> n >> k;
    long long sum = 0;
    for (int i=0; i<n; i++) {
        long long ai, bi;
        cin >> ai >> bi;
        pair<long long, long long> p(ai, bi);
        ab.push_back(p);
    }

    sort(ab.begin(), ab.end(), asc);

    long long i = 0;
    long long sum_idx = ab[i].second;
    while (sum_idx < k) {
        i++;
        sum_idx += ab[i].second;
    }

    cout << ab[i].first << endl;

    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int n,a[300001];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*3;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n*3+1);
	long long ans=0;
	for(int i=n+1;i<=n*3;i+=2)
		ans+=a[i];
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod =1e9+7; 
const int maxm=1010;

char grid[maxm][maxm];
int dp[maxm][maxm],vis[maxm][maxm];
int r,c;

int solve(int i,int j)
{
    if(i>=r || j>=c)
    return 0;
    if(grid[i][j]=='#')
    return 0;
    if(vis[i][j])
    return dp[i][j];
    
    if(i==r-1 && j==c-1)
    return dp[i][j]=1;
    
    vis[i][j]=1;
    return dp[i][j]=(solve(i+1,j)+solve(i,j+1))%mod;
}

int main() {
	cin>>r>>c;
	for(int i=0;i<r;i++)
	{
	    for(int j=0;j<c;j++)
	    cin>>grid[i][j];
	}
	cout<<solve(0,0);
	return 0;
}

Measured memory_bytes: 9344
using System;

class P2012
{
  public static void Main()
  {
    int e = Int32.Parse(Console.ReadLine());
    while(e!=0)
      {
	int y=0,z=0;

	int maxY = (int)Math.Sqrt(e);
	int maxZ = maxY;
	while(maxZ*maxZ*maxZ>e)maxZ--;

	int min = e;
	for(int i=maxZ; i>=0; i--)
	  {
	    z = i*i*i;
	    for(int j=maxY; j>=0; j--)
	      {
		y = j*j;
		if(e-z-y>=0)min = Math.Min(min,i+j+(e-z-y));	
	      }
	  }

	Console.WriteLine(min);

	e = Int32.Parse(Console.ReadLine());
      }
  }
}

Measured memory_bytes: 5796
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

double EPS = 1e-10;
const double PI = acos(-1);

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
  
  bool operator == ( const point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct segment{
  point a,b;
};

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

point intersection_ls(point a1, point a2, point b1, point b2) {
  point b = b2-b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);

  return a1 + (a2-a1) * t;
}

int main(void){
  segment s[3];

  while(true){
    for(int i=0;i<3;i++){
      cin >> s[i].a.x >> s[i].a.y >> s[i].b.x >> s[i].b.y;
      if( s[i].a.x==0 && s[i].a.y==0 && s[i].b.x==0 && s[i].b.y==0)return 0;
      }
    
    int fg[3]={0};
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	if(i!=j)
	  fg[i]+=is_intersected_ls(s[i].a,s[i].b,s[j].a,s[j].b);
      }
    }

    if(fg[0]==2 && fg[1]==2 && fg[2]==2){
      point p[3];
      for(int i=0;i<2;i++)
	    p[i]=intersection_ls(s[i].a,s[i].b,s[i+1].a,s[i+1].b);
      p[2]=intersection_ls(s[2].a,s[2].b,s[0].a,s[0].b);

      double z=(dist(p[0],p[1])+dist(p[1],p[2])+dist(p[2],p[0]))/2;
      double res=sqrt(z*(z-dist(p[0],p[1]))*(z-dist(p[1],p[2]))*(z-dist(p[2],p[0])));

      if(res>1900000-EPS)cout <<"dai-kichi"<<endl;
      else if(res>1000000-EPS)cout <<"chu-kichi"<<endl;
      else if(res>100000-EPS)cout <<"kichi"<<endl;
      else if(res>0+EPS)cout << "syo-kichi"<<endl;
      else cout <<"kyo"<<endl;
    }
    else cout <<"kyo"<<endl;
    }
  return 0;
}

Measured memory_bytes: 0
import fractions
from functools import reduce
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
 
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
 
n = int(input())
t = [int(input()) for i in range(n)]
 
print(lcm(*t))

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

using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ll curr = (ll)i * (i + 1) / 2;
    ans += curr;
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    if (u > v)
      swap(u, v);
    ll left = u;
    ll right = n - v + 1;
    ans -= left * right;
  }
  cout << ans;
}

Measured memory_bytes: 3596
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N+1];
        for(int i=1;i<=N;i++){
            p[i] = sc.nextInt();
        }
        int left =  1;
        int ans = 0;
        while(left<=N){
            if(p[left]!=left) left++;
            else{
                int right = left;
                while(right<=N&&p[right]==right) right++;
                ans += (right-left+1)/2;
                left = right;
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
  int a, b, c, d, e;
  cin >> a;
  b = a / 100;
  e = b;
  a = (a - b * 100);
  c = a / 10;
  e = e + c;
  a = a - c * 10;
  e = e + a;
  cout << e << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int k,n; cin>>k>>n;
    vector<int> a(n);
    vector<int> d(n);
    for(int i=0;i<n;i++) cin>>a[i]; 
    for(int i=0;i<n-1;i++) d[i]=a[i+1]-a[i];
    d[n-1]=k-a[n-1]+a[0];
    sort(d.begin(),d.end(),greater<int>());
    cout<<k-d[0]<<endl;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int mxn = 1e6 + 4;
vector<int> spf(mxn+1);

void sieve()
{
	for (int i=1; i<=mxn; i++)
		spf[i] = i;
	for (int i=2; i<=mxn; i+=2)
		spf[i] = 2;
	for (int i=3; i*i<=mxn; i+=2) {
		if (spf[i] == i) {
			for (int j=i*i; j<=mxn; j+=i) {
				if (spf[j] == j)
					spf[j] = i;
			}
		}
	}
}

bool isPairwiseCoprime(vector<int>& a)
{
	vector<int> prime_cnt(mxn+1);
	for (int x : a) {
		if (x == 1) continue;
		while (x > 1) {
			int fac = spf[x];
			prime_cnt[fac]++;
			if (prime_cnt[fac] > 1) return false;
			while (x%fac == 0)
				x /= fac;
		}
	}
	return true;
}

bool isSetwiseCoprime(vector<int>& a, int n)
{
	int gcd = a[0];
	for (int i=1; i<n; i++) {
		gcd = __gcd(gcd, a[i]);
	}
	return gcd == 1;
}

int main()
{
	fastIO;
	sieve();	
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin >> a[i];

	if (isPairwiseCoprime(a)) {
		cout << "pairwise coprime\n";
	}
	else if (isSetwiseCoprime(a, n)) {
		cout << "setwise coprime\n";
	}
	else {
		cout << "not coprime\n";
	}
}

Measured memory_bytes: 15008
s = input().rstrip()
n = len(s)

# 1 and n-1 must be exist
if s[0] == "0" or s[-1] == "1":
    print(-1)
    exit()
# x and n-x must be exist at the same
for fs, bs in zip(s[:-1], s[:-1][::-1]):
    if fs != bs:
        print(-1)
        exit()

made = set()
node_num = 0
base = 0
for i, ch in enumerate(s[:-1]):
    if ch == "1" and i+1 not in made:
        node_num += 1
        print(node_num + 1, base + 1)
        base = node_num
        made.add(i+1)
        made.add(n-i-1)
    else:
        node_num += 1
        print(base + 1, node_num + 1)

Measured memory_bytes: 12904
def is_kaibun(s):
    for i, j in enumerate(s[:int(len(s)/2)+1]):
        if j != s[-(i+1)]:
            return False
    return True


def main():
    s = input()
    n = len(s)
    result = is_kaibun(s)
    if result:
        s_2 = s[0:int((n-1)/2)]
        result = is_kaibun(s_2)
    if result:
        s_3 = s[int((n + 3) / 2 - 1):]
        result = is_kaibun(s_3)
    print("Yes" if result else "No")

main()

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

namespace AGC026
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 1; i < n; i++)
            {
                if (a[i - 1] == a[i]) { a[i] = 0; ans++; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/ruby
require 'mathn'
while(l=gets.split)!=["0","0"]
	n=l[0].to_i;m=l[1].to_i(n)
	if n==0 then break end
	p n.prime_division.map{|a,b|
		z=m;r=0
		while z>0 do z=(z/a).to_i;r+=z end
		(r/b).to_i
	}.min
end

Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return 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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = INF;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int cnt = 0;
        while(a & 1 ^ 1) {
            cnt++;
            a /= 2;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  int ans = SUM(a) - n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
     int arr[5] ;
     for(int i=0 ; i<5 ; i++)cin >> arr[i] ;
     for(int j=0 ; j< 5 ; j++){
          if(arr[j] == 0){cout << j +1 ; break; }
     }
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 2 ; i <= 55555; i++) {
            if (isPrime(i) && i % 5 == 3) {
                list.add(i);
            }
        }

        for (int i = 0 ; i < n ; i++) {
            System.out.print(list.get(i));
            System.out.print(" ");
        }
        System.out.println();
    }

    static boolean isPrime(int i) {
        for (int j = 2 ; j < Math.sqrt(i) ; j++) {
            if (i % j == 0) {
                return false;
            }
        }
        return true;
    }

}

Measured memory_bytes: 23764
from bisect import bisect_left, bisect_right

n = int(input())
al = list(map(int, input().split()))

al2 = [ [] for _ in range(20)]
for a in al:
    for i in range(20):
        if a&(1<<i) > 0:
            al2[i].append(1)
        else:
            al2[i].append(0)

al2_cum = []
for i in range(20):
    cum = 0
    cumsum = [0]
    for a in al2[i]:
        cum += a
        cumsum.append(cum)
    al2_cum.append(cumsum)

# print(al2)
# print(al2_cum)
ans = 0
for i in range(n+1):
    curr_maxind = 0
    for j in range(20):
        curr_cum = al2_cum[j]
        curr_1_cnt = curr_cum[i]
        if curr_1_cnt <= 1:
            continue
        else:
            ind = bisect_left(curr_cum, curr_1_cnt-1)
            curr_maxind = max(curr_maxind,ind)
    ans += (i-curr_maxind)

print(ans)

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

using namespace std;

int main(){
	vector<string> S,T;

	string s, t;
	cin >> s;
	sort(s.begin(), s.end());

	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if(s < t) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
}


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 = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();
		
		//間違った解法
		/*if(Math.abs(A - B) < 2) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}*/
		
		if(A <= 8 && B <= 8) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}
	}
}

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

const int mod=1000000007;
int n,h[110],f[110],mi[110][110];
long long cnt[110][110];

int quickmi(int a,long long b)
{
	int t=1;
	for (; b; b>>=1,a=1ll*a*a%mod)
		if (b&1) t=1ll*t*a%mod;
	return t;
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d",&h[i]);
	for (int i=1; i<=n; i++)
	{
		mi[i][i]=h[i];
		for (int j=i+1; j<=n; j++) mi[i][j]=min(mi[i][j-1],h[j]);
	}
	for (int i=1; i<=n; i++)
	{
		cnt[i][i]=h[i];
		for (int j=i+1; j<=n; j++) cnt[i][j]=cnt[i][j-1]+max(h[j]-h[j-1],0);
	}
	for (int i=1; i<n; i++)
	{
		int H=min(h[i],h[i+1]);
		f[i]=quickmi(2,cnt[1][i]-H);
		for (int j=1; j<i; j++)
			if (h[j]<h[j+1]) f[i]=(f[i]+1ll*f[j]*quickmi(2,cnt[j][i]-h[j]-H+mi[j][i+1]))%mod;
			else f[i]=(f[i]+1ll*f[j]*quickmi(2,cnt[j+1][i]-h[j+1]-H+mi[j+1][i+1]))%mod;
	}
	f[n]=quickmi(2,cnt[1][n]);
	for (int j=1; j<n; j++)
		if (h[j]<h[j+1]) f[n]=(f[n]+1ll*f[j]*quickmi(2,cnt[j][n]-h[j]+1))%mod;
		else f[n]=(f[n]+1ll*f[j]*quickmi(2,cnt[j+1][n]-h[j+1]+1))%mod;
	return printf("%d\n",f[n]),0;
}

Measured memory_bytes: 384
const Main = input=>{                                                               
  const given = input.split(' ')                                                    
  given.forEach((elm,i,arr)=>{arr[i] = Number(elm);});                              
  const AtoC = given[2] - given[0];                                                 
  const CtoB = given[1] - given[2];                                                 

  console.log(Math.sign(AtoC)===Math.sign(CtoB) ? "Yes":"No");                      
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
pi ara[56];

int main()
{
    int n,c,i;
    cin>>n;
    for(i=0; i<n; i++)
    {
        scanf("%d",&ara[i].first);
        ara[i].second=i;
    }
    sort(ara,ara+n);
    c=0;
    for(i=0; i<n; i++)
    {
        if(i!=ara[i].second)c++;
    }
    if(c>2)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    inf = 10**17
    #mod = 10**9 + 7

    N,M,L = map(int, input().split())
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for _ in range(M):
        a,b,c = map(int, input().split())
        dp[a-1][b-1] = c
        dp[b-1][a-1] = c

    #kを経由してiからjに行く行き方を考える
    #これで上手く行くのは与えられた辺の和しか考えていないため
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp[i][j] > dp[i][k] + dp[k][j]:
                    dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]

    dp2 =  [[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dp[i][j] <= L:
                dp2[i][j] = dp2[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dp2[i][j] > dp2[i][k] + dp2[k][j]:
                    dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dp2[s-1][t-1] == inf:
            print(-1)
        else:
            print(dp2[s-1][t-1]-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 55516
n, k = map(int,input().split())

balls = list(map(int,input().split()))

max_n = 200000

ball_counts = [0]*max_n

for ball in balls:
    ball_counts[ball-1] += 1


counts = []

for n in ball_counts:
    if n !=0:
        counts.append(n)
        
counts = sorted(counts)

print(sum(counts[0:len(counts)-k]))
    

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

int main(){
	int n=0,a=0,b=0;
	int aa,bb;
	while(cin>>n,n){
		aa=0;
		bb=0;
		for(int i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		if(a>b)aa+=a+b;
		else if(a<b)bb+=a+b;
		else {
			aa+=a;
			bb+=b;
		}
		}
		cout<<aa<<" "<<bb<<endl;
	}
}

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






int main(){
	ios::sync_with_stdio(false);
	int N,M; cin>>N>>M;
	vector<int> H(N+1);
	rep(i,N) cin>>H[i+1];
	vector<set<int>> load(N+1,set<int>());
	rep(i,M){
		int a,b; cin>>a>>b;
		load[a].insert(b);
		load[b].insert(a);
	}

	int ans=0;
	// vector<int> ck(N+1,1);
	for(int i=1; i<=N; i++){
		// queue<int> que;
		int high = H[i];
		bool flg = true;
		for(int y:load[i]){
			if(high <= H[y]) flg=false;
		}
	
		if(flg) ans++;
	}
	cout << ans << endl;
}


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());
#define vnn(x,y,name) vector<vector<int>> name(x, vector<int>(y));

string yes="Yes",no="No";
ll mod=1e9+7;


int main() {
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ans+=1+(2*n-i+1)*i/2;
        
        ans-=i*(i-1)/2;
        ans%=mod;
       
    }
     cout<<ans<<endl;
    
}


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

int main() {
  ll n, m, c;
  cin >> n >> m;
  ll a[m], b[m], mask[m] = {0};
  rep(i, m) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) {
      cin >> c, c--;
      mask[i] += pow(2, c);
    }
  }

  ll dp[1 << n];
  rep(i, 1 << n) dp[i] = INF;
  dp[0] = 0;

  rep(i, 1 << n) rep(j, m) dp[i | mask[j]] = min(dp[i | mask[j]], dp[i] + a[j]);
  ll ans = dp[(1 << n) - 1];
  cout << (ans != INF ? ans : -1) << endl;
  return 0;
}

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

#define vint vector<int>
#define vvint vector<vint>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}

void Main(){
    int n, k;
    cin >> n >> k;
    vint ans(n);
    rep(i,k){
        int d;
        cin >> d;
        vint a = CinLine(d);
        rep(j,a.size()){
            ans.at(a.at(j)-1)++;
        }
    }
    int c = 0;
    rep(i,ans.size()){
        if(ans.at(i) == 0){
            c++;
        }
    }
    ct(c);
}

int main() {
    Main();
}


Measured memory_bytes: 3632
A = input()
B = input()

if len(A) > len(B):
    print("GREATER")
elif len(A) < len(B):
    print("LESS")
else:
    for i in range(len(A)):
        if int(A[i]) > int(B[i]):
            print("GREATER")
            break
        elif int(A[i]) < int(B[i]):
            print("LESS")
            break
    else:
        print("EQUAL")

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

struct fast_input{
  #if local
    static constexpr int input_max = 1e2;
  #else
    static constexpr int input_max = 1e7;
  #endif
  char buf[input_max];
  char* itr;
  fast_input(){fread(buf,1,input_max,stdin);itr=buf;}
  constexpr inline bool isdigit(char* ptr)const noexcept{
    return '0' <= *ptr and *ptr <= '9';
  }
  constexpr inline uint32_t operator()(){
    while(!isdigit(itr))itr++;
    uint32_t num{};
    while(isdigit(itr)){
      num *= 10;
      num += *itr-'0';
      itr++;
    }
    return num;
  }
  template<class T = int64_t>
  T get(){
    while(!isdigit(itr) and *itr!='-')itr++;
    bool negative = *itr=='-';
    if(negative)itr++;
    T num{};
    while(isdigit(itr)){
      num *= 10;
      num += *itr-'0';
      itr++;
    }
    return negative?-num:num;
  }
}in;
void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  head = in.get<>();
  input(std::forward<Tail>(tail)...);
}
int main(){
  using namespace std;
  int64_t a,b,n;
  input(a,b,n);
  auto f = [&](int64_t x){return a*x/b-a*(x/b);};
  cout<< f(min(b-1,n)) <<endl;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

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

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin>> H[i];
    int maxHeight = 0;
    int count=0;
    rep(i,N){
        if(maxHeight <= H[i]){
            count++;
        }
        maxHeight = max(maxHeight, H[i]);
    }
    cout << count << endl;
}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._

  val Array(n, m, x, y) = readLine.trim.split(' ').map(_.toInt)
  val maxX = readLine.trim.split(' ').map(_.toInt).max
  val minY = readLine.trim.split(' ').map(_.toInt).min
  println(
    if (maxX < y && x < minY && maxX < minY) "No War"
    else "War"
  )
}


Measured memory_bytes: 27212
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
  int n,k;
 
  while(cin >> n >> k ,n | k){
    int sum = 0;
    int array[n];
 
    for(int i = 0 ; i < n ; i++){
      cin >> array[i];
    }
    for(int i = 0 ; i < k ; i++){
      sum += array[i];
    }
 
    int res = sum;
    for(int i = k ; i < n ; i++){
      sum += array[i];
      sum -= array[i-k];
      res = max(res,sum);
    }
    cout << res << endl;
  }
 
  return 0;
}

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

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

	int minc = (1 << 21);
	int cost, time;
	for (int i = 1; i <= n; i++) {
		cin >> cost >> time;
		if (time <= t) {
			minc = min(minc, cost);
		}
		if (i == n && minc == (1 << 21)) {
			cout << "TLE" << endl;
			return 0;
		}
	}
	cout << minc << endl;

	return 0;
}

Measured memory_bytes: 256
SA = input()
SB = input()
SC = input()

next_ = SA[0]
SA = SA[1:]
while True:
    if next_ == 'a':
        if len(SA) == 0:
            print('A')
            exit()
        next_ = SA[0]
        SA = SA[1:]
    elif next_ == 'b':
        if len(SB) == 0:
            print('B')
            exit()
        next_ = SB[0]
        SB = SB[1:]
    elif next_ == 'c':
        if len(SC) == 0:
            print('C')
            exit()
        next_ = SC[0]
        SC = SC[1:]


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

template<typename T,typename U>
void Printarray2(T f,U n){
  for(int i=0;i<n;i++) cout<<f[i]<<endl;
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vector<int> v(m),v2(m);Inparray(v,m);sort(All(v));
  v2[0]=0;
  for (int i = 1; i < m; ++i){
  	v2[i]=v[i]-v[i-1];
  }
  sort(All(v2));
  // Printarray(v2,m);
  int ans=0;
  for (int i = 0; i < m-n+1; ++i)ans+=v2[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
def main():
  AC = 0
  WA = 0
  
  solving = {}
  solved = {}
  
  N,M = map(int, input().split())
  
  for i in range(M):
    p, s = input().split()
    if p in solved:
      continue
    elif s == 'WA':
      if p in solving:
        _wa = solving[p]
        solving[p] = _wa + 1
      else:
        solving[p] = 1
    else:
      AC += 1
      if p in solving:
      	WA += solving[p]
      solved[p] = True
  
  print(AC, WA)
  return 0
 
if __name__ == "__main__":
  main()


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

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

    uint32_t a;
    std::unordered_set<uint32_t> A;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        if (A.count(a) == 1) {
            std::cout << "NO\n";
            return 0;
        }

        A.insert(a);
    }

    std::cout << "YES\n"; 

    return 0;
}


Measured memory_bytes: 8520
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var ps = new long[n];
        var bs = new long[n];
        for (int i = 0; i < ps.Length; i++)
        {
            var pb = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            ps[i] = pb[0];
            bs[i] = pb[1];
        }

        Array.Sort(ps, bs);
        var cost = 0L;
        for (int i = 0; i < ps.Length; i++)
        {
            if (m <= bs[i])
            {
                cost += ps[i] * m;
                break;
            }

            cost += ps[i] * bs[i];
            m -= bs[i];
        }
        Console.WriteLine(cost);
    }
}


Measured memory_bytes: 16952
#include<iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[2][n];
	for(int j=0;j<2;j++){
		for(int i=0;i<n;i++){
			cin >> a[j][i];
		}
	}
	int temp=a[0][0];
	for(int i=0;i<n;i++){
		temp+=a[1][i];
	}

	int max=temp;
	for(int i=0;i<n-1;i++){
		temp=temp+a[0][i+1]-a[1][i];
		if(temp>max)max=temp;
	}
	cout << max << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(true) {
				int n = Integer.parseInt(sc.nextLine());
				if(n==0) break;
				int [] kouho = new int[26];
				int [] sokuhou = new int[26];
				String[] vote = new String[n];
				for(int i=0;i<26;i++) {
					kouho[i] = 0;
				}
				vote = sc.nextLine().split(" ");
				boolean flag = true;
				loop:for(int i=1;i<=n;i++) {
					int d = vote[i-1].charAt(0) - 'A';
					kouho[d] += 1;
					for(int j=0;j<26;j++) {
						sokuhou[j] = kouho[j];
					}
					Arrays.sort(sokuhou);
					if(sokuhou[24]+(n-i)<sokuhou[25]) {
						int k=0;
						for(k=0;k<26;k++) {
							if(kouho[k] == sokuhou[25]) break;
						}
						System.out.printf("%c %d", k +'A',i);
						System.out.println();
						flag = false;
						break loop;
					}
				}
				if(flag) System.out.println("TIE");
			}

		}	
	}
}



Measured memory_bytes: 49208
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;



// void solve(){

// string s;
// cin>>s;


// }
 


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i =0;i<n;i++) cin>>a[i];
    int all = 0;
  for (int i = 0;i<n;i++) all = all ^ a[i];
    for (int i = 0;i<n;i++) {int t = all^ a[i]; cout<< t  <<" ";}
    cout<<"\n";


}



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

int n;
vector<int> a;

void mainmain(){
    for (int i = 0;i < 3; i++){
        int n;
        cin >> n;
        a.push_back(n);
    }

    string str = to_string(a[1]) + to_string(a[2]);
    int b = stoi(str);
    if (b%4==0){cout << "YES" << endl;}
    else{cout << "NO" << endl;}

}

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

Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

#endif
#include <cstdio>
#include <queue>
#include <cassert>
#include <cstdlib>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

inline int lowbit(int x) { return x & - x; }

int TOT;
struct Treap {
	Treap *son[2];
	int val, weight, lazy, max, size;
	inline void update() {
		max = val;
		size = 1;
		if(son[0]) {
			assert(weight >= son[0] -> weight);
			max = std::max(max, son[0] -> max + lazy);
			size += son[0] -> size;
		}
		if(son[1]) {
			assert(weight >= son[1] -> weight);
			max = std::max(max, son[1] -> max + lazy);
			size += son[1] -> size;
		}
	}
	inline void push_down() {
		if(son[0]) {
			son[0] -> lazy += lazy;
			son[0] -> val += lazy;
		}
		if(son[1]) {
			son[1] -> lazy += lazy;
			son[1] -> val += lazy;
		}
		lazy = 0;
	}
	static Treap *merge(Treap *a, Treap *b) {
		if(not a) return b;
		if(not b) return a;
		if(a -> weight > b -> weight) {
			a -> push_down();
			a -> son[1] = merge(a -> son[1], b);
			a -> update();
			return a;
		} else {
			b -> push_down();
			b -> son[0] = merge(a, b -> son[0]);
			b -> update();
			return b;
		}
	}
	void split(int k, Treap *&x, Treap *&y) {
		TOT ++;
		int lsize = son[0] ? son[0] -> size : 0;
		push_down();
		if(k <= 0) {
			x = nullptr;
			y = this;
		} else if(k <= lsize) {
			assert(son[0]);
			y = this;
			son[0] -> split(k, x, son[0]);
		} else if(k <= lsize + 1) {
			x = this;
			y = son[1];
			son[1] = nullptr;
		} else if(k <= size) {
			assert(son[1]);
			x = this;
			son[1] -> split(k - lsize - 1, son[1], y);
		} else
			assert(false);
		update();
	}
	inline void add(int x) {
		val += x;
		lazy += x;
		max += x;
	}
	inline Treap(): son(), val(0), weight(rand()), lazy(0), max(0), size(1) { }
};

const int maxn = 1000005;
char s[maxn], t[maxn];
std::priority_queue<int> last[30];

int main() {
	int n = input();
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	for(int i = 1; i <= n; i ++)
		last[s[i] - 'a'].push(i);
	Treap *T = nullptr;
	for(int i = 1; i <= n; i ++)
		T = Treap::merge(T, new Treap());
	int m = n;
	for(int i = n, find = 0; i; i -= find) {
		if(last[t[i] - 'a'].empty()) {
			puts("-1");
			return 0;
		}
		int p = last[t[i] - 'a'].top();
		while(m >= p) {
			last[s[m] - 'a'].pop();
			m --;
		}
		if(i != p) {
			Treap *t1, *t2, *t3, *t4, *t5;
			T -> split(p - 1, t1, t2);
			t2 -> split(1, t2, t3);
			t3 -> split(i - p - 1, t3, t4);
			t4 -> split(1, t4, t5);
			if(t2 and t4)
				t2 -> add(t4 -> val - t2 -> val + 1);
			if(t3)
				t3 -> add(1);
			if(t4)
				t4 -> add(1);
#if 0
			debug("%d - %d\n", p, i);
			debug("%d, %d, %d, %d, %d\n",
					t1 ? t1 -> max : 0,
					t2 ? t2 -> max : 0,
					t3 ? t3 -> max : 0,
					t4 ? t4 -> max : 0,
					t5 ? t5 -> max : 0);
			debug("%d\n", TOT);
			fflush(stderr);
#endif
			T = Treap::merge(
					t1, Treap::merge(
						t3, Treap::merge(
							t4, Treap::merge(
								t2, t5))));
			// for(int j = p; j < i; j ++)
				// deep[j] = deep[j + 1] + 1;
			// deep[i] ++;
		}
		find = 0;
		for(int j = i; j >= p and t[j] == t[i]; j --)
			find ++;
	}
	printf("%d\n", T -> max);
}


Measured memory_bytes: 53704