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

int main(){
    int k,s;
    cin >> k >> s;
    int ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k ; j++){
            int l = s - i - j;
            if(0 <= l and l <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
x = [0] * n
x[0] = sum(a) // 2 - sum(a[1::2])
for i in range(n - 1):
    x[i + 1] = a[i] - x[i]
print(*[i * 2 for i in x], sep=' ')
#  ok = 0
#  ng = 2 * int(1e9) + 1
#  while abs(ok - ng) > 1:
#      m = (ok + ng) // 2
#      x = [0] * n
#      x[0] = m
#      f = True
#      for i in range(n):
#          x[(i + 1) % n] = a[i] - x[i]
#          if (i % 2 == 0) and (x[(i + 1) % n] < 0):
#              f = False
#          if (i % 2 == 1) and (x[(i + 1) % n] <= 0):
#              f = True
#      if x[-1] + x[0] < a[-1]:
#          f = False
#      if f:
#          ok = m
#      else:
#          ng = m
#  print(*[i * 2 for i in x], sep=' ')


Measured memory_bytes: 16920
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string a = ReadLine();
        string b = ReadLine();
        int al = a.Length;
        int bl = b.Length;
        if(al != bl){
            if(al>bl){
                WriteLine("GREATER");
            }else{
                WriteLine("LESS");
            }
        }else{
            int count = 0;
            for(int i=0;i<al;i++){
                int ai = int.Parse(a[i].ToString());
                int bi = int.Parse(b[i].ToString());
                if(ai > bi){
                    WriteLine("GREATER");
                    break;
                }else if(ai < bi){
                    WriteLine("LESS");
                    break;
                }else{
                    count++;
                }
            }
            if(count == al){
            WriteLine("EQUAL");
            }
        }
    }
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

vector<pii> res;

void solve()
{
   int n,m;
    cin >> n >> m;
    
   if(n%2 == 0)
   {
       int l = 1;
       int r = (n/2);
           
       while(res.size() < m)
       {
           res.pb({l,r});
           l++;
           r--;
           
           if(r<=l) break;
       }
      
       l = (n/2) + 1;
       r = n-1;
       
       while(res.size() < m)
       {
           res.pb({l,r});
           l++;
           r--;
           
           if(r<=l) break;
       }
       
   }
    else f(i,m) res.pb({i+1,n-i});
    
   assert(res.size() == m);
    
   f(i,m) cout <<res[i].F << ' '<<res[i].S <<'\n';
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 5304
#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
const int LIM = 4e6+3;
pair<int,int> arr[LIM+3];
int main(){
  int a,b,c;cin >> a >> b >> c;
  c-=a-b;
  cout << max(c,0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001],b[100001];
int a1,a2,b1,b2;
int main(){
    cin>>n;
    for(int i=0,x,y;i<n;i+=2){
        cin>>x>>y;
        a[x]++;
        b[y]++;
    }
    for(int i=1;i<100001;i++){
        if(a[i]>=a[a1]){
            a2=a1;
            a1=i;
        }else if(a[i]>a[a2])a2=i;
        if(b[i]>=b[b1]){
            b2=b1;
            b1=i;
        }else if(b[i]>b[b2])b2=i;
    }
    if(a1!=b1)cout<<n-a[a1]-b[b1];
    else cout<<n-max(a[a1]+b[b2],a[a2]+b[b1]);
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, a, b;
	cin >> x >> a >> b;

	x -= a;
	x %= b;

	dunk(x);

	return 0;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  sum = C
  for j in range(M):
    sum += A[j] * B[j]
  if sum > 0:
    ans += 1
print(ans)

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  int a,b;
  cin >> a >> b;
  int x1= (a*100)/8;
  if((a*100)%8)x1++;
  int x2=((a+1)*100)/8;
    if(((a+1)*100)%8==0)x2--;
  int y1=b*10;
  int y2=(b+1)*10;

  
  int ans= 100100100;
  for(int i= x1;i<=x2;i++){
    for(int j=y1;j<y2;j++){
      if(i==j)ans=min(ans,i);
    }
  }
if(ans==100100100){cout << -1;}
else{ cout << ans;}

}

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

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

string S;

int main() {
    cin >> S;
    int n = S.size();
    int nzeros = 0;
    rep(i, n) {
        if (S[i] == '0') nzeros ++;
    }
    int nones = n - nzeros;
    cout << n - abs(nzeros - nones) << endl;
    return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

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

int32_t main(){
  DESYNC;
  int a,p;
  cin >> a >> p;
  cout << (3*a +p)/2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main(){
	int n;
	int s[100];
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		ans += s[i];
	}
	sort(s, s + n);
	if (ans % 10 == 0) {
		for (int j=0;;j++) {
			if (s[j] % 10 != 0) {
				ans -= s[j];
				cout << ans << endl;
				return 0;
			}
			else if (j == n - 1) {
				cout << "0" << endl;
				return 0;
			}
			else {
				continue;
			}
		}
	 }
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
    int h,w;
    cin >> h >> w ;
    
    for (int i=0; i<w+2; i++) cout << "#";
    cout <<endl;
    
    for (int j=0; j<h; j++){
        vector<char> vec(w+1);
        for (int i=0;i<w; i++) {
            cin>> vec.at(i);
        }

        for (int i=w; i>0;i--){
            vec.at(i)=vec.at(i-1);
        }
        vec[0]='#';
        
        for (int i=0; i<w+1; i++)cout << vec.at(i);
        cout << "#"<<endl;

    }
    
    for (int i=0; i<w+2; i++) cout << "#";
    cout <<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<bool> ball(n+1, false);
    for(int i=n; i>=1; --i){
        int cnt = 0;
        for(int j=2*i; j<=n; j+=i){
            if(ball[j])
                ++ cnt;
        }
        if(cnt % 2 != a[i])
            ball[i] = true;
    }

    vector<int> ans;
    for(int i=1; i<=n; ++i){
        if(ball[i])
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int x : ans)
        cout << x << endl;

    return 0;
}


Measured memory_bytes: 2428
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int getmin(bitset<100001>& a) {
	for (int i = 1;; i++) {
		if (!a[i])return i;
	}
}
void dfs(int pos, int prev, vector<vector<pair<int, int>>>& T, vector<int>& col) {
	bitset<100001> *e = new bitset<100001>();
	for (int i = 0; i < T[pos].size(); i++) {
		if (col[T[pos][i].second] != INF)(*e)[col[T[pos][i].second]] = true;
	}
	for (int i = 0; i < T[pos].size(); i++) {
		if (T[pos][i].first == prev)continue;
		int c;
		for (int i = 1;; i++) {
			if ((*e)[i] != true) {
				c = i;
				break;
			}
		}
		col[T[pos][i].second] = c;
		e->set(c);
		dfs(T[pos][i].first, pos, T, col);
	}
        delete e;
}
int main() {
	int N;
	cin >> N;
	vector<vector<pair<int, int>>> T(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		T[a].push_back({ b,i });
		T[b].push_back({ a,i });
	}
	vector<int> col(N - 1, INF);
	dfs(0, -1, T, col);
	cout << *max_element(col.begin(), col.end()) << endl;
	for (int i = 0; i < N - 1; i++) {
		cout << col[i] << endl;
	}
}


Measured memory_bytes: 720768
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n;
	int a[3];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for (int i = 1; i < (a[n - 1] / 2 + 5); i++) {
		bool b = true;
		for (int j = 0; j < n; j++) {
			if (a[j] % i != 0) b = false;
		}
		if (b) cout << i << endl;
	}
}

Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(void){
    int n;
    while(cin >> n && n) {
        char preUd = 'd', state = 'd';
        int count = 0;
        for (int i = 0; i < n; ++i) {
            string move;
            cin >> move;
            char ud = move[1];
            if (preUd == ud && state != ud) {
                ++count;
                state = ud;
            }
            preUd = ud;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
//url:
//problem name:

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

const ll MAX = 1LL<<60;

bool isPrime(int N) {
    if(N == 1) return false;
    bool ans = true;
    for(int i = 2; i*i <= N; i++) {
        if(N%i == 0) ans = false;
    }
    return ans;
}

int main() {
    vector<int> a(1e5);
    REP(i,1e5) {
        if(i%2 == 0) continue;
        if(isPrime(i) && isPrime((i+1)/2)) a[i] = 1;
    }

    vector<int> s(1e5+1, 0);
    for (int i = 0; i < 1e5; ++i) s[i+1] = s[i] + a[i];

    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
	  static int solve=0;
      public static void main(String[]args) {
    	  Scanner scan=new Scanner(System.in);
    	  int a=scan.nextInt();
    	  int b=scan.nextInt();
    	  int c=scan.nextInt();
    	  int x=scan.nextInt();
    	  int numa=x/500;
    	  int i=0;
    	  while(i<=numa&&i<=a) {
    		  int numb=(x-i*500)/100;
    		  int j=0;
    		  while(j<=numb&&j<=b) {
    			  int numc=(x-i*500-j*100)/50;
    			  if(numc<=c) {
    				  solve++;
    			  }
    			  j++;
    		  }
    		  i++;
    	  }
    	  System.out.println(solve);
      }
}


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

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k, a, b; cin >> k >> a >> b;
    if(b - a < 2)
    {
        cout << k + 1;
        return 0;
    }
    cout << a + (b - a) * ((k - a + 1)/2) + ((k - a + 1) % 2);

    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d',$N);
$L=explode(" ",trim(fgets(STDIN)));
rsort($L);
$Lsum=0;
for ($i=1; $i <=$N-1 ; $i++) {
  // code...
  $Lsum+=$L[$i];
}
if($Lsum>$L[0]){
  echo "Yes";
}else{
  echo "No";
}


 ?>

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x[100020],y[100020],t[100020],ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t[i]>>x[i]>>y[i];
	}
	for(int i=1;i<=n;i++){
		if((x[i]+y[i])%2!=t[i]%2){
			cout<<"No";
			return 0;
		}
		if(x[i]+y[i]<=t[i]){
			ans=ans+1;
		}
	}
	if(ans==n){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast") 

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

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define print(...) for(auto xas:{__VA_ARGS__})cerr<<xas<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)
#define coutd(x,y) printf("%0.y lf",x);

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

typedef vector<int> vec; 
typedef pair<int, int> pa; 
typedef vector<pa> vecp; 
typedef set<int> se;
typedef map<int,int> ma;

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

void manupulate(string &str)
{
    for(int i=0;i<str.size();++i)
    str[i]-=48;
}

bool isprime(int n)
{
    if(n<=1)
        return false;
    for(int i=2;i*i<=n;++i)
    if(n%i==0)
        return false;
    return true;
}

int expo(int a,int n)
{
    if(n==0)
        return 1;
    if(n==1)
        return a;
    int tmp=expo(a,n/2);
    tmp=(tmp*tmp)%mod;
    if(n&1)
        tmp=(tmp*a)%mod;
    return tmp;
}


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



signed main() {
bew;
    tar(n);
    cout<<2*3.1415*n;





return 0;
}

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

using namespace std;

long long n,A,B;
int main()
{
	cin >> n >> A >> B;
	if(n==1&&A!=B) cout << 0 << endl;
	else if(A>B) cout << 0 << endl;
	else cout << A+(n-1)*B-B-(n-1)*A+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,a[105],ans;
int main()
{
    //IOS;
    cin>>n;
    rep(i,1,n)
    {
        cin>>a[i];
    }
    rep(i,1,n)
    {
        rep(j,1,n)
        {
            if(i==j)
            {
                continue;
            }
            else

            {
                ans+=(a[i]*a[j]);
            }

        }
    }
    cout<<ans/2<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    a, b, c = gets.chomp.split.map(&:to_i)

    if a <= c && c <= b
      puts "Yes"
    else
      puts "No"
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = int64_t;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(int i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(int i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
typedef v(vvi) vvvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  int N;
  cin >> N;
  vector<char> S(N);
  cin >> S;

  set<int> s[26];
  rep(i,26){
    s[i].insert(N+1);
  }
  rep(i,N){
    s[S[i]-'a'].insert(i);
  }

  int Q;
  cin >> Q;
  int type, x, l, r;
  char c;
  v(bool) ans(26,false);
  rep(_,Q){
    cin >> type;
    if(type == 1){
      cin >> x >> c;
      x--;
      s[S[x]-'a'].erase(x);
      S[x] = c;
      s[S[x]-'a'].insert(x);
    } else {
      cin >> l >> r;
      l--;
      r--;
      i64 ans = 0;
      rep(i,26) {
        if(*(s[i].upper_bound(l-1))<=r) ans++;
      }
      cout << ans << "\n";
    }
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 24192
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

  int N; cin>>N;
  vector<int> v(N); rep(i,N) cin>>v[i];
  sort(ALL(v));
  int start = v[N/2-1]+1;
  int end = v[N/2];

  cout << max(0, end-start+1) << endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define size 300010
#define inf 1e9+7
#define ll long long
#define db double
#define il inline
#define rint register int
#define gc getchar()
#define rep(i,s,n) for (register int i=s;i<=n;i++)
#define sro_zyb_orz int main()
#define calc(i,j) (m*(i-1)+j)

using namespace std;


il ll r()
{
	char c; ll x,f=1;
	for (c=gc;!isdigit(c);c=gc) if (c=='-') f=-1; x=c-'0';
	for (c=gc;isdigit(c);c=gc) x=x*10+c-'0'; return x*f;
}

char c[100][100];
int n,m,num,fa[size],dx[4]={0,0,1,-1},dy[4]={1,-1,0,0},cntx=0,M=0;
int head[size],to[size],nxt[size],len[size],dis[size],q[size];
bool inq[size]; 
void add(int x,int y,int z)
{
	num++;to[num]=y;len[num]=z;nxt[num]=head[x];head[x]=num; 
}

void Add(int x,int y,int z) 
{
	add(x,y,z);add(y,x,z);
}

bool islegal(int tx,int ty)
{
	if (tx>n||ty>m) return 0;
	if (tx<=0||ty<=0) return 0;
	if (c[tx][ty]=='#') return 0; return 1;
}

void spfa(int A)
{
    int f=0,r=1;
    for (int i=1;i<=n*m;i++) dis[i]=inf;
    dis[A]=1;q[r]=A;inq[A]=1;
    while (f!=r)
    {
      int x=q[++f]; 
      inq[x]=0;
      for (int p=head[x];p;p=nxt[p])
      {
      	  if (dis[to[p]]>dis[x]+len[p])
      	  {
          	  dis[to[p]]=dis[x]+len[p];
          	  if (!inq[to[p]]) 
          	  {
          	  	q[++r]=to[p];
          	  }
      	  }
      }
    }
   // for (int i=1;i<=n;i++) printf("%d ",dis[i]);
    
} 

sro_zyb_orz
{
	n=r(); m=r(); 
	rep(i,1,n)
	{
		scanf("%s",c[i]+1);
		rep(j,1,m)
			if (c[i][j]=='.')
			{
				rep(k,0,3) 
					if (islegal(dx[k]+i,dy[k]+j))
						Add(calc(i,j),calc(dx[k]+i,dy[k]+j),1);
			}	
	}
	cntx=0;
	rep(i,1,n) rep(j,1,m) if (c[i][j]=='.') cntx++;//cout<<cntx<<endl; 
	spfa(1);//cout<<dis[n*m]<<endl;
	if (dis[n*m]==inf)  cntx=-1; else cntx-=dis[n*m];
	cout<<cntx<<endl;
	return 0;
}



Measured memory_bytes: 6400
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

// (a ^ b) % mod
ll powMod(ll x, ll k, ll m) {
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k / 2, m);
	else            return x*powMod(x, k - 1, m) % m;
}

int main() {

	ll n;
	cin >> n;

	for (ll i = 1; i <= 3500; i++) {
		for (ll j = 1; j <= 3500; j++) {

			if ((4 * i*j - n*(i + j)) == 0) continue;

			if ((n*i*j) / (4 * i*j - n*(i + j))*(4 * i*j - n*(i + j)) == n*i*j) {
				if ((n*i*j) / (4 * i*j - n*(i + j)) < 0) continue;
				cout << i << " " << j << " " << (n*i*j) / (4 * i*j - n*(i + j)) << endl;
				return 0;
			}

		}
	}

	return 0;
}



Measured memory_bytes: 384
n,c,k = map(int,input().split())
t = sorted([int(input()) for _ in range(n)])

res = 0
count_teiin = 0
prev_bus = -1
for i in t:
    # 前のバスが行ってしまったら、i分に出発するバスを手配
    if prev_bus == -1 or prev_bus+k < i:
        res += 1
        prev_bus = i
        count_teiin = 1
    else:
        count_teiin += 1
    # 定員になったら出発
    if count_teiin == c:
        prev_bus = -1
print(res)


Measured memory_bytes: 8404
/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

string s;
int t;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    ll int ar[n+1];
    
    ll pre[n+1];
    pre[0]=0;
    
    for(int i=1; i<=n; i++){
    	cin >> ar[i];
    	pre[i]=(pre[i-1]%MOD+ar[i]%MOD)%MOD;
	}
	
	ll ans=0;
	
	
	for(int i=1; i<=n; i++){
		ans = (ans+MOD + (ar[i]*pre[i-1])%MOD)%MOD;
	}
	
	cout << ans;
}


Measured memory_bytes: 6704
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

string S;
vector<set<int>> posLists;

int main()
{
    posLists.assign(26, set<int>{500001});
    int N; cin >> N >> S;
    for (int i = 0; i < N; ++i)
    {
        posLists[S[i] - 'a'].insert(i);
    }
    int Q; cin >> Q;
    // Type1はO(log(N))，Type2はO(#alphabet*logN)より，総計算量はO(Q*#alphabet*logN)~O(10e6)でギリギリ？
    while (Q--)
    {
        int type; cin >> type;
        if (type == 1)
        {
            // 文字の位置を更新:O(logN)
            int iq; char cq; cin >> iq >> cq; --iq;
            posLists[S[iq] - 'a'].erase(iq);  // O(logN)
            posLists[cq - 'a'].insert(iq);  // O(logN)
            S[iq] = cq;
        }
        else
        {
            int lq, rq; cin >> lq >> rq; --lq;
            int ret = 0;
            // 各文字について[L, R]の範囲に存在するかどうか調べる:O(#alphabet*logN)
            for (const auto &posList : posLists)
            {
                // L以上R以下の要素を持つかどうか探索する:O(logN)
                const auto lb = *posList.lower_bound(lq);
                const auto rb = *posList.lower_bound(rq);
                if (lb < rb) ++ret;
            }
            cout << ret << endl;
        }
    }
}


Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
	string s;
	int k;
	cin >> s >> k;
	
	for(int i = 0; i < s.size() - 1; ++i){
        if(s[i] == 'a') continue;
		if((26 - (int)(s[i] - 'a')) <= k){
			k -= 26 - (int)(s[i] - 'a');
			s[i] = 'a';
		}
	}
	if(k > 0){
		s[s.size() - 1] = (char)(((int)(s[s.size() - 1] - 'a') + k) % 26) + 'a';
	}
	
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans = 0;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	if (n % 2 == 1) ans = 0;
	else {
		ans = a[n / 2] - a[n / 2 - 1];
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
// garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ppi pair<int ,int >
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define MAXN 
using namespace std;
ll modex(ll a,ll b,ll p){ll res=1;a%=p;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b>>=1;}return res;}
const int MD = (int)1e9+7;
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
 
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);cout.tie(NULL);	
 	
 	int n;
 	cin>>n;

 	map<string, int> mp;

 	for(int i=0;i<n;i++) {
 		string s;
 		cin>>s;
 		mp[s]++;
 	}

 	cout<<mp.size();
 
 
	return 0;
}

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

bool dp[30009][4][1009];
string S; int N;

int main() {
	cin >> N >> S;
	dp[0][0][0] = true;
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 3; j++) {
			for (int k = 0; k < 1000; k++) {
				if (dp[i][j][k] == false) continue;
				
				dp[i + 1][j][k] = true;
				if (j <= 2) {
					dp[i + 1][j + 1][k * 10 + (S[i] - '0')] = true;
				}
			}
		}
	}
	
	int cnt = 0;
	for (int i = 0; i < 1000; i++) {
		if (dp[N][3][i] == true) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 118528
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(n) scanf("%s",n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof a)
#define mem(a,b,n) memset(a,b,n*sizeof(int))
#define uint unsigned int

const  int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int t,n,m;
int a[N];
int b[N];

int main()
{
	sc(n);
	fo(i,1,n+1)
	{
		sc(a[i]);
	}
	fo(i,1,n)
	{
		sc(b[i]);
	}
	ll ans=0;
	fo(i,1,n)
	{
		int minn=min(a[i],b[i]);
		ans+=minn;
		b[i]-=minn;
		minn=min(a[i+1],b[i]);
		ans+=minn;
		a[i+1]-=minn;
	}
	cout<<ans<<endl;

}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string s,a,z;
  cin>>s;
  string &S=s;
  int N,p=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int t;
    cin>>t;
    if(t==1){
  p++;
    }    
    else{
      int T;
      string c;
      cin>>T>>c;
      T+=p;
      if(T%2==1){
        a=c+a;
      }
      else{
        z=z+c;
      }
    }
    
  }
  S=a+S+z;
  if(p%2==0){
  cout<<S;
  }
  else{
    reverse(S.begin(),S.end());
    cout<<S;
  }
  
  
}

Measured memory_bytes: 1512
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    s=input()
    n=len(s)
    G=groupby(s)
    A=[]
    for i,g in enumerate(G):
        key,iter=g
        if(i%2==0): a=len(list(iter))
        else: A.append((a,len(list(iter))))
    ans=[0]*n
    idx=-1
    for x,y in A:
        idx+=x
        ans[idx]=x-x//2+y//2
        ans[idx+1]=x//2+y-y//2
        idx+=y
    print(*ans)
resolve()

Measured memory_bytes: 53616
K = input()
D = int(input())
N = len(K)
mod = 10**9+7

dp0 = [[0] * D for _ in range(N+1)]
dp1 = [[0] * D for _ in range(N+1)]
dp0[0][0] = 1
for i in range(N):
    k = int(K[i])
    for j in range(D):
        dp0[i+1][(j+k)%D] = (dp0[i+1][(j+k)%D] + dp0[i][j]) % mod
        dp1[i+1][(j+k)%D] = (dp1[i+1][(j+k)%D] + dp1[i][j]) % mod
        for k_ in range(k):
            dp1[i+1][(j+k_)%D] = (dp1[i+1][(j+k_)%D] + dp0[i][j] + dp1[i][j]) % mod
        for k_ in range(k+1, 10):
            dp1[i + 1][(j + k_) % D] = (dp1[i + 1][(j + k_) % D] + dp1[i][j]) % mod

print((dp0[-1][0] + dp1[-1][0] - 1) % mod)


Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define N 200010
using namespace std;
int ____, a[N], b[N];
bool S(int i, int j, int k) {
	return a[i] <= k && a[j] <= k;
}
bool B(int i, int j, int k) {
	return a[i] > k && a[j] > k; 
}
int chk(int k) {
	for (int i = 0; i < ____ - 1; ++i) {
		if (B(____ + i, ____ + i + 1, k) || B(____ - i, ____ - i - 1, k)) return 0;
		if (S(____ + i, ____ + i + 1, k) || S(____ - i, ____ - i - 1, k)) return 1;
	}
	return S(1, 1, ____);
}
int main() {
	scanf("%d", &____);
	for (int i = 1; i <= 2 * ____ - 1; ++i) scanf("%d", &a[i]);
	int l = 1, r = 2 * ____ - 1, ans = 0;
	for (; l < r; ) {
		int mid = (l + r) / 2;
		if (chk(mid)) {
			r = mid;
		} else l = mid + 1;
	}
	printf("%d", r);
	return 0;
}


Measured memory_bytes: 1024
import java.lang.Math.*

const val MOD = 1000000007L

fun main(args: Array<String>) {
    val s = readList().first()
    val dp = Array<Array<Long>>(1000000) {
        Array(13) {
            return@Array 0L
        }
    }

    dp[0][0] = 1
    s.length.rep { i ->
        var c = -1
        if (s[i] != '?') {
            c = s[i] - '0'
        }

        if (c == -1) {
            10.rep { j ->
                13.rep { k ->
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % MOD
                }
            }

        } else {
            13.rep { k ->
                dp[i + 1][(k * 10 + c) % 13] += dp[i][k] % MOD
            }
        }
        13.rep { k ->
            dp[i + 1][k] %= MOD
        }
    }

    println(dp[s.length][5])
}

fun readList() = readLine()!!.split(' ')
fun readInt() = readLine()!!.split(' ').map(String::toInt).first()
fun readIntList() = readList().map(String::toInt)
fun readLongList() = readList().map(String::toLong)
fun readDoubleList() = readList().map(String::toDouble)

fun readPair(): Pair<String, String> {
    val splite = readLine()!!.split(' ')
    return Pair(splite[0], splite[1])
}

fun <T> List<T>.copy() = this.map { it }

// 速度のためforEachは避ける
inline fun Int.rep(start: Int = 0, body: (Int) -> Unit) {
    for (i in start until this + start) {
        body(i)
    }
}

inline fun Long.rep(start: Long = 0, body: (Long) -> Unit) {
    for (i in start until this + start) {
        body(i)
    }
}

// 約数のList
fun divisor(value: Long): List<Long> {
    val max = sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

// 素因数分解
fun decom(value: Long): List<Long> {
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base: String, a: String, b: String): String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

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

int main(){
	int a, b;
	int d, r;
	double f;
	
	cin >> a >> b;
	
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	
	cout << d << ' ' << r << ' ' << fixed << f << endl;
	
	return 0;
}

Measured memory_bytes: 1240
import java.io.*;
import java.util.*;

public class Main {
	public static long solve(int n, int m, Map<Integer, List<Integer>> graph) {
		int[] color = new int[n];
		Queue<Integer> q = new LinkedList<>();
		q.offer(0);
		color[0] = 1;
		int blackCount = 1;
		int whiteCount = 0;
		while(!q.isEmpty()) {
			int next = q.poll();
			List<Integer> neighbors = graph.get(next);
			for(int neighbor : neighbors) {
				if(color[neighbor] == color[next]) {
					long total = ((long) n) * (n - 1) / 2;
					return total - m;
				} else if(color[neighbor] == 0) {
					int newColor = 3 - color[next];
					color[neighbor] = newColor;
					if(newColor == 1) {
						blackCount++;
					} else {
						whiteCount++;
					}
					q.offer(neighbor);
				}
			}
		}
		long count = 0;
		for(int i = 0; i < n; i++) {
			if(color[i] == 1) {
				count += whiteCount - graph.get(i).size();
			} else {
				count += blackCount - graph.get(i).size();
			}
		}
		return count/2;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		Map<Integer, List<Integer>> graph = new HashMap<>();
		for(int i = 0; i < n; i++) {
			graph.put(i, new ArrayList<>());
		}
		for(int i = 0; i < m; i++) {
			st = new StringTokenizer(f.readLine());
			int to = Integer.parseInt(st.nextToken()) - 1;
			int from = Integer.parseInt(st.nextToken()) - 1;
			graph.get(to).add(from);
			graph.get(from).add(to);
		}
		long answer = solve(n, m, graph);
		System.out.println(answer);
	}
}


Measured memory_bytes: 69008
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
long long dfs(long long csum, string s){
    if(s.size() == 0){
        return csum;
    }

    long long sum = 0;
    int slen = s.size();
    for(int i=0; i<slen; i++){
        string ls = s.substr(0, i+1);
        string rs = s.substr(i+1);

        long long lsval = stoll(ls);
        sum += dfs(csum + lsval, rs);
    }
    return sum;
}


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

    cout << dfs(0, s) << endl;

   return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [[i for i in map(int, input().split())] for _ in range(2)]

queue = [(0, 0, a[0][0])]

max_score = 0

append = queue.append

while queue:
    x, y, score = queue.pop()

    if y == 1 and x == n - 1:
        max_score = max(max_score, score)
        continue

    if x < n-1:
        append((x+1, y, score+a[y][x+1]))
    if y < 1:
        append((x, y+1, score+a[y+1][x]))


print(max_score)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=205;
int n,k;
char s[N];
vector<int>len;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%d",&k);
	for(int i=1,j=1;i<=n;i=j)
	{
		j=i;
		while(j<=n&&s[i]==s[j]) j++;
		len.push_back(j-i);
	}
	if(k==1)
	{
		int res=0;
		for(int L:len)
			res+=L/2;
		printf("%d",res);
		return 0;
	}
	if(s[1]==s[n])
	{
		int l=len.front(),r=len.back();
		if(len.size()==1)
		{
			long long ans=1LL*n*k/2;
			printf("%lld",ans);
			return 0;
		}
		len.erase(len.begin());
		len.pop_back();
		len.push_back(l+r);
		int res=0;
		for(int L:len)
			res+=L/2;
		long long ans=0;
		if(k>=2) ans+=1LL*res*(k-2);
		len.pop_back();
		len.insert(len.begin(),l);
		for(int L:len)
			ans+=L/2;
		len.erase(len.begin());
		len.push_back(l+r);
		len.push_back(r);
		for(int L:len)
			ans+=L/2;
		printf("%lld",ans);
		return 0;
	}
	int res=0;
	for(int L:len)
		res+=L/2;
	long long ans=1LL*res*k;
	printf("%lld",ans);
	return 0;
}

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

const int INF = (int)1e6 + 1;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M), c(M);
    for (int i = 0; i < M; i++)
    {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }

    vector<vector<int>> dist(N, vector<int>(N, INF));
    vector<vector<bool>> used(N, vector<bool>(N));
    for (int i = 0; i < M; i++)
    {
        int u = a.at(i) - 1, v = b.at(i) - 1;
        dist.at(u).at(v) = c.at(i);
        dist.at(v).at(u) = c.at(i);
        used.at(u).at(v) = true;
        used.at(v).at(u) = true;
    }

    int res = 0;
    for (int k = 0; k < N; k++)
    {
        for (int u = 0; u < N; u++)
        {
            for (int v = 0; v < N; v++)
            {
                if (dist.at(u).at(k) + dist.at(k).at(v) < dist.at(u).at(v))
                {
                    dist.at(u).at(v) = dist.at(u).at(k) + dist.at(k).at(v);
                    if (used.at(u).at(v))
                    {
                        res++;
                        used.at(u).at(v) = false;
                        used.at(v).at(u) = false;
                    }
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, a, b;
	int max, min;

	cin >> n >> a >> b;

	if (a < b) max = a;
	else max = b;

	min = n - a - b;
	if (min > 0) {
		min = 0;
	}
	else {
		min = -min;
	}

	cout << max << " " << min << endl;
}

Measured memory_bytes: 256
getGcd :: Int -> Int -> Int
getGcd a 0 = a
getGcd a b
    | a `mod` b == 0 = b
    | otherwise = getGcd b $ a `mod` b
    
main = do
    k <- read <$> getLine
    print $ sum [ getGcd c (getGcd a b) | a <- [1..k], b <- [1..k], c <- [1..k] ]

Measured memory_bytes: 4920
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    a, b, x = il()
    return b // x - (a - 1) // x


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3064
w, a, b = map(int, input().split())
if a < b:
    if ((a <= b) & (b <= a+w)):
        ans = 0
    else:
        ans = abs(b-a-w)
elif a >= b:
    if ((b <= a) & (a <= b+w)):
        ans = 0
    else:
        ans = abs(a-b-w)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main(void){

  int N=0;//文字列の個数
  int L=0;//文字列の長さ
  int i=0, j=0;
  char str[100][101];
  char tmp[101];

  scanf("%d", &N);
  scanf("%d", &L);
  for(i=0; i<N; i++){
    scanf("%s", str+i);
  }
i=0;

for(i=0; i<N-1; i++){
  for(j=i+1; j<N; j++){
    if(strcmp(str[i], str[j])>0){
      strcpy(tmp, &str[i][0]);
      strcpy(&str[i][0], &str[j][0]);
      strcpy(&str[j][0], tmp);
    }
  }
}

for(i=0; i<N; i++){
  printf("%s", str[i]);
}

return 0;
}


Measured memory_bytes: 128
import Control.Monad
import Control.Applicative

solver :: Int -> Int
solver num = length xs
  where xs = [(a,b,c,d) | a <- [0..9], b <- [0..9], c <- [0..9], d <- [0..9], a + b + c + d == num]


main :: IO()
main = do
  contents <- map (read :: String -> Int) . lines <$> getContents
  mapM_ print $ map solver contents

Measured memory_bytes: 4004
MAX = pow(10,18)
def main():
    N = int(input())
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

    ans = 1
    for a in A:
        ans *= a
        if ans > MAX:
            print(-1)
            return

    print(ans)

main()


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

using namespace std;

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

void Bubble_Sort(int N, vector<string> &A){
  bool flag = true;

  while(flag){
    flag = false;
    for(int j = N-1; j > 0; j--){
      if(A.at(j).at(1) < A.at(j -1).at(1)){
        swap(A.at(j), A.at(j-1));
        flag = true;
      }
    }
  }
}

void SelectionS(int N, vector<string> &A){
  rep(i, N){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A.at(j).at(1) < A.at(minj).at(1)){
        minj = j;
      }
    }
    if(minj!=i){
      swap(A.at(i), A.at(minj));
    }
  }
}

void stable_check(int N, vector<string> &A, map<int, queue<char>> dup){
  string stability = "Stable";
  rep(i, N){
    int value = A.at(i).at(1);
    char mark = A.at(i).at(0);
    if((dup.at(value).size() > 1) && (dup.at(value).front() != mark)){
      stability = "Not stable";
    }
    dup.at(value).pop();
  }

  cout << stability << endl;
}

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

  map<int, queue<char>> dup;
  vector<string> A(N);

  rep(i,N){
    cin >> A.at(i);
    int kvalue = A.at(i).at(1);
    char mark = A.at(i).at(0);
    if(!dup.count(kvalue)){
      queue<char> alpha; //ここいちいち初期化できるか不安
      alpha.push(mark);
      dup[kvalue] = alpha;
    }
    else dup.at(kvalue).push(mark);
  }

  vector<string> B = A;
  map<int, queue<char>> dup2 = dup;


  Bubble_Sort(N, A);
  rep(i, N){
    cout << A.at(i);
    if(i!=N-1) cout << " ";
    else cout << endl;
  }

  stable_check(N,A,dup);

  SelectionS(N, B);
  rep(i, N){
    cout << B.at(i);
    if(i!=N-1) cout << " ";
    else cout << endl;
  }

  stable_check(N, B, dup2);
}



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

int n, m;
int a[85][85], b[85][85];
int dp[85][85][13000];
int k = 6500;

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

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> b[i][j];
		}
	}
	dp[1][1][a[1][1] - b[1][1] + k] = 1;
	dp[1][1][b[1][1] - a[1][1] + k] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			for (int x = -k; x <= k; ++x) {
				if (dp[i][j][x + k]) {
					dp[i + 1][j][x + a[i + 1][j] - b[i + 1][j] + k] = 1;
					dp[i + 1][j][x + b[i + 1][j] - a[i + 1][j] + k] = 1;
					dp[i][j + 1][x + a[i][j + 1] - b[i][j + 1] + k] = 1;
					dp[i][j + 1][x + b[i][j + 1] - a[i][j + 1] + k] = 1;
				}
			}
		}
	}

	int ans = INT_MAX;
	for (int i = -k; i <= k; ++i) {
		if (dp[n][m][i + k] > 0) {
			ans = min(ans, abs(i));
		}
	}
	cout << ans << endl;
}

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

