akhauriyash/Code-Regression huggingface dataset:
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
const ll MAX=200000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    COMinit();
    ll n,k;cin >> n >> k;
    vector<ll> a(n);REP(i,n) cin >> a[i];
    sort(ALL(a));
    ll ans=0;
    if(k==1){cout << 0 << endl;return 0;}
    //まずはMAXを考える
    REP(i,n){
        ans+=(COM(i,k-1)*a[i]);
        ans%=MOD;
    }
    REP(i,n){
        ans-=(COM(n-i-1,k-1)*a[i]);
        if(ans<0){
            ans=MOD-abs(ans)%MOD;
        }else{
            ans%=MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <stdio.h>
int matchx(int x){
    int to;
    switch (x) {
        case 'A': to=0;
            break;
        case 'B': to=1;
            break;
        case 'C': to=2;
            break;
    }
    return to;
}
int matchy(int y){
    int go;
    switch (y) {
        case 'A':go=0;
            break;
        case 'B':go=1;
            break;
        case 'C':go=2;
            break;
    }
    return go;
}
int main ( void ) {
    int a[3]={0},work,to,go;
    char x[2],y[2];
    a[0]=1;
    while(scanf("%1s,%1s",x,y)!=EOF){
        to=matchx(x[0]);
        go=matchy(y[0]);
        work=a[to];
        a[to]=a[go];
        a[go]=work;
    }
    if(a[0]==1){
        puts("A");
    }else if(a[1]==1){
        puts("B");
    }else puts("C");
    
    
    
    
    
    
    return 0;
}

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

#define ll long long int
#define ull unsigned long long int
#define Max 1000005
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define pi acos(-1.0)
#define pb push_back
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define endl '\n'

#define sc(n) scanf("%d",&n)
#define scan(n) scanf("%lld",&n)
/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;

//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;
typedef tuple<ll,ll,ll>tpl;

int main()
{
    int n;
    cin>> n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int aa;
        cin >> aa;
        if(aa%2 and i%2)ans++;
    }
    return cout<<ans<<endl,0;
}
/*
     remember:
     ll vs int
     array size
     case for 1 2 3 
*/



Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))

ab_pairs = [list(map(int, input().split(' '))) for _ in range(N)]
ab_pairs.sort(key=lambda x: x[0])

rest = M
ret = 0
for a, b in ab_pairs:
    n = min(rest, b)
    ret += a * n
    rest -= n

print(ret)

Measured memory_bytes: 64856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    const int mod = 1000000007;
    
    lint N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    lint cnt = 0, X = 0;
    rep(i, N) rep(j, N) {
        if (i < j && a[i] > a[j]) ++cnt;
        if (a[i] > a[j]) ++X;
    }
    cout << (cnt * K % mod + (K - 1) * K / 2 % mod * X % mod) % mod << "\n";
    return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

int main()
{
  int n, q;cin>>n>>q;
  string str;cin>>str;

  vector<int> s(n + 1, 0);
  for (int i = 0;i<n;i++){
    if(i+1<n&&str[i]=='A'&&str[i+1]=='C')s[i + 1] = s[i] + 1;
    else s[i + 1] = s[i];
  }

  for (int i = 0; i < q; i++)
  {
    int l, r;cin >> l >> r;
    cout << s[r - 1] - s[l- 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
import numpy as np
n = int(input())
s = np.array([int(input()) for i in range(n)])
s = np.sort(s)

s10 = s[s % 10 != 0]

total = sum(s)
for si in s10:
  if total % 10 != 0:
    break
    
  total -= si

print(total if total % 10 != 0 else 0)

Measured memory_bytes: 12564
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<iomanip>
#include<set>
#define REP(i,x,y) for(ll i=x;i<y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>x;i--)
typedef long long ll;
using namespace std;

int main(){
    ll N;
    cin>>N;
    vector<vector<ll>> A(N,vector<ll>(N,0));
    //ll A[N][N];
    REP(i,0,N){
        REP(j,0,N){
        cin>>A.at(i).at(j);
        }
    }
    vector<vector<ll>> dp(N+1, vector<ll>(1<<N,0));
    //ll dp[N+1][1<<N];
    dp[0][0]=1;
    ll mod;
    mod=1000000007;
    REP(S,0,(1<<N)-1){
        ll i;
        i=__builtin_popcount(S);
        //cout<<i<<endl;
        REP(j,0,N){
            if (A.at(i).at(j)==1){
                if (!(S&(1<<j))){
                //dp[i+1][S | (1<<j)]+=dp[i][S];
                dp.at(i+1).at(S | (1<<j))+=dp.at(i).at(S);
                //dp[i+1][S | (1<<j)]%=mod;
                dp.at(i+1).at(S | (1<<j))%=mod;
                }
            }
        }
        
    }
    //cout<< dp[N][(1<<N)-1] << endl;
    cout<< dp.at(N).at((1<<N)-1) << endl;
}






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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to, id;
  Edge(int from, int to, int id) : from(from), to(to), id(id) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2, i));
    graph[v2].push_back(Edge(v2, v1, i));
  }
  return graph;
}

int BitCount(int64 x) {
  int count = 0;
  while (x > 0) {
    count += x % 2;
    x /= 2;
  }
  return count;
}

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

  int n;
  cin >> n;
  auto graph = ReadUndirectedGraph(n, n - 1, true);
  int m;
  cin >> m;
  vector<int64> edge_sets(m);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--;
    v2--;

    vector<int> parents(n, -1);
    vector<int> parent_edges(n, -1);
    function<void(int, int)> dfs_fn = [&](int v, int p) {
      for (const auto& e : graph[v]) {
        if (e.to == p) continue;
        parents[e.to] = v;
        parent_edges[e.to] = e.id;
        dfs_fn(e.to, v);
      }
    };
    dfs_fn(v1, -1);
    int c = v2;
    int64 edge_set = 0;
    while (c != v1) {
      edge_set |= 1L << parent_edges[c];
      c = parents[c];
    }
    edge_sets[i] = edge_set;
    // cout << "i: " << i << " edge_set: " << edge_set << endl;
  }

  int64 sum = 0;
  for (int s = 0; s < 1 << m; s++) {
    if (s == 0) continue;
    int64 edge_set = 0;
    for (int i = 0; i < m; i++) {
      if (s & (1 << i)) {
        edge_set |= edge_sets[i];
      }
    }
    // cout << "s: " << s << " edge_set: " << edge_set << endl;

    int64 x = 1;
    for (int i = 0; i < (n - 1) - BitCount(edge_set); i++) {
      x *= 2;
    }
    // cout << "s: " << s << " x: " << x << endl;
    if (BitCount(s) % 2 == 0) x *= -1;
    sum += x;
  }
  // cout << "sum: " << sum << endl;

  int64 ans = 1;
  for (int i = 0; i < n - 1; i++) {
    ans *= 2;
  }
  ans -= sum;
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b<c+d){
    cout << "Right" << endl;
  }
  else if(a+b==c+d){
    cout << "Balanced" <<endl;
  }
  else{
    cout << "Left" << endl;
  }
}


Measured memory_bytes: 256
Module Module1

    Sub Main()
        Dim instr() As String = Split(Console.ReadLine())
        Dim n As Integer = CInt(instr(0))
        Dim m As Integer = CInt(instr(1))
        Dim a As Integer = -1

        For i As Integer = n To CInt(m / 2)
            If m Mod i = 0 Then
                a = i
                Exit For
            End If
        Next
        If a <> -1 Then
            Console.WriteLine(m / a)
        Else
            Console.WriteLine(1)
        End If
    End Sub

End Module


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

int main(void){
    int n;
    char s[10000];

    scanf("%d", &n);
    scanf("%s", s);

    int len = strlen(s);
    for (int i = 0; i < len; i++){
        if (s[i] + n <= 'Z')
            printf("%c", s[i]+n);
        else
            printf("%c", s[i]+n-26);
    }

    return 0;

}

Measured memory_bytes: 128
from collections import Counter
N=int(input())
a=[]
for i in range(N):
  a.append(input())
c = Counter(a)

print("AC x "+str(a.count("AC")))
print("WA x "+str(a.count("WA")))
print("TLE x "+str(a.count("TLE")))
print("RE x "+str(a.count("RE")))

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