int main() {
  int x, y;
  cin >> x >> y;

  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      if (i + j == x && 2 * i + 4 * j == y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3620
#coding:utf-8
A, B = map(int, input().rstrip().split())
if A != 1 and B != 1:
  if A > B:
    print("Alice")
  elif A < B:
    print("Bob")
  else:
    print("Draw")
else:
  if A < B:
    print("Alice")
  elif A > B:
    print("Bob")
  else:
    print("Draw")

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

int main() {
	int N;
	long K;
	cin >> N >> K;
	long a[N];
	int count[40] = {0};
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		for(int j = 39; j >= 0; j--) {
			if(a[i] & (1L<<j)) {
				count[j]++;
			}
		}
	}
	long used = 0;
	int div = N / 2;
	bool isOdd = N % 2 == 1;
	for(int j = 39; j >= 0; j--) {
		if((used + (1L<<j)) <= K) {
			if(count[j] < N - count[j]) {
				used += (1L<<j);
			}
		}
	}
	long result = 0;
	for(int i = 0; i < N; i++) {
		result += used^a[i];
	}
	
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int n, t;
int ans = 199999999;

struct node{
	int ti;
	int ci;
	bool operator < (const node & a) const
	{
		if (a.ti == ti) return ci < a.ci;
		return  ti < a.ti;
	}
}a[3333];

int main()
{
	cin >> n >> t;
	for (int i = 1; i <= n; ++i) cin >> a[i].ci >> a[i].ti;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
	{
		if (a[i].ti > t)  break;
		ans = min(a[i].ci, ans);
	}
	if (ans == 199999999) cout << "TLE";
	else cout << ans;
}

Measured memory_bytes: 256