int main() {
  int N;
  cin >> N;
  
  vector<int> V(N);
  vector<int> C(N);
  
  for(int i=0;i<N;i++){
    cin >> V.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  
  int sum = 0;
  
  for(int i=0;i<N;i++){
    if(V.at(i)>C.at(i)){
      sum = sum + V.at(i)-C.at(i);
    }
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3552
from collections import defaultdict
class Graph(object):
    #隣接リストによる有向グラフ
    def __init__(self):
        self.graph = defaultdict(list)
    def __len__(self):
        return len(self.graph)
    def add_edge(self, src, dst):
        self.graph[src].append(dst)
N,M = map(int,input().split())
loapdic = {}
ga = Graph()
for i in range(M):
    a,b = map(int,input().split())
    ga.add_edge(a, b)
    ga.add_edge(b, a)
for n in range(1,N+1):
    print(len(ga.graph[n]))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int s[105];
int sum;
int main(void){
    int n; cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    if(sum%10!=0){
        cout<<sum<<endl;
        return 0;
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
        if(s[i]%10!=0){
            cout<<sum-s[i]<<endl;
            return 0;
        }
    }
    cout<<0<<endl;

}


Measured memory_bytes: 3588
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
(N,M) = (int(i) for i in input().split(" "))

m = 3000
if M-N >= 2019:
	print(0)
else:
	for i in range(N,M):
		for j in range(i+1,M+1):
			k=i*j
			k%=2019
			if k < m:
				m=k
	print(m)



Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}



int main(){
  vector<ll> ans,b;
  FOR(i,1,10)b.push_back(i);
  FOR(i,1,10)ans.push_back(i);
  ll k;
  cin >> k;
  while(ans.size() < k){
    vector<ll> t;
    for(auto &&x:b){
      ll e = x%10;
      if(e)t.push_back(x*10+e-1);
      t.push_back(x*10+e);
      if(e!=9)t.push_back(x*10+e+1);
      if(e)ans.push_back(x*10+e-1);
      ans.push_back(x*10+e);
      if(e!=9)ans.push_back(x*10+e+1);
    }
    b = t;
  }
  SORT(ans);
  cout << ans[k-1] << endl;
}


Measured memory_bytes: 5232
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int D;
	int[] c;
	int[][] s;
	int[] last;

	Main(BufferedReader in) throws IOException {
		D = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		c = new int[tokens.length];
		for (int i = 0; i < tokens.length; ++i) {
			c[i] = Integer.parseInt(tokens[i]);
		}
		s = new int[D][c.length];
		for (int i = 0; i < D; ++i) {
			tokens = in.readLine().split(" ");
			for (int j = 0; j < tokens.length; ++j) {
				s[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		last = new int[c.length];
		Arrays.fill(last, 0);
	}

	int sub(int day, int contest, int prevDayContest) {
		int result = s[day][contest];
		int minus = 0;
		for (int i = 0; i < c.length; ++i) {
			if (i != contest) {
				if (i != prevDayContest) {
					minus += (day - last[i]) * c[i];
				} else {
					minus += c[i];
				}
			}
		}
		return result - minus;
	}

	int sub(int day, int contest) {
		int result = s[day][contest];
		int minus = 0;
		for (int i = 0; i < c.length; ++i) {
			if (i != contest) {
				minus += (day - last[i]) * c[i];
			}
		}
		return result - minus;
	}

	int sub(int day) {
		int result = -1;
		int max = Integer.MIN_VALUE;
		if (day == D - 1) {
			// 最も得られる満足度が高いものを選ぶ
			for (int contest = 0; contest < c.length; ++contest) {
				int effort = sub(day, contest);
				if (max < effort) {
					result = contest;
					max = effort;
				}
			}
		} else {
			// 2日読む
			for (int contest = 0; contest < c.length; ++contest) {
				int effort1 = sub(day, contest);
				for (int j = 0; j < c.length; ++j) {
					int effort2 = sub(day, j, contest);
					if (max < effort1 + effort2) {
						result = contest;
						max = effort1 + effort2;
					}
				}
			}
		}

		return result;
	}

	void calc() {
		// まずは最大のSを選ぶことにする
		for (int i = 0; i < D; ++i) {
			int r = sub(i);
			if (r >= 0) {
				System.out.println((r + 1));
				last[r] = i;
			} else {
				System.out.println("1");
				last[0] = i;
			}

		}
	}

	void showResult() {
	}
}

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

class UnionFind{
	public:
	vector<int> par;
	
	UnionFind(int N){
		par = vector<int>(N, -1);
	}
	int root(int x){
		if(par[x] < 0)return x;
		
		return par[x] = root(par[x]);
	}
	int size(int x){
		return -par[root(x)];
	}
	
	
	bool unite(int x, int y){
			x = root(x);
			y = root(y);
			if(x == y){
				return false;
			}
			if(size(x) < size(y))swap(x, y);
			
			par[x] += par[y];
			par[y] = x;
			return true;
	}
};
int main(){
	int N,M;
	cin>>N>>M;
	vector<int> A(M);
	vector<int> B(M);
	
	for(int i = 0; i < M; i++){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
	}
	UnionFind Bridges(N);
	vector<long long> inconvenience(M);
	inconvenience[M - 1] = (long long)N * (N - 1) / 2;
	for(int i = M - 1; i >= 1; i--){
		inconvenience[i - 1] = inconvenience[i];
		if(Bridges.root(A[i]) != Bridges.root(B[i])){
			inconvenience[i - 1] -= (long long)Bridges.size(A[i]) * Bridges.size(B[i]);
			Bridges.unite(A[i], B[i]);
		}
	}
	for(int i = 0; i < M; i++){
		cout<<inconvenience[i]<<endl;
	}
	return 0;
}

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

using namespace std;

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

    int n, l;
    cin >> n >> l;
    vector<string> vec;
    for (int i = 0; i < n; i ++) {
        string s ;
        cin >> s;

        vec.push_back(s);
    }

    sort(vec.begin(), vec.end());

    for (string s : vec)
        cout << s;

    return 0;
}

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

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

	int ret = 1;

	for (int i = 1; i < n; i++) {
		int h_i = h[i];
		bool false_flag = false;
		for (int j = 0; j < i + 1; j++) {
			if (h_i < h[j]) {
				false_flag = true;
				break;
			}
		}
		if (!false_flag) {
			ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	
	int count = 1;
	while (count <= 10000000000) {
		if (count > A && count > B){ break; }
		if(abs(A - count) == abs(B - count)) {
			cout << count << endl;
			return 0;
		}
		count++;
	}
	cout << "IMPOSSIBLE" << endl;
}

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

int main()
{
	//char arr[] = {'AC','TLE','WA','RE'};
	map<int,string>arr;
	arr[0] = "AC";
	arr[1] = "WA";
	arr[2] = "TLE";
	arr[3] = "RE";
	ll n;
	cin>>n;
	ll a=0,b=0,c=0,d=0;
	while(n--)
	{
		string x;
		cin>>x;
		if(x==arr[0])a++;
		if(x==arr[1])b++;
		if(x==arr[2])c++;
		if(x==arr[3])d++;
	}
	cout<<"AC "<<"x "<<a<<endl;
	cout<<"WA "<<"x "<<b<<endl;
	cout<<"TLE "<<"x "<<c<<endl;
	cout<<"RE "<<"x "<<d<<endl;
	
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

ll A[200002];

int bin_search(int l, int r){
    ll offset = l > 0 ? A[l - 1] : 0;

    // Case : left part is smaller
    // left part is [l, i] for i in [low, high).
    int low = l, high = r - 1;
    while(high - low > 1){
        int i = (low + high) / 2;
        ll s_left = A[i] - offset;
        ll s_right = A[r - 1] - A[i];
        if(s_left > s_right){
            high = i;
        }else{
            low = i;
        }
    }
    int i1 = low;

    // Case : left part is larger
    // left part is [l, i] for i in (low, high].
    low = l - 1, high = r - 2;
    while(high - low > 1){
        int i = (low + high) / 2;
        ll s_left = A[i] - offset;
        ll s_right = A[r - 1] - A[i];
        if(s_left < s_right){
            low = i;
        }else{
            high = i;
        }
    }
    int i2 = high;

    if(abs((A[i1] - offset) - (A[r - 1] - A[i1])) < abs((A[i2] - offset) - (A[r - 1] - A[i2]))){
        return i1;
    }else{
        return i2;
    }
}

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

    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=1;i<N;i++){
        A[i] += A[i - 1];
    }

    ll ans = 1LL << 60;
    for(int d=2;d<N-1;d++){
        int a_end = bin_search(0, d);
        int c_end = bin_search(d, N);
        ll diff = max({A[a_end], A[d - 1] - A[a_end], A[c_end] - A[d - 1], A[N - 1] - A[c_end]})
            - min({A[a_end], A[d - 1] - A[a_end], A[c_end] - A[d - 1], A[N - 1] - A[c_end]});
        ans = min(ans, diff);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
int N,K;
cin>>N>>K;
int sum = 1;
for(int i = 0;i<N;i++){
if(sum<K){
sum+=sum;}
else{sum+=K;}
}
cout<<sum;
}

Measured memory_bytes: 3528
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] w = scanner.nextLine().toCharArray();
			Map<Character, Integer> map = new HashMap<>();
			for (char c : w) {
				map.put(c, map.getOrDefault(c, 0) + 1);
			}
			boolean result = true;
			for (Character c : map.keySet()) {
				if (0 != (map.get(c) & 1)) {
					result = false;
					break;
				}
			}
			System.out.println(result ? "Yes" : "No");
		}
	}
}


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

int main(){
	int r, c, table[1000][1000], a;

	cin >> r >> c;

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][j] = 0;
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> table[i][j];
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][c] += table[i][j];
		}
	}

	for (int i = 0; i < c; i++){
		for (int j = 0; j < r; j++){
			table[r][i] += table[j][i];
		}
	}

	for (int i = 0; i < r; i++){
		table[r][c] += table[i][c];
	}

	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c; j++){
			cout << table[i][j] << " ";
		}
		cout << table[i][c] << endl;
	}

	return 0;
}


Measured memory_bytes: 3452
#include <stdio.h>

int main(void) {
    int n;
    char s[100002];
 
    scanf("%d", &n);
    scanf("%s", s);
    
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1]) ans++;
    }

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

Measured memory_bytes: 1828
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}

bool prime(ll N){
  bool A=true;
  rep(i,N){
    if(i>=2){
      if(N%i==0)A=false;
    }
  }
  if(N>=2)return A;
  else return false;
}
int main()
{
  ll N;
  cin>>N;
  ll ans=1;
  ll b=1;
  ll M;
  rep(i,N+1){
    M=N;
    b=1;
    if(i>=2){
      if(prime(i)){
        while(M>=i){
          M/=i;
          b+=M;
        }
        ans=(ans*b)%MOD;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int main(){
	
	int k;
	while(cin>>k,k!=0){
		int d=(k*(k-1))/2;
		vector<int> a(d);
		int s=0;
		for(int i=0;i<d;i++){
			cin>>a[i];
			s+=a[i];
		}
		if(k!=1)
		s=s/(k-1);
		cout<<s<<endl;
			
	}
	
	
 	
}

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

using namespace std;

/**/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/**/

#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;

int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int a, b; cin >> a >> b;

	if (b == 1) {
		cout << 0 << '\n';
		return 0;
	}

	int qt = 0, emptys = 0;

	while (1) {
		emptys += a; ++qt;
		if (emptys >= b) break;
		emptys -= 1;
	}

	cout << qt << '\n';

	return 0;
}



Measured memory_bytes: 256
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct
  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m <> i then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(m); t.node.(m) <- tmp;
        max_heapify m
      end in
    max_heapify 1;
    ret

  let push x t =
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      if i > 1 && M.compare t.node.(parent i) t.node.(i) < 0 then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(parent i); t.node.(parent i) <- tmp;
        doit (parent i)
      end in
    doit t.size
end

module H = MakeBinaryHeap(struct type t = (int * int) let compare x y = snd x - snd y end)

let dijkstra g n =
  let h = H.make 100000 (0, 0) in
  let d = Array.make n max_int in
  let b = Array.make n false in
  d.(0) <- 0;
  b.(0) <- true;
  H.push (0, 0) h;
  let rec doit () =
    if not (H.empty_p h) then begin
      let (u, x) = H.pop h in
      b.(u) <- true;
      if d.(u) >= -x then duduwa u g.(u);
      doit ()
    end
  and duduwa u = function
    | [] -> ()
    | (v, c) :: tl when b.(v) = true || d.(v) <= d.(u) + c -> duduwa u tl
    | (v, c) :: tl ->
      begin
        d.(v) <- d.(u) + c;
        H.push (v, -d.(v)) h;
        duduwa u tl
      end in
  doit ();
  d

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> exit 1

let () =
  let n = read_int () in
  let g = Array.make n [] in
  let rec read i =
    if i < n then
      match List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) with
      | u :: _ :: l -> (g.(u) <- make_pair [] l; read (i + 1))
      | _ -> exit 1
  in read 0;
  Array.iteri (fun i e -> print_int i; print_string " "; print_int e; print_string "\n") (dijkstra g n)

Measured memory_bytes: 30636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

string[] substrings(string s)
{
    if (s == "") {
        return [];
    } else {
        string[] buf;
        foreach (i; 0..min(s.length, 5)) {
            buf ~= s[0..i+1];
        }
        return buf ~ substrings(s[1..$]);
    }
}

void main()
{
    auto s = readln.chomp;
    auto K = readln.chomp.to!int;

    auto substrs = substrings(s);
    sort(substrs);

    writeln(substrs.uniq.array[K-1]);
}

Measured memory_bytes: 5756
S = input()
cnt=0
result = 0
for i in range(2**(len(S)-1)):
  mark_list = S[0]
  for j in range(len(S)-1):
    if (i>>j)&1 == 1:
      mark_list+="+"+S[j+1] 
    else:
      mark_list+=S[j+1]
  result+=eval(mark_list)
print(result)

Measured memory_bytes: 3060
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

x,y = ips()
print(lcm(x,y))

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

const int HOUR  = 24;
int main() {
	int M = 0;
	std::cin >> M;
	if (M > 0 && M <= 23)
	{
		std::cout << (24-M) + 24 << endl;
	}
	else
	{
		std::cin >> M;
	}
}

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2019-06-06.
//

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

int main() {
    int n, tmp;
    vector<int> v, c;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> tmp;
        v.push_back(tmp);
    }
    for(int i = 0; i < n; ++i) {
        cin >> tmp;
        c.push_back(tmp);
    }

    int res = 0;
    for(int i = 0; i < n; ++i) {
        res += max(0, v[i] - c[i]);
    }
    cout << res << endl;

    return 0;
}

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

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> numbers(N);
  int zero_index = -1;;
  for (int i = 0; i < N; ++i) {
    cin >> numbers[i];
    if (numbers[i] == 0) {
      zero_index = i;
    }
  }

  // If there exists a number 0, idx_before and idx_after are
  // equal to the index of this number.
  int idx_before = -1;
  int idx_after = 0;
  if (zero_index >= 0) {
    idx_before = zero_index;
    idx_after = zero_index;
  } else {
    for (int i = 0; i < N; ++i) {
      if (numbers[i] < 0) {
        ++idx_before;
        ++idx_after;
      } else {
        break;
      }
    }
  }

  int mn = numeric_limits<int>::max();
  for (int l = idx_before - K + 1; l <= idx_after; ++l) {
    int r = l + K - 1;
    if (l >= 0 && r < N) {
      if (numbers[l] < 0 && numbers[r] > 0) {
        mn = min(mn,
                 min(2 * abs(numbers[l]) + abs(numbers[r]),
                     abs(numbers[l]) + 2 * abs(numbers[r])));
      } else {
        mn = min(mn, max(abs(numbers[l]), abs(numbers[r])));
      }
    }
  }
  cout << mn << endl;
}

int main() {
  solve();
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

const int maxn = 1234;

bool isprime(int x){
    for(int i = 2; i * i <= x; ++i)if(x%i == 0)return false;
    return true;
}
int main(int argc, char const *argv[])
{
    // freopen("input.txt", "r", stdin);
    int X;
    cin>>X;
    while(!isprime(X))X++;
    cout<<X<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void)
{
  char z;
  scanf("%c", &z);

  if (z == 'a')
    printf("b");

  else if (z == 'b')
    printf("c");
  else if (z == 'c')
    printf("d");
  else if (z == 'd')
    printf("e");
  else if (z == 'e')
    printf("f");
  else if (z == 'f')
    printf("g");
  else if (z == 'g')
    printf("h");
  else if (z == 'h')
    printf("i");
  else if (z == 'i')
    printf("j");
  else if (z == 'k')
    printf("l");
  else if (z == 'l')
    printf("m");
  else if (z == 'm')
    printf("n");
  else if (z == 'n')
    printf("o");
  else if (z == 'o')
    printf("p");
  else if (z == 'p')
    printf("q");
  else if (z == 'q')
    printf("r");
  else if (z == 'r')
    printf("s");
  else if (z == 's')
    printf("t");
  else if (z == 't')
    printf("u");
  else if (z == 'u')
    printf("v");
  else if (z == 'v')
    printf("w");
  else if (z == 'w')
    printf("x");
  else if (z == 'x')
    printf("y");
  else
    printf("z");
  return 0;
}

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

int main(){
  int n,m; cin>>n>>m;
  if(n==m) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

tmp = 0
sum = 0
for i in range(N+1):
    if i == N:
        if A[i] - tmp < 0:
            sum += A[i]
        else:
            sum += tmp

    else:
        if A[i] - (B[i] + tmp) < 0:
            sum += A[i]
            A[i] = A[i] - tmp
            if A[i] < 0:
                A[i] = 0
            tmp = B[i] - A[i]
        else:
            sum += B[i] + tmp
            tmp = 0

print(sum)


Measured memory_bytes: 18624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))



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

int gcd(int a,int b);

int main(void)
{
  int n,m;
  scanf("%d%d",&n,&m);
  int k[10], s[10][10], p[10];
  int i,j;
  REP(i,m)
  {
    scanf("%d",&k[i]);
    REP(j,k[i])
    {
      scanf("%d",&s[i][j]);
      //printf("%d\n",s[i][j]);
    }
  }
  REP(i,m) scanf("%d",&p[i]);
  int flag,q,ans = 0,miniflag;

  int light[10] = {0};
  REP(i,1<<n)
  {
    //printf("%d\n",i);
    flag = 0;
    REP(j,m)//j個の電球について調べる
    {
      miniflag = 0;
      REP(q,k[j])//１個の電球に関するki個のスイッチについて調べる。
      {
        //s[j][p]
        if((i>>(n-s[j][q]))&1)
        {
          //printf("\t%dはon!\n",s[j][q]);
          miniflag++;
        }
        //else printf("\t%dはoff:(\n",s[j][q]);
      }
      if(miniflag%2==p[j]) flag++;


      else break;
    }
    if(flag==m)
    {
      //printf("%dのとき全部ついた%dこめ\n",i,ans);
      ans++;

    }
  }
  printf("%d",ans);
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp  make_pair
#define pb  push_back
#define endl "\n"
#define rep(i,a,n) for(int i=a;i<n;i++)
const int mod = 1e9 + 7;
void solve() {
	int n;
	cin >> n;
	int a[n];
	rep(i, 0, n) {
		cin >> a[i];
	}
	int s = 0;
	rep(i, 1, n) {
		if (a[i] < a[i - 1]) {
			s += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << s << endl;
}
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int X[110000];
int cnt[110000], modcnt[110000], modbonus[110000];
signed main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> X[i], cnt[X[i]]++, modcnt[X[i] % M]++;
        if (cnt[X[i]] % 2 == 0) { modbonus[X[i] % M]++; }
    }
    int ans = 0;
    reps(i, (M + 1) / 2 - 1) {
        if (modcnt[i] > modcnt[M - i]) { ans += modcnt[M - i] + min((modcnt[i] - modcnt[M - i]) / 2, modbonus[i]); }
        else { ans += modcnt[i] + min((modcnt[M - i] - modcnt[i]) / 2, modbonus[M - i]); }
    }
    ans += modcnt[0] / 2;
    if (M % 2 == 0) { ans += modcnt[M / 2] / 2; }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;
char s[200010];
long long res[10010];
int main(){
    long long n, p;
    scanf("%lld %lld", &n, &p);
    scanf("%s", s + 1);
    long long ans = 0;
    if(10 % p == 0){
        for(int i = 1; i <= n; i ++){
            if((s[i] - '0') % p == 0)
                ans += (long long)i;
        }
    }
    else{
        long long base = 1;
        long long now = 0;
        for(int i = n; i >= 1; i --){
            res[now] ++;
            now = (now + (base * (s[i] - '0'))) % p;
            base = (base * 10) % p;
            ans += res[now];
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli data[200100];

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	REP(i,0,n){
		cin>>a[i];
		data[a[i]]++;
	}

	lli ans = 0;
	REP(i,0,200100){
		if(data[i]==0)continue;
		ans += data[i]*(data[i]-1)/2;
	}

	REP(i,0,n){
		lli tmp = data[a[i]]*(data[a[i]]-1)/2 - (data[a[i]]-1)*(data[a[i]]-2)/2;
		cout<<ans-tmp<<endl;
	}

	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main(void)
{
	int w,h,n,x[100000],y[100000],Xmax,cnt,flg[100000],kyori,ymax,i;
	scanf("%d%d%d",&w,&h,&n);
	Xmax=0;
	for(i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
		if(Xmax<x[i]) Xmax=x[i];
	}
	for(i=0;i<=Xmax;i++) flg[i]=-1;
	flg[0]=0;
	for(i=0;i<n;i++){
		if(flg[x[i]]<y[i]) flg[x[i]]=y[i];
	}
	//for(i=0;i<=Xmax;i++) printf("flg[%d]=%d\n",i,flg[i]);
	kyori=1000000; ymax=0;
	for(i=Xmax;i>=0;i--){
		if(flg[i]!=-1){
			if(kyori>ymax+i) kyori=ymax+i;
			if(ymax<flg[i]) ymax=flg[i];
		}
		//printf("i=%d ymax=%d\n",i,ymax);
	}
	printf("%d\n",kyori);
	return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>

int main(){
   int  i,j,k,n,d1,d2;

   scanf("%d",&n);
   for (k=j=i=0;i<n;i++) {
      scanf("%d %d",&d1,&d2);
      if (d1==d2) {
         j++;
         if (j>=3) k++;
      } else
         j=0;
   }
   if (k>0) puts("Yes");
   else     puts("No");
   return 0;
}

Measured memory_bytes: 1664
fun main(args: Array<String>) {
  val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
  solve(sc)
}

fun solve(sc: java.util.Scanner) {
  val N = sc.nextLong()
  println((1..N).fold(1L, { acc, i -> (acc * i) % 1000000007 }))
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

ll modmul(ll a,ll b,ll mod){
    return a%mod * (b%mod) %mod;
}

ll modpow(ll a,ll b,ll mod){
    if(b==0) return 1;
    else if(b%2==0) return modpow(modmul(a,a,mod),b/2,mod);
    else return modmul(modpow(a,b-1,mod),a,mod);
}

ll moddiv(ll a,ll b,ll mod){
    return a%mod * modpow(b,mod-2,mod) %mod;
}

int main(void)
{
    ll n,m; cin>>n>>m;
    map<ll,ll> mp;
    rep(i,m){
        ll a,b; cin>>a>>b;
        mp[--a]++;
        mp[--b]++;
    }
    rep(i,n) cout<<mp[i]<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n;
ll a[2002];
bitset<4002001> dp,tmp,one;

int main(){
  cin>>n;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  sum=(sum+1)/2;
  dp=1;
  one=1;
  rep(i,n){
    dp|=(dp<<a[i]);
  }
  repl(i,sum,4000001){
    if(((dp>>i)&one)==one){
      cout<<i<<endl;
      return 0;
    }
  }
	return 0;
}


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

int main(){
  int n, m; scanf("%d %d", &n, &m);
  priority_queue<ll> que;
  for(int i = 0; i < n; i++){
      ll x; scanf("%lld", &x);
      que.push(x);
  }
  for(int i = 0; i < m; i++){
      int x = que.top(); que.pop();
      que.push(x/2);
  }
  ll ans = 0;
  while(que.size()){
      ans += que.top();
      que.pop();
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 4284
s1 = str(input())

s2 = s1[ int((len(s1)+3)/2)-1: len(s1)]

kai1 = ''
kai2 = ''

for i in range(len(s1), 0, -1):
    kai1 = kai1+s1[i-1]
for i in range(len(s2), 0, -1):
    kai2 = kai2+s2[i-1]


if s1 == kai1 and s2 == kai2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n, q; cin >> n >> q;
	deque<pair<string, int>> dq;
	{string s; int t; rep(i, 0, n) { cin >> s >> t; dq.eb(mp(s,t));}}
	string name;
	int time, ans = 0;
	while(!dq.empty()) {
		tie(name, time) = dq.front(); dq.pop_front();
		if(time <= q) {
			ans += time;
			cout << name << " " << ans << endl;
		} else {
			ans += q;
			time -= q;
			dq.eb(mp(name, time));
		}
	}
	return 0;
}

Measured memory_bytes: 6376
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong();
		long B = scan.nextLong();
		long re = gcd(A,B);

		System.out.println(lcm(A,B,re)) ;

		scan.close();

	}

	public static long gcd(long a,long b) {

		for(long i=a;i>0;i--) {
			if(a%i == 0 && b%i == 0) {
				return i;
			}
		}
		return 1;
	}

	public static long lcm(long a,long b, long gcd) {

		return a*b/gcd;
	}

}


Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, m, c[1010], k[1010], kk[1010][20];
int dp[(1 << 12)];
bool b[20];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> c[i] >> k[i];
		for(int j = 0; j < k[i]; j++){
			cin >> kk[i][j];
			kk[i][j]--;
			b[kk[i][j]] = 1;
		}
	}
	
	for(int i = 0; i < n; i++){
		if(!b[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i = 0; i < (1 << 12); i++){
		dp[i] = INF;
	}
	dp[0] = 0;
	
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < m; j++){
			int cnt = 0;
			for(int jj = 0; jj < k[j]; jj++){
				cnt += (1 << kk[j][jj]);
			}
			int cc = 0;
			for(int jj = 0; jj < n; jj++){
				cc += (1 << jj & i) | (1 << jj & cnt);
			}
			dp[cc] = min(dp[i] + c[j], dp[cc]);
		}
	}
	
	cout << dp[(1 << n)-1] << endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			for(int i=0; i<2; i++){
				int a=sc.nextInt();
				int b=sc.nextInt();
				if(a==0){
					break;
				}
				square(a,b);
				System.out.println();
			}
		}











	}
	public static void square(int a,int b){
		for(int i=1; i<=a; i++){
			for(int j=1; j<=b; j++){
				if(i==1 || i==a){
					System.out.print("#");
				}else if(j==1 || j==b){
					System.out.print("#");
				}else{
					System.out.print(".");
				}

			}
			System.out.println();
		}
	}



}


Measured memory_bytes: 32